Enables source map tracking only if sourceMap is not falsy.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 14 Nov 2014 21:56:20 +0000 (21:56 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 8 Dec 2014 09:39:15 +0000 (09:39 +0000)
lib/clean.js
lib/utils/input-source-map-tracker.js
test/source-map-test.js

index 29b111b..be1a4f8 100644 (file)
@@ -79,7 +79,8 @@ CleanCSS.prototype.minify = function(data, callback) {
 
 function runMinifier(callback, self) {
   return function (data) {
-    self.inputSourceMapTracker = new InputSourceMapTracker(self.options).track(data);
+    if (self.options.sourceMap)
+      self.inputSourceMapTracker = new InputSourceMapTracker(self.options).track(data);
 
     data = self.options.debug ?
       minifyWithDebug(self, data) :
index 15ebe08..faf52a4 100644 (file)
@@ -15,7 +15,6 @@ function InputSourceMapStore(options) {
 InputSourceMapStore.prototype.track = function (data) {
   if (typeof this.options.sourceMap == 'string') {
     this.maps[undefined] = new SourceMapConsumer(this.options.sourceMap);
-    this.options.sourceMap = true;
     return this;
   }
 
@@ -45,7 +44,6 @@ InputSourceMapStore.prototype.track = function (data) {
     } else if (nextAt == mapMatch.index) {
       var inputMapData = fs.readFileSync(path.join(this.options.root || '', mapMatch[1]), 'utf-8');
       this.maps[files[files.length - 1] || undefined] = new SourceMapConsumer(inputMapData);
-      this.options.sourceMap = true;
     }
 
     cursor += nextAt + 1;
index a9089ca..3c655e6 100644 (file)
@@ -229,7 +229,7 @@ vows.describe('source-map')
       }
     },
     'input map from source': {
-      'topic': new CleanCSS().minify('div > a {\n  color: red;\n}/*# sourceMappingURL=' + inputMapPath + ' */'),
+      'topic': new CleanCSS({ sourceMap: true }).minify('div > a {\n  color: red;\n}/*# sourceMappingURL=' + inputMapPath + ' */'),
       'should have 2 mappings': function (minified) {
         assert.equal(2, minified.sourceMap._mappings.length);
       },
@@ -257,7 +257,7 @@ vows.describe('source-map')
       }
     },
     'input map from source with root': {
-      'topic': new CleanCSS({ root: path.dirname(inputMapPath) }).minify('div > a {\n  color: red;\n}/*# sourceMappingURL=styles.css.map */'),
+      'topic': new CleanCSS({ sourceMap: true, root: path.dirname(inputMapPath) }).minify('div > a {\n  color: red;\n}/*# sourceMappingURL=styles.css.map */'),
       'should have 2 mappings': function (minified) {
         assert.equal(2, minified.sourceMap._mappings.length);
       },
@@ -285,7 +285,7 @@ vows.describe('source-map')
       }
     },
     'complex input map': {
-      'topic': new CleanCSS({ root: path.dirname(inputMapPath) }).minify('@import url(import.css);'),
+      'topic': new CleanCSS({ sourceMap: true, root: path.dirname(inputMapPath) }).minify('@import url(import.css);'),
       'should have 4 mappings': function (minified) {
         assert.equal(4, minified.sourceMap._mappings.length);
       },