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 475e871fca10..40d76e5535b2 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 @@ -3,4 +3,4 @@ (function () { return 42; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2Jhci9iYXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiKCgpID0+IDQyKSJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFOO0FBQUEsQ0FBRCJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2Jhci9iYXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiKCgpID0+IDQyKSJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFFO0FBQUEifQ== \ No newline at end of file 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 6915f5c70848..f72d4eedae70 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;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBSixDQUFRLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVI7QUFBQSxDQUFUIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBRyxDQUFDLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVU7QUFBQSxFQUFDIn0= \ No newline at end of file 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 f7447a76f04e..57dfb0cd4ac1 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,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAN;AAAA,CAAD"} \ No newline at end of file +{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAE;AAAA"} \ 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 7e7ba2c03a92..632758421a8b 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,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAU;AAAA,EAAC"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js index 475e871fca10..40d76e5535b2 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js @@ -3,4 +3,4 @@ (function () { return 42; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2Jhci9iYXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiKCgpID0+IDQyKSJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFOO0FBQUEsQ0FBRCJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2Jhci9iYXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiKCgpID0+IDQyKSJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFFO0FBQUEifQ== \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js.map b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js.map index f7447a76f04e..57dfb0cd4ac1 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/bar/bar.js.map @@ -1 +1 @@ -{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAN;AAAA,CAAD"} \ No newline at end of file +{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAE;AAAA"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js index 6915f5c70848..f72d4eedae70 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js @@ -3,4 +3,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBSixDQUFRLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVI7QUFBQSxDQUFUIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBRyxDQUFDLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVU7QUFBQSxFQUFDIn0= \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js.map b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js.map index 7e7ba2c03a92..632758421a8b 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-both/out-files/lib/foo.js.map @@ -1 +1 @@ -{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAU;AAAA,EAAC"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/bar/bar.js.map b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/bar/bar.js.map index f7447a76f04e..57dfb0cd4ac1 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/bar/bar.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/bar/bar.js.map @@ -1 +1 @@ -{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAN;AAAA,CAAD"} \ No newline at end of file +{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAE;AAAA"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/foo.js.map b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/foo.js.map index 7e7ba2c03a92..632758421a8b 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/foo.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline-cli-true/out-files/lib/foo.js.map @@ -1 +1 @@ -{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAU;AAAA,EAAC"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/bar/bar.js b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/bar/bar.js index 475e871fca10..40d76e5535b2 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/bar/bar.js +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/bar/bar.js @@ -3,4 +3,4 @@ (function () { return 42; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2Jhci9iYXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiKCgpID0+IDQyKSJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFOO0FBQUEsQ0FBRCJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2Jhci9iYXIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiKCgpID0+IDQyKSJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFFO0FBQUEifQ== \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/foo.js b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/foo.js index 6915f5c70848..f72d4eedae70 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/foo.js +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-inline/out-files/lib/foo.js @@ -3,4 +3,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBSixDQUFRLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVI7QUFBQSxDQUFUIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBRyxDQUFDLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVU7QUFBQSxFQUFDIn0= \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/bar/bar.js.map b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/bar/bar.js.map index f7447a76f04e..57dfb0cd4ac1 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/bar/bar.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/bar/bar.js.map @@ -1 +1 @@ -{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAN;AAAA,CAAD"} \ No newline at end of file +{"version":3,"file":"bar.js","names":[],"sources":["../../src/bar/bar.js"],"sourcesContent":["(() => 42)"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAE;AAAA"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/foo.js.map b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/foo.js.map index 7e7ba2c03a92..632758421a8b 100644 --- a/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/foo.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir-sourcemap-config-true/out-files/lib/foo.js.map @@ -1 +1 @@ -{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"foo.js","names":["arr","map","x","MULTIPLIER"],"sources":["../src/foo.js"],"sourcesContent":["arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAU;AAAA,EAAC"} \ 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 fe9df475388f..598cb7acdfa8 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;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0Mi5qcyIsIm5hbWVzIjpbImFyciIsIm1hcCIsIngiLCJNVUxUSVBMSUVSIl0sInNvdXJjZXMiOlsic2NyaXB0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il0sIm1hcHBpbmdzIjoiOztBQUFBQSxHQUFHLENBQUNDLEdBQUosQ0FBUSxVQUFBQyxDQUFDO0VBQUEsT0FBSUEsQ0FBQyxHQUFHQyxVQUFSO0FBQUEsQ0FBVCJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0Mi5qcyIsIm5hbWVzIjpbImFyciIsIm1hcCIsIngiLCJNVUxUSVBMSUVSIl0sInNvdXJjZXMiOlsic2NyaXB0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il0sIm1hcHBpbmdzIjoiOztBQUFBQSxHQUFHLENBQUNDLEdBQUcsQ0FBQyxVQUFBQyxDQUFDO0VBQUEsT0FBSUEsQ0FBQyxHQUFHQyxVQUFVO0FBQUEsRUFBQyJ9 \ No newline at end of file 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 index 6d70837d0ea2..c25911f046e9 100644 --- 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 @@ -4,4 +4,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0Mi5qcyIsIm5hbWVzIjpbImFyciIsIngiXSwic291cmNlcyI6WyJvcmlnaW5hbC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXSwibWFwcGluZ3MiOiI7O0FBQUFBO0VBQUEsT0FBVUMsY0FBVjtBQUFBIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0Mi5qcyIsIm5hbWVzIjpbImFyciIsIngiXSwic291cmNlcyI6WyJvcmlnaW5hbC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXSwibWFwcGluZ3MiOiI7O0FBQUFBO0VBQUEsT0FBVUMsYyJ9 \ No newline at end of file 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 6ec5a3e83f21..7c0f7a650a8d 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 @@ -9,4 +9,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0My5qcyIsIm5hbWVzIjpbImFyciIsIm1hcCIsIngiLCJNVUxUSVBMSUVSIl0sInNvdXJjZXMiOlsic2NyaXB0LmpzIiwic2NyaXB0Mi5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyIoKCkgPT4gNDIpIiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUEsQ0FBQztFQUFBLE9BQU0sRUFBTjtBQUFBLENBQUQ7OztBQ0FBQSxHQUFHLENBQUNDLEdBQUosQ0FBUSxVQUFBQyxDQUFDO0VBQUEsT0FBSUEsQ0FBQyxHQUFHQyxVQUFSO0FBQUEsQ0FBVCJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NyaXB0My5qcyIsIm5hbWVzIjpbImFyciIsIm1hcCIsIngiLCJNVUxUSVBMSUVSIl0sInNvdXJjZXMiOlsic2NyaXB0LmpzIiwic2NyaXB0Mi5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyIoKCkgPT4gNDIpIiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUEsQ0FBQztFQUFBLE9BQU0sRUFBRTtBQUFBOzs7QUNBVEEsR0FBRyxDQUFDQyxHQUFHLENBQUMsVUFBQUMsQ0FBQztFQUFBLE9BQUlBLENBQUMsR0FBR0MsVUFBVTtBQUFBLEVBQUMifQ== \ No newline at end of file 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 a17b280ac01a..92ee347fe7c0 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,"file":"script3.js","names":["arr","map","x","MULTIPLIER"],"sources":["script.js","script2.js"],"sourcesContent":["(() => 42)\n\n// some comments","arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAN;AAAA,CAAD,E,CAEA;;;ACFAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"script3.js","names":["arr","map","x","MULTIPLIER"],"sources":["script.js","script2.js"],"sourcesContent":["(() => 42)\n\n// some comments","arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAE;AAAA,GAAC,CAEV;;;ACFAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAU;AAAA,EAAC"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js b/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js index aa412959bf73..d830585672ce 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js +++ b/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js @@ -3,10 +3,10 @@ (function () { return 42; }); // some comments -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsic2NyaXB0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbIigoKSA9PiA0MilcblxuLy8gc29tZSBjb21tZW50cyJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFOO0FBQUEsQ0FBRCxFLENBRUEifQ== +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsic2NyaXB0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbIigoKSA9PiA0MilcblxuLy8gc29tZSBjb21tZW50cyJdLCJtYXBwaW5ncyI6Ijs7QUFBQSxDQUFDO0VBQUEsT0FBTSxFQUFFO0FBQUEsR0FBQyxDQUVWIn0= "use strict"; arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbInNjcmlwdDIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBSixDQUFRLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVI7QUFBQSxDQUFUIn0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4IiwiTVVMVElQTElFUiJdLCJzb3VyY2VzIjpbInNjcmlwdDIuanMiXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBRyxDQUFDLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdDLFVBQVU7QUFBQSxFQUFDIn0= \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js.map b/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js.map index f3d8c393f8d6..3a8f49a36f66 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js.map +++ b/packages/babel-cli/test/fixtures/babel/filenames-sourcemap-config-both/out-files/script3.js.map @@ -1 +1 @@ -{"version":3,"file":"script3.js","names":["arr","map","x","MULTIPLIER"],"sources":["script.js","script2.js"],"sourcesContent":["(() => 42)\n\n// some comments","arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAN;AAAA,CAAD,E,CAEA;;;;ACFAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"script3.js","names":["arr","map","x","MULTIPLIER"],"sources":["script.js","script2.js"],"sourcesContent":["(() => 42)\n\n// some comments","arr.map(x => x * MULTIPLIER);"],"mappings":";;AAAA,CAAC;EAAA,OAAM,EAAE;AAAA,GAAC,CAEV;;;;ACFAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGC,UAAU;AAAA,EAAC"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/stdin --out-file --source-maps/out-files/test.js.map b/packages/babel-cli/test/fixtures/babel/stdin --out-file --source-maps/out-files/test.js.map index e0a6d6c85f4a..f2513784d3e8 100644 --- a/packages/babel-cli/test/fixtures/babel/stdin --out-file --source-maps/out-files/test.js.map +++ b/packages/babel-cli/test/fixtures/babel/stdin --out-file --source-maps/out-files/test.js.map @@ -1 +1 @@ -{"version":3,"file":"test.js","names":["arr","map","x"],"sources":["stdin"],"sourcesContent":["arr.map(x => x * x);"],"mappings":";;AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGA,CAAR;AAAA,CAAT"} \ No newline at end of file +{"version":3,"file":"test.js","names":["arr","map","x"],"sources":["stdin"],"sourcesContent":["arr.map(x => x * x);"],"mappings":";;AAAAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGA,CAAC;AAAA,EAAC"} \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/stdin --source-maps inline/stdout.txt b/packages/babel-cli/test/fixtures/babel/stdin --source-maps inline/stdout.txt index db57d03f3c0a..3b81510c3fbd 100644 --- a/packages/babel-cli/test/fixtures/babel/stdin --source-maps inline/stdout.txt +++ b/packages/babel-cli/test/fixtures/babel/stdin --source-maps inline/stdout.txt @@ -3,6 +3,6 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sInNvdXJjZXMiOlsic3RkaW4iXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiB4KTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBSixDQUFRLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdBLENBQVI7QUFBQSxDQUFUIn0= +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sInNvdXJjZXMiOlsic3RkaW4iXSwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiB4KTsiXSwibWFwcGluZ3MiOiI7O0FBQUFBLEdBQUcsQ0FBQ0MsR0FBRyxDQUFDLFVBQUFDLENBQUM7RUFBQSxPQUFJQSxDQUFDLEdBQUdBLENBQUM7QUFBQSxFQUFDIn0= //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Rkb3V0IiwibmFtZXMiOltdLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJtYXBwaW5ncyI6IiJ9 diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-map.json new file mode 100644 index 000000000000..e4e51810ff8a --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-map.json @@ -0,0 +1,14 @@ +{ + "version": 3, + "names": [ + "t", + "x" + ], + "sources": [ + "source-maps/arrow-function/input.js" + ], + "sourcesContent": [ + "var t = x => x * x;" + ], + "mappings": "AAAA,IAAIA,CAAC,GAAG,SAAJA,CAAC,CAAGC,CAAC;EAAA,OAAIA,CAAC,GAAGA,CAAC;AAAA" +} \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/class/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/class/source-map.json new file mode 100644 index 000000000000..9c1dbd2e61b0 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/class/source-map.json @@ -0,0 +1,16 @@ +{ + "version": 3, + "names": [ + "Test", + "Error", + "test", + "bar" + ], + "sources": [ + "source-maps/class/input.js" + ], + "sourcesContent": [ + "class Test {\n get bar() {\n throw new Error(\"wow\");\n }\n}\n\nvar test = new Test;\ntest.bar;" + ], + "mappings": "IAAMA,IAAI;EAAA;;EAAA;IAAA;EAAA;;EAAA;IAAA;IAAA,KACR,YAAU;MACR,MAAM,IAAIC,KAAK,CAAC,KAAK,CAAC;IACxB;EAAC;EAAA;AAAA;;AAGH,IAAIC,IAAI,GAAG,IAAIF,IAAI;AACnBE,IAAI,CAACC,GAAG" +} \ No newline at end of file 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 b5dfb95a4e3f..fb099c40af8d 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 @@ -11,5 +11,5 @@ "sourcesContent": [ "arr.map(x => x * x);" ], - "mappings": "AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGA,CAAR;AAAA,CAAT" + "mappings": "AAAAA,GAAG,CAACC,GAAG,CAAC,UAAAC,CAAC;EAAA,OAAIA,CAAC,GAAGA,CAAC;AAAA,EAAC" } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js b/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js index 5b37b2b86a1d..0ff1eab8b6ca 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js @@ -1,4 +1,4 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sInNvdXJjZXMiOlsic291cmNlLW1hcHMvaW5saW5lL2lucHV0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il0sIm1hcHBpbmdzIjoiQUFBQUEsR0FBRyxDQUFDQyxHQUFKLENBQVEsVUFBQUMsQ0FBQztFQUFBLE9BQUlBLENBQUMsR0FBR0EsQ0FBUjtBQUFBLENBQVQifQ== +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sInNvdXJjZXMiOlsic291cmNlLW1hcHMvaW5saW5lL2lucHV0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il0sIm1hcHBpbmdzIjoiQUFBQUEsR0FBRyxDQUFDQyxHQUFHLENBQUMsVUFBQUMsQ0FBQztFQUFBLE9BQUlBLENBQUMsR0FBR0EsQ0FBQztBQUFBLEVBQUMifQ== diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-map.json index 24e9b62b706d..f37e715c9e79 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-map.json @@ -1,6 +1,6 @@ { "version": 3, - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsFA;EACAA,kBADA;;EAEAC;IACA;MACAC;IADA;EAGA;;AANA,C", + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsFA;EACAA;;EACAC;IACA;MACAC;IACA;EACA;;AACA", "names": [ "name", "data", diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-mappings.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-mappings.json index fe0fa3321505..f41b80a82318 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-mappings.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-complex/source-mappings.json @@ -55,7 +55,7 @@ "column": 4 }, "original": { - "line": 90, + "line": 92, "column": 0 } }, diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json index 748a24a3a8b6..1b9392bc5377 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-external/source-map.json @@ -1,7 +1,11 @@ { - "mappings": "AAAA,UAAU,Y;SAAM;AAAC,CAAjB", + "version": 3, + "mappings": "AAAA,UAAU,Y;SAAM,C;CAAC", "names": [], - "sources": ["original.js"], - "sourcesContent": ["var foo = () => 4;"], - "version": 3 -} + "sources": [ + "original.js" + ], + "sourcesContent": [ + "var foo = () => 4;" + ] +} \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json index 81a440f3e2b8..050799fd70f9 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources-complete-replace/source-map.json @@ -1,15 +1,13 @@ { "version": 3, - "mappings": "AAAC,KCAD;ACAA,K", + "mappings": "AAAC,KAAG;ACAJ,KAAG", "names": [], "sources": [ "bar.js", - "input.tsx", "baz.js" ], "sourcesContent": [ "", - "foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}", "baz();" ] } \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json index 0c76c1a5ef2f..5e932eee0d4c 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-multiple-output-sources/source-map.json @@ -1,6 +1,6 @@ { "version": 3, - "mappings": "AAAC,KCAD;;AACA,SAASA,GAAT,CAAaC,GAAb,EAAwB;EACpB,MAAM,IAAIC,KAAJ,CAAU,cAAV,CAAN;AACH", + "mappings": "AAAC,KAAG;;ACCJ,SAASA,GAAG,CAACC,GAAW;EACpB,MAAM,IAAIC,KAAK,CAAC,cAAc,CAAC;AACnC", "names": [ "foo", "bar", diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json index f538878eed17..0dde70b60b7c 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-same-location/source-map.json @@ -1,7 +1,11 @@ { - "mappings": "AAAA,UAAU,Y;SAAM;AAAC,CAAjB", + "version": 3, + "mappings": "AAAA,UAAU,Y;SAAM,C;CAAC", "names": [], - "sources": ["source-maps/input-source-map-same-location/input.js"], - "sourcesContent": ["var foo = () => 4;"], - "version": 3 -} + "sources": [ + "source-maps/input-source-map-same-location/input.js" + ], + "sourcesContent": [ + "var foo = () => 4;" + ] +} \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json index c58a997a828d..4a26e2136a38 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/source-map.json @@ -1,13 +1,11 @@ { "version": 3, - "mappings": "AAAC,KCAD", + "mappings": "AAAC,KAAG", "names": [], "sources": [ - "test.js", - "input.tsx" + "test.js" ], "sourcesContent": [ - "", - "foo(1);\nfunction foo(bar: number): never {\n throw new Error('Intentional.');\n}" + "" ] } \ No newline at end of file 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 index 748a24a3a8b6..1b9392bc5377 100644 --- 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 @@ -1,7 +1,11 @@ { - "mappings": "AAAA,UAAU,Y;SAAM;AAAC,CAAjB", + "version": 3, + "mappings": "AAAA,UAAU,Y;SAAM,C;CAAC", "names": [], - "sources": ["original.js"], - "sourcesContent": ["var foo = () => 4;"], - "version": 3 -} + "sources": [ + "original.js" + ], + "sourcesContent": [ + "var foo = () => 4;" + ] +} \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/interpreter-directive-prefix/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/interpreter-directive-prefix/source-map.json index cb9c3ee27571..959b94b15038 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/interpreter-directive-prefix/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/interpreter-directive-prefix/source-map.json @@ -1,5 +1,5 @@ { - "mappings": "AAAA;AAEAA,OAAO,CAACC,GAAR,CAAY,eAAZ", + "version": 3, "names": [ "console", "log" @@ -10,5 +10,5 @@ "sourcesContent": [ "#!env node\n\nconsole.log(\"Hello, world!\");" ], - "version": 3 -} + "mappings": "AAAA;AAEAA,OAAO,CAACC,GAAG,CAAC,eAAe,CAAC" +} \ No newline at end of file diff --git a/packages/babel-generator/src/buffer.ts b/packages/babel-generator/src/buffer.ts index e7c7c206007d..219a814092c4 100644 --- a/packages/babel-generator/src/buffer.ts +++ b/packages/babel-generator/src/buffer.ts @@ -27,15 +27,6 @@ type QueueItem = { filename: string | undefined; }; -function SourcePos(): SourcePos { - return { - identifierName: undefined, - line: undefined, - column: undefined, - filename: undefined, - }; -} - export default class Buffer { constructor(map?: SourceMap | null) { this._map = map; @@ -55,13 +46,11 @@ export default class Buffer { line: 1, column: 0, }; - _sourcePosition = SourcePos(); - _disallowedPop: SourcePos & { objectReusable: boolean } = { + _sourcePosition: SourcePos = { identifierName: undefined, line: undefined, column: undefined, filename: undefined, - objectReusable: true, // To avoid deleting and re-creating objects, we reuse existing objects when they are not needed anymore. }; _allocQueue() { @@ -230,6 +219,7 @@ export default class Buffer { _append(str: string, sourcePos: SourcePos, maybeNewline: boolean): void { const len = str.length; + const position = this._position; this._last = str.charCodeAt(len - 1); @@ -243,7 +233,7 @@ export default class Buffer { } if (!maybeNewline && !this._map) { - this._position.column += len; + position.column += len; return; } @@ -265,18 +255,18 @@ export default class Buffer { // Now, find each reamining newline char in the string. while (i !== -1) { - this._position.line++; - this._position.column = 0; + position.line++; + position.column = 0; last = i + 1; // We mark the start of each line, which happens directly after this newline char // unless this is the last char. - if (last < str.length) { + if (last < len) { this._mark(++line, 0, identifierName, filename); } i = str.indexOf("\n", last); } - this._position.column += str.length - last; + position.column += len - last; } _mark( @@ -370,15 +360,7 @@ export default class Buffer { cb(); - // In cases where tokens are printed after this item, we want to - // ensure that they get the location of the _end_ of the identifier. - // To accomplish this, we assign the location and explicitly disable - // the standard Buffer withSource previous-position "reactivation" - // logic. This means that if another item calls '.source()' to set - // the location after the identifier, it is fine, but the position won't - // be automatically replaced with the previous value. this.source("end", loc); - this._disallowPop("start", loc); } /** @@ -387,75 +369,51 @@ export default class Buffer { */ source(prop: "start" | "end", loc: Loc | undefined): void { - if (!loc) return; + if (!this._map) return; // Since this is called extremely often, we re-use the same _sourcePosition // object for the whole lifetime of the buffer. - this._normalizePosition(prop, loc, this._sourcePosition); + this._normalizePosition(prop, loc, 0, 0); + } + + sourceWithOffset( + prop: "start" | "end", + loc: Loc | undefined, + lineOffset: number, + columnOffset: number, + ): void { + if (!this._map) return; + + this._normalizePosition(prop, loc, lineOffset, columnOffset); } /** - * Call a callback with a specific source location and restore on completion. + * Call a callback with a specific source location */ withSource(prop: "start" | "end", loc: Loc, cb: () => void): void { if (!this._map) return cb(); - // Use the call stack to manage a stack of "source location" data because - // the _sourcePosition object is mutated over the course of code generation, - // and constantly copying it would be slower. - const originalLine = this._sourcePosition.line; - const originalColumn = this._sourcePosition.column; - const originalFilename = this._sourcePosition.filename; - const originalIdentifierName = this._sourcePosition.identifierName; - this.source(prop, loc); cb(); - - if ( - // Verify if reactivating this specific position has been disallowed. - this._disallowedPop.objectReusable || - this._disallowedPop.line !== originalLine || - this._disallowedPop.column !== originalColumn || - this._disallowedPop.filename !== originalFilename - ) { - this._sourcePosition.line = originalLine; - this._sourcePosition.column = originalColumn; - this._sourcePosition.filename = originalFilename; - this._sourcePosition.identifierName = originalIdentifierName; - this._disallowedPop.objectReusable = true; - } } - /** - * Allow printers to disable the default location-reset behavior of the - * sourcemap output, so that certain printers can be sure that the - * "end" location that they set is actually treated as the end position. - */ - _disallowPop(prop: "start" | "end", loc: Loc) { - if (!loc) return; - - const disallowedPop = this._disallowedPop; - - this._normalizePosition(prop, loc, disallowedPop); - - disallowedPop.objectReusable = false; - } - - _normalizePosition(prop: "start" | "end", loc: Loc, targetObj: SourcePos) { + _normalizePosition( + prop: "start" | "end", + loc: Loc, + lineOffset: number, + columnOffset: number, + ) { const pos = loc[prop]; + const target = this._sourcePosition; - targetObj.identifierName = + target.identifierName = (prop === "start" && loc.identifierName) || undefined; if (pos) { - targetObj.line = pos.line; - targetObj.column = pos.column; - targetObj.filename = loc.filename; - } else { - targetObj.line = null; - targetObj.column = null; - targetObj.filename = null; + target.line = pos.line + lineOffset; + target.column = pos.column + columnOffset; + target.filename = loc.filename; } } diff --git a/packages/babel-generator/src/generators/base.ts b/packages/babel-generator/src/generators/base.ts index fed810d55ab9..7bf482ca908a 100644 --- a/packages/babel-generator/src/generators/base.ts +++ b/packages/babel-generator/src/generators/base.ts @@ -36,15 +36,11 @@ export function BlockStatement(this: Printer, node: t.BlockStatement) { this.printSequence(node.body, node, { indent: true }); this.removeTrailingNewline(); - this.source("end", node.loc); - if (!this.endsWith(charCodes.lineFeed)) this.newline(); - - this.rightBrace(); - } else { - this.source("end", node.loc); - this.token("}"); } + + this.sourceWithOffset("end", node.loc, 0, -1); + this.rightBrace(); } export function Directive(this: Printer, node: t.Directive) { diff --git a/packages/babel-generator/src/generators/classes.ts b/packages/babel-generator/src/generators/classes.ts index 01416fa82828..0f8ef2179ac6 100644 --- a/packages/babel-generator/src/generators/classes.ts +++ b/packages/babel-generator/src/generators/classes.ts @@ -79,6 +79,8 @@ export function ClassBody(this: Printer, node: t.ClassBody) { if (!this.endsWith(charCodes.lineFeed)) this.newline(); + this.sourceWithOffset("end", node.loc, 0, -1); + this.rightBrace(); } } @@ -88,7 +90,8 @@ export function ClassProperty(this: Printer, node: t.ClassProperty) { // catch up to property key, avoid line break // between member modifiers and the property key. - this.source("end", node.key.loc); + const endLine = node.key.loc?.end?.line; + if (endLine) this.catchUp(endLine); this.tsPrintClassMemberModifiers(node); @@ -127,7 +130,8 @@ export function ClassAccessorProperty( // catch up to property key, avoid line break // between member modifiers and the property key. - this.source("end", node.key.loc); + const endLine = node.key.loc?.end?.line; + if (endLine) this.catchUp(endLine); // TS does not support class accessor property yet this.tsPrintClassMemberModifiers(node); @@ -201,9 +205,12 @@ export function _classMethodHead( node: t.ClassMethod | t.ClassPrivateMethod | t.TSDeclareMethod, ) { this.printJoin(node.decorators, node); + // catch up to method key, avoid line break // between member modifiers/method heads and the method key. - this.source("end", node.key.loc); + const endLine = node.key.loc?.end?.line; + if (endLine) this.catchUp(endLine); + this.tsPrintClassMemberModifiers(node); this._methodHead(node); } @@ -219,6 +226,9 @@ export function StaticBlock(this: Printer, node: t.StaticBlock) { this.printSequence(node.body, node, { indent: true, }); + + this.sourceWithOffset("end", node.loc, 0, -1); + this.rightBrace(); } } diff --git a/packages/babel-generator/src/generators/expressions.ts b/packages/babel-generator/src/generators/expressions.ts index 28a27b2c7df3..64b52752d91f 100644 --- a/packages/babel-generator/src/generators/expressions.ts +++ b/packages/babel-generator/src/generators/expressions.ts @@ -358,6 +358,9 @@ export function ModuleExpression(this: Printer, node: t.ModuleExpression) { } else { this.newline(); this.printSequence(node.body.body, node, { indent: true }); + + this.sourceWithOffset("end", node.loc, 0, -1); + this.rightBrace(); } } diff --git a/packages/babel-generator/src/generators/types.ts b/packages/babel-generator/src/generators/types.ts index 0ff05db52a9d..54f0418292d4 100644 --- a/packages/babel-generator/src/generators/types.ts +++ b/packages/babel-generator/src/generators/types.ts @@ -4,9 +4,7 @@ import type * as t from "@babel/types"; import jsesc from "jsesc"; export function Identifier(this: Printer, node: t.Identifier) { - this.exactSource(node.loc, () => { - this.word(node.name); - }); + this.word(node.name); } export function ArgumentPlaceholder(this: Printer) { @@ -32,6 +30,8 @@ export function ObjectExpression(this: Printer, node: t.ObjectExpression) { this.space(); } + this.sourceWithOffset("end", node.loc, 0, -1); + this.token("}"); } diff --git a/packages/babel-generator/src/generators/typescript.ts b/packages/babel-generator/src/generators/typescript.ts index 42c2654c9cb3..23ce5853561a 100644 --- a/packages/babel-generator/src/generators/typescript.ts +++ b/packages/babel-generator/src/generators/typescript.ts @@ -310,10 +310,11 @@ function tsPrintBraced(printer: Printer, members: t.Node[], node: t.Node) { printer.newline(); } printer.dedent(); - printer.rightBrace(); - } else { - printer.token("}"); } + + printer.sourceWithOffset("end", node.loc, 0, -1); + + printer.rightBrace(); } export function TSArrayType(this: Printer, node: t.TSArrayType) { diff --git a/packages/babel-generator/src/printer.ts b/packages/babel-generator/src/printer.ts index 5c4b5e3cc9ae..e8064fb939d8 100644 --- a/packages/babel-generator/src/printer.ts +++ b/packages/babel-generator/src/printer.ts @@ -283,22 +283,41 @@ class Printer { } exactSource(loc: Loc | undefined, cb: () => void) { + if (!loc) return cb(); + this._catchUp("start", loc); this._buf.exactSource(loc, cb); } source(prop: "start" | "end", loc: Loc | undefined): void { + if (!loc) return; + this._catchUp(prop, loc); this._buf.source(prop, loc); } + sourceWithOffset( + prop: "start" | "end", + loc: Loc | undefined, + lineOffset: number, + columnOffset: number, + ): void { + if (!loc) return; + + this._catchUp(prop, loc); + + this._buf.sourceWithOffset(prop, loc, lineOffset, columnOffset); + } + withSource( prop: "start" | "end", loc: Loc | undefined, cb: () => void, ): void { + if (!loc) return cb(); + this._catchUp(prop, loc); this._buf.withSource(prop, loc, cb); @@ -443,6 +462,17 @@ class Printer { parenPushNewlineState.printed = true; } + catchUp(line: number) { + if (!this.format.retainLines) return; + + // catch up to this nodes newline if we're behind + const count = line - this._buf.getCurrentLine(); + + for (let i = 0; i < count; i++) { + this._newline(); + } + } + _catchUp(prop: "start" | "end", loc?: Loc) { if (!this.format.retainLines) return; @@ -557,7 +587,7 @@ class Printer { const loc = nodeType === "Program" || nodeType === "File" ? null : node.loc; - this.withSource("start", loc, printMethod.bind(this, node, parent)); + this.exactSource(loc, printMethod.bind(this, node, parent)); if (noLineTerminator && !this._noLineTerminator) { this._noLineTerminator = true; @@ -811,11 +841,8 @@ class Printer { // Avoid creating //* comments if (this.endsWith(charCodes.slash)) this._space(); - this.withSource( - "start", - comment.loc, - this._append.bind(this, val, maybeNewline), - ); + this.source("start", comment.loc); + this._append(val, maybeNewline); if (printNewLines) this.newline(1); } diff --git a/packages/babel-generator/test/fixtures/decorators-legacy/ts-class-modifier-with-retainlines/output.js b/packages/babel-generator/test/fixtures/decorators-legacy/ts-class-modifier-with-retainlines/output.js index cd301a712d47..739d94514278 100644 --- a/packages/babel-generator/test/fixtures/decorators-legacy/ts-class-modifier-with-retainlines/output.js +++ b/packages/babel-generator/test/fixtures/decorators-legacy/ts-class-modifier-with-retainlines/output.js @@ -19,4 +19,5 @@ class A { private [cm]() - {}} + {} +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/regression/11870/output.js b/packages/babel-generator/test/fixtures/regression/11870/output.js index 7dee47804925..515b0cdd2358 100644 --- a/packages/babel-generator/test/fixtures/regression/11870/output.js +++ b/packages/babel-generator/test/fixtures/regression/11870/output.js @@ -1,3 +1,4 @@ class Test { @TestDecorator - async decorateMe() {}} \ No newline at end of file + async decorateMe() {} +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/input.js b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/input.js new file mode 100644 index 000000000000..ea56b39d27ef --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/input.js @@ -0,0 +1,15 @@ +class Foo { + static {} +} + +class A1 { + static{ + foo; + } +} + +class A2 { + static { + foo;bar; + } +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/options.json b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/options.json new file mode 100644 index 000000000000..219de99ead2d --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/options.json @@ -0,0 +1,3 @@ +{ + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/output.js b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/output.js new file mode 100644 index 000000000000..8ce10b0ba345 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/output.js @@ -0,0 +1,16 @@ +class Foo { + static {} +} + +class A1 { + static { + foo; + } +} + +class A2 { + static { + foo; + bar; + } +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/source-map.json new file mode 100644 index 000000000000..c5131632aeed --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ClassBody-StaticBlock/source-map.json @@ -0,0 +1,17 @@ +{ + "version": 3, + "names": [ + "Foo", + "A1", + "foo", + "A2", + "bar" + ], + "sources": [ + "fixtures/sourcemaps/ClassBody-StaticBlock/input.js" + ], + "sourcesContent": [ + "class Foo {\n static {}\n}\n\nclass A1 {\n static{\n foo;\n }\n}\n\nclass A2 {\n static {\n foo;bar;\n }\n}" + ], + "mappings": "AAAA,MAAMA,GAAG,CAAC;EACR;AACF;;AAEA,MAAMC,EAAE,CAAC;EACP;IACEC,GAAG;EACL;AACF;;AAEA,MAAMC,EAAE,CAAC;EACP;IACED,GAAG;IAACE,GAAG;EACT;AACF" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/input.js b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/input.js new file mode 100644 index 000000000000..28f5488c7300 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/input.js @@ -0,0 +1,6 @@ +const m = module { export const foo = "foo" }; +module { + foo; + bar; +}; +foo(module {}); diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/options.json b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/options.json new file mode 100644 index 000000000000..d64e8d9018c2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/options.json @@ -0,0 +1,5 @@ +{ + "plugins": ["moduleBlocks"], + "sourceType": "module", + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/output.js b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/output.js new file mode 100644 index 000000000000..0a069dd6ff93 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/output.js @@ -0,0 +1,8 @@ +const m = module { + export const foo = "foo"; +}; +module { + foo; + bar; +}; +foo(module {}); \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/source-map.json new file mode 100644 index 000000000000..2aa1a99e2c71 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/ModuleExpression/source-map.json @@ -0,0 +1,15 @@ +{ + "version": 3, + "names": [ + "m", + "foo", + "bar" + ], + "sources": [ + "fixtures/sourcemaps/ModuleExpression/input.js" + ], + "sourcesContent": [ + "const m = module { export const foo = \"foo\" };\nmodule {\n foo;\n bar;\n};\nfoo(module {});" + ], + "mappings": "AAAA,MAAMA,CAAC,GAAG;EAAS,OAAO,MAAMC,GAAG,GAAG,KAAK;AAAC,CAAC;AAC7C;EACEA,GAAG;EACHC,GAAG;AACL,CAAC;AACDD,GAAG,CAAC,SAAS,CAAC" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/input.js b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/input.js new file mode 100644 index 000000000000..7c81c1fb8e2c --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/input.js @@ -0,0 +1 @@ +(() => { return 42; }) diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/options.json b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/options.json new file mode 100644 index 000000000000..b27818ea4218 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/options.json @@ -0,0 +1,4 @@ +{ + "compact": true, + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/output.js b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/output.js new file mode 100644 index 000000000000..5479fdf08a87 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/output.js @@ -0,0 +1 @@ +()=>{return 42;}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/source-map.json new file mode 100644 index 000000000000..f376fb6c09e0 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function-compact/source-map.json @@ -0,0 +1,11 @@ +{ + "version": 3, + "names": [], + "sources": [ + "fixtures/sourcemaps/arrow-function-compact/input.js" + ], + "sourcesContent": [ + "(() => { return 42; })" + ], + "mappings": "AAAC,IAAM,CAAE,MAAO,GAAE,CAAE,CAAC" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/input.js b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/input.js new file mode 100644 index 000000000000..7c81c1fb8e2c --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/input.js @@ -0,0 +1 @@ +(() => { return 42; }) diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/options.json b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/options.json new file mode 100644 index 000000000000..219de99ead2d --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/output.js b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/output.js new file mode 100644 index 000000000000..9226b13ec6c5 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/output.js @@ -0,0 +1,3 @@ +() => { + return 42; +}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/source-map.json new file mode 100644 index 000000000000..7b03ae9945a8 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/arrow-function/source-map.json @@ -0,0 +1,11 @@ +{ + "version": 3, + "names": [], + "sources": [ + "fixtures/sourcemaps/arrow-function/input.js" + ], + "sourcesContent": [ + "(() => { return 42; })" + ], + "mappings": "AAAC,MAAM;EAAE,OAAO,EAAE;AAAE,CAAC" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/input.js b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/input.js new file mode 100644 index 000000000000..0ecee4504448 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/input.js @@ -0,0 +1,2 @@ +let a = [| 1 |]; +let b = {| a: 1 |}; diff --git a/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/options.json b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/options.json new file mode 100644 index 000000000000..d2821ea96086 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/options.json @@ -0,0 +1,5 @@ +{ + "recordAndTupleSyntaxType": "bar", + "plugins": [["recordAndTuple", { "syntaxType": "bar" }]], + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/output.js b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/output.js new file mode 100644 index 000000000000..573e5a57d26a --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/output.js @@ -0,0 +1,4 @@ +let a = [|1|]; +let b = {| + a: 1 +|}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/source-map.json new file mode 100644 index 000000000000..c4f449905b4e --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/bar-record-tuple/source-map.json @@ -0,0 +1,14 @@ +{ + "version": 3, + "names": [ + "a", + "b" + ], + "sources": [ + "fixtures/sourcemaps/bar-record-tuple/input.js" + ], + "sourcesContent": [ + "let a = [| 1 |];\nlet b = {| a: 1 |};" + ], + "mappings": "AAAA,IAAIA,CAAC,GAAG,EAAG,CAAC,EAAG;AACf,IAAIC,CAAC,GAAG;EAAGD,CAAC,EAAE;AAAC,EAAG" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/options.json b/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/options.json new file mode 100644 index 000000000000..381b90bf7391 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["typescript"], + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/source-map.json index 31627242a891..912ec14f6d8a 100644 --- a/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/source-map.json +++ b/packages/babel-generator/test/fixtures/sourcemaps/call-identifiers/source-map.json @@ -11,5 +11,5 @@ "sourcesContent": [ "foo;\nfoo();\nfoo().bar;\nobj.foo;\nobj.foo();\nobj.foo.bar;\nobj.foo().bar;\n{\n foo;\n foo();\n foo().bar;\n obj.foo;\n obj.foo();\n obj.foo.bar;\n obj.foo().bar;\n}" ], - "mappings": "AAAAA,GAAG;AACHA,GAAG;AACHA,GAAG,GAAGC,GAAN;AACAC,GAAG,CAACF,GAAJ;AACAE,GAAG,CAACF,GAAJ;AACAE,GAAG,CAACF,GAAJ,CAAQC,GAAR;AACAC,GAAG,CAACF,GAAJ,GAAUC,GAAV;AACA;EACED,GAAG;EACHA,GAAG;EACHA,GAAG,GAAGC,GAAN;EACAC,GAAG,CAACF,GAAJ;EACAE,GAAG,CAACF,GAAJ;EACAE,GAAG,CAACF,GAAJ,CAAQC,GAAR;EACAC,GAAG,CAACF,GAAJ,GAAUC,GAAV;AACD" + "mappings": "AAAAA,GAAG;AACHA,GAAG,EAAE;AACLA,GAAG,EAAE,CAACC,GAAG;AACTC,GAAG,CAACF,GAAG;AACPE,GAAG,CAACF,GAAG,EAAE;AACTE,GAAG,CAACF,GAAG,CAACC,GAAG;AACXC,GAAG,CAACF,GAAG,EAAE,CAACC,GAAG;AACb;EACED,GAAG;EACHA,GAAG,EAAE;EACLA,GAAG,EAAE,CAACC,GAAG;EACTC,GAAG,CAACF,GAAG;EACPE,GAAG,CAACF,GAAG,EAAE;EACTE,GAAG,CAACF,GAAG,CAACC,GAAG;EACXC,GAAG,CAACF,GAAG,EAAE,CAACC,GAAG;AACf" } \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/input.js b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/input.js new file mode 100644 index 000000000000..8f3d3da881b1 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/input.js @@ -0,0 +1,2 @@ +let a = #[1, 2, 3]; +let b = #{a: 1, b: 2, c: 3}; diff --git a/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/options.json b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/options.json new file mode 100644 index 000000000000..46b9d494bf8a --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/options.json @@ -0,0 +1,5 @@ +{ + "recordAndTupleSyntaxType": "hash", + "plugins": [["recordAndTuple", { "syntaxType": "hash" }]], + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/output.js b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/output.js new file mode 100644 index 000000000000..984d0f9461d5 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/output.js @@ -0,0 +1,6 @@ +let a = #[1, 2, 3]; +let b = #{ + a: 1, + b: 2, + c: 3 +}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/source-map.json new file mode 100644 index 000000000000..a8d89c1584cb --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/hash-record-tuple/source-map.json @@ -0,0 +1,15 @@ +{ + "version": 3, + "names": [ + "a", + "b", + "c" + ], + "sources": [ + "fixtures/sourcemaps/hash-record-tuple/input.js" + ], + "sourcesContent": [ + "let a = #[1, 2, 3];\nlet b = #{a: 1, b: 2, c: 3};" + ], + "mappings": "AAAA,IAAIA,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAClB,IAAIC,CAAC,GAAG;EAAED,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE;AAAC,CAAC" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/input.ts b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/input.ts new file mode 100644 index 000000000000..14e63c070ab0 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/input.ts @@ -0,0 +1,168 @@ +// From packages\babel-cli\src\babel\watcher.ts + +import { createRequire } from "module"; +import path from "path"; +import type { WatchOptions, FSWatcher } from "chokidar"; + +const fileToDeps = new Map>(); +const depToFiles = new Map>(); + +let isWatchMode = false; +let watcher: FSWatcher; +const watchQueue = new Set(); +let hasStarted = false; + +export function enable({ enableGlobbing }: { enableGlobbing: boolean }) { + isWatchMode = true; + + const { FSWatcher } = requireChokidar(); + + const options: WatchOptions = { + disableGlobbing: !enableGlobbing, + persistent: true, + ignoreInitial: true, + awaitWriteFinish: { + stabilityThreshold: 50, + pollInterval: 10, + }, + }; + watcher = new FSWatcher(options); + + watcher.on("unlink", unwatchFile); +} + +export function startWatcher() { + hasStarted = true; + + for (const dep of watchQueue) { + watcher.add(dep); + } + watchQueue.clear(); + + watcher.on("ready", () => { + console.log("The watcher is ready."); + }); +} + +export function watch(filename: string): void { + if (!isWatchMode) { + throw new Error( + "Internal Babel error: .watch called when not in watch mode.", + ); + } + + if (!hasStarted) { + watchQueue.add(path.resolve(filename)); + } else { + watcher.add(path.resolve(filename)); + } +} + +/** + * Call @param callback whenever a dependency (source file)/ + * external dependency (non-source file) changes. + * + * Handles mapping external dependencies to their corresponding + * dependencies. + */ +export function onFilesChange( + callback: (filenames: string[], event: string, cause: string) => void, +): void { + if (!isWatchMode) { + throw new Error( + "Internal Babel error: .onFilesChange called when not in watch mode.", + ); + } + + watcher.on("all", (event, filename) => { + if (event !== "change" && event !== "add") return; + + const absoluteFile = path.resolve(filename); + callback( + [absoluteFile, ...(depToFiles.get(absoluteFile) ?? [])], + event, + absoluteFile, + ); + }); +} + +export function updateExternalDependencies( + filename: string, + dependencies: Set, +) { + if (!isWatchMode) return; + + // Use absolute paths + const absFilename = path.resolve(filename); + const absDependencies = new Set( + Array.from(dependencies, dep => path.resolve(dep)), + ); + + const deps = fileToDeps.get(absFilename); + if (deps) { + for (const dep of deps) { + if (!absDependencies.has(dep)) { + removeFileDependency(absFilename, dep); + } + } + } + for (const dep of absDependencies) { + let deps = depToFiles.get(dep); + if (!deps) { + depToFiles.set(dep, (deps = new Set())); + + if (!hasStarted) { + watchQueue.add(dep); + } else { + watcher.add(dep); + } + } + + deps.add(absFilename); + } + + fileToDeps.set(absFilename, absDependencies); +} + +function removeFileDependency(filename: string, dep: string) { + const deps = depToFiles.get(dep) as Set; + deps.delete(filename); + + if (deps.size === 0) { + depToFiles.delete(dep); + + if (!hasStarted) { + watchQueue.delete(dep); + } else { + watcher.unwatch(dep); + } + } +} + +function unwatchFile(filename: string) { + const deps = fileToDeps.get(filename); + if (!deps) return; + + for (const dep of deps) { + removeFileDependency(filename, dep); + } + fileToDeps.delete(filename); +} + +function requireChokidar(): any { + const require = createRequire(import.meta.url); + + try { + return process.env.BABEL_8_BREAKING + ? require("chokidar") + : parseInt(process.versions.node) >= 8 + ? require("chokidar") + : require("@nicolo-ribaudo/chokidar-2"); + } catch (err) { + console.error( + "The optional dependency chokidar failed to install and is required for " + + "--watch. Chokidar is likely not supported on your platform.", + ); + throw err; + } +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/options.json b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/options.json new file mode 100644 index 000000000000..381b90bf7391 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["typescript"], + "sourceMaps": true +} diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/output.js b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/output.js new file mode 100644 index 000000000000..9fdbf2c3f072 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/output.js @@ -0,0 +1,143 @@ +// From packages\babel-cli\src\babel\watcher.ts +import { createRequire } from "module"; +import path from "path"; +import type { WatchOptions, FSWatcher } from "chokidar"; +const fileToDeps = new Map>(); +const depToFiles = new Map>(); +let isWatchMode = false; +let watcher: FSWatcher; +const watchQueue = new Set(); +let hasStarted = false; +export function enable({ + enableGlobbing +}: { + enableGlobbing: boolean; +}) { + isWatchMode = true; + const { + FSWatcher + } = requireChokidar(); + const options: WatchOptions = { + disableGlobbing: !enableGlobbing, + persistent: true, + ignoreInitial: true, + awaitWriteFinish: { + stabilityThreshold: 50, + pollInterval: 10 + } + }; + watcher = new FSWatcher(options); + watcher.on("unlink", unwatchFile); +} +export function startWatcher() { + hasStarted = true; + + for (const dep of watchQueue) { + watcher.add(dep); + } + + watchQueue.clear(); + watcher.on("ready", () => { + console.log("The watcher is ready."); + }); +} +export function watch(filename: string): void { + if (!isWatchMode) { + throw new Error("Internal Babel error: .watch called when not in watch mode."); + } + + if (!hasStarted) { + watchQueue.add(path.resolve(filename)); + } else { + watcher.add(path.resolve(filename)); + } +} +/** + * Call @param callback whenever a dependency (source file)/ + * external dependency (non-source file) changes. + * + * Handles mapping external dependencies to their corresponding + * dependencies. + */ + +export function onFilesChange(callback: (filenames: string[], event: string, cause: string) => void): void { + if (!isWatchMode) { + throw new Error("Internal Babel error: .onFilesChange called when not in watch mode."); + } + + watcher.on("all", (event, filename) => { + if (event !== "change" && event !== "add") return; + const absoluteFile = path.resolve(filename); + callback([absoluteFile, ...(depToFiles.get(absoluteFile) ?? [])], event, absoluteFile); + }); +} +export function updateExternalDependencies(filename: string, dependencies: Set) { + if (!isWatchMode) return; // Use absolute paths + + const absFilename = path.resolve(filename); + const absDependencies = new Set(Array.from(dependencies, dep => path.resolve(dep))); + const deps = fileToDeps.get(absFilename); + + if (deps) { + for (const dep of deps) { + if (!absDependencies.has(dep)) { + removeFileDependency(absFilename, dep); + } + } + } + + for (const dep of absDependencies) { + let deps = depToFiles.get(dep); + + if (!deps) { + depToFiles.set(dep, deps = new Set()); + + if (!hasStarted) { + watchQueue.add(dep); + } else { + watcher.add(dep); + } + } + + deps.add(absFilename); + } + + fileToDeps.set(absFilename, absDependencies); +} + +function removeFileDependency(filename: string, dep: string) { + const deps = (depToFiles.get(dep) as Set); + deps.delete(filename); + + if (deps.size === 0) { + depToFiles.delete(dep); + + if (!hasStarted) { + watchQueue.delete(dep); + } else { + watcher.unwatch(dep); + } + } +} + +function unwatchFile(filename: string) { + const deps = fileToDeps.get(filename); + if (!deps) return; + + for (const dep of deps) { + removeFileDependency(filename, dep); + } + + fileToDeps.delete(filename); +} + +function requireChokidar(): any { + const require = createRequire(import.meta.url); + + try { + return process.env.BABEL_8_BREAKING ? require("chokidar") : parseInt(process.versions.node) >= 8 ? require("chokidar") : require("@nicolo-ribaudo/chokidar-2"); + } catch (err) { + console.error("The optional dependency chokidar failed to install and is required for " + "--watch. Chokidar is likely not supported on your platform."); + throw err; + } +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json new file mode 100644 index 000000000000..541ebd4329e8 --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file1/source-map.json @@ -0,0 +1,78 @@ +{ + "version": 3, + "names": [ + "createRequire", + "path", + "WatchOptions", + "FSWatcher", + "fileToDeps", + "Map", + "Set", + "depToFiles", + "isWatchMode", + "watcher", + "watchQueue", + "hasStarted", + "enable", + "enableGlobbing", + "requireChokidar", + "options", + "disableGlobbing", + "persistent", + "ignoreInitial", + "awaitWriteFinish", + "stabilityThreshold", + "pollInterval", + "on", + "unwatchFile", + "startWatcher", + "dep", + "add", + "clear", + "console", + "log", + "watch", + "filename", + "Error", + "resolve", + "onFilesChange", + "callback", + "filenames", + "event", + "cause", + "absoluteFile", + "get", + "updateExternalDependencies", + "dependencies", + "absFilename", + "absDependencies", + "Array", + "from", + "deps", + "has", + "removeFileDependency", + "set", + "delete", + "size", + "unwatch", + "require", + "import", + "meta", + "url", + "process", + "env", + "BABEL_8_BREAKING", + "parseInt", + "versions", + "node", + "err", + "error" + ], + "sources": [ + "fixtures/sourcemaps/real-world-babel-file1/input.ts" + ], + "sourcesContent": [ + "// From packages\\babel-cli\\src\\babel\\watcher.ts\n\nimport { createRequire } from \"module\";\nimport path from \"path\";\nimport type { WatchOptions, FSWatcher } from \"chokidar\";\n\nconst fileToDeps = new Map>();\nconst depToFiles = new Map>();\n\nlet isWatchMode = false;\nlet watcher: FSWatcher;\nconst watchQueue = new Set();\nlet hasStarted = false;\n\nexport function enable({ enableGlobbing }: { enableGlobbing: boolean }) {\n isWatchMode = true;\n\n const { FSWatcher } = requireChokidar();\n\n const options: WatchOptions = {\n disableGlobbing: !enableGlobbing,\n persistent: true,\n ignoreInitial: true,\n awaitWriteFinish: {\n stabilityThreshold: 50,\n pollInterval: 10,\n },\n };\n watcher = new FSWatcher(options);\n\n watcher.on(\"unlink\", unwatchFile);\n}\n\nexport function startWatcher() {\n hasStarted = true;\n\n for (const dep of watchQueue) {\n watcher.add(dep);\n }\n watchQueue.clear();\n\n watcher.on(\"ready\", () => {\n console.log(\"The watcher is ready.\");\n });\n}\n\nexport function watch(filename: string): void {\n if (!isWatchMode) {\n throw new Error(\n \"Internal Babel error: .watch called when not in watch mode.\",\n );\n }\n\n if (!hasStarted) {\n watchQueue.add(path.resolve(filename));\n } else {\n watcher.add(path.resolve(filename));\n }\n}\n\n/**\n * Call @param callback whenever a dependency (source file)/\n * external dependency (non-source file) changes.\n *\n * Handles mapping external dependencies to their corresponding\n * dependencies.\n */\nexport function onFilesChange(\n callback: (filenames: string[], event: string, cause: string) => void,\n): void {\n if (!isWatchMode) {\n throw new Error(\n \"Internal Babel error: .onFilesChange called when not in watch mode.\",\n );\n }\n\n watcher.on(\"all\", (event, filename) => {\n if (event !== \"change\" && event !== \"add\") return;\n\n const absoluteFile = path.resolve(filename);\n callback(\n [absoluteFile, ...(depToFiles.get(absoluteFile) ?? [])],\n event,\n absoluteFile,\n );\n });\n}\n\nexport function updateExternalDependencies(\n filename: string,\n dependencies: Set,\n) {\n if (!isWatchMode) return;\n\n // Use absolute paths\n const absFilename = path.resolve(filename);\n const absDependencies = new Set(\n Array.from(dependencies, dep => path.resolve(dep)),\n );\n\n const deps = fileToDeps.get(absFilename);\n if (deps) {\n for (const dep of deps) {\n if (!absDependencies.has(dep)) {\n removeFileDependency(absFilename, dep);\n }\n }\n }\n for (const dep of absDependencies) {\n let deps = depToFiles.get(dep);\n if (!deps) {\n depToFiles.set(dep, (deps = new Set()));\n\n if (!hasStarted) {\n watchQueue.add(dep);\n } else {\n watcher.add(dep);\n }\n }\n\n deps.add(absFilename);\n }\n\n fileToDeps.set(absFilename, absDependencies);\n}\n\nfunction removeFileDependency(filename: string, dep: string) {\n const deps = depToFiles.get(dep) as Set;\n deps.delete(filename);\n\n if (deps.size === 0) {\n depToFiles.delete(dep);\n\n if (!hasStarted) {\n watchQueue.delete(dep);\n } else {\n watcher.unwatch(dep);\n }\n }\n}\n\nfunction unwatchFile(filename: string) {\n const deps = fileToDeps.get(filename);\n if (!deps) return;\n\n for (const dep of deps) {\n removeFileDependency(filename, dep);\n }\n fileToDeps.delete(filename);\n}\n\nfunction requireChokidar(): any {\n const require = createRequire(import.meta.url);\n\n try {\n return process.env.BABEL_8_BREAKING\n ? require(\"chokidar\")\n : parseInt(process.versions.node) >= 8\n ? require(\"chokidar\")\n : require(\"@nicolo-ribaudo/chokidar-2\");\n } catch (err) {\n console.error(\n \"The optional dependency chokidar failed to install and is required for \" +\n \"--watch. Chokidar is likely not supported on your platform.\",\n );\n throw err;\n }\n}" + ], + "mappings": "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" +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/input.ts b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/input.ts new file mode 100644 index 000000000000..2220d7e94d4e --- /dev/null +++ b/packages/babel-generator/test/fixtures/sourcemaps/real-world-babel-file2/input.ts @@ -0,0 +1,888 @@ +// From packages\babel-generator\src\printer.ts + +import Buffer from "./buffer"; +import type { Loc } from "./buffer"; +import * as n from "./node"; +import type * as t from "@babel/types"; +import type { + RecordAndTuplePluginOptions, + PipelineOperatorPluginOptions, +} from "@babel/parser"; +import type { Opts as jsescOptions } from "jsesc"; + +import * as generatorFunctions from "./generators"; +import type SourceMap from "./source-map"; +import * as charCodes from "charcodes"; + +const SCIENTIFIC_NOTATION = /e/i; +const ZERO_DECIMAL_INTEGER = /\.0+$/; +const NON_DECIMAL_LITERAL = /^0[box]/; +const PURE_ANNOTATION_RE = /^\s*[@#]__PURE__\s*$/; + +const { needsParens, needsWhitespaceAfter, needsWhitespaceBefore } = n; + +export type Format = { + shouldPrintComment: (comment: string) => boolean; + retainLines: boolean; + retainFunctionParens: boolean; + comments: boolean; + auxiliaryCommentBefore: string; + auxiliaryCommentAfter: string; + compact: boolean | "auto"; + minified: boolean; + concise: boolean; + indent: { + adjustMultilineComment: boolean; + style: string; + }; + recordAndTupleSyntaxType: RecordAndTuplePluginOptions["syntaxType"]; + jsescOption: jsescOptions; + jsonCompatibleStrings?: boolean; + /** + * For use with the Hack-style pipe operator. + * Changes what token is used for pipe bodies’ topic references. + */ + topicToken?: PipelineOperatorPluginOptions["topicToken"]; + /** + * @deprecated Removed in Babel 8 + */ + decoratorsBeforeExport?: boolean; +}; + +interface AddNewlinesOptions { + addNewlines(leading: boolean, node: t.Node): number; +} + +interface PrintSequenceOptions extends Partial { + statement?: boolean; + indent?: boolean; +} + +interface PrintListOptions { + separator?: (this: Printer) => void; + statement?: boolean; + indent?: boolean; +} + +type PrintJoinOptions = PrintListOptions & + PrintSequenceOptions & { + iterator?: (node: t.Node, index: number) => void; + }; +class Printer { + constructor(format: Format, map: SourceMap) { + this.format = format; + this._buf = new Buffer(map); + + this._indentChar = format.indent.style.charCodeAt(0); + this._indentRepeat = format.indent.style.length; + } + + declare format: Format; + inForStatementInitCounter: number = 0; + + declare _buf: Buffer; + _printStack: Array = []; + _indent: number = 0; + _indentChar: number = 0; + _indentRepeat: number = 0; + _insideAux: boolean = false; + _parenPushNewlineState: { printed: boolean } | null = null; + _noLineTerminator: boolean = false; + _printAuxAfterOnNextUserNode: boolean = false; + _printedComments = new Set(); + _endsWithInteger = false; + _endsWithWord = false; + + generate(ast: t.Node) { + this.print(ast); + this._maybeAddAuxComment(); + + return this._buf.get(); + } + + /** + * Increment indent size. + */ + + indent(): void { + if (this.format.compact || this.format.concise) return; + + this._indent++; + } + + /** + * Decrement indent size. + */ + + dedent(): void { + if (this.format.compact || this.format.concise) return; + + this._indent--; + } + + /** + * Add a semicolon to the buffer. + */ + + semicolon(force: boolean = false): void { + this._maybeAddAuxComment(); + if (force) { + this._appendChar(charCodes.semicolon); + } else { + this._queue(charCodes.semicolon); + } + } + + /** + * Add a right brace to the buffer. + */ + + rightBrace(): void { + if (this.format.minified) { + this._buf.removeLastSemicolon(); + } + this.token("}"); + } + + /** + * Add a space to the buffer unless it is compact. + */ + + space(force: boolean = false): void { + if (this.format.compact) return; + + if (force) { + this._space(); + } else if (this._buf.hasContent()) { + const lastCp = this.getLastChar(); + if (lastCp !== charCodes.space && lastCp !== charCodes.lineFeed) { + this._space(); + } + } + } + + /** + * Writes a token that can't be safely parsed without taking whitespace into account. + */ + + word(str: string): void { + // prevent concatenating words and creating // comment out of division and regex + if ( + this._endsWithWord || + (str.charCodeAt(0) === charCodes.slash && this.endsWith(charCodes.slash)) + ) { + this._space(); + } + + this._maybeAddAuxComment(); + this._append(str, false); + + this._endsWithWord = true; + } + + /** + * Writes a number token so that we can validate if it is an integer. + */ + + number(str: string): void { + this.word(str); + + // Integer tokens need special handling because they cannot have '.'s inserted + // immediately after them. + this._endsWithInteger = + Number.isInteger(+str) && + !NON_DECIMAL_LITERAL.test(str) && + !SCIENTIFIC_NOTATION.test(str) && + !ZERO_DECIMAL_INTEGER.test(str) && + str.charCodeAt(str.length - 1) !== charCodes.dot; + } + + /** + * Writes a simple token. + */ + + token(str: string, maybeNewline = false): void { + // space is mandatory to avoid outputting