2013-03-04 14:19:08 -05:00
|
|
|
return if global.testingBrowser
|
|
|
|
|
2013-03-18 07:23:05 -04:00
|
|
|
SourceMap = require '../src/sourcemap'
|
2013-02-28 15:51:29 -05:00
|
|
|
|
|
|
|
vlqEncodedValues = [
|
2017-09-01 04:06:45 -04:00
|
|
|
[1, 'C'],
|
|
|
|
[-1, 'D'],
|
|
|
|
[2, 'E'],
|
|
|
|
[-2, 'F'],
|
|
|
|
[0, 'A'],
|
|
|
|
[16, 'gB'],
|
|
|
|
[948, 'o7B']
|
2013-02-28 15:51:29 -05:00
|
|
|
]
|
|
|
|
|
2013-03-18 07:23:05 -04:00
|
|
|
test "encodeVlq tests", ->
|
2013-02-28 15:51:29 -05:00
|
|
|
for pair in vlqEncodedValues
|
2013-03-18 07:23:05 -04:00
|
|
|
eq ((new SourceMap).encodeVlq pair[0]), pair[1]
|
2013-02-28 15:51:29 -05:00
|
|
|
|
|
|
|
test "SourceMap tests", ->
|
2013-03-18 07:23:05 -04:00
|
|
|
map = new SourceMap
|
|
|
|
map.add [0, 0], [0, 0]
|
|
|
|
map.add [1, 5], [2, 4]
|
|
|
|
map.add [1, 6], [2, 7]
|
|
|
|
map.add [1, 9], [2, 8]
|
|
|
|
map.add [3, 0], [3, 4]
|
|
|
|
|
|
|
|
testWithFilenames = map.generate {
|
2017-09-01 04:06:45 -04:00
|
|
|
sourceRoot: ''
|
|
|
|
sourceFiles: ['source.coffee']
|
|
|
|
generatedFile: 'source.js'
|
2016-06-02 03:04:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
deepEqual testWithFilenames, {
|
|
|
|
version: 3
|
2017-09-01 04:06:45 -04:00
|
|
|
file: 'source.js'
|
|
|
|
sourceRoot: ''
|
|
|
|
sources: ['source.coffee']
|
2016-06-02 03:04:58 -04:00
|
|
|
names: []
|
2017-09-01 04:06:45 -04:00
|
|
|
mappings: 'AAAA;;IACK,GAAC,CAAG;IAET'
|
2016-06-02 03:04:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
deepEqual map.generate(), {
|
|
|
|
version: 3
|
2017-09-01 04:06:45 -04:00
|
|
|
file: ''
|
|
|
|
sourceRoot: ''
|
|
|
|
sources: ['<anonymous>']
|
2016-06-02 03:04:58 -04:00
|
|
|
names: []
|
2017-09-01 04:06:45 -04:00
|
|
|
mappings: 'AAAA;;IACK,GAAC,CAAG;IAET'
|
2016-06-02 03:04:58 -04:00
|
|
|
}
|
2013-02-28 15:51:29 -05:00
|
|
|
|
|
|
|
# Look up a generated column - should get back the original source position.
|
2013-03-18 07:23:05 -04:00
|
|
|
arrayEq map.sourceLocation([2,8]), [1,9]
|
2013-02-28 15:51:29 -05:00
|
|
|
|
2014-08-26 21:34:45 -04:00
|
|
|
# Look up a point further along on the same line - should get back the same source position.
|
2013-03-18 07:23:05 -04:00
|
|
|
arrayEq map.sourceLocation([2,10]), [1,9]
|
2017-09-01 04:06:45 -04:00
|
|
|
|
|
|
|
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/'
|