|
1
|
import ts from "typescript" |
|
2
|
|
|
3
|
/** |
|
4
|
* Retrieves the symbol of a node. |
|
5
|
* |
|
6
|
* @param {ts.Node} node - The node to retrieve its symbol. |
|
7
|
* @param {ts.TypeChecker} checker - The type checker of the TypeScript program the symbol is in. |
|
8
|
* @returns {ts.Symbol | undefined} The symbol if found. |
|
9
|
*/ |
|
10
|
export default function getSymbol( |
|
11
|
node: ts.Node, |
|
12
|
checker: ts.TypeChecker |
|
13
|
): ts.Symbol | undefined { |
|
14
|
if ( |
|
15
|
ts.isVariableStatement(node) && |
|
16
|
node.declarationList.declarations.length |
|
17
|
) { |
|
18
|
return getSymbol(node.declarationList.declarations[0], checker) |
|
19
|
} |
|
20
|
|
|
21
|
return "symbol" in node && node.symbol |
|
22
|
? (node.symbol as ts.Symbol) |
|
23
|
: undefined |
|
24
|
} |