Skip to content

Commit

Permalink
fix: node name for TS parser
Browse files Browse the repository at this point in the history
thanks to @ArnaudBarre, closes #102

Co-authored-by: ArnaudBarre <arnaud.barre72@gmail.com>
  • Loading branch information
sxzz and ArnaudBarre committed Nov 21, 2024
1 parent 2ed1f8e commit 90b634e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions composables/parser/javascript/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Typescript.SyntaxKind, string>
for (const [key, value] of Object.entries(ts.SyntaxKind)) {
if (typeof value === 'number' && !syntaxKinds[value]) {
syntaxKinds[value] = key
}
}
return syntaxKinds[kind]

This comment has been minimized.

Copy link
@ArnaudBarre

ArnaudBarre Nov 21, 2024

Author Contributor

Ah yeah TS is not global here so you are generating the mapping for every node. I'm a bit afraid this could be an issue for big AST, and it could be safe to have a global Map<TypeScirpt, Record<SyntaxKind, string>> to cache the record creation

}

0 comments on commit 90b634e

Please sign in to comment.