Merge pull request #4193 from DylanPiercey/master
Allow for external and inline sourcemap generation separately
This commit is contained in:
commit
65c35e05a1
|
@ -50,11 +50,9 @@ withPrettyErrors = (fn) ->
|
|||
exports.compile = compile = withPrettyErrors (code, options) ->
|
||||
{merge, extend} = helpers
|
||||
options = extend {}, options
|
||||
generateSourceMap = options.sourceMap or options.inlineMap
|
||||
|
||||
if options.inlineMap
|
||||
options.sourceMap ?= yes
|
||||
|
||||
if options.sourceMap
|
||||
if generateSourceMap
|
||||
map = new SourceMap
|
||||
|
||||
tokens = lexer.tokenize code, options
|
||||
|
@ -74,7 +72,7 @@ exports.compile = compile = withPrettyErrors (code, options) ->
|
|||
js = ""
|
||||
for fragment in fragments
|
||||
# Update the sourcemap with data from each fragment
|
||||
if options.sourceMap
|
||||
if generateSourceMap
|
||||
# Do not include empty, whitespace, or semicolon-only fragments.
|
||||
if fragment.locationData and not /^[;\s]*$/.test fragment.code
|
||||
map.add(
|
||||
|
@ -95,18 +93,19 @@ exports.compile = compile = withPrettyErrors (code, options) ->
|
|||
header = "Generated by CoffeeScript #{@VERSION}"
|
||||
js = "// #{header}\n#{js}"
|
||||
|
||||
if options.sourceMap
|
||||
if generateSourceMap
|
||||
v3SourceMap = map.generate(options, code)
|
||||
|
||||
if options.inlineMap
|
||||
sourceMapDataURI = "//# sourceMappingURL=data:application/json;base64,#{base64encode v3SourceMap}"
|
||||
sourceURL = "//# sourceURL=#{options.filename ? 'coffeescript'}"
|
||||
"#{js}\n#{sourceMapDataURI}\n#{sourceURL}"
|
||||
else
|
||||
answer = {js}
|
||||
answer.sourceMap = map
|
||||
answer.v3SourceMap = map.generate(options, code)
|
||||
answer
|
||||
if options.inlineMap
|
||||
sourceMapDataURI = "//# sourceMappingURL=data:application/json;base64,#{base64encode v3SourceMap}"
|
||||
sourceURL = "//# sourceURL=#{options.filename ? 'coffeescript'}"
|
||||
js = "#{js}\n#{sourceMapDataURI}\n#{sourceURL}"
|
||||
|
||||
if options.sourceMap
|
||||
answer = {js}
|
||||
answer.sourceMap = map
|
||||
answer.v3SourceMap = v3SourceMap
|
||||
answer
|
||||
else
|
||||
js
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ SWITCHES = [
|
|||
['-i', '--interactive', 'run an interactive CoffeeScript REPL']
|
||||
['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling']
|
||||
['-m', '--map', 'generate source map and save as .js.map files']
|
||||
['-M', '--inline-map', 'generate source map and include it directly in output']
|
||||
['-M', '--inline-map', 'generate source map and include it directly in output']
|
||||
['-n', '--nodes', 'print out the parse tree that the parser produces']
|
||||
[ '--nodejs [ARGS]', 'pass options directly to the "node" binary']
|
||||
[ '--no-header', 'suppress the "Generated by" header']
|
||||
|
|
Loading…
Reference in New Issue