import type * as ts from 'typescript' ; import { Scope } from '../../scope/scope' ; import { core } from '../../core/core' ; import { GetDescriptor } from '../descriptor' ; import { createLiteral , createNumericLiteral , createStringLiteral , } from '../../../typescriptFactory/typescriptFactory' ; export function GetLiteralDescriptor ( node , scope ) { const type = core . typeChecker . getTypeAtLocation ( node ) ; const literalType = type as ts . LiteralType ; if ( literalType . value ) { return createLiteral ( literalType ) ; } else { if ( ! node . literal ) { return GetLiteralTokenDescriptor ( node ) ; } return GetDescriptor ( node . literal , scope ) ; } } function GetLiteralTokenDescriptor ( node ) { const nodeToken = node as any ; if ( nodeToken . kind === core . ts . SyntaxKind . NumericLiteral ) { return createNumericLiteral ( parseInt ( nodeToken . text , 10 ) ) ; } return createStringLiteral ( nodeToken . text ) ; }