Files
medusa-store/docs-util/packages/docblock-generator/src/utils/get-symbol.ts
T
2024-01-24 11:13:40 +01:00

25 lines
654 B
TypeScript

import ts from "typescript"
/**
* Retrieves the symbol of a node.
*
* @param {ts.Node} node - The node to retrieve its symbol.
* @param {ts.TypeChecker} checker - The type checker of the TypeScript program the symbol is in.
* @returns {ts.Symbol | undefined} The symbol if found.
*/
export default function getSymbol(
node: ts.Node,
checker: ts.TypeChecker
): ts.Symbol | undefined {
if (
ts.isVariableStatement(node) &&
node.declarationList.declarations.length
) {
return getSymbol(node.declarationList.declarations[0], checker)
}
return "symbol" in node && node.symbol
? (node.symbol as ts.Symbol)
: undefined
}