Merge branch 'sourcemaps' of https://github.com/surjikal/coffee-script into sourcemaps

This commit is contained in:
Jason Walton 2013-03-01 08:47:42 -05:00
commit 0e718f0968
5 changed files with 10 additions and 5 deletions

View File

@ -391,6 +391,7 @@
sourceMapPath = outputPath(sourcePath, base, ".map");
jsDir = path.dirname(jsPath);
compile = function() {
var generatedSourceMap;
if (opts.compile) {
if (js.length <= 0) {
js = ' ';
@ -407,7 +408,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

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

View File

@ -274,7 +274,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]