You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Source map line numbers off by two with no plugins #926
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:
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 :)
PostCSS source maps are good. Sass source maps are good. Problem comes from mozilla’s source-map, when it try to merge source maps.
Since Sass compatibility is not goal for PostCSS, I will close this issue (anyway I don’t know solution right now).
Possible solutions:
Short-term: use postcss-based preprocessors like PreCSS or cssnext. In this case you will get 100% compatibility with other postcss-based tools like Autoprefixer or Stylelint.
I want to file a bug to source-map package regarding the issue. Or at least try to figure out why the mappings change. So I'd like to have a test case with source-map package alone.
Well, my case might be a little off compared to this issue, but certainly related.
Ruby sass sourcemaps are lacking a lot according to previous discussions with am11. I decided to do better than that and therefore libsass has much more detailed source-maps than ruby sass does (not sure if this is still true, since those discussion are over a year old).
Also, I'm curious what makes source-map package change source maps when no code changes.
P.S. I'm going to check if OP's issue still holds.
I now see. Regarding OP's test case. IMO nothing is broken in the "after" source map (as well as in the "before" one). source-map-vizualization doesn't have the last word in it. It's just another consumer. Which happens to be a visualization tool, and not the bestone if you ask me. The whole issue with source maps comes from—correct me if I'm wrong—non-strict spec. source-map package doesn't do anything wrong, it just follows another interpretation of the spec. Not that I'm trying to put the blame on the spec, it probably has its reasons.
Then, these days the issue can't be reproduced (line numbers off by two). Or line numbers are simply off by one consistently across the whole stylesheet. At least in Chromium 63.0.3239.132. From what I can see, Chromium takes the first mappingafter the opening curly bracket.
Regarding my test case, I was wondering why so much less mappings was left after postcss. So, postcss parses the css code, which results in AST with line/column numbers. No processing is done. Then source map is generated based on the AST. After which original source map is applied.
Now then, what does "apply" here mean again? We have source code (A), source code A after processing with sass (B), and source code B after processing with postcss (C, nothing has changed). And we have two source maps: B -> A, C -> B. When applying, source-map package takes a mapping from C -> B source map, its original position (B) and maps it using B -> A source map to original original position (A). That gives us as many mappings as was generated by postcss, but there could be less (when adjacent mappings point to the same position).
Activity
ai commentedon Dec 2, 2016
Thanks for investigation. Yeap,
aselector 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 commentedon Dec 4, 2016
@ai Yep that's fine, just wanted to make sure that it was logged somewhere.
alexturpin commentedon Jan 4, 2017
Hello!
Just wondering if there have been any updates on this? :)
ai commentedon 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 commentedon Jan 5, 2017
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
GaryJones commentedon Feb 8, 2017
FWIW, I can see evidence of this too.
ai commentedon Feb 8, 2017
Be prepare that this issue will not be fixed for few months:
ai commentedon Feb 8, 2017
I am always open for PR ;)
alexturpin commentedon Feb 8, 2017
@ai What do you mean by pure PostCSS stack? Weback plugin?
ai commentedon Feb 8, 2017
I mean do all CSS work inside PostCSS: linting, preprocessing, prefixes, postprocessing
alexturpin commentedon Feb 8, 2017
Ah so it's a result of incompatibility between other sourcemaps and PostCSS' sourcemaps then?
ai commentedon Feb 8, 2017
Yeap this issue happen when you have previous source map
ai commentedon Feb 8, 2017
Of course, it is a error and I will fix it. PostCSS should update others source map.
alexturpin commentedon Feb 8, 2017
No worries! Just trying to understand better :)
subicura commentedon Mar 15, 2017
+1
ai commentedon Mar 16, 2017
@subicura I will look into it again after React London (March 28)
subicura commentedon Mar 16, 2017
@ai Thanks!!
ai commentedon Apr 14, 2017
I tried few changes but had no success.
PostCSS source maps are good. Sass source maps are good. Problem comes from mozilla’s
source-map, when it try to merge source maps.Since Sass compatibility is not goal for PostCSS, I will close this issue (anyway I don’t know solution right now).
Possible solutions:
x-yuri commentedon Jan 26, 2018
@ai Could you please help me reproduce the issue without
postcss?1.scss:node-sassproduces the following mappings:But after
postcssI get:I want to file a bug to
source-mappackage regarding the issue. Or at least try to figure out why the mappings change. So I'd like to have a test case withsource-mappackage alone.Well, my case might be a little off compared to this issue, but certainly related.
ai commentedon Jan 26, 2018
What is a problem with this mapping? PostCSS generates less nodes, so result mapping is smaller
x-yuri commentedon Jan 26, 2018
Let the author speak for himself:
Also, I'm curious what makes
source-mappackage change source maps when no code changes.P.S. I'm going to check if OP's issue still holds.
x-yuri commentedon Jan 26, 2018
...By the way, it might be the root cause of this issue.
x-yuri commentedon Jan 31, 2018
I now see. Regarding OP's test case. IMO nothing is broken in the "after" source map (as well as in the "before" one).
source-map-vizualizationdoesn't have the last word in it. It's just another consumer. Which happens to be a visualization tool, and not the best one if you ask me. The whole issue with source maps comes from—correct me if I'm wrong—non-strict spec.source-mappackage doesn't do anything wrong, it just follows another interpretation of the spec. Not that I'm trying to put the blame on the spec, it probably has its reasons.Then, these days the issue can't be reproduced (line numbers off by two). Or line numbers are simply off by one consistently across the whole stylesheet. At least in Chromium 63.0.3239.132. From what I can see, Chromium takes the first mapping after the opening curly bracket.
Regarding my test case, I was wondering why so much less mappings was left after
postcss. So,postcssparses the css code, which results in AST with line/column numbers. No processing is done. Then source map is generated based on the AST. After which original source map is applied.Now then, what does "apply" here mean again? We have source code (
A), source codeAafter processing withsass(B), and source codeBafter processing withpostcss(C, nothing has changed). And we have two source maps:B -> A,C -> B. When applying,source-mappackage takes a mapping fromC -> Bsource map, its original position (B) and maps it usingB -> Asource map to original original position (A). That gives us as many mappings as was generated bypostcss, but there could be less (when adjacent mappings point to the same position).