Fixes building source maps for styles with and without an input map.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 1 Dec 2014 20:40:59 +0000 (20:40 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 8 Dec 2014 09:39:16 +0000 (09:39 +0000)
* Previously stringifier was raisining an issue about a missing input source map.

lib/selectors/source-map-stringifier.js
lib/utils/input-source-map-tracker.js
test/data/source-maps/no-map-import.css [new file with mode: 0644]
test/data/source-maps/no-map.css [new file with mode: 0644]
test/source-map-test.js

index 8ca43ba..1e54d1e 100644 (file)
@@ -96,7 +96,7 @@ Rebuilder.prototype.track = function (value, metadata) {
 };
 
 Rebuilder.prototype.trackMetadata = function (metadata) {
-  var original = this.inputMapTracker.isTracking() ?
+  var original = this.inputMapTracker.isTracking(metadata) ?
     this.inputMapTracker.originalPositionFor(metadata) :
     {};
 
index 9f962f2..f2c5025 100644 (file)
@@ -124,8 +124,8 @@ InputSourceMapStore.prototype.track = function (data, whenDone) {
     fromSource(this, data, whenDone, { files: [], cursor: 0, errors: this.errors });
 };
 
-InputSourceMapStore.prototype.isTracking = function () {
-  return Object.keys(this.maps).length > 0;
+InputSourceMapStore.prototype.isTracking = function (sourceInfo) {
+  return !!this.maps[sourceInfo.source];
 };
 
 InputSourceMapStore.prototype.originalPositionFor = function (sourceInfo) {
diff --git a/test/data/source-maps/no-map-import.css b/test/data/source-maps/no-map-import.css
new file mode 100644 (file)
index 0000000..18656de
--- /dev/null
@@ -0,0 +1,2 @@
+@import url(styles.css);
+@import url(no-map.css);
diff --git a/test/data/source-maps/no-map.css b/test/data/source-maps/no-map.css
new file mode 100644 (file)
index 0000000..25118c1
--- /dev/null
@@ -0,0 +1 @@
+div { color: red; }
index 3b874cc..4cb7005 100644 (file)
@@ -407,6 +407,24 @@ vows.describe('source-map')
       'should have 4 mappings': function (minified) {
         assert.equal(4, minified.sourceMap._mappings.length);
       }
+    },
+    'complex but partial input map referenced by path': {
+      'topic': new CleanCSS({ sourceMap: true }).minify('@import url(test/data/source-maps/no-map-import.css);'),
+      'should have 4 mappings': function (minified) {
+        assert.equal(4, minified.sourceMap._mappings.length);
+      },
+      'should have 2 mappings to .less file': function (minified) {
+        var fromLess = minified.sourceMap._mappings.filter(function (mapping) {
+          return mapping.source == 'styles.less';
+        });
+        assert.equal(2, fromLess.length);
+      },
+      'should have 2 mappings to .css file': function (minified) {
+        var fromCSS = minified.sourceMap._mappings.filter(function (mapping) {
+          return mapping.source.indexOf('no-map.css') > 0;
+        });
+        assert.equal(2, fromCSS.length);
+      }
     }
   })
   .addBatch({