ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
30 lines (23 loc) • 935 B
Markdown
title: Finding References
## Finding References
Find all the references of a node by calling `.findReferences()` on an identifier.
### Example
Simple example:
```typescript
const classDeclaration = ...; // get a class or some other declaration somehow
const referencedSymbols = classDeclaration.getNameNode().findReferences();
for (const referencedSymbol of referencedSymbols) {
for (const reference of referencedSymbol.getReferences()) {
console.log("---------")
console.log("REFERENCE")
console.log("---------")
console.log("File path: " + reference.getSourceFile().getFilePath());
console.log("Start: " + reference.getTextSpan().getStart());
console.log("Length: " + reference.getTextSpan().getLength());
console.log("Parent kind: " + reference.getNode().getParentOrThrow().getKindName());
console.log("\n");
}
}
```