Source map line numbers off by two with no plugins #926

Open
alexturpin opened this Issue Dec 2, 2016 · 5 comments

Projects

None yet

2 participants

@alexturpin

Hey all,

I've encountered a bit of an issue with sourcemaps. My workflow is that I first compile my SASS code down to CSS, and then use PostCSS on the resulting code / source maps.

My problem is that even with no plugins, after going through PostCSS, source map line numbers are off by 2 (they point to 2 lines before the actual line).

This is the input CSS and input source map generated from SASS:

p{color:red}a{color:green}

/*# sourceMappingURL=before.css.map */
{
	"version": 3,
	"file": "styles.css",
	"sources": [
		"styles.scss"
	],
	"sourcesContent": [
		"p {\n\tcolor: red;\n}\n\na {\n\tcolor: green;\n}\n"
	],
	"mappings": "AAAA,AAAA,CAAC,AAAC,CACD,KAAK,CAAE,GAAI,CACX,AAED,AAAA,CAAC,AAAC,CACD,KAAK,CAAE,KAAM,CACb",
	"names": []
}

As can be seen on source-map-visualization everything is still linked properly.

Now running them through PostCSS without plugins with this code:

var postcss = require('postcss');
var fs = require('fs');
var path = require('path');

var beforeStyles = fs.readFileSync('before.css', 'utf-8');
var beforeMap = fs.readFileSync('before.css.map', 'utf-8');

postcss([])
	.process(beforeStyles, { from: 'before.css', to: 'after.css', map: { inline: false, prev: beforeMap } })
	.then(function(result) {
		fs.writeFileSync('after.css', result.css);
		fs.writeFileSync('after.css.map', result.map);
	}, function(err) {
		console.log(err);
	});

Results in the following output:

p{color:red}a{color:green}
/*# sourceMappingURL=after.css.map */
{"version":3,"sources":["styles.scss"],"names":[],"mappings":"AAAA,EACC,SAAW,CACX,EAGA,WAAa,CACb","file":"after.css","sourcesContent":["p {\n\tcolor: red;\n}\n\na {\n\tcolor: green;\n}\n"]}

Which, we can observe on source-map-visualization, is broken. The a selector has no corresponding line number.

@ai
Member
ai commented Dec 2, 2016 edited

Thanks for investigation. Yeap, a selector mapping is broken.

Right now I am preparing for conference and will be free after Dec 11. Could it wait until this date? Maybe I will have time on next week.

@alexturpin

@ai Yep that's fine, just wanted to make sure that it was logged somewhere.

@alexturpin

Hello!

Just wondering if there have been any updates on this? :)

@ai
Member
ai commented Jan 4, 2017

Sorry, I am in other project. Because we had no other reports and problem is not critical this issue is low priority right now.

Do you want to try to fix it by your own? I will help you.

@alexturpin

No worries. It's not critical enough for me right now to focus time on fixing it, but if I ever come around to it I'll hit you up to ask for tips on where to look to fix it :)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment