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.
This commit is contained in:
Nicolas Porter 2013-03-01 05:58:26 -05:00
parent 7073d18f23
commit 88e02322e5
5 changed files with 10 additions and 5 deletions

View File

@ -397,6 +397,7 @@
sourceMapPath = outputPath(sourcePath, base, ".map");
jsDir = path.dirname(jsPath);
compile = function() {
var generatedSourceMap;
if (opts.compile) {
if (js.length <= 0) {
js = ' ';
@ -413,7 +414,8 @@
});
}
if (sourceMap) {
return fs.writeFile(sourceMapPath, sourcemap.generateV3SourceMap(sourceMap), function(err) {
generatedSourceMap = sourcemap.generateV3SourceMap(sourceMap, base);
return fs.writeFile(sourceMapPath, generatedSourceMap, function(err) {
if (err) {
return printLine("Could not write source map: " + err.message);
}

View File

@ -144,7 +144,7 @@
version: 3,
file: generatedFile,
sourceRoot: "",
source: [sourceFile],
sources: sourceFile ? [sourceFile] : [],
names: [],
mappings: mappings
};

View File

@ -279,7 +279,8 @@ writeJs = (base, sourcePath, js, sourceMap = null) ->
else if opts.compile and opts.watch
timeLog "compiled #{sourcePath}"
if sourceMap
fs.writeFile sourceMapPath, (sourcemap.generateV3SourceMap sourceMap), (err) ->
generatedSourceMap = sourcemap.generateV3SourceMap sourceMap, base
fs.writeFile sourceMapPath, generatedSourceMap, (err) ->
if err
printLine "Could not write source map: #{err.message}"
exists jsDir, (itExists) ->

View File

@ -146,7 +146,7 @@ exports.generateV3SourceMap = (sourceMap, sourceFile=null, generatedFile=null) -
version: 3
file: generatedFile
sourceRoot: ""
source: [sourceFile]
sources: if sourceFile then [sourceFile] else []
names: []
mappings
}

View File

@ -30,7 +30,9 @@ test "SourceMap tests", ->
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":"","source":["source.coffee"],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
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]