make source-map-root and prefix act on sourceMappingURL, fixes #47

This commit is contained in:
Francois Rejete 2012-11-14 00:02:41 +09:00
parent 60c0f40250
commit 5224540940

View File

@ -197,9 +197,7 @@ try {
files.forEach(function(file) { files.forEach(function(file) {
var code = read_whole_file(file); var code = read_whole_file(file);
if (ARGS.p != null) { file = drop_prefix(file, ARGS.p);
file = file.replace(/^\/+/, "").split(/\/+/).slice(ARGS.p).join("/");
}
time_it("parse", function(){ time_it("parse", function(){
if (ARGS.spidermonkey) { if (ARGS.spidermonkey) {
var program = JSON.parse(code); var program = JSON.parse(code);
@ -268,7 +266,7 @@ output = output.get();
if (SOURCE_MAP) { if (SOURCE_MAP) {
fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8"); fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8");
output += "\n//@ sourceMappingURL=" + ARGS.source_map; output += "\n//@ sourceMappingURL=" + ARGS.source_map_root + drop_prefix(ARGS.source_map, ARGS.p);
} }
if (OUTPUT_FILE) { if (OUTPUT_FILE) {
@ -347,6 +345,13 @@ function read_whole_file(filename) {
} }
} }
function drop_prefix(filename, prefix) {
if (prefix != null) {
filename = filename.replace(/^\/+/, "").split(/\/+/).slice(prefix).join("/");
}
return filename;
}
function time_it(name, cont) { function time_it(name, cont) {
var t1 = new Date().getTime(); var t1 = new Date().getTime();
var ret = cont(); var ret = cont();