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

Function getDeclaration

packages/compiler-cli/src/ngtsc/testing/src/utils.ts:69–90  ·  view source on GitHub ↗
(
  program: ts.Program,
  fileName: AbsoluteFsPath,
  name: string,
  assert: (value: any) => value is T,
)

Source from the content-addressed store, hash-verified

67 * the `predicate` test.
68 */
69export function getDeclaration<T extends DeclarationNode>(
70 program: ts.Program,
71 fileName: AbsoluteFsPath,
72 name: string,
73 assert: (value: any) => value is T,
74): T {
75 const sf = getSourceFileOrError(program, fileName);
76 const chosenDecls = walkForDeclarations(name, sf);
77
78 if (chosenDecls.length === 0) {
79 throw new Error(`No such symbol: ${name} in ${fileName}`);
80 }
81 const chosenDecl = chosenDecls.find(assert);
82 if (chosenDecl === undefined) {
83 throw new Error(
84 `Symbols with name ${name} in ${fileName} have types: ${chosenDecls.map(
85 (decl) => ts.SyntaxKind[decl.kind],
86 )}. Expected one to pass predicate "${assert.name}()".`,
87 );
88 }
89 return chosenDecl;
90}
91
92/**
93 * Walk the AST tree from the `rootNode` looking for a declaration that has the given `name`.

Callers 15

ts_host_spec.tsFile · 0.90
getMembersFunction · 0.90
getComponentDeclarationFunction · 0.90
emitter_spec.tsFile · 0.90
default_spec.tsFile · 0.90
evaluator_spec.tsFile · 0.90
traceExpressionFunction · 0.90
makeExpressionFunction · 0.90
createEmitterFunction · 0.90
ng_module_spec.tsFile · 0.90
component_spec.tsFile · 0.90

Calls 4

getSourceFileOrErrorFunction · 0.90
walkForDeclarationsFunction · 0.85
mapMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…