From 45f4c1f07f68617e5e819a87a78f0bc5999d4482 Mon Sep 17 00:00:00 2001 From: Sneh Khatri Date: Wed, 15 Dec 2021 22:02:44 +0530 Subject: [PATCH 1/9] Fix: modules-systemjs transformation --- .../babel-helper-hoist-variables/src/index.ts | 3 +++ .../output.js | 6 +++--- .../output.js | 6 +++--- .../exec.js | 2 +- .../output.js | 8 ++++---- .../systemjs/export-fn-decl/output.mjs | 2 +- .../systemjs/module-level-variable/input.mjs | 8 ++++++++ .../systemjs/module-level-variable/output.mjs | 19 +++++++++++++++++++ 8 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs diff --git a/packages/babel-helper-hoist-variables/src/index.ts b/packages/babel-helper-hoist-variables/src/index.ts index 1cb3b8a3c4c5..bc2aa485c7af 100644 --- a/packages/babel-helper-hoist-variables/src/index.ts +++ b/packages/babel-helper-hoist-variables/src/index.ts @@ -40,6 +40,9 @@ const visitor = { for (const declar of declarations) { firstId = declar.node.id; + if (declar.parentPath.parentPath.isBlockStatement()) { + declar.scope.rename(declar.node.id.name); + } if (declar.node.init) { nodes.push( diff --git a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js index 076bb9588515..4946e58376f4 100644 --- a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js +++ b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js @@ -1,6 +1,6 @@ -var y; +var _y; const x = (async () => { - y = 21; - return y + y; + _y = 21; + return _y + _y; })(); diff --git a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js index c16ec333a147..8e51b31f9280 100644 --- a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js +++ b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js @@ -1,7 +1,7 @@ -var y; +var _y; const x = (async () => { await Promise.resolve(); - y = 21; - return y + y; + _y = 21; + return _y + _y; })(); diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js index 455e0b795f0c..180343ca6231 100644 --- a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js @@ -7,4 +7,4 @@ expect( bar; } ).toBe("foo"); -expect(bar).toBe("foo"); +// expect(bar).toBe("foo"); diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js index 0444f3903f31..5135743702d8 100644 --- a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js @@ -1,7 +1,7 @@ -var bar; +var _bar; var x = function () { - bar = "foo"; - if (!bar) throw new Error("unreachable"); - return bar; + _bar = "foo"; + if (!_bar) throw new Error("unreachable"); + return _bar; }(); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/output.mjs index c3c2159be301..fbb9746586f9 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/output.mjs @@ -15,4 +15,4 @@ System.register([], function (_export, _context) { _export("testProp", testProp = 'test property'); } }; -}); \ No newline at end of file +}); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/input.mjs new file mode 100644 index 000000000000..5d2aef55c5e9 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/input.mjs @@ -0,0 +1,8 @@ +import { x } from './x.js'; + +if (true) { + const x = 1; + console.log(x); +} + +new (class extends x {})(); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs new file mode 100644 index 000000000000..e73a807698f8 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs @@ -0,0 +1,19 @@ +System.register(["./x.js"], function (_export, _context) { + "use strict"; + + var x, _x; + + return { + setters: [function (_xJs) { + x = _xJs.x; + }], + execute: function () { + if (true) { + _x = 1; + console.log(_x); + } + + new class extends x {}(); + } + }; +}); From 8199f3130f0c6acda6e05fec6dabdb0acb4cc155 Mon Sep 17 00:00:00 2001 From: Sneh Khatri Date: Tue, 21 Dec 2021 11:49:31 +0530 Subject: [PATCH 2/9] var declarations won't be renamed --- packages/babel-helper-hoist-variables/src/index.ts | 5 ++++- .../hoist-variables-assgined-in-sync-context/output.js | 6 +++--- .../hoist-variables-assigned-in-async-context/output.js | 6 +++--- .../variable-declaration-start-to-iife/output.js | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/babel-helper-hoist-variables/src/index.ts b/packages/babel-helper-hoist-variables/src/index.ts index bc2aa485c7af..f175c4d291ce 100644 --- a/packages/babel-helper-hoist-variables/src/index.ts +++ b/packages/babel-helper-hoist-variables/src/index.ts @@ -40,7 +40,10 @@ const visitor = { for (const declar of declarations) { firstId = declar.node.id; - if (declar.parentPath.parentPath.isBlockStatement()) { + if ( + declar.parentPath.parentPath.isBlockStatement() && + declar.parent.kind !== "var" + ) { declar.scope.rename(declar.node.id.name); } diff --git a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js index 4946e58376f4..076bb9588515 100644 --- a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js +++ b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assgined-in-sync-context/output.js @@ -1,6 +1,6 @@ -var _y; +var y; const x = (async () => { - _y = 21; - return _y + _y; + y = 21; + return y + y; })(); diff --git a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js index 8e51b31f9280..c16ec333a147 100644 --- a/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js +++ b/packages/babel-plugin-proposal-async-do-expressions/test/fixtures/async-do-expressions/hoist-variables-assigned-in-async-context/output.js @@ -1,7 +1,7 @@ -var _y; +var y; const x = (async () => { await Promise.resolve(); - _y = 21; - return _y + _y; + y = 21; + return y + y; })(); diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js index 5135743702d8..0444f3903f31 100644 --- a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/output.js @@ -1,7 +1,7 @@ -var _bar; +var bar; var x = function () { - _bar = "foo"; - if (!_bar) throw new Error("unreachable"); - return _bar; + bar = "foo"; + if (!bar) throw new Error("unreachable"); + return bar; }(); From 69c067b2c3f175e9cd6a9111dd06d84db34eb669 Mon Sep 17 00:00:00 2001 From: Sneh Khatri Date: Wed, 22 Dec 2021 14:53:02 +0530 Subject: [PATCH 3/9] check hoisted outside the for loop --- packages/babel-helper-hoist-variables/src/index.ts | 8 ++++---- .../variable-declaration-start-to-iife/exec.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/babel-helper-hoist-variables/src/index.ts b/packages/babel-helper-hoist-variables/src/index.ts index f175c4d291ce..d3aa2934fe4e 100644 --- a/packages/babel-helper-hoist-variables/src/index.ts +++ b/packages/babel-helper-hoist-variables/src/index.ts @@ -38,12 +38,12 @@ const visitor = { > = path.get("declarations"); let firstId; + const needsRename = + path.node.kind !== "var" && path.parentPath.isBlockStatement(); + for (const declar of declarations) { firstId = declar.node.id; - if ( - declar.parentPath.parentPath.isBlockStatement() && - declar.parent.kind !== "var" - ) { + if (needsRename) { declar.scope.rename(declar.node.id.name); } diff --git a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js index 180343ca6231..455e0b795f0c 100644 --- a/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js +++ b/packages/babel-plugin-proposal-do-expressions/test/fixtures/do-expressions/variable-declaration-start-to-iife/exec.js @@ -7,4 +7,4 @@ expect( bar; } ).toBe("foo"); -// expect(bar).toBe("foo"); +expect(bar).toBe("foo"); From a312fe237b98c994ad518f8c52d51688660f52c1 Mon Sep 17 00:00:00 2001 From: Sneh Khatri Date: Mon, 3 Jan 2022 16:06:07 +0530 Subject: [PATCH 4/9] TS warning fixed --- packages/babel-helper-hoist-variables/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-hoist-variables/src/index.ts b/packages/babel-helper-hoist-variables/src/index.ts index d3aa2934fe4e..ddf0e7d88615 100644 --- a/packages/babel-helper-hoist-variables/src/index.ts +++ b/packages/babel-helper-hoist-variables/src/index.ts @@ -44,7 +44,9 @@ const visitor = { for (const declar of declarations) { firstId = declar.node.id; if (needsRename) { - declar.scope.rename(declar.node.id.name); + for (const name of Object.keys(declar.getBindingIdentifiers())) { + declar.scope.rename(name); + } } if (declar.node.init) { From 15714de4b195b3645b0cf0b64336dc4904ee2e58 Mon Sep 17 00:00:00 2001 From: Sneh Khatri Date: Tue, 4 Jan 2022 16:42:06 +0530 Subject: [PATCH 5/9] test added for destructuring --- .../input.mjs | 8 +++++++ .../output.mjs | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/input.mjs new file mode 100644 index 000000000000..035f6e9ba424 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/input.mjs @@ -0,0 +1,8 @@ +import { x } from './x.js'; + +if (true) { + const { x } = { x: 1 }; + console.log(x); +} + +new (class extends x {})(); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs new file mode 100644 index 000000000000..81eee80931c7 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs @@ -0,0 +1,23 @@ +System.register(["./x.js"], function (_export, _context) { + "use strict"; + + var x, _x; + + return { + setters: [function (_xJs) { + x = _xJs.x; + }], + execute: function () { + if (true) { + ({ + x: _x + } = { + x: 1 + }); + console.log(_x); + } + + new class extends x {}(); + } + }; +}); From 6fe46d8e09409054743a9adf19aa78ac526e40e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 16 Mar 2022 22:31:23 +0100 Subject: [PATCH 6/9] Improve TS types --- .../src/index.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/babel-plugin-transform-modules-systemjs/src/index.ts b/packages/babel-plugin-transform-modules-systemjs/src/index.ts index 6a573f487bf5..4d74fd3616f3 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.ts +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.ts @@ -4,8 +4,9 @@ import { template, types as t } from "@babel/core"; import { getImportSource } from "babel-plugin-dynamic-import-node/utils"; import { rewriteThis, getModuleName } from "@babel/helper-module-transforms"; import { isIdentifierName } from "@babel/helper-validator-identifier"; +import type { NodePath } from "@babel/traverse"; -const buildTemplate = template(` +const buildTemplate = template.statement(` SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) { "use strict"; BEFORE_BODY; @@ -16,7 +17,7 @@ const buildTemplate = template(` }); `); -const buildExportAll = template(` +const buildExportAll = template.statement(` for (var KEY in TARGET) { if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY]; } @@ -286,7 +287,7 @@ export default declare((api, options) => { rewriteThis(path); } }, - exit(path, state: PluginState) { + exit(path: NodePath, state: PluginState) { const scope = path.scope; const exportIdent = scope.generateUid("export"); const { contextIdent, stringSpecifiers } = state; @@ -332,7 +333,7 @@ export default declare((api, options) => { const exportNames = []; const exportValues = []; - const body: Array = path.get("body"); + const body = path.get("body"); for (const path of body) { if (path.isFunctionDeclaration()) { @@ -362,8 +363,8 @@ export default declare((api, options) => { path.remove(); } else if (path.isExportDefaultDeclaration()) { const declar = path.get("declaration"); - const id = declar.node.id; if (declar.isClassDeclaration()) { + const id = declar.node.id; if (id) { exportNames.push("default"); exportValues.push(scope.buildUndefinedNode()); @@ -384,6 +385,7 @@ export default declare((api, options) => { removedPaths.push(path); } } else if (declar.isFunctionDeclaration()) { + const id = declar.node.id; if (id) { beforeBody.push(declar.node); exportNames.push("default"); @@ -403,7 +405,7 @@ export default declare((api, options) => { if (declar.node) { path.replaceWith(declar); - if (path.isFunction()) { + if (declar.isFunction()) { const node = declar.node; const name = node.id.name; addExportName(name, name); @@ -411,7 +413,7 @@ export default declare((api, options) => { exportNames.push(name); exportValues.push(t.cloneNode(node.id)); removedPaths.push(path); - } else if (path.isClass()) { + } else if (declar.isClass()) { const name = declar.node.id.name; exportNames.push(name); exportValues.push(scope.buildUndefinedNode()); @@ -443,7 +445,10 @@ export default declare((api, options) => { const nodes = []; for (const specifier of specifiers) { + // @ts-expect-error This isn't an "export ... from" declaration + // because path.node.source is falsy, so the local specifier exists. const { local, exported } = specifier; + const binding = scope.getBinding(local.name); const exportedName = getExportSpecifierName( exported, @@ -565,19 +570,15 @@ export default declare((api, options) => { // @ts-expect-error todo(flow->ts): do not reuse variables if (moduleName) moduleName = t.stringLiteral(moduleName); - hoistVariables( - path, - (id, name, hasInit) => { - variableIds.push(id); - if (!hasInit && name in exportMap) { - for (const exported of exportMap[name]) { - exportNames.push(exported); - exportValues.push(scope.buildUndefinedNode()); - } + hoistVariables(path, (id, name, hasInit) => { + variableIds.push(id); + if (!hasInit && name in exportMap) { + for (const exported of exportMap[name]) { + exportNames.push(exported); + exportValues.push(scope.buildUndefinedNode()); } - }, - null, - ); + } + }); if (variableIds.length) { beforeBody.unshift( @@ -620,6 +621,7 @@ export default declare((api, options) => { Function(path) { path.skip(); }, + // @ts-expect-error - todo: add noScope to type definitions noScope: true, }); From 14e9cfd1e2183e882e266ed8206680607bf1b080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 16 Mar 2022 22:36:43 +0100 Subject: [PATCH 7/9] Don't hoist let/const in blocks --- .../src/index.ts | 9 +++++++++ .../module-level-variable-destructuring/output.mjs | 11 +++++------ .../systemjs/module-level-variable/output.mjs | 7 +++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/babel-plugin-transform-modules-systemjs/src/index.ts b/packages/babel-plugin-transform-modules-systemjs/src/index.ts index 4d74fd3616f3..3841e1421b6e 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.ts +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.ts @@ -350,6 +350,10 @@ export default declare((api, options) => { ), ), ); + } else if (path.isVariableDeclaration()) { + // Convert top-level variable declarations to "var", + // because they must be hoisted + path.node.kind = "var"; } else if (path.isImportDeclaration()) { const source = path.node.source.value; pushModule(source, "imports", path.node.specifiers); @@ -429,6 +433,11 @@ export default declare((api, options) => { ); addExportName(name, name); } else { + if (declar.isVariableDeclaration()) { + // Convert top-level variable declarations to "var", + // because they must be hoisted + declar.node.kind = "var"; + } for (const name of Object.keys( declar.getBindingIdentifiers(), )) { diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs index 81eee80931c7..881cd6c8cd4c 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable-destructuring/output.mjs @@ -1,20 +1,19 @@ System.register(["./x.js"], function (_export, _context) { "use strict"; - var x, _x; - + var x; return { setters: [function (_xJs) { x = _xJs.x; }], execute: function () { if (true) { - ({ - x: _x + const { + x } = { x: 1 - }); - console.log(_x); + }; + console.log(x); } new class extends x {}(); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs index e73a807698f8..d60e0ca64406 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/module-level-variable/output.mjs @@ -1,16 +1,15 @@ System.register(["./x.js"], function (_export, _context) { "use strict"; - var x, _x; - + var x; return { setters: [function (_xJs) { x = _xJs.x; }], execute: function () { if (true) { - _x = 1; - console.log(_x); + const x = 1; + console.log(x); } new class extends x {}(); From aa5593e969f8e2658554d6b7fcd57aabce20ee21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 17 Mar 2022 12:19:33 +0100 Subject: [PATCH 8/9] Revert changes to `helper-hoist-variables` --- packages/babel-helper-hoist-variables/src/index.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/babel-helper-hoist-variables/src/index.ts b/packages/babel-helper-hoist-variables/src/index.ts index ddf0e7d88615..1cb3b8a3c4c5 100644 --- a/packages/babel-helper-hoist-variables/src/index.ts +++ b/packages/babel-helper-hoist-variables/src/index.ts @@ -38,16 +38,8 @@ const visitor = { > = path.get("declarations"); let firstId; - const needsRename = - path.node.kind !== "var" && path.parentPath.isBlockStatement(); - for (const declar of declarations) { firstId = declar.node.id; - if (needsRename) { - for (const name of Object.keys(declar.getBindingIdentifiers())) { - declar.scope.rename(name); - } - } if (declar.node.init) { nodes.push( From aeb81ef3b5e89eb69910a2f5dd6db0ed27c3c96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 17 Mar 2022 12:20:42 +0100 Subject: [PATCH 9/9] Add test --- .../systemjs/export-let-const/input.mjs | 9 ++++++++ .../systemjs/export-let-const/output.mjs | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/output.mjs diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/input.mjs new file mode 100644 index 000000000000..aa63c9567459 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/input.mjs @@ -0,0 +1,9 @@ +let l_foo = 1; +const c_foo = 2; + +{ let l_foo, l_bar; const c_foo = 3; const c_bar = 4; } + +export { l_foo, c_foo }; + +export let l_bar = 4; +export const c_bar = 6; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/output.mjs new file mode 100644 index 000000000000..389e52e886dd --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-let-const/output.mjs @@ -0,0 +1,23 @@ +System.register([], function (_export, _context) { + "use strict"; + + var l_foo, c_foo, l_bar, c_bar; + return { + setters: [], + execute: function () { + _export("l_foo", l_foo = 1); + + _export("c_foo", c_foo = 2); + + { + let l_foo, l_bar; + const c_foo = 3; + const c_bar = 4; + } + + _export("l_bar", l_bar = 4); + + _export("c_bar", c_bar = 6); + } + }; +});