Skip to content
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

Refactoring: Inline function & Inline local #30101

Closed
Closed
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4871,5 +4871,21 @@
"Enable the 'experimentalDecorators' option in your configuration file": {
"category": "Message",
"code": 95074
},
"Inline local": {
"category": "Message",
"code": 95080
},
"Inline here": {
"category": "Message",
"code": 95081
},
"Inline all": {
"category": "Message",
"code": 95082
},
"Inline function": {
"category": "Message",
"code": 95083
}
}
19 changes: 19 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ namespace ts {
}
}

/**
* Collects all descendants whose predicate results in a truthy value.
* If no descendant is found, returns empty array.
*/
export function findDescendants<T extends Node>(node: Node | undefined, predicate: (element: Node) => element is T): ReadonlyArray<T>;
export function findDescendants(node: Node | undefined, predicate: (element: Node) => boolean): ReadonlyArray<Node>;
export function findDescendants(node: Node, predicate: (n: Node) => boolean) {
const nodes: Node[] = [];
collectDescendants(node);
return nodes;

function collectDescendants(node: Node) {
forEachChild(node, n => {
if (predicate(n)) nodes.push(n);
collectDescendants(n);
});
}
}

/**
* Calls `callback` for each entry in the map, returning the first truthy result.
* Use `map.forEach` instead for normal iteration.
Expand Down
Loading