Skip to content

Commit

Permalink
fix: Detect and normalize unique symbol names
Browse files Browse the repository at this point in the history
Resolves #1514
  • Loading branch information
Gerrit0 committed Feb 20, 2021
1 parent ebf322f commit 441fea2
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/lib/converter/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,18 @@ export class Context {
}

const builtInSymbolRegExp = /^__@(\w+)$/;
const uniqueSymbolRegExp = /^__@(.*)@\d+$/;

function getHumanName(name: string) {
const match = builtInSymbolRegExp.exec(name);
let match = builtInSymbolRegExp.exec(name);
if (match) {
return `[Symbol.${match[1]}]`;
}

match = uniqueSymbolRegExp.exec(name);
if (match) {
return `[${match[1]}]`;
}

return name;
}
97 changes: 85 additions & 12 deletions src/test/converter/variables/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1374,13 +1374,85 @@
},
{
"id": 99,
"name": "variable",
"name": "symbols",
"kind": 1,
"kindString": "Module",
"flags": {},
"children": [
{
"id": 101,
"name": "ComputedUniqueName",
"kind": 256,
"kindString": "Interface",
"flags": {},
"children": [
{
"id": 102,
"name": "[UNIQUE_SYMBOL]",
"kind": 1024,
"kindString": "Property",
"flags": {},
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"groups": [
{
"title": "Properties",
"kind": 1024,
"children": [
102
]
}
]
},
{
"id": 100,
"name": "UNIQUE_SYMBOL",
"kind": 32,
"kindString": "Variable",
"flags": {
"isConst": true
},
"type": {
"type": "query",
"queryType": {
"type": "reference",
"id": 100,
"name": "UNIQUE_SYMBOL"
}
},
"defaultValue": "..."
}
],
"groups": [
{
"title": "Interfaces",
"kind": 256,
"children": [
101
]
},
{
"title": "Variables",
"kind": 32,
"children": [
100
]
}
]
},
{
"id": 103,
"name": "variable",
"kind": 1,
"kindString": "Module",
"flags": {},
"children": [
{
"id": 104,
"name": "myConst",
"kind": 32,
"kindString": "Variable",
Expand All @@ -1394,7 +1466,7 @@
"defaultValue": "15"
},
{
"id": 101,
"id": 105,
"name": "myLet",
"kind": 32,
"kindString": "Variable",
Expand All @@ -1408,7 +1480,7 @@
"defaultValue": "15"
},
{
"id": 102,
"id": 106,
"name": "myVar",
"kind": 32,
"kindString": "Variable",
Expand All @@ -1420,7 +1492,7 @@
"defaultValue": "15"
},
{
"id": 103,
"id": 107,
"name": "x",
"kind": 32,
"kindString": "Variable",
Expand All @@ -1433,7 +1505,7 @@
}
},
{
"id": 104,
"id": 108,
"name": "y",
"kind": 32,
"kindString": "Variable",
Expand All @@ -1452,7 +1524,7 @@
}
},
{
"id": 105,
"id": 109,
"name": "z",
"kind": 32,
"kindString": "Variable",
Expand All @@ -1476,12 +1548,12 @@
"title": "Variables",
"kind": 32,
"children": [
100,
101,
102,
103,
104,
105
105,
106,
107,
108,
109
]
}
]
Expand All @@ -1495,7 +1567,8 @@
1,
15,
30,
99
99,
103
]
}
]
Expand Down
10 changes: 9 additions & 1 deletion src/test/converter/variables/specs.nodoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@
},
{
"id": 24,
"name": "symbols",
"kind": 1,
"kindString": "Module",
"flags": {}
},
{
"id": 25,
"name": "variable",
"kind": 1,
"kindString": "Module",
Expand All @@ -428,7 +435,8 @@
1,
15,
19,
24
24,
25
]
}
]
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter/variables/symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const UNIQUE_SYMBOL = Symbol();

export interface ComputedUniqueName {
// GH#1514
[UNIQUE_SYMBOL]: string;
}

0 comments on commit 441fea2

Please sign in to comment.