From cf35bb4aa4349ff21df1cdc2568761cee94b4f81 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sun, 11 Oct 2020 05:35:51 -0700 Subject: [PATCH 1/2] systemjs tla support --- .../src/index.js | 23 +++++++++++++++---- .../test/fixtures/tla/not-tla/input.mjs | 1 + .../test/fixtures/tla/not-tla/output.mjs | 10 ++++++++ .../test/fixtures/tla/options.json | 3 +++ .../test/fixtures/tla/tla-block/input.mjs | 3 +++ .../test/fixtures/tla/tla-block/output.mjs | 12 ++++++++++ .../test/fixtures/tla/tla/input.mjs | 2 ++ .../test/fixtures/tla/tla/output.mjs | 10 ++++++++ 8 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/output.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/output.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/output.mjs diff --git a/packages/babel-plugin-transform-modules-systemjs/src/index.js b/packages/babel-plugin-transform-modules-systemjs/src/index.js index 56e9001428b1..edbaa621f1e4 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.js @@ -10,9 +10,7 @@ const buildTemplate = template(` BEFORE_BODY; return { setters: SETTERS, - execute: function () { - BODY; - } + execute: EXECUTE, }; }); `); @@ -547,6 +545,17 @@ export default declare((api, options) => { path.remove(); } + let hasTLA = false; + path.traverse({ + AwaitExpression(path) { + hasTLA = true; + path.stop(); + }, + Function(path) { + path.skip(); + }, + }); + path.node.body = [ buildTemplate({ SYSTEM_REGISTER: t.memberExpression( @@ -556,8 +565,14 @@ export default declare((api, options) => { BEFORE_BODY: beforeBody, MODULE_NAME: moduleName, SETTERS: t.arrayExpression(setters), + EXECUTE: t.functionExpression( + null, + [], + t.blockStatement(path.node.body), + false, + hasTLA, + ), SOURCES: t.arrayExpression(sources), - BODY: path.node.body, EXPORT_IDENTIFIER: t.identifier(exportIdent), CONTEXT_IDENTIFIER: t.identifier(contextIdent), }), diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/input.mjs new file mode 100644 index 000000000000..5987e69429f6 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/input.mjs @@ -0,0 +1 @@ +async () => await test; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/output.mjs new file mode 100644 index 000000000000..1da3c2b62642 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/not-tla/output.mjs @@ -0,0 +1,10 @@ +System.register([], function (_export, _context) { + "use strict"; + + return { + setters: [], + execute: function () { + async () => await test; + } + }; +}); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json new file mode 100644 index 000000000000..39c5d8d3f529 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-modules-systemjs", "syntax-top-level-await"] +} diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/input.mjs new file mode 100644 index 000000000000..87669a0caaa8 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/input.mjs @@ -0,0 +1,3 @@ +if (maybe) { + await test; +} diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/output.mjs new file mode 100644 index 000000000000..0a912481b600 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla-block/output.mjs @@ -0,0 +1,12 @@ +System.register([], function (_export, _context) { + "use strict"; + + return { + setters: [], + execute: async function () { + if (maybe) { + await test; + } + } + }; +}); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/input.mjs new file mode 100644 index 000000000000..c2a4f87ba798 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/input.mjs @@ -0,0 +1,2 @@ +await test; + diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/output.mjs new file mode 100644 index 000000000000..5af85cee630e --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/tla/output.mjs @@ -0,0 +1,10 @@ +System.register([], function (_export, _context) { + "use strict"; + + return { + setters: [], + execute: async function () { + await test; + } + }; +}); From a6e0ff025f3cae0e3b6c522ba4cfaf453c104a78 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 13 Oct 2020 06:53:05 -0700 Subject: [PATCH 2/2] Update packages/babel-plugin-transform-modules-systemjs/src/index.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Huáng Jùnliàng --- packages/babel-plugin-transform-modules-systemjs/src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/babel-plugin-transform-modules-systemjs/src/index.js b/packages/babel-plugin-transform-modules-systemjs/src/index.js index edbaa621f1e4..9e0d142b224b 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.js @@ -554,6 +554,7 @@ export default declare((api, options) => { Function(path) { path.skip(); }, + noScope: true, }); path.node.body = [