Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(48231): Cannot declare unique symbol type in jsdoc in js file #48270

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43973,13 +43973,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) {
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/uniqueSymbolsDeclarationsInJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class C {
readonlyCall = Symbol();
readwriteCall = Symbol();
}

/** @type {unique symbol} */
const a = Symbol();


//// [uniqueSymbolsDeclarationsInJs-out.js]
Expand All @@ -46,6 +49,8 @@ class C {
static { this.readonlyStaticTypeAndCall = Symbol(); }
static { this.readwriteStaticCall = Symbol(); }
}
/** @type {unique symbol} */
const a = Symbol();


//// [uniqueSymbolsDeclarationsInJs-out.d.ts]
Expand All @@ -71,3 +76,5 @@ declare class C {
readonly readonlyCall: symbol;
readwriteCall: symbol;
}
/** @type {unique symbol} */
declare const a: unique symbol;
Original file line number Diff line number Diff line change
Expand Up @@ -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, --, --))

6 changes: 6 additions & 0 deletions tests/baselines/reference/uniqueSymbolsDeclarationsInJs.types
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ class C {
>Symbol : SymbolConstructor
}

/** @type {unique symbol} */
const a = Symbol();
>a : symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor

Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ class C {
readonlyCall = Symbol();
readwriteCall = Symbol();
}

/** @type {unique symbol} */
const a = Symbol();