From f71402b56e81b7ca9492ae7d2cf4c24239e7cd7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 30 Sep 2020 09:58:28 -0400 Subject: [PATCH] feat: support { "some imports" as "some exports" } in systemjs --- .../src/index.js | 6 +++++- .../export-from-string-as-string/input.mjs | 1 + .../export-from-string-as-string/output.mjs | 10 ++++++++++ .../export-from-string/input.mjs | 1 + .../export-from-string/output.mjs | 10 ++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/output.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/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 607fd01005c9..f30daf04b52d 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.js @@ -519,7 +519,11 @@ export default declare((api, options) => { ); exportNames.push(exportedName); exportValues.push( - t.memberExpression(t.identifier(target), node.local), + t.memberExpression( + t.identifier(target), + node.local, + t.isStringLiteral(node.local), + ), ); } else { // todo diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/input.mjs new file mode 100644 index 000000000000..9af06dedb8e3 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/input.mjs @@ -0,0 +1 @@ +export { "some imports" as "some exports" } from "foo"; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/output.mjs new file mode 100644 index 000000000000..a05cb4a573b1 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string-as-string/output.mjs @@ -0,0 +1,10 @@ +System.register(["foo"], function (_export, _context) { + "use strict"; + + return { + setters: [function (_foo) { + _export("some exports", _foo["some imports"]); + }], + execute: function () {} + }; +}); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/input.mjs new file mode 100644 index 000000000000..cf064000fd95 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/input.mjs @@ -0,0 +1 @@ +export { "some exports" } from "foo"; diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/output.mjs new file mode 100644 index 000000000000..958e879b24fc --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/interop-module-string-names/export-from-string/output.mjs @@ -0,0 +1,10 @@ +System.register(["foo"], function (_export, _context) { + "use strict"; + + return { + setters: [function (_foo) { + _export("some exports", _foo["some exports"]); + }], + execute: function () {} + }; +});