MCPcopy Index your code
hub / github.com/angular/angular / walkForDeclarations

Function walkForDeclarations

packages/compiler-cli/src/ngtsc/testing/src/utils.ts:95–126  ·  view source on GitHub ↗
(name: string, rootNode: ts.Node)

Source from the content-addressed store, hash-verified

93 * Walk the AST tree from the `rootNode` looking for a declaration that has the given `name`.
94 */
95export function walkForDeclarations(name: string, rootNode: ts.Node): DeclarationNode[] {
96 const chosenDecls: DeclarationNode[] = [];
97 rootNode.forEachChild((node) => {
98 if (ts.isVariableStatement(node)) {
99 node.declarationList.declarations.forEach((decl) => {
100 if (bindingNameEquals(decl.name, name)) {
101 chosenDecls.push(decl);
102 if (decl.initializer) {
103 chosenDecls.push(...walkForDeclarations(name, decl.initializer));
104 }
105 } else {
106 chosenDecls.push(...walkForDeclarations(name, node));
107 }
108 });
109 } else if (isNamedDeclaration(node)) {
110 if (node.name !== undefined && node.name.text === name) {
111 chosenDecls.push(node);
112 }
113 chosenDecls.push(...walkForDeclarations(name, node));
114 } else if (
115 ts.isImportDeclaration(node) &&
116 node.importClause !== undefined &&
117 node.importClause.name !== undefined &&
118 node.importClause.name.text === name
119 ) {
120 chosenDecls.push(node.importClause);
121 } else {
122 chosenDecls.push(...walkForDeclarations(name, node));
123 }
124 });
125 return chosenDecls;
126}
127
128export function isNamedDeclaration(node: ts.Node): node is ts.Declaration & {name: ts.Identifier} {
129 const namedNode = node as {name?: ts.Identifier};

Callers 1

getDeclarationFunction · 0.85

Calls 4

bindingNameEqualsFunction · 0.85
isNamedDeclarationFunction · 0.70
forEachMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…