Skip to content

Commit

Permalink
Use value meaning for computed property name for visibility check (#4…
Browse files Browse the repository at this point in the history
…9678)

* Test

* Use value meaning for computed property name
Fixes #49562
  • Loading branch information
sheetalkamat committed Jun 27, 2022
1 parent df21926 commit 7e91485
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/compiler/checker.ts
Expand Up @@ -43363,13 +43363,20 @@ namespace ts {
if (!fileToDirective) {
return undefined;
}
// computed property name should use node as value
// property access can only be used as values, or types when within an expression with type arguments inside a heritage clause
// qualified names can only be used as types\namespaces
// identifiers are treated as values only if they appear in type queries
let meaning = SymbolFlags.Type | SymbolFlags.Namespace;
if ((node.kind === SyntaxKind.Identifier && isInTypeQuery(node)) || (node.kind === SyntaxKind.PropertyAccessExpression && !isInHeritageClause(node))) {
let meaning;
if (node.parent.kind === SyntaxKind.ComputedPropertyName) {
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
}
else {
meaning = SymbolFlags.Type | SymbolFlags.Namespace;
if ((node.kind === SyntaxKind.Identifier && isInTypeQuery(node)) || (node.kind === SyntaxKind.PropertyAccessExpression && !isInHeritageClause(node))) {
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
}
}

const symbol = resolveEntityName(node, meaning, /*ignoreErrors*/ true);
return symbol && symbol !== unknownSymbol ? getTypeReferenceDirectivesForSymbol(symbol, meaning) : undefined;
Expand Down
@@ -0,0 +1,16 @@
//// [computedPropertyNameAndTypeParameterConflict.ts]
declare const O: unique symbol;
declare class Bar<O> {
[O]: number;
}



//// [computedPropertyNameAndTypeParameterConflict.js]


//// [computedPropertyNameAndTypeParameterConflict.d.ts]
declare const O: unique symbol;
declare class Bar<O> {
[O]: number;
}
@@ -0,0 +1,14 @@
=== tests/cases/compiler/computedPropertyNameAndTypeParameterConflict.ts ===
declare const O: unique symbol;
>O : Symbol(O, Decl(computedPropertyNameAndTypeParameterConflict.ts, 0, 13))

declare class Bar<O> {
>Bar : Symbol(Bar, Decl(computedPropertyNameAndTypeParameterConflict.ts, 0, 31))
>O : Symbol(O, Decl(computedPropertyNameAndTypeParameterConflict.ts, 1, 18))

[O]: number;
>[O] : Symbol(Bar[O], Decl(computedPropertyNameAndTypeParameterConflict.ts, 1, 22))
>O : Symbol(O, Decl(computedPropertyNameAndTypeParameterConflict.ts, 0, 13))
}


@@ -0,0 +1,13 @@
=== tests/cases/compiler/computedPropertyNameAndTypeParameterConflict.ts ===
declare const O: unique symbol;
>O : unique symbol

declare class Bar<O> {
>Bar : Bar<O>

[O]: number;
>[O] : number
>O : unique symbol
}


@@ -0,0 +1,6 @@
// @declaration: true
declare const O: unique symbol;
declare class Bar<O> {
[O]: number;
}

0 comments on commit 7e91485

Please sign in to comment.