forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Identifier.ts
40 lines (36 loc) · 1.39 KB
/
Identifier.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ts } from "../../../typescript";
import { ReferenceFindableNode, RenameableNode } from "../base";
import { PrimaryExpression } from "../expression/PrimaryExpression";
import { DefinitionInfo, ImplementationLocation } from "../../tools";
import { Node } from "./Node";
export const IdentifierBase = ReferenceFindableNode(RenameableNode(PrimaryExpression));
export class Identifier extends IdentifierBase<ts.Identifier> {
/**
* Gets the text for the identifier.
*/
getText() {
return this.compilerNode.text;
}
/**
* Gets the definition nodes of the identifier.
* @remarks This is similar to "go to definition" and `.getDefinitions()`, but only returns the nodes.
*/
getDefinitionNodes(): Node[] {
return this.getDefinitions().map(d => d.getDeclarationNode()).filter(d => d != null) as Node[];
}
/**
* Gets the definitions of the identifier.
* @remarks This is similar to "go to definition." Use `.getDefinitionNodes()` if you only care about the nodes.
*/
getDefinitions(): DefinitionInfo[] {
return this._context.languageService.getDefinitions(this);
}
/**
* Gets the implementations of the identifier.
*
* This is similar to "go to implementation."
*/
getImplementations(): ImplementationLocation[] {
return this._context.languageService.getImplementations(this);
}
}