From 7da7e760a6ffa6566a0e949ad5344a68f4a428c4 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 1 Jun 2018 23:07:29 +0200 Subject: [PATCH] support import.meta in system transform --- .../src/index.js | 14 ++++++++++++++ .../fixtures/dynamic-import/import-meta/input.mjs | 1 + .../fixtures/dynamic-import/import-meta/output.mjs | 10 ++++++++++ .../test/fixtures/dynamic-import/options.json | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/input.mjs create mode 100644 packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/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 3111665fa9..4e4085a9cd 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.js @@ -87,6 +87,20 @@ export default declare((api, options) => { } }, + MetaProperty(path, state) { + if ( + path.node.meta.name === "import" && + path.node.property.name === "meta" + ) { + path.replaceWith( + t.memberExpression( + t.identifier(state.contextIdent), + t.identifier("meta"), + ), + ); + } + }, + ReferencedIdentifier(path, state) { if ( path.node.name == "__moduleName" && diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/input.mjs new file mode 100644 index 0000000000..0c4061a00d --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/input.mjs @@ -0,0 +1 @@ +console.log(import.meta.url); \ No newline at end of file diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/output.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/output.mjs new file mode 100644 index 0000000000..2d127a5d0e --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/import-meta/output.mjs @@ -0,0 +1,10 @@ +System.register([], function (_export, _context) { + "use strict"; + + return { + setters: [], + execute: function () { + console.log(_context.meta.url); + } + }; +}); diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/options.json b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/options.json index e10d38ab34..d9d5e3ac62 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/options.json +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/dynamic-import/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "syntax-dynamic-import", "transform-modules-systemjs"] + "plugins": ["external-helpers", "syntax-dynamic-import", "syntax-import-meta", "transform-modules-systemjs"] }