Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 33 additions & 18 deletions packages/babel-cli/src/babel/file.js
Expand Up @@ -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;
}
});
Expand Down Expand Up @@ -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();
});
};
Expand All @@ -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);
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.