Use the real sourcemap API and handle input sourcemaps - fixes T7259 (#3456)

This commit is contained in:
Logan Smyth 2016-09-20 10:39:01 -07:00 committed by Henry Zhu
parent 8f6d4ae5cf
commit 46eb99b18b
2 changed files with 34 additions and 19 deletions

View File

@ -24,31 +24,35 @@ module.exports = function (commander, filenames, opts) {
let offset = 0;
_.each(results, function (result) {
let filename = result.filename || "stdout";
code += result.code + "\n";
if (result.map) {
let consumer = new sourceMap.SourceMapConsumer(result.map);
let sourceFilename = filename;
if (commander.outFile) {
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
}
sourceFilename = slash(sourceFilename);
map._sources.add(sourceFilename);
map.setSourceContent(sourceFilename, result.actual);
let sources = new Set();
consumer.eachMapping(function (mapping) {
map._mappings.add({
generatedLine: mapping.generatedLine + offset,
generatedColumn: mapping.generatedColumn,
originalLine: mapping.source == null ? null : mapping.originalLine,
originalColumn: mapping.source == null ? null : mapping.originalColumn,
source: mapping.source == null ? null : sourceFilename
if (mapping.source != null) sources.add(mapping.source);
map.addMapping({
generated: {
line: mapping.generatedLine + offset,
column: mapping.generatedColumn,
},
source: mapping.source,
original: mapping.source == null ? null : {
line: mapping.originalLine,
column: mapping.originalColumn,
},
});
});
sources.forEach((source) => {
let content = consumer.sourceContentFor(source, true);
if (content !== null){
map.setSourceContent(source, content);
}
});
offset = code.split("\n").length;
}
});
@ -93,7 +97,9 @@ module.exports = function (commander, filenames, opts) {
});
process.stdin.on("end", function () {
results.push(util.transform(commander.filename, code));
results.push(util.transform(commander.filename, code, {
sourceFileName: "stdin",
}));
output();
});
};
@ -120,7 +126,16 @@ module.exports = function (commander, filenames, opts) {
_.each(_filenames, function (filename) {
if (util.shouldIgnore(filename)) return;
let data = util.compile(filename);
let sourceFilename = filename;
if (commander.outFile) {
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
}
sourceFilename = slash(sourceFilename);
let data = util.compile(filename, {
sourceFileName: sourceFilename,
});
if (data.ignored) return;
results.push(data);
});

View File

@ -4,4 +4,4 @@ var foo = function foo() {
return 4;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLFVBQVUsZTtTLEFBQU07QUFBQyIsImZpbGUiOiJzY3JpcHQyLmpzIiwic291cmNlc0NvbnRlbnQiOlsidmFyIGZvbyA9IGZ1bmN0aW9uICgpIHtcbiAgcmV0dXJuIDQ7XG59O1xuXG4vLyMgc291cmNlTWFwcGluZ1VSTD1kYXRhOmFwcGxpY2F0aW9uL2pzb247YmFzZTY0LGV5SjJaWEp6YVc5dUlqb3pMQ0p6YjNWeVkyVnpJanBiSW05eWFXZHBibUZzTG1weklsMHNJbTVoYldWeklqcGJYU3dpYldGd2NHbHVaM01pT2lKQlFVRkJMRlZCUVZVc1dUdFRRVUZOTEVNN1EwRkJReUlzSW5OdmRYSmpaWE5EYjI1MFpXNTBJanBiSW5aaGNpQm1iMjhnUFNBb0tTQTlQaUEwT3lKZGZRPT0iXX0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsVUFBVSxlO1MsQUFBTTtBQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXX0=