fix(static-module-record): preserve function hoisting when export defaulted
MODIFY
packages/static-module-record/src/babelPlugin.js
packages/static-module-record/src/babelPlugin.js
@@ -62,19 +62,22 @@ function makeModulePlugins(options) {
};
const markExported = (name, force = undefined) => {
- if (force === 'fixed' || (!force && topLevelIsOnce[name])) {
+ const isOnce = topLevelIsOnce[name];
+ if (force === 'fixed' || (!force && isOnce)) {
topLevelExported[name].forEach(
importTo => (fixedExportMap[importTo] = [name]),
);
return hOnceId;
}
- if (force === 'live' || (!force && !topLevelIsOnce[name])) {
+ if (force === 'live' || (!force && !isOnce)) {
topLevelExported[name].forEach(
importTo => (liveExportMap[importTo] = [name, true]),
);
return hLiveId;
}
+
+ return undefined;
};
const rewriteVars = (vids, isConst, needsHoisting) =>
@@ -307,7 +310,7 @@ function makeModulePlugins(options) {
return;
}
- // const {default: $c_default} = {default: expr.id}; $h_once.default($c_default);
+ // const {default: $c_default} = {default: (XXX)}; $h_once.default($c_default);
path.replaceWithMultiple([
t.variableDeclaration('const', [
t.variableDeclarator(

MODIFY
packages/static-module-record/test/test-static-module-record.js
packages/static-module-record/test/test-static-module-record.js
@@ -396,7 +396,7 @@ export function F(arg) { return arg; }
t.is(F.name, 'F', 'F function name');
});
-test.failing('hoist default async export named function', async t => {
+test('hoist default async export named function', async t => {
const { namespace } = initialize(
t,
`\
@@ -404,22 +404,21 @@ F(123);
export default async function F(arg) { return arg; }
`,
);
- const { F } = namespace;
+ const { default: F } = namespace;
t.is(F.name, 'F', 'F function name');
const ret = F('foo');
t.truthy(ret instanceof Promise, 'F is async');
t.is(await ret, 'foo', 'F returns correctly');
});
-test.failing('hoist default async export anonymous function', async t => {
+test('hoist default async export anonymous function', async t => {
const { namespace } = initialize(
t,
`\
-F(123);
export default async function (arg) { return arg; }
`,
);
- const { F } = namespace;
+ const { default: F } = namespace;
t.is(F.name, 'default', 'default function name');
const ret = F('foo');
t.truthy(ret instanceof Promise, 'F is async');

fix(static-module-record): preserve function hoisting when export defaulted