diff --git a/packages/babel-cli/src/babel/file.js b/packages/babel-cli/src/babel/file.js index 9bf50f6759..9dd8789c1b 100644 --- a/packages/babel-cli/src/babel/file.js +++ b/packages/babel-cli/src/babel/file.js @@ -43,9 +43,9 @@ module.exports = function (commander, filenames, opts) { map._mappings.add({ generatedLine: mapping.generatedLine + offset, generatedColumn: mapping.generatedColumn, - originalLine: mapping.originalLine, - originalColumn: mapping.originalColumn, - source: sourceFilename + originalLine: mapping.source == null ? null : mapping.originalLine, + originalColumn: mapping.source == null ? null : mapping.originalColumn, + source: mapping.source == null ? null : sourceFilename }); }); diff --git a/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/.babelrc b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/.babelrc new file mode 100644 index 0000000000..b80b3c8331 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/.babelrc @@ -0,0 +1,3 @@ +{ + "inlineSourceMap": true +} diff --git a/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/script.js b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/script.js new file mode 100644 index 0000000000..2c7d540acb --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/in-files/script.js @@ -0,0 +1,5 @@ +var foo = function () { + return 4; +}; + +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFVBQVUsWTtTQUFNLEM7Q0FBQyIsInNvdXJjZXNDb250ZW50IjpbInZhciBmb28gPSAoKSA9PiA0OyJdfQ== diff --git a/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/options.json b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/options.json new file mode 100644 index 0000000000..d62fc24401 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/options.json @@ -0,0 +1,3 @@ +{ + "args": ["script.js", "--source-maps", "inline", "--out-file", "script2.js"] +} diff --git a/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/out-files/script2.js b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/out-files/script2.js new file mode 100644 index 0000000000..15cc7b65d8 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/filename-sourcemap --out-file --source-maps inline/out-files/script2.js @@ -0,0 +1,7 @@ +"use strict"; + +var foo = function foo() { + return 4; +}; + +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBO1MsQUFBZ0IsQUFBQyxFO0NBQVAiLCJmaWxlIjoic2NyaXB0Mi5qcyIsInNvdXJjZXNDb250ZW50IjpbInZhciBmb28gPSBmdW5jdGlvbiAoKSB7XG4gIHJldHVybiA0O1xufTtcblxuLy8jIHNvdXJjZU1hcHBpbmdVUkw9ZGF0YTphcHBsaWNhdGlvbi9qc29uO2Jhc2U2NCxleUoyWlhKemFXOXVJam96TENKemIzVnlZMlZ6SWpwYkltOXlhV2RwYm1Gc0xtcHpJbDBzSW01aGJXVnpJanBiWFN3aWJXRndjR2x1WjNNaU9pSkJRVUZCTEZWQlFWVXNXVHRUUVVGTkxFTTdRMEZCUXlJc0luTnZkWEpqWlhORGIyNTBaVzUwSWpwYkluWmhjaUJtYjI4Z1BTQW9LU0E5UGlBME95SmRmUT09Il19 diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 74098e6446..ab1f1e650e 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -391,7 +391,7 @@ export default class File extends Store { mergedGenerator.addMapping({ source: mapping.source, - original: { + original: mapping.source == null ? null : { line: mapping.originalLine, column: mapping.originalColumn }, diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/actual.js b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/actual.js new file mode 100644 index 0000000000..2c7d540acb --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/actual.js @@ -0,0 +1,5 @@ +var foo = function () { + return 4; +}; + +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFVBQVUsWTtTQUFNLEM7Q0FBQyIsInNvdXJjZXNDb250ZW50IjpbInZhciBmb28gPSAoKSA9PiA0OyJdfQ== diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/expected.js b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/expected.js new file mode 100644 index 0000000000..cf3efeceb3 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/expected.js @@ -0,0 +1,3 @@ +var foo = function () { + return 4; +}; diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/options.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/options.json new file mode 100644 index 0000000000..0e6084f210 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/options.json @@ -0,0 +1,3 @@ +{ + "inputSourceMap": true +} diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json new file mode 100644 index 0000000000..ba7a5c1760 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map/source-map.json @@ -0,0 +1,11 @@ +{ + "version": 3, + "mappings": "AAAA;SAAgB,A,AAAC,E;CAAP", + "names": [], + "sources": [ + "original.js" + ], + "sourcesContent": [ + "var foo = () => 4;" + ] +}