From 90b634e5446781cec269fbc51389320de6a1b975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Thu, 21 Nov 2024 09:38:17 +0800 Subject: [PATCH] fix: node name for TS parser thanks to @ArnaudBarre, closes #102 Co-authored-by: ArnaudBarre --- composables/parser/javascript/typescript.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/composables/parser/javascript/typescript.ts b/composables/parser/javascript/typescript.ts index b52fa66..59594e0 100644 --- a/composables/parser/javascript/typescript.ts +++ b/composables/parser/javascript/typescript.ts @@ -30,8 +30,19 @@ export const typescript: Parser< getAstLocation: genGetAstLocation('typescript'), astTitleField: 'kind', getAstTitle(value) { - const kind = value?.kind + const kind: Typescript.SyntaxKind | undefined = value?.kind if (kind == null) return - return this.SyntaxKind[kind] + return getSyntaxKind(this, kind) }, } + +function getSyntaxKind(ts: typeof Typescript, kind: Typescript.SyntaxKind) { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + const syntaxKinds = {} as Record + for (const [key, value] of Object.entries(ts.SyntaxKind)) { + if (typeof value === 'number' && !syntaxKinds[value]) { + syntaxKinds[value] = key + } + } + return syntaxKinds[kind] +}