Skip to content

Commit 441fea2

Browse files
committed
fix: Detect and normalize unique symbol names
Resolves #1514
1 parent ebf322f commit 441fea2

File tree

4 files changed

+108
-14
lines changed

4 files changed

+108
-14
lines changed

src/lib/converter/context.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,18 @@ export class Context {
268268
}
269269

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

272273
function getHumanName(name: string) {
273-
const match = builtInSymbolRegExp.exec(name);
274+
let match = builtInSymbolRegExp.exec(name);
274275
if (match) {
275276
return `[Symbol.${match[1]}]`;
276277
}
278+
279+
match = uniqueSymbolRegExp.exec(name);
280+
if (match) {
281+
return `[${match[1]}]`;
282+
}
283+
277284
return name;
278285
}

src/test/converter/variables/specs.json

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,13 +1374,85 @@
13741374
},
13751375
{
13761376
"id": 99,
1377-
"name": "variable",
1377+
"name": "symbols",
13781378
"kind": 1,
13791379
"kindString": "Module",
13801380
"flags": {},
13811381
"children": [
1382+
{
1383+
"id": 101,
1384+
"name": "ComputedUniqueName",
1385+
"kind": 256,
1386+
"kindString": "Interface",
1387+
"flags": {},
1388+
"children": [
1389+
{
1390+
"id": 102,
1391+
"name": "[UNIQUE_SYMBOL]",
1392+
"kind": 1024,
1393+
"kindString": "Property",
1394+
"flags": {},
1395+
"type": {
1396+
"type": "intrinsic",
1397+
"name": "string"
1398+
}
1399+
}
1400+
],
1401+
"groups": [
1402+
{
1403+
"title": "Properties",
1404+
"kind": 1024,
1405+
"children": [
1406+
102
1407+
]
1408+
}
1409+
]
1410+
},
13821411
{
13831412
"id": 100,
1413+
"name": "UNIQUE_SYMBOL",
1414+
"kind": 32,
1415+
"kindString": "Variable",
1416+
"flags": {
1417+
"isConst": true
1418+
},
1419+
"type": {
1420+
"type": "query",
1421+
"queryType": {
1422+
"type": "reference",
1423+
"id": 100,
1424+
"name": "UNIQUE_SYMBOL"
1425+
}
1426+
},
1427+
"defaultValue": "..."
1428+
}
1429+
],
1430+
"groups": [
1431+
{
1432+
"title": "Interfaces",
1433+
"kind": 256,
1434+
"children": [
1435+
101
1436+
]
1437+
},
1438+
{
1439+
"title": "Variables",
1440+
"kind": 32,
1441+
"children": [
1442+
100
1443+
]
1444+
}
1445+
]
1446+
},
1447+
{
1448+
"id": 103,
1449+
"name": "variable",
1450+
"kind": 1,
1451+
"kindString": "Module",
1452+
"flags": {},
1453+
"children": [
1454+
{
1455+
"id": 104,
13841456
"name": "myConst",
13851457
"kind": 32,
13861458
"kindString": "Variable",
@@ -1394,7 +1466,7 @@
13941466
"defaultValue": "15"
13951467
},
13961468
{
1397-
"id": 101,
1469+
"id": 105,
13981470
"name": "myLet",
13991471
"kind": 32,
14001472
"kindString": "Variable",
@@ -1408,7 +1480,7 @@
14081480
"defaultValue": "15"
14091481
},
14101482
{
1411-
"id": 102,
1483+
"id": 106,
14121484
"name": "myVar",
14131485
"kind": 32,
14141486
"kindString": "Variable",
@@ -1420,7 +1492,7 @@
14201492
"defaultValue": "15"
14211493
},
14221494
{
1423-
"id": 103,
1495+
"id": 107,
14241496
"name": "x",
14251497
"kind": 32,
14261498
"kindString": "Variable",
@@ -1433,7 +1505,7 @@
14331505
}
14341506
},
14351507
{
1436-
"id": 104,
1508+
"id": 108,
14371509
"name": "y",
14381510
"kind": 32,
14391511
"kindString": "Variable",
@@ -1452,7 +1524,7 @@
14521524
}
14531525
},
14541526
{
1455-
"id": 105,
1527+
"id": 109,
14561528
"name": "z",
14571529
"kind": 32,
14581530
"kindString": "Variable",
@@ -1476,12 +1548,12 @@
14761548
"title": "Variables",
14771549
"kind": 32,
14781550
"children": [
1479-
100,
1480-
101,
1481-
102,
1482-
103,
14831551
104,
1484-
105
1552+
105,
1553+
106,
1554+
107,
1555+
108,
1556+
109
14851557
]
14861558
}
14871559
]
@@ -1495,7 +1567,8 @@
14951567
1,
14961568
15,
14971569
30,
1498-
99
1570+
99,
1571+
103
14991572
]
15001573
}
15011574
]

src/test/converter/variables/specs.nodoc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@
414414
},
415415
{
416416
"id": 24,
417+
"name": "symbols",
418+
"kind": 1,
419+
"kindString": "Module",
420+
"flags": {}
421+
},
422+
{
423+
"id": 25,
417424
"name": "variable",
418425
"kind": 1,
419426
"kindString": "Module",
@@ -428,7 +435,8 @@
428435
1,
429436
15,
430437
19,
431-
24
438+
24,
439+
25
432440
]
433441
}
434442
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const UNIQUE_SYMBOL = Symbol();
2+
3+
export interface ComputedUniqueName {
4+
// GH#1514
5+
[UNIQUE_SYMBOL]: string;
6+
}

0 commit comments

Comments
 (0)