Skip to content

Commit 6256940

Browse files
committed
fix(codemod): walk through container nodes in declaredBeforeUse hoist check
The runs check for function-like nodes only looked at the immediate parent, missing parenthesized IIFEs (whose parent is ParenthesizedExpression, not CallExpression) and methods/arrows nested inside object or array arguments of a call. Walk up through ParenthesizedExpression, PropertyAssignment, ObjectLiteralExpression, ArrayLiteralExpression, and SpreadElement before checking whether the ancestor is a call whose callee or argument the function is.
1 parent 34b5e90 commit 6256940

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/codemod/src/transform.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,20 @@ class ModuleTransform {
863863
const visit = (/** @type {ts.Node} */ node) => {
864864
if (!safe) return;
865865
if (isFunctionLike(node)) {
866-
const call = node.parent;
866+
let wrapped = /** @type {ts.Node} */ (node);
867+
while (
868+
ts.isParenthesizedExpression(wrapped.parent) ||
869+
ts.isPropertyAssignment(wrapped.parent) ||
870+
ts.isObjectLiteralExpression(wrapped.parent) ||
871+
ts.isArrayLiteralExpression(wrapped.parent) ||
872+
ts.isSpreadElement(wrapped.parent)
873+
) {
874+
wrapped = wrapped.parent;
875+
}
876+
const call = wrapped.parent;
867877
const runs =
868878
(ts.isCallExpression(call) || ts.isNewExpression(call)) &&
869-
(call.expression === node || call.arguments?.includes(/** @type {any} */ (node)));
879+
(call.expression === wrapped || call.arguments?.includes(/** @type {any} */ (wrapped)));
870880
if (!runs) return;
871881
} else if (ts.isIdentifier(node) && node !== fn.name) {
872882
const declaration = this.declarationOf(node);

0 commit comments

Comments
 (0)