From: Jakub Pawlowicz Date: Fri, 14 Nov 2014 21:56:20 +0000 (+0000) Subject: Enables source map tracking only if sourceMap is not falsy. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=211187d7ed2de8161a9fb64290ff4157b8eebff8;p=clean-css.git Enables source map tracking only if sourceMap is not falsy. --- diff --git a/lib/clean.js b/lib/clean.js index 29b111ba..be1a4f84 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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) : diff --git a/lib/utils/input-source-map-tracker.js b/lib/utils/input-source-map-tracker.js index 15ebe085..faf52a4f 100644 --- a/lib/utils/input-source-map-tracker.js +++ b/lib/utils/input-source-map-tracker.js @@ -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; diff --git a/test/source-map-test.js b/test/source-map-test.js index a9089caa..3c655e66 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -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); },