mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-06 15:24:36 -05:00
feat(48231): allow unique symbol for constant variables (#48270)
This commit is contained in:
@@ -43992,13 +43992,11 @@ namespace ts {
|
||||
if (node.type.kind !== SyntaxKind.SymbolKeyword) {
|
||||
return grammarErrorOnNode(node.type, Diagnostics._0_expected, tokenToString(SyntaxKind.SymbolKeyword));
|
||||
}
|
||||
|
||||
let parent = walkUpParenthesizedTypes(node.parent);
|
||||
if (isInJSFile(parent) && isJSDocTypeExpression(parent)) {
|
||||
parent = parent.parent;
|
||||
if (isJSDocTypeTag(parent)) {
|
||||
// walk up past JSDoc comment node
|
||||
parent = parent.parent.parent;
|
||||
const host = getJSDocHost(parent);
|
||||
if (host) {
|
||||
parent = getSingleVariableOfVariableStatement(host) || host;
|
||||
}
|
||||
}
|
||||
switch (parent.kind) {
|
||||
|
||||
@@ -23,6 +23,9 @@ class C {
|
||||
readonlyCall = Symbol();
|
||||
readwriteCall = Symbol();
|
||||
}
|
||||
|
||||
/** @type {unique symbol} */
|
||||
const a = Symbol();
|
||||
|
||||
|
||||
//// [uniqueSymbolsDeclarationsInJs-out.js]
|
||||
@@ -46,6 +49,8 @@ class C {
|
||||
static { this.readonlyStaticTypeAndCall = Symbol(); }
|
||||
static { this.readwriteStaticCall = Symbol(); }
|
||||
}
|
||||
/** @type {unique symbol} */
|
||||
const a = Symbol();
|
||||
|
||||
|
||||
//// [uniqueSymbolsDeclarationsInJs-out.d.ts]
|
||||
@@ -71,3 +76,5 @@ declare class C {
|
||||
readonly readonlyCall: symbol;
|
||||
readwriteCall: symbol;
|
||||
}
|
||||
/** @type {unique symbol} */
|
||||
declare const a: unique symbol;
|
||||
|
||||
@@ -41,3 +41,8 @@ class C {
|
||||
>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, --, --))
|
||||
}
|
||||
|
||||
/** @type {unique symbol} */
|
||||
const a = Symbol();
|
||||
>a : Symbol(a, Decl(uniqueSymbolsDeclarationsInJs.js, 26, 5))
|
||||
>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, --, --))
|
||||
|
||||
|
||||
@@ -46,3 +46,9 @@ class C {
|
||||
>Symbol : SymbolConstructor
|
||||
}
|
||||
|
||||
/** @type {unique symbol} */
|
||||
const a = Symbol();
|
||||
>a : symbol
|
||||
>Symbol() : unique symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
|
||||
@@ -31,3 +31,6 @@ class C {
|
||||
readonlyCall = Symbol();
|
||||
readwriteCall = Symbol();
|
||||
}
|
||||
|
||||
/** @type {unique symbol} */
|
||||
const a = Symbol();
|
||||
|
||||
Reference in New Issue
Block a user