in packages/transform/src/hoist.js [85:124]
FunctionDeclaration: function(path) {
let node = path.node;
vars[node.id.name] = node.id;
let assignment = t.expressionStatement(
t.assignmentExpression(
"=",
t.clone(node.id),
t.functionExpression(
path.scope.generateUidIdentifierBasedOnNode(node),
node.params,
node.body,
node.generator,
node.expression
)
)
);
if (path.parentPath.isBlockStatement()) {
// Insert the assignment form before the first statement in the
// enclosing block.
path.parentPath.unshiftContainer("body", assignment);
// Remove the function declaration now that we've inserted the
// equivalent assignment form at the beginning of the block.
path.remove();
} else {
// If the parent node is not a block statement, then we can just
// replace the declaration with the equivalent assignment form
// without worrying about hoisting it.
util.replaceWithOrRemove(path, assignment);
}
// Remove the binding, to avoid "duplicate declaration" errors when it will
// be injected again.
path.scope.removeBinding(node.id.name);
// Don't hoist variables out of inner functions.
path.skip();
},