diff --git a/packages/babel-plugin-transform-modules-systemjs/src/index.js b/packages/babel-plugin-transform-modules-systemjs/src/index.js index 5f93094be5..242d132163 100644 --- a/packages/babel-plugin-transform-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-modules-systemjs/src/index.js @@ -332,8 +332,23 @@ export default declare((api, options) => { const nodes = []; for (const specifier of specifiers) { - // only globals exported this way - if (!path.scope.getBinding(specifier.local.name)) { + const binding = path.scope.getBinding( + specifier.local.name, + ); + // hoisted function export + if ( + binding && + t.isFunctionDeclaration(binding.path.node) + ) { + beforeBody.push( + buildExportCall( + specifier.exported.name, + t.cloneNode(specifier.local), + ), + ); + } + // only globals also exported this way + else if (!binding) { nodes.push( buildExportCall( specifier.exported.name, diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/input.mjs b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/input.mjs new file mode 100644 index 0000000000..3c230f1867 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/input.mjs @@ -0,0 +1,10 @@ +var testProp = 'test property'; + +function testFunc() { + return 'test function'; +} + +export { + testFunc, + testProp +}; 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 new file mode 100644 index 0000000000..c3c2159be3 --- /dev/null +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/output.mjs @@ -0,0 +1,18 @@ +System.register([], function (_export, _context) { + "use strict"; + + var testProp; + + function testFunc() { + return 'test function'; + } + + _export("testFunc", testFunc); + + return { + setters: [], + execute: function () { + _export("testProp", testProp = 'test property'); + } + }; +}); \ No newline at end of file