Skip to content

Commit 546a87f

Browse files
authored
feat(48231): allow unique symbol for constant variables (microsoft#48270)
1 parent cf8ed8f commit 546a87f

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

Diff for: src/compiler/checker.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -43992,13 +43992,11 @@ namespace ts {
4399243992
if (node.type.kind !== SyntaxKind.SymbolKeyword) {
4399343993
return grammarErrorOnNode(node.type, Diagnostics._0_expected, tokenToString(SyntaxKind.SymbolKeyword));
4399443994
}
43995-
4399643995
let parent = walkUpParenthesizedTypes(node.parent);
4399743996
if (isInJSFile(parent) && isJSDocTypeExpression(parent)) {
43998-
parent = parent.parent;
43999-
if (isJSDocTypeTag(parent)) {
44000-
// walk up past JSDoc comment node
44001-
parent = parent.parent.parent;
43997+
const host = getJSDocHost(parent);
43998+
if (host) {
43999+
parent = getSingleVariableOfVariableStatement(host) || host;
4400244000
}
4400344001
}
4400444002
switch (parent.kind) {

Diff for: tests/baselines/reference/uniqueSymbolsDeclarationsInJs.js

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class C {
2323
readonlyCall = Symbol();
2424
readwriteCall = Symbol();
2525
}
26+
27+
/** @type {unique symbol} */
28+
const a = Symbol();
2629

2730

2831
//// [uniqueSymbolsDeclarationsInJs-out.js]
@@ -46,6 +49,8 @@ class C {
4649
static { this.readonlyStaticTypeAndCall = Symbol(); }
4750
static { this.readwriteStaticCall = Symbol(); }
4851
}
52+
/** @type {unique symbol} */
53+
const a = Symbol();
4954

5055

5156
//// [uniqueSymbolsDeclarationsInJs-out.d.ts]
@@ -71,3 +76,5 @@ declare class C {
7176
readonly readonlyCall: symbol;
7277
readwriteCall: symbol;
7378
}
79+
/** @type {unique symbol} */
80+
declare const a: unique symbol;

Diff for: tests/baselines/reference/uniqueSymbolsDeclarationsInJs.symbols

+5
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ class C {
4141
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
4242
}
4343

44+
/** @type {unique symbol} */
45+
const a = Symbol();
46+
>a : Symbol(a, Decl(uniqueSymbolsDeclarationsInJs.js, 26, 5))
47+
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
48+

Diff for: tests/baselines/reference/uniqueSymbolsDeclarationsInJs.types

+6
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,9 @@ class C {
4646
>Symbol : SymbolConstructor
4747
}
4848

49+
/** @type {unique symbol} */
50+
const a = Symbol();
51+
>a : symbol
52+
>Symbol() : unique symbol
53+
>Symbol : SymbolConstructor
54+

Diff for: tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarationsInJs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ class C {
3131
readonlyCall = Symbol();
3232
readwriteCall = Symbol();
3333
}
34+
35+
/** @type {unique symbol} */
36+
const a = Symbol();

0 commit comments

Comments
 (0)