Skip to content

Commit 364beac

Browse files
committed
i should start at 2 instead of 0 because it's always used as i + 2
1 parent 33ff4ff commit 364beac

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

src/slang-nodes/MemberAccessExpression.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,26 @@ function isEndOfChain(
2424
path: AstPath<StrictAstNode>
2525
): boolean {
2626
for (
27-
let i = 0,
28-
currentNode: StrictAstNode = node,
29-
grandparentNode = path.getNode(i + 2)!;
30-
isChainableExpression(grandparentNode);
31-
i += 2,
32-
currentNode = grandparentNode,
33-
grandparentNode = path.getNode(i + 2)!
27+
let i = 2, current: StrictAstNode = node, grandparent = path.getNode(i)!;
28+
isChainableExpression(grandparent);
29+
i += 2, current = grandparent, grandparent = path.getNode(i)!
3430
) {
35-
switch (grandparentNode.kind) {
31+
switch (grandparent.kind) {
3632
case NonterminalKind.MemberAccessExpression:
37-
// If direct ParentNode is a MemberAccess we are not at the end of the
38-
// chain.
33+
// If `grandparent` is a MemberAccessExpression we are not at the end
34+
// of the chain.
3935
return false;
4036
case NonterminalKind.IndexAccessExpression:
41-
// If direct ParentNode is an IndexAccess and currentNode is not the
42-
// operand then it must be the start or the end in which case it is the
43-
// end of the chain.
44-
if (currentNode !== grandparentNode.operand.variant) return true;
37+
// If `grandparent` is an IndexAccessExpression and `current` is not
38+
// the operand then it must be the start or the end in which case it is
39+
// the end of the chain.
40+
if (current !== grandparent.operand.variant) return true;
4541
break;
4642
case NonterminalKind.FunctionCallExpression:
47-
// If direct ParentNode is a FunctionCall and currentNode is not the
48-
// operand then it must be and argument in which case it is the end
43+
// If `grandparent` is a FunctionCallExpression and `current` is not
44+
// the operand then it must be and argument in which case it is the end
4945
// of the chain.
50-
if (currentNode !== grandparentNode.operand.variant) return true;
46+
if (current !== grandparent.operand.variant) return true;
5147
break;
5248
}
5349
}

0 commit comments

Comments
 (0)