From 9b79fbcdf5fe474638457c5ca1874ba17ad8c401 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 17 Dec 2015 23:39:33 -0600 Subject: [PATCH 1/4] Avoid emitting duplicate source map entries --- .../out-files/lib/foo.js | 2 +- .../out-files/lib/foo.js.map | 2 +- .../out-files/script2.js | 2 +- .../out-files/script3.js | 2 +- .../out-files/script3.js.map | 2 +- .../source-maps/full/source-map.json | 2 +- .../source-maps/inline/expected.js | 2 +- packages/babel-generator/src/source-map.js | 20 +++++++++++++++++-- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js index 3537587fad..b85deb8a28 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js @@ -3,4 +3,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxHQUFHLENBQUMsR0FBRyxDQUFDLFVBQUEsQ0FBQztTQUFJLENBQUMsR0FBRyxVQUFVO0NBQUEsQ0FBQyxDQUFDIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxHQUFHLENBQUMsR0FBRyxDQUFDLFdBQUM7U0FBSSxDQUFDLEdBQUcsVUFBVTtFQUFDLENBQUMiLCJmaWxlIjoiZm9vLmpzIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map index 77300ca29a..8a97ef8479 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/foo.js"],"names":[],"mappings":";;AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,UAAU;CAAA,CAAC,CAAC","file":"foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]} +{"version":3,"sources":["../src/foo.js"],"names":[],"mappings":";;AAAA,GAAG,CAAC,GAAG,CAAC,WAAC;SAAI,CAAC,GAAG,UAAU;EAAC,CAAC","file":"foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]} diff --git a/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js b/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js index 31da0b4f1a..a7d0097e5f 100644 --- a/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js +++ b/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js @@ -4,4 +4,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLEdBQUcsQ0FBQyxHQUFHLENBQUMsVUFBQSxDQUFDO1NBQUksQ0FBQyxHQUFHLFVBQVU7Q0FBQSxDQUFDLENBQUMiLCJmaWxlIjoic2NyaXB0Mi5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLEdBQUcsQ0FBQyxHQUFHLENBQUMsV0FBQztTQUFJLENBQUMsR0FBRyxVQUFVO0VBQUMsQ0FBQyIsImZpbGUiOiJzY3JpcHQyLmpzIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js index a32030e61a..6f597b3783 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js +++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js @@ -11,4 +11,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLElBQUksWUFBSixJQUFJO3dCQUFKLElBQUk7Ozs7O0FDQVYsR0FBRyxDQUFDLEdBQUcsQ0FBQyxVQUFBLENBQUM7U0FBSSxDQUFDLEdBQUcsVUFBVTtDQUFBLENBQUMsQ0FBQyIsImZpbGUiOiJzY3JpcHQzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgVGVzdCB7XG5cbn0iLCJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ== +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLElBQUksWUFBSixJQUFJO3dCQUFKLElBQUk7Ozs7O0FDQVYsR0FBRyxDQUFDLEdBQUcsQ0FBQyxXQUFDO1NBQUksQ0FBQyxHQUFHLFVBQVU7RUFBQyxDQUFDIiwiZmlsZSI6InNjcmlwdDMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSIsImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map index 941e54cb54..d408aa06b1 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map +++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map @@ -1 +1 @@ -{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI;;;;;ACAV,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,UAAU;CAAA,CAAC,CAAC","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} +{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI;;;;;ACAV,GAAG,CAAC,GAAG,CAAC,WAAC;SAAI,CAAC,GAAG,UAAU;EAAC,CAAC","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json index b2b351d8bb..0495ac768b 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json @@ -3,6 +3,6 @@ "file": "source-maps/full/expected.js", "sources": ["source-maps/full/actual.js"], "names": [], - "mappings": "AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC", + "mappings": "AAAA,GAAG,CAAC,GAAG,CAAC,WAAC;SAAI,CAAC,GAAG,CAAC;EAAC,CAAC", "sourcesContent": ["arr.map(x => x * x);"] } diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js index f93d2fbb34..847e47e539 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js @@ -1,4 +1,4 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsR0FBRyxDQUFDLEdBQUcsQ0FBQyxVQUFBLENBQUM7U0FBSSxDQUFDLEdBQUcsQ0FBQztDQUFBLENBQUMsQ0FBQyIsImZpbGUiOiJzb3VyY2UtbWFwcy9pbmxpbmUvZXhwZWN0ZWQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIHgpOyJdfQ== +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsR0FBRyxDQUFDLEdBQUcsQ0FBQyxXQUFDO1NBQUksQ0FBQyxHQUFHLENBQUM7RUFBQyxDQUFDIiwiZmlsZSI6InNvdXJjZS1tYXBzL2lubGluZS9leHBlY3RlZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 diff --git a/packages/babel-generator/src/source-map.js b/packages/babel-generator/src/source-map.js index f1b3ee3727..0734edef85 100644 --- a/packages/babel-generator/src/source-map.js +++ b/packages/babel-generator/src/source-map.js @@ -9,6 +9,7 @@ export default class SourceMap { constructor(position, opts, code) { this.position = position; this.opts = opts; + this.last = {generated: {}, original: {}}; if (opts.sourceMaps) { this.map = new sourceMap.SourceMapGenerator({ @@ -57,10 +58,25 @@ export default class SourceMap { let original = loc[type]; - map.addMapping({ + // Avoid emitting duplicates on either side. Duplicated + // original values creates unnecesssarily large source maps + // and increases compile time. Duplicates on the generated + // side can lead to incorrect mappings. + if (comparePosition(original, this.last.original) + || comparePosition(generated, this.last.generated)) { + return; + } + + this.last = { source: this.opts.sourceFileName, generated: generated, original: original - }); + }; + + map.addMapping(this.last); } } + +function comparePosition(a, b) { + return a.line === b.line && a.column === b.column; +} From 94e7e4da8e8219468f308f99f34fdd491a304833 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Fri, 18 Dec 2015 00:16:20 -0600 Subject: [PATCH 2/4] Update source map handling to be reentrant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than repeating the original location when we exit a node, we need to restore the previous parent’s original line location, since the source map format denotes the start location. --- .../out-files/lib/bar/bar.js | 2 +- .../dir --out-dir --source-maps inline/out-files/lib/foo.js | 2 +- .../dir --out-dir --source-maps/out-files/lib/bar/bar.js.map | 2 +- .../dir --out-dir --source-maps/out-files/lib/foo.js.map | 2 +- .../out-files/script2.js | 2 +- .../out-files/script3.js | 2 +- .../out-files/script3.js.map | 2 +- .../source-maps/arrow-function/source-mappings.json | 2 +- .../fixtures/transformation/source-maps/full/source-map.json | 2 +- .../fixtures/transformation/source-maps/inline/expected.js | 2 +- packages/babel-generator/src/printer.js | 4 ++-- packages/babel-generator/src/source-map.js | 4 ++-- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js index 7c44c97342..2101b6c9d7 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js @@ -5,4 +5,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var Test = function Test() { _classCallCheck(this, Test); }; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7SUFBTSxJQUFJLFlBQUosSUFBSTt3QkFBSixJQUFJIiwiZmlsZSI6ImJhci5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7SUFBTSIsImZpbGUiOiJiYXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSJdfQ== diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js index b85deb8a28..d9c86c7221 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js @@ -3,4 +3,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxHQUFHLENBQUMsR0FBRyxDQUFDLFdBQUM7U0FBSSxDQUFDLEdBQUcsVUFBVTtFQUFDLENBQUMiLCJmaWxlIjoiZm9vLmpzIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxJQUFJLEdBQUosQ0FBUTtTQUFLLElBQUksVUFBSjtDQUFMLENBQVIiLCJmaWxlIjoiZm9vLmpzIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map index d2f66bb31f..e44ef77215 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/bar/bar.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI","file":"bar.js","sourcesContent":["class Test {\n\n}"]} +{"version":3,"sources":["../../src/bar/bar.js"],"names":[],"mappings":";;;;IAAM","file":"bar.js","sourcesContent":["class Test {\n\n}"]} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map index 8a97ef8479..96682885b2 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/foo.js"],"names":[],"mappings":";;AAAA,GAAG,CAAC,GAAG,CAAC,WAAC;SAAI,CAAC,GAAG,UAAU;EAAC,CAAC","file":"foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]} +{"version":3,"sources":["../src/foo.js"],"names":[],"mappings":";;AAAA,IAAI,GAAJ,CAAQ;SAAK,IAAI,UAAJ;CAAL,CAAR","file":"foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js b/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js index a7d0097e5f..7e591ab7bb 100644 --- a/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js +++ b/packages/babel-cli/test/fixtures/babel/filename --out-file --source-maps inline/out-files/script2.js @@ -4,4 +4,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLEdBQUcsQ0FBQyxHQUFHLENBQUMsV0FBQztTQUFJLENBQUMsR0FBRyxVQUFVO0VBQUMsQ0FBQyIsImZpbGUiOiJzY3JpcHQyLmpzIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLElBQUksR0FBSixDQUFRO1NBQUssSUFBSSxVQUFKO0NBQUwsQ0FBUiIsImZpbGUiOiJzY3JpcHQyLmpzIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js index 6f597b3783..c1fc202b90 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js +++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js @@ -11,4 +11,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLElBQUksWUFBSixJQUFJO3dCQUFKLElBQUk7Ozs7O0FDQVYsR0FBRyxDQUFDLEdBQUcsQ0FBQyxXQUFDO1NBQUksQ0FBQyxHQUFHLFVBQVU7RUFBQyxDQUFDIiwiZmlsZSI6InNjcmlwdDMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSIsImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNOzs7Ozs7QUNBTixJQUFJLEdBQUosQ0FBUTtTQUFLLElBQUksVUFBSjtDQUFMLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map index d408aa06b1..4443440920 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map +++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map @@ -1 +1 @@ -{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI;;;;;ACAV,GAAG,CAAC,GAAG,CAAC,WAAC;SAAI,CAAC,GAAG,UAAU;EAAC,CAAC","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} +{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM;;;;;;ACAN,IAAI,GAAJ,CAAQ;SAAK,IAAI,UAAJ;CAAL,CAAR","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json index a1d1d31e4a..47d5aab7a2 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json @@ -1,7 +1,7 @@ [{ "original": { "line": 1, - "column": 14 + "column": 13 }, "generated": { "line": 2, diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json index 0495ac768b..35d93706a8 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json @@ -3,6 +3,6 @@ "file": "source-maps/full/expected.js", "sources": ["source-maps/full/actual.js"], "names": [], - "mappings": "AAAA,GAAG,CAAC,GAAG,CAAC,WAAC;SAAI,CAAC,GAAG,CAAC;EAAC,CAAC", + "mappings": "AAAA,IAAI,GAAJ,CAAQ;SAAK,IAAI,CAAJ;CAAL,CAAR", "sourcesContent": ["arr.map(x => x * x);"] } diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js index 847e47e539..6e490e6707 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js @@ -1,4 +1,4 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsR0FBRyxDQUFDLEdBQUcsQ0FBQyxXQUFDO1NBQUksQ0FBQyxHQUFHLENBQUM7RUFBQyxDQUFDIiwiZmlsZSI6InNvdXJjZS1tYXBzL2lubGluZS9leHBlY3RlZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSSxHQUFKLENBQVE7U0FBSyxJQUFJLENBQUo7Q0FBTCxDQUFSIiwiZmlsZSI6InNvdXJjZS1tYXBzL2lubGluZS9leHBlY3RlZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index 79102ade5c..9ba7865893 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -46,7 +46,7 @@ export default class Printer extends Buffer { if (opts.before) opts.before(); - this.map.mark(node, "start"); + this.map.mark(node); this._print(node, parent); @@ -58,7 +58,7 @@ export default class Printer extends Buffer { if (needsParens) this.push(")"); // end - this.map.mark(node, "end"); + if (parent) this.map.mark(parent); if (opts.after) opts.after(); this.format.concise = oldConcise; diff --git a/packages/babel-generator/src/source-map.js b/packages/babel-generator/src/source-map.js index 0734edef85..942f931b9f 100644 --- a/packages/babel-generator/src/source-map.js +++ b/packages/babel-generator/src/source-map.js @@ -40,7 +40,7 @@ export default class SourceMap { * Mark a node's generated position, and add it to the sourcemap. */ - mark(node, type) { + mark(node) { let loc = node.loc; if (!loc) return; // no location info @@ -56,7 +56,7 @@ export default class SourceMap { column: position.column }; - let original = loc[type]; + let original = loc.start; // Avoid emitting duplicates on either side. Duplicated // original values creates unnecesssarily large source maps From 3791491b795df689926ede59eb45d6813cc7209c Mon Sep 17 00:00:00 2001 From: kpdecker Date: Fri, 18 Dec 2015 01:13:28 -0600 Subject: [PATCH 3/4] Strip location information from import remaps Fixes https://phabricator.babeljs.io/T6851 --- .../src/index.js | 2 +- .../auxiliary-comment/overview/expected.js | 4 +- .../test/fixtures/strict/import/actual.js | 1 + .../test/fixtures/strict/import/expected.js | 3 +- .../strict/import/source-mappings.json | 43 +++++++++++++++++++ packages/babel-types/src/index.js | 10 +++++ 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/source-mappings.json diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index ed744a5815..73e165e732 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -330,7 +330,7 @@ export default function () { ])); } } - remaps[specifier.local.name] = t.memberExpression(target, specifier.imported); + remaps[specifier.local.name] = t.memberExpression(target, t.cloneWithoutLoc(specifier.imported)); } } } else { diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js index c7b4852b07..49880b4ef2 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js @@ -26,8 +26,8 @@ var _foo5 = require("foo5"); exports. /*after*/test = test; var test = /*before*/exports. /*after*/test = 5; -/*before*/(0, _foo4. /*after*/bar)( /*before*/_foo2.default) /*after*/; +/*before*/(0, _foo4.bar)(_foo2.default) /*after*/; /* my comment */ -/*before*/_foo5. /*after*/foo; +/*before*/_foo5.foo; /*after*/ /*before*/_foo2.default; /*after*/ diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/actual.js index ffb7f73072..5b84f44e66 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/actual.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/actual.js @@ -6,3 +6,4 @@ import * as foo4 from "foo"; foo; foo2; foo3; +foo3(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/expected.js index e042c60eb4..260f28745b 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/expected.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/expected.js @@ -4,4 +4,5 @@ var _foo = require("foo"); _foo.default; _foo.default; -_foo.foo3; \ No newline at end of file +_foo.foo3; +(0, _foo.foo3)(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/source-mappings.json b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/source-mappings.json new file mode 100644 index 0000000000..0db931042d --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import/source-mappings.json @@ -0,0 +1,43 @@ +[{ + "original": { + "line": 6, "column": 0 + }, + "generated": { + "line": 5, "column": 0 + } +},{ + "original": { + "line": 6, "column": 0 + }, + "generated": { + "line": 5, "column": 12 + } +},{ + "original": { + "line": 8, "column": 0 + }, + "generated": { + "line": 7, "column": 0 + } +},{ + "original": { + "line": 8, "column": 0 + }, + "generated": { + "line": 7, "column": 9 + } +},{ + "original": { + "line": 9, "column": 0 + }, + "generated": { + "line": 8, "column": 0 + } +},{ + "original": { + "line": 9, "column": 0 + }, + "generated": { + "line": 8, "column": 9 + } +}] diff --git a/packages/babel-types/src/index.js b/packages/babel-types/src/index.js index 50abbb4ecf..3046db78db 100644 --- a/packages/babel-types/src/index.js +++ b/packages/babel-types/src/index.js @@ -239,6 +239,16 @@ export function clone(node: Object): Object { return newNode; } +/** + * Create a shallow clone of a `node` excluding `_private` and location properties. + */ + +export function cloneWithoutLoc(node: Object): Object { + let newNode = clone(node); + delete newNode.loc; + return newNode; +} + /** * Create a deep clone of a `node` and all of it's child nodes * exluding `_private` properties. From 9e382b16861a4b87bc48f6233ef6fc969665d62c Mon Sep 17 00:00:00 2001 From: kpdecker Date: Fri, 18 Dec 2015 01:37:26 -0600 Subject: [PATCH 4/4] Fix aux comment termination in lists and calls --- packages/babel-generator/src/generators/expressions.js | 1 + packages/babel-generator/src/printer.js | 4 ++++ .../test/fixtures/auxiliary-comment/overview/actual.js | 2 +- .../test/fixtures/auxiliary-comment/overview/expected.js | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/babel-generator/src/generators/expressions.js b/packages/babel-generator/src/generators/expressions.js index db021892af..832f818a22 100644 --- a/packages/babel-generator/src/generators/expressions.js +++ b/packages/babel-generator/src/generators/expressions.js @@ -92,6 +92,7 @@ export function Decorator(node: Object) { export function CallExpression(node: Object) { this.print(node.callee, node); + if (node.loc) this.printAuxAfterComment(); this.push("("); diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index 9ba7865893..4158f132bd 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -130,6 +130,10 @@ export default class Printer extends Buffer { opts.iterator(node, i); } + if (opts.separator && parent.loc) { + this.printAuxAfterComment(); + } + if (opts.separator && i < len - 1) { this.push(opts.separator); } diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/actual.js index df37d9e5a5..cdcfa374df 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/actual.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/actual.js @@ -9,7 +9,7 @@ import {foo as bar2} from "foo5"; export {test}; export var test = 5; -bar(foo); +bar(foo, bar2); /* my comment */ bar2; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js index 49880b4ef2..f821389ada 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/auxiliary-comment/overview/expected.js @@ -26,7 +26,7 @@ var _foo5 = require("foo5"); exports. /*after*/test = test; var test = /*before*/exports. /*after*/test = 5; -/*before*/(0, _foo4.bar)(_foo2.default) /*after*/; +/*before*/(0, _foo4.bar) /*after*/( /*before*/_foo2.default /*after*/, /*before*/_foo5.foo /*after*/); /* my comment */ /*before*/_foo5.foo; /*after*/