feat(48231): allow unique symbol for constant variables (#48270)

This commit is contained in:
Oleksandr T
2022-03-17 02:00:27 +02:00
committed by GitHub
parent cf8ed8fec1
commit 546a87fa31
5 changed files with 24 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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, --, --))

View File

@@ -46,3 +46,9 @@ class C {
>Symbol : SymbolConstructor
}
/** @type {unique symbol} */
const a = Symbol();
>a : symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor

View File

@@ -31,3 +31,6 @@ class C {
readonlyCall = Symbol();
readwriteCall = Symbol();
}
/** @type {unique symbol} */
const a = Symbol();