1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/sourcemap.coffee
Nicolas Porter 88e02322e5 Fixed key name in source map, added coffee file to map sources
These are the modifications I had to do in order to get source maps working
in 27.0.1425.2 (Official Build 185250) canary. I haven't tested other
browsers.

I first looked at the V3 spec and a few examples, and I saw that the
`source` key of the source map should be called `sources`.

After doing the `source` to `sources` change, the coffee source and for
some odd reason the javascript file would not show up in the browser
dev tools (it was being fetched but not evaluated).

To fix this, I had to add the coffee source to the `sources` list in the
source map file.
2013-03-01 05:58:26 -05:00

41 lines
1.4 KiB
CoffeeScript

sourcemap = require '../src/sourcemap'
vlqEncodedValues = [
[1, "C"],
[-1, "D"],
[2, "E"],
[-2, "F"],
[0, "A"],
[16, "gB"],
[948, "o7B"]
]
test "vlqEncodeValue tests", ->
for pair in vlqEncodedValues
eq (sourcemap.vlqEncodeValue pair[0]), pair[1]
test "vlqDecodeValue tests", ->
for pair in vlqEncodedValues
arrayEq (sourcemap.vlqDecodeValue pair[1]), [pair[0], pair[1].length]
test "vlqDecodeValue with offset", ->
for pair in vlqEncodedValues
# Try with an offset, and some cruft at the end.
arrayEq (sourcemap.vlqDecodeValue ("abc" + pair[1] + "efg"), 3), [pair[0], pair[1].length]
test "SourceMap tests", ->
map = new sourcemap.SourceMap()
map.addMapping [0, 0], [0, 0]
map.addMapping [1, 5], [2, 4]
map.addMapping [1, 6], [2, 7]
map.addMapping [1, 9], [2, 8]
map.addMapping [3, 0], [3, 4]
eq (sourcemap.generateV3SourceMap map, "source.coffee", "source.js"), '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.coffee"],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
eq (sourcemap.generateV3SourceMap map), '{"version":3,"file":null,"sourceRoot":"","sources":[],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
# Look up a generated column - should get back the original source position.
arrayEq map.getSourcePosition([2,8]), [1,9]
# Look up a point futher along on the same line - should get back the same source position.
arrayEq map.getSourcePosition([2,10]), [1,9]