Skip to content

Commit 378a04e

Browse files
committed
Fix jashkenas#3965, sourcemaps for bare programs.
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).)
1 parent 1e62781 commit 378a04e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/coffee-script.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ exports.compile = compile = withPrettyErrors (code, options) ->
6262
for fragment in fragments
6363
# Update the sourcemap with data from each fragment
6464
if options.sourceMap
65-
if fragment.locationData
65+
# Do not include empty, whitespace, or semicolon-only fragments.
66+
if fragment.locationData and not /^[;\s]*$/.test fragment.code
6667
map.add(
6768
[fragment.locationData.first_line, fragment.locationData.first_column]
6869
[currentLine, currentColumn]

0 commit comments

Comments
 (0)