Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit badfcbf

Browse filesBrowse files
author
Andy Hanson
committed
findAncestor: Add generic overload for use with type predicates
1 parent 2a9a6e8 commit badfcbf
Copy full SHA for badfcbf

3 files changed

+8-2Lines changed: 8 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ namespace ts {
13001300
return <ImportEqualsDeclaration>node;
13011301
}
13021302

1303-
return findAncestor(node, n => n.kind === SyntaxKind.ImportDeclaration) as ImportDeclaration;
1303+
return findAncestor(node, isImportDeclaration);
13041304
}
13051305
}
13061306

@@ -22638,7 +22638,7 @@ namespace ts {
2263822638
const symbolIsUmdExport = symbolFile !== referenceFile;
2263922639
return symbolIsUmdExport ? undefined : symbolFile;
2264022640
}
22641-
return findAncestor(node.parent, n => isModuleOrEnumDeclaration(n) && getSymbolOfNode(n) === parentSymbol) as ModuleDeclaration | EnumDeclaration;
22641+
return findAncestor(node.parent, (n): n is ModuleDeclaration | EnumDeclaration => isModuleOrEnumDeclaration(n) && getSymbolOfNode(n) === parentSymbol);
2264222642
}
2264322643
}
2264422644
}
Collapse file

‎src/compiler/core.ts‎

Copy file name to clipboardExpand all lines: src/compiler/core.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ namespace ts {
230230
* If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit"
231231
* At that point findAncestor returns undefined.
232232
*/
233+
export function findAncestor<T extends Node>(node: Node, callback: (element: Node) => element is T): T | undefined;
234+
export function findAncestor(node: Node, callback: (element: Node) => boolean | "quit"): Node | undefined;
233235
export function findAncestor(node: Node, callback: (element: Node) => boolean | "quit"): Node {
234236
while (node) {
235237
const result = callback(node);
Collapse file

‎src/compiler/utilities.ts‎

Copy file name to clipboardExpand all lines: src/compiler/utilities.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,6 +4010,10 @@ namespace ts {
40104010
return node.kind === SyntaxKind.ImportEqualsDeclaration;
40114011
}
40124012

4013+
export function isImportDeclaration(node: Node): node is ImportDeclaration {
4014+
return node.kind === SyntaxKind.ImportDeclaration;
4015+
}
4016+
40134017
export function isImportClause(node: Node): node is ImportClause {
40144018
return node.kind === SyntaxKind.ImportClause;
40154019
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.