System module format - fixes function hoisting failure case (#8820)
* failing test case * fix function hoist bug
This commit is contained in:
parent
850bc1d3dd
commit
3fa4f53d0a
@ -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,
|
||||
|
||||
10
packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/input.mjs
vendored
Normal file
10
packages/babel-plugin-transform-modules-systemjs/test/fixtures/systemjs/export-fn-decl/input.mjs
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
var testProp = 'test property';
|
||||
|
||||
function testFunc() {
|
||||
return 'test function';
|
||||
}
|
||||
|
||||
export {
|
||||
testFunc,
|
||||
testProp
|
||||
};
|
||||
@ -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');
|
||||
}
|
||||
};
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user