Skip to content

Avoid climbing ancestors in getAnyImportSyntax #17832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Aug 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,13 +1330,18 @@ namespace ts {
return parent && !!findAncestor(initial, n => n === stopAt || isFunctionLike(n) ? "quit" : n === parent);
}

function getAnyImportSyntax(node: Node): AnyImportSyntax {
if (isAliasSymbolDeclaration(node)) {
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
return <ImportEqualsDeclaration>node;
}

return findAncestor(node, isImportDeclaration);
function getAnyImportSyntax(node: Node): AnyImportSyntax | undefined {
switch (node.kind) {
case SyntaxKind.ImportEqualsDeclaration:
return node as ImportEqualsDeclaration;
case SyntaxKind.ImportClause:
return (node as ImportClause).parent;
case SyntaxKind.NamespaceImport:
return (node as NamespaceImport).parent.parent;
case SyntaxKind.ImportSpecifier:
return (node as ImportSpecifier).parent.parent.parent;
default:
return undefined;
}
}

Expand Down