From 7670176d9a94b603068e0b0f3e4fb5fd6e20eb20 Mon Sep 17 00:00:00 2001 From: Roman Dvornov Date: Mon, 16 Jan 2017 18:07:26 +0300 Subject: [PATCH] fix source map generation --- lib/utils/translateWithSourceMap.js | 2 +- test/translateWithSourceMaps.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/utils/translateWithSourceMap.js b/lib/utils/translateWithSourceMap.js index 67d1966e..169bf228 100644 --- a/lib/utils/translateWithSourceMap.js +++ b/lib/utils/translateWithSourceMap.js @@ -97,7 +97,7 @@ function createSourceNode(info, children) { } return new SourceNode( - info.start ? info.line : null, + info.start ? info.start.line : null, info.start ? info.start.column - 1 : null, info.source, children diff --git a/test/translateWithSourceMaps.js b/test/translateWithSourceMaps.js index 4d1fd53d..4b57e8c3 100644 --- a/test/translateWithSourceMaps.js +++ b/test/translateWithSourceMaps.js @@ -25,4 +25,15 @@ describe('translateWithSourceMap', function() { }); }, /Unknown node type/); }); + + it.only('should generate a map', function() { + var ast = parse('.a {\n color: red;\n}\n', { + filename: 'test.css', + positions: true + }); + var result = translateWithSourceMap(ast); + + assert.equal(result.css, '.a{color:red}'); + assert.equal(result.map.toString(), '{"version":3,"sources":["test.css"],"names":[],"mappings":"AAAA,E,CACE,S"}'); + }); });