Skip to content

Commit

Permalink
Inline function [refactor]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 17, 2023
1 parent 0c308b8 commit 0130861
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions lib/instrument/visitors/identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ function NewTargetExpression(node, state) {
function visitIdentifier(node, varName, isReadFrom, isAssignedTo, state) {
const fn = state.currentFunction;
if (fn) {
resolveIdentifierInSecondPass(
node, state.currentBlock, varName, fn, isReadFrom, isAssignedTo, state
// Resolve the binding var refers to in 2nd pass
state.secondPass(
resolveIdentifier,
node, state.currentBlock, varName, fn, [...state.trail],
isReadFrom, isAssignedTo, state.isStrict, state
);
} else {
// Not inside a function, so identifier won't be resolved and therefore misses out
Expand All @@ -133,24 +136,6 @@ function visitIdentifier(node, varName, isReadFrom, isAssignedTo, state) {
}
}

/**
* Schedule resolving the binding var refers to and recording it's usage in parent function in 2nd pass.
* @param {Object} node - Identifier or `this` expression AST node
* @param {Object} block - Block object
* @param {string} varName - Var name
* @param {Object} fn - Function object for function identifier is within
* @param {boolean} isReadFrom - `true` if variable is read from e.g. `x + 1`, `x++`
* @param {boolean} isAssignedTo - `true` if variable is assigned to e.g. `x = 1`, `x++`
* @param {Object} state - State object
* @returns {undefined}
*/
function resolveIdentifierInSecondPass(node, block, varName, fn, isReadFrom, isAssignedTo, state) {
state.secondPass(
resolveIdentifier,
node, block, varName, fn, [...state.trail], isReadFrom, isAssignedTo, state.isStrict, state
);
}

/**
* Resolve binding an identifier refers to and record its usage on function it's used within.
* @param {Object} node - Identifier AST node (not needed but passed for debug reasons)
Expand Down

0 comments on commit 0130861

Please sign in to comment.