Skip to content

Commit

Permalink
Instrument: Correctly set isVar for nested function declarations [i…
Browse files Browse the repository at this point in the history
…mprove]

Makes no actual difference, as `isVar` is only used minimally, but better to make it correct.
  • Loading branch information
overlookmotel committed Aug 31, 2023
1 parent 0b883ea commit 8b49cd3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/instrument/visitors/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ function FunctionDeclaration(node, state, parent, key) {
// Existing binding must be a `var` declaration or another function declaration
binding.isFunction = true;
} else {
binding = createBinding(block, fnName, {isVar: true, isFunction: true}, state);
const isTopLevel = block === hoistBlock;
binding = createBinding(block, fnName, {isVar: isTopLevel, isFunction: true}, state);

// If is a sloppy-mode function declaration which may need to be hoisted, record that.
// Determine whether to hoist after 1st pass is complete, once all other bindings created.
if (block !== hoistBlock && !state.isStrict && !node.async && !node.generator) {
if (!isTopLevel && !state.isStrict && !node.async && !node.generator) {
state.sloppyFunctionDeclarations.push({varName: fnName, binding, block, hoistBlock});
}
}
Expand Down Expand Up @@ -564,7 +565,7 @@ function hoistSloppyFunctionDeclaration(declaration) {
if (hoistBlockBinding) {
hoistBlockBinding.isFunction = true;
} else {
hoistBlock.bindings[varName] = declaration.binding;
hoistBlock.bindings[varName] = {...declaration.binding, isVar: true};
}
}

Expand Down

0 comments on commit 8b49cd3

Please sign in to comment.