@@ -49,9 +49,9 @@ withPrettyErrors = (fn) ->
49
49
# a stack trace. Assuming that most of the time, code isn’t throwing
50
50
# exceptions, it’s probably more efficient to compile twice only when we
51
51
# need a stack trace, rather than always generating a source map even when
52
- # it’s not likely to be used. Save in form of `filename`: `(source)`
52
+ # it’s not likely to be used. Save in form of `filename`: [ `(source)`]
53
53
sources = {}
54
- # Also save source maps if generated, in form of `filename `: `(source map)`.
54
+ # Also save source maps if generated, in form of `(source) `: [ `(source map)`] .
55
55
sourceMaps = {}
56
56
57
57
# Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.
@@ -75,7 +75,8 @@ exports.compile = compile = withPrettyErrors (code, options) ->
75
75
76
76
checkShebangLine filename, code
77
77
78
- sources[filename] = code
78
+ sources[filename] ?= []
79
+ sources[filename].push code
79
80
map = new SourceMap if generateSourceMap
80
81
81
82
tokens = lexer .tokenize code, options
@@ -124,8 +125,9 @@ exports.compile = compile = withPrettyErrors (code, options) ->
124
125
js = " // #{ header} \n #{ js} "
125
126
126
127
if generateSourceMap
127
- v3SourceMap = map .generate (options, code)
128
- sourceMaps[filename] = map
128
+ v3SourceMap = map .generate options, code
129
+ sourceMaps[filename] ?= []
130
+ sourceMaps[filename].push map
129
131
130
132
if options .inlineMap
131
133
encoded = base64encode JSON .stringify v3SourceMap
@@ -266,14 +268,14 @@ formatSourcePosition = (frame, getSourceMapping) ->
266
268
267
269
getSourceMap = (filename ) ->
268
270
if sourceMaps[filename]?
269
- sourceMaps[filename]
270
- # CoffeeScript compiled in a browser may get compiled with `options.filename`
271
- # of `<anonymous>`, but the browser may request the stack trace with the
272
- # filename of the script file.
271
+ sourceMaps[filename][sourceMaps[filename].length - 1 ]
273
272
else if sourceMaps[' <anonymous>' ]?
274
- sourceMaps[' <anonymous>' ]
273
+ # CoffeeScript compiled in a browser may get compiled with `options.filename`
274
+ # of `<anonymous>`, but the browser may request the stack trace with the
275
+ # filename of the script file.
276
+ sourceMaps[' <anonymous>' ][sourceMaps[' <anonymous>' ].length - 1 ]
275
277
else if sources[filename]?
276
- answer = compile sources[filename],
278
+ answer = compile sources[filename][sources[filename]. length - 1 ] ,
277
279
filename : filename
278
280
sourceMap : yes
279
281
literate : helpers .isLiterate filename
0 commit comments