From bbec2114ce55c9194f719a6a0f210ef92f25c250 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 24 Nov 2015 16:07:37 -0500 Subject: [PATCH 1/2] Fixes T2864 - Drops input mappings that cannot be mapped through Babel's sourcemap - For example, Babel's sourcemap does not have mappings for leading comments, so any mapping from an input sourcemap for those leading comments must be dropped from the merged sourcemap --- .../src/transformation/file/index.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 5b47df51ea..58282100e2 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -360,20 +360,23 @@ export default class File extends Store { }); inputMapConsumer.eachMapping(function (mapping) { - mergedGenerator.addMapping({ - source: mapping.source, - - original: { - line: mapping.originalLine, - column: mapping.originalColumn - }, - - generated: outputMapConsumer.generatedPositionFor({ - line: mapping.generatedLine, - column: mapping.generatedColumn, - source: outputMapConsumer.file - }) + const generatedPosition = outputMapConsumer.generatedPositionFor({ + line: mapping.generatedLine, + column: mapping.generatedColumn, + source: outputMapConsumer.file }); + if(generatedPosition.column != null) { + mergedGenerator.addMapping({ + source: mapping.source, + + original: { + line: mapping.originalLine, + column: mapping.originalColumn + }, + + generated: generatedPosition + }); + } }); let mergedMap = mergedGenerator.toJSON(); From 9c27f1e86a9c90312d7ae91249d8163b10b9067a Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 24 Nov 2015 16:10:10 -0500 Subject: [PATCH 2/2] Fixes the wrong source path being passed to SourceMapConsumer#generatedPositionFor `generatedPositionFor` accepts a position in one of the sourcemap's *input* source files. Therefore the `source` path should be one of the sourcemap's input `sources`, not the output `file`. --- packages/babel-core/src/transformation/file/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 58282100e2..51dd9a43d4 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -359,11 +359,15 @@ export default class File extends Store { sourceRoot: inputMapConsumer.sourceRoot }); + // This assumes the output map always has a single source, since Babel always compiles a single source file to a + // single output file. + const source = outputMapConsumer.sources[0]; + inputMapConsumer.eachMapping(function (mapping) { const generatedPosition = outputMapConsumer.generatedPositionFor({ line: mapping.generatedLine, column: mapping.generatedColumn, - source: outputMapConsumer.file + source: source }); if(generatedPosition.column != null) { mergedGenerator.addMapping({