gulp-sourcemaps / vinyl-sourcemaps-apply

Helper for implementing source map support in Gulp plugins
19 stars 8 forks source link

LESS files that only contain comments cause an error to be thrown #3

Closed allenrice closed 10 years ago

allenrice commented 10 years ago

I have a couple of LESS files in my project that only contain a comment:

/* TODO: Add styles for component: hello-world */

And this now causes the following error to be thrown

error : Source map to be applied is missing the "mappings" property at assertProperty (root\node_modules\gulp-less\node_modules\vinyl-sourcemaps-apply\index.js:32:13) at applySourceMap (root\node_modules\gulp-less\node_modules\vinyl-sourcemaps-apply\index.js:12:3) at root\node_modules\gulp-less\index.js:66:13 at root\node_modules\gulp-less\node_modules\less\lib\less\index.js:29:17 at Object.finish as _finish at Object.tree.importVisitor.run (root\node_modules\gulp-less\node_modules\less\lib\less\import-visitor.js:34:22) at Object.Parser.parser.parse (root\node_modules\gulp-less\node_modules\less\lib\less\parser.js:675:22) at Object.less.render (root\node_modules\gulp-less\node_modules\less\lib\less\index.js:22:20) at Transform._transform (root\node_modules\gulp-less\index.js:42:10) at Transform._read (root\node_modules\gulp-less\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:184:10)

If I remove the comments and make it an empty file, it works fine. However, if I also change the assertProperty method from:

function assertProperty(sourceMap, propertyName) {
  if (!sourceMap[propertyName]) {
    var e = new Error('Source map to be applied is missing the \"' + propertyName + '\" property');
    throw e;
  }
}

to:

function assertProperty(sourceMap, propertyName) {
  // protect against falsey values by using typeof, instead
  if (typeof sourceMap[propertyName] === 'undefined') {
    var e = new Error('Source map to be applied is missing the \"' + propertyName + '\" property');
    throw e;
  }
}

Then that also works fine. The problem is that the value, an empty string, is coming through as falsey. I believe that checking for an undefined property is what is actually intended here. My sincerest apologies for the lack of a pull request, I'm new to GitHub.