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
Coffeescript maps every generated newline and semicolon to the source position (0,0), which means that short bare programs (which are unindented) end up mapping the beginning of every generated line to (0,0). So function calls written at the top-level in browser-based coffeescript do not source map correctly.
This causes problems for me on pencilcode.net, when students are trying to debug short programs all the time.
Here is the simplest possible repro:
test.coffee:
alert()
alert()
Now compile bare and get source maps with:
coffee -b -m -o . test.coffee
That produces this simple test.js:
// Generated by CoffeeScript 1.9.2alert();alert();//# sourceMappingURL=test.js.map
And the resulting test.js.map contains this encoded mapping string:
The problem is on the second line (mappings for output line 3): whitespace and semicolons map from (0,0), which is bad, but what's worse is that the first column of output position (3, 0), which contains the "alert" call, is also mapped from (0, 0). It actually comes from (1, 0) in the source.
In a bigger program, all generated code in column 0 in a bare program will get mapped to line (0,0) in the source program. That's a side effect of the problem of mapping all whitespace to (0,0).
What we want is a source map that looks like this, with (1, 0) mapping to (3, 0):
Instead of mapping all generated spaces and semicolons and newlines
to the source position (0,0), we avoid generating sourcemap information
for generated space-or-semicolon-only fragments.
(In addition to shortening sourcemaps, this fixes a correctness issue
where an empty fragment at the beginning of each line maps from (0,0),
but in a bare program, that position at the begining of the line
should map from the actual source line. When this conflict occurred,
(0,0) would win, resulting in an incorrect sourcemap, where each
top-level function call mapped to (0,0).)
davidbau
added a commit
to davidbau/coffee-script
that referenced
this issue
May 1, 2015
Instead of mapping all generated spaces and semicolons and newlines
to the source position (0,0), we avoid generating sourcemap information
for generated space-or-semicolon-only fragments.
(In addition to shortening sourcemaps, this fixes a correctness issue
where an empty fragment at the beginning of each line maps from (0,0),
but in a bare program, that position at the begining of the line
should map from the actual source line. When this conflict occurred,
(0,0) would win, resulting in an incorrect sourcemap, where each
top-level function call mapped to (0,0).)
Coffeescript maps every generated newline and semicolon to the source position (0,0), which means that short bare programs (which are unindented) end up mapping the beginning of every generated line to (0,0). So function calls written at the top-level in browser-based coffeescript do not source map correctly.
This causes problems for me on pencilcode.net, when students are trying to debug short programs all the time.
Here is the simplest possible repro:
test.coffee:
Now compile bare and get source maps with:
That produces this simple test.js:
And the resulting test.js.map contains this encoded mapping string:
If you plug this into a source map decoder like http://murzwin.com/base64vlq.html, you see that maps our two-line program as follows:
The problem is on the second line (mappings for output line 3): whitespace and semicolons map from (0,0), which is bad, but what's worse is that the first column of output position (3, 0), which contains the "alert" call, is also mapped from (0, 0). It actually comes from (1, 0) in the source.
In a bigger program, all generated code in column 0 in a bare program will get mapped to line (0,0) in the source program. That's a side effect of the problem of mapping all whitespace to (0,0).
What we want is a source map that looks like this, with (1, 0) mapping to (3, 0):
In other words, for this program, we should have v3sourcemap like:
We should probably not output sourcemapping for generated spaces and semicolons.
A simple fix coming soon.
The text was updated successfully, but these errors were encountered: