Skip to content

Commit 78524c1

Browse files
author
Andy
authored
Avoid climbing ancestors in getAnyImportSyntax (#17832)
1 parent 6168d6f commit 78524c1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,13 +1351,18 @@ namespace ts {
13511351
return parent && !!findAncestor(initial, n => n === stopAt || isFunctionLike(n) ? "quit" : n === parent);
13521352
}
13531353

1354-
function getAnyImportSyntax(node: Node): AnyImportSyntax {
1355-
if (isAliasSymbolDeclaration(node)) {
1356-
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
1357-
return <ImportEqualsDeclaration>node;
1358-
}
1359-
1360-
return findAncestor(node, isImportDeclaration);
1354+
function getAnyImportSyntax(node: Node): AnyImportSyntax | undefined {
1355+
switch (node.kind) {
1356+
case SyntaxKind.ImportEqualsDeclaration:
1357+
return node as ImportEqualsDeclaration;
1358+
case SyntaxKind.ImportClause:
1359+
return (node as ImportClause).parent;
1360+
case SyntaxKind.NamespaceImport:
1361+
return (node as NamespaceImport).parent.parent;
1362+
case SyntaxKind.ImportSpecifier:
1363+
return (node as ImportSpecifier).parent.parent.parent;
1364+
default:
1365+
return undefined;
13611366
}
13621367
}
13631368

0 commit comments

Comments
 (0)