Skip to content

Commit caae509

Browse files
rbucktonGerrit0
authored andcommitted
Improve output for computed property names
1 parent 60b49a8 commit caae509

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/lib/converter/factories/declaration.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const nonStaticMergeKinds = [
2323
ts.SyntaxKind.InterfaceDeclaration
2424
];
2525

26+
const builtInSymbolRegExp = /^__@(\w+)$/;
27+
2628
/**
2729
* Create a declaration reflection from the given TypeScript node.
2830
*
@@ -48,6 +50,21 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
4850
} else {
4951
return;
5052
}
53+
54+
// rename built-in symbols
55+
const match = builtInSymbolRegExp.exec(name);
56+
if (match) {
57+
name = `[Symbol.${match[1]}]`;
58+
} else if (kind & ReflectionKind.ClassMember && name === '__computed') {
59+
// rename computed properties
60+
const declName = ts.getNameOfDeclaration(node);
61+
const symbol = declName && context.checker.getSymbolAtLocation(declName);
62+
if (symbol) {
63+
name = context.checker.symbolToString(symbol, /*enclosingDeclaration*/ undefined, ts.SymbolFlags.ClassMember);
64+
} else if (declName) {
65+
name = declName.getText();
66+
}
67+
}
5168
}
5269

5370
const modifiers = ts.getCombinedModifierFlags(node);

src/lib/models/reflections/abstract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export enum ReflectionKind {
6262
ClassOrInterface = Class | Interface,
6363
VariableOrProperty = Variable | Property,
6464
FunctionOrMethod = ReflectionKind.Function | Method,
65+
ClassMember = Accessor | Constructor | Method | Property | Event,
6566
SomeSignature = CallSignature | IndexSignature | ConstructorSignature | GetSignature | SetSignature,
6667
SomeModule = Module | ExternalModule,
6768
SomeType = Interface | TypeLiteral | TypeParameter | TypeAlias,

0 commit comments

Comments
 (0)