fix(needsHoisting): properly hoist function definitions
Function definitions aren't assignments: they should always be
in scope.
MODIFY
src/babelPlugin.js
src/babelPlugin.js
@@ -90,13 +90,17 @@ function makeModulePlugins(options) {
if (needsHoisting) {
// Hoist the declaration and soften.
soften(id);
- options.hoistedDecls.push(name);
+ if (needsHoisting === 'function') {
+ options.hoistedDecls.push([name, id.name]);
+ } else {
// Rewrite to be just name = value.
+ options.hoistedDecls.push([name]);
prior.push(
t.expressionStatement(
t.assignmentExpression('=', t.identifier(name), id),
),
);
+ }
for (const importTo of topLevelExported[name]) {
liveExportMap[importTo] = [name, true];
}
@@ -133,7 +137,9 @@ function makeModulePlugins(options) {
const replace = rewriteVars(
vids,
isConst,
- !isConst && decl.kind !== 'let',
+ decl.type === 'FunctionDeclaration'
+ ? 'function'
+ : !isConst && decl.kind !== 'let',
);
if (replace.length > 0) {

MODIFY
src/index.js
src/index.js
@@ -113,7 +113,7 @@ const makeModuleTransformer = (babelCore, importer) => {
)
.join(',')}]));`;
preamble += sourceOptions.hoistedDecls
- .map(vname => `${h.HIDDEN_LIVE}.${vname}();`)
+ .map(([vname, cvname]) => `${h.HIDDEN_LIVE}.${vname}(${cvname || ''});`)
.join('');
// The functor captures the SES `arguments`, which is definitely

fix(needsHoisting): properly hoist function definitions

Function definitions aren't assignments: they should always be
in scope.