-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcemap: Mapping of end of blocks is unexpected #4833
Comments
I assume this is the visualization you mean? I’m not sure the behavior you describe is incorrect. Just taking the last I can see the argument for why this is correct: that It seems like the bigger picture is that you want to get a proper abstract syntax tree out of the CoffeeScript compiler, and you’re using source maps as an approximation for that. I proposed some improvements along those lines in coffeescript6/discuss#92. See also #4556. |
In my understanding I simplified my case by leaving out, that my approach has to work for any js compiler. |
Source maps map characters to nodes of the syntax tree. Whitespace isn't mapped. |
First, thanks for the time you are investing 👍 Then I must say I disagree: Where did you get I hope I don't offend you by opposing. |
When I say that whitespace isn’t mapped, I just mean that at present, in CoffeeScript, it isn’t. But as far as I can tell, other tools that generate source maps (see above) don’t map whitespace either. Something to understand is that source maps are tracking grammar— Another thing to remember is that source maps are unidirectional: they go from the CoffeeScript to the JavaScript, not the other way around. The point of source maps is to be able to set breakpoints in a debugger. For that purpose, when I click on the CoffeeScript Rather than working from the source maps, I think what you should look into is working from the CoffeeScript nodes. Go to http://asaayers.github.io/clfiddle/ and click on AST, and click on any of the nodes in the tree. You’ll see |
All sort of error-generation need the js -> coffeescript path. And I didn't propose to map all the whitespaces, but only the one significant for the end of a block. |
Sorry, I have only skimmed through this thread. As far as I know, source maps are used for two things, mainly in browsers:
It can be debated what is the most "correct" mapping for every token, but all that matters (I think) is how well the browsers' devtools manage to do the above. I don't understand what your end goal is @paulpflug? What are you trying to do? (Sorry if I missed that among all the comments.) An example would be perfect. Input CSS code, and your desired output. What you need to do that. Why you encounter problems. Also remember that it is possible to map generated code to nothing (JS -> null) if that helps. |
I want to search generated js ast for function calls (normally multi-line)
and output those in the original used language.
But no information about the end of those calls is contained in the
coffeescript source map.
Use case is a test runner where the test content is printed along with the
error.
|
I’m sorry, I’m just not understanding what you’re asking for. Looking at https://sokra.github.io/source-map-visualization/, even for Babel all I see are mappings from the start of an item in one language to the start of the corresponding item in the other language. I don’t see any lengths or end positions. If you know where a function call ends on the JavaScript side, by finding If that doesn’t work, I think the next best thing is to use the CoffeeScript AST, as you can see in http://asaayers.github.io/clfiddle/ (click on the AST tab), as it does have start/end coordinates. You should be able to map the AST to the source maps, as the coordinates should match. Even if we wanted to change something in the CoffeeScript compiler to make this easier for you, it’s not clear to me what exactly that would be. I would need detailed examples of source maps now versus the different source maps you wished were generated, and an explanation of how the latter is different (and how it could be generated, at least manually). |
compiles to
Each column of the end of the expression statement in js
};
(line:4, column: 1 to 3}
is mapped to the start of the expression in cs (line:1, column:0
), expected would be end (line:2, column:15
).This makes it impossible to find expressions in js and translate back to coffee.
Boiled down, what I'm trying to do:
https://sokra.github.io/source-map-visualization/#coffee also shows this strange mapping
The text was updated successfully, but these errors were encountered: