Skip to content

Commit

Permalink
fix: getPropertyName handles sourceless nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Oct 16, 2022
1 parent 4163f8f commit b428d2d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/NodeParser/TypeLiteralNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@ export class TypeLiteralNodeParser implements SubNodeParser {
protected getPropertyName(propertyName: ts.PropertyName): string {
if (propertyName.kind === ts.SyntaxKind.ComputedPropertyName) {
const symbol = this.typeChecker.getSymbolAtLocation(propertyName);

if (symbol) {
return symbol.getName();
}
}
return propertyName.getText();

try {
return propertyName.getText();
} catch {
// When propertyName was programmatically created, it doesn't have a source file.
// Then, getText() will throw an error. But, for programmatically created nodes,`
// `escapedText` is available.
return (propertyName as ts.Identifier).escapedText as string;
}
}
}

0 comments on commit b428d2d

Please sign in to comment.