Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/sections/nodejs_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ The `compile` method has the signature `compile(code, options)` where `code` is

* `options.sourceMap`, boolean: if true, a source map will be generated; and instead of returning a string, `compile` will return an object of the form `{js, v3SourceMap, sourceMap}`.
* `options.inlineMap`, boolean: if true, output the source map as a base64-encoded string in a comment at the bottom.
* `options.filename`, string: the filename to use for the source map.
* `options.filename`, string: the filename to use for the source map. It can include a path (relative or absolute).
* `options.bare`, boolean: if true, output without the [top-level function safety wrapper](#lexical-scope).
* `options.header`, boolean: if true, output the `Generated by CoffeeScript` header.
5 changes: 3 additions & 2 deletions lib/coffeescript/sourcemap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/sourcemap.litcoffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,18 @@ The starting column in the original source, relative to the previous column.

Produce the canonical JSON object format for a "v3" source map.

sources = if options.sourceFiles
options.sourceFiles
else if options.filename
[options.filename]
else
['<anonymous>']

v3 =
version: 3
file: options.generatedFile or ''
sourceRoot: options.sourceRoot or ''
sources: options.sourceFiles or ['']
sources: sources
names: []
mappings: buffer

Expand Down
46 changes: 28 additions & 18 deletions test/sourcemap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ return if global.testingBrowser
SourceMap = require '../src/sourcemap'

vlqEncodedValues = [
[1, "C"],
[-1, "D"],
[2, "E"],
[-2, "F"],
[0, "A"],
[16, "gB"],
[948, "o7B"]
[1, 'C'],
[-1, 'D'],
[2, 'E'],
[-2, 'F'],
[0, 'A'],
[16, 'gB'],
[948, 'o7B']
]

test "encodeVlq tests", ->
Expand All @@ -25,31 +25,41 @@ test "SourceMap tests", ->
map.add [3, 0], [3, 4]

testWithFilenames = map.generate {
sourceRoot: ""
sourceFiles: ["source.coffee"]
generatedFile: "source.js"
sourceRoot: ''
sourceFiles: ['source.coffee']
generatedFile: 'source.js'
}

deepEqual testWithFilenames, {
version: 3
file: "source.js"
sourceRoot: ""
sources: ["source.coffee"]
file: 'source.js'
sourceRoot: ''
sources: ['source.coffee']
names: []
mappings: "AAAA;;IACK,GAAC,CAAG;IAET"
mappings: 'AAAA;;IACK,GAAC,CAAG;IAET'
}

deepEqual map.generate(), {
version: 3
file: ""
sourceRoot: ""
sources: [""]
file: ''
sourceRoot: ''
sources: ['<anonymous>']
names: []
mappings: "AAAA;;IACK,GAAC,CAAG;IAET"
mappings: 'AAAA;;IACK,GAAC,CAAG;IAET'
}

# Look up a generated column - should get back the original source position.
arrayEq map.sourceLocation([2,8]), [1,9]

# Look up a point further along on the same line - should get back the same source position.
arrayEq map.sourceLocation([2,10]), [1,9]

test "#3075: v3 source map fields", ->
{ js, v3SourceMap, sourceMap } = CoffeeScript.compile 'console.log Date.now()',
filename: 'tempus_fugit.coffee'
sourceMap: yes
sourceRoot: './www_root/coffee/'

v3SourceMap = JSON.parse v3SourceMap
arrayEq v3SourceMap.sources, ['tempus_fugit.coffee']
eq v3SourceMap.sourceRoot, './www_root/coffee/'
2 changes: 1 addition & 1 deletion test/support/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.eq = (a, b, msg) ->
"Expected #{reset}#{a}#{red} to equal #{reset}#{b}#{red}"

exports.arrayEq = (a, b, msg) ->
ok arrayEgal(a,b), msg or
ok arrayEgal(a, b), msg or
"Expected #{reset}#{a}#{red} to deep equal #{reset}#{b}#{red}"

exports.eqJS = (input, expectedOutput, msg) ->
Expand Down