( program: ts.Program, fileName: AbsoluteFsPath, name: string, assert: (value: any) => value is T, )
| 67 | * the `predicate` test. |
| 68 | */ |
| 69 | export 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`. |
no test coverage detected
searching dependent graphs…