Skip to content

Commit add7981

Browse files
authored
Fix checkGrammarForInvalidDynamicName (#1063)
1 parent e58aed7 commit add7981

File tree

115 files changed

+108
-1723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+108
-1723
lines changed

internal/checker/grammarchecks.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,17 @@ func (c *Checker) checkGrammarTypeOperatorNode(node *ast.TypeOperatorNode) bool
14191419
}
14201420

14211421
func (c *Checker) checkGrammarForInvalidDynamicName(node *ast.DeclarationName, message *diagnostics.Message) bool {
1422-
if c.isNonBindableDynamicName(node) {
1422+
if !c.isNonBindableDynamicName(node) {
1423+
return false
1424+
}
1425+
var expression *ast.Node
1426+
if ast.IsElementAccessExpression(node) {
1427+
expression = ast.SkipParentheses(node.AsElementAccessExpression().ArgumentExpression)
1428+
} else {
1429+
expression = node.Expression()
1430+
}
1431+
1432+
if !ast.IsEntityNameExpression(expression) {
14231433
return c.grammarErrorOnNode(node, message)
14241434
}
14251435

testdata/baselines/reference/submodule/compiler/capturedParametersInInitializers2.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
capturedParametersInInitializers2.ts(3,20): error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.
22
capturedParametersInInitializers2.ts(4,14): error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.
33
capturedParametersInInitializers2.ts(6,10): error TS2373: Parameter 'y' cannot reference identifier 'z' declared after it.
4-
capturedParametersInInitializers2.ts(13,26): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type.
54
capturedParametersInInitializers2.ts(13,27): error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.
65

76

8-
==== capturedParametersInInitializers2.ts (5 errors) ====
7+
==== capturedParametersInInitializers2.ts (4 errors) ====
98
function foo(
109
y = class {
1110
static c = x;
@@ -25,8 +24,6 @@ capturedParametersInInitializers2.ts(13,27): error TS2373: Parameter 'y' cannot
2524
y.c
2625
}
2726
function foo2(y = class {[x] = x}, x = 1) {
28-
~~~
29-
!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type.
3027
~
3128
!!! error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.
3229
}

testdata/baselines/reference/submodule/compiler/capturedParametersInInitializers2.errors.txt.diff

Lines changed: 0 additions & 24 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/complicatedPrivacy.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
complicatedPrivacy.ts(11,24): error TS1054: A 'get' accessor cannot have parameters.
2-
complicatedPrivacy.ts(35,5): error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
32
complicatedPrivacy.ts(35,6): error TS2693: 'number' only refers to a type, but is being used as a value here.
43
complicatedPrivacy.ts(73,55): error TS2694: Namespace 'mglo5' has no exported member 'i6'.
54

65

7-
==== complicatedPrivacy.ts (4 errors) ====
6+
==== complicatedPrivacy.ts (3 errors) ====
87
module m1 {
98
export module m2 {
109

@@ -42,8 +41,6 @@ complicatedPrivacy.ts(73,55): error TS2694: Namespace 'mglo5' has no exported me
4241
export function f4(arg1:
4342
{
4443
[number]: C1; // Used to be indexer, now it is a computed property
45-
~~~~~~~~
46-
!!! error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
4744
~~~~~~
4845
!!! error TS2693: 'number' only refers to a type, but is being used as a value here.
4946
}) {

testdata/baselines/reference/submodule/compiler/complicatedPrivacy.errors.txt.diff

Lines changed: 0 additions & 23 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/declarationEmitComputedPropertyNameEnum2.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
type.ts(1,28): error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
21
type.ts(1,29): error TS2304: Cannot find name 'Enum'.
32

43

5-
==== type.ts (2 errors) ====
4+
==== type.ts (1 errors) ====
65
export type Type = { x?: { [Enum.A]: 0 } };
7-
~~~~~~~~
8-
!!! error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
96
~~~~
107
!!! error TS2304: Cannot find name 'Enum'.
118

testdata/baselines/reference/submodule/compiler/declarationEmitComputedPropertyNameEnum2.errors.txt.diff

Lines changed: 0 additions & 15 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/declarationEmitComputedPropertyNameEnum3.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
type.ts(7,28): error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
21
type.ts(7,28): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
32

43

5-
==== type.ts (2 errors) ====
4+
==== type.ts (1 errors) ====
65
export namespace Foo {
76
export enum Enum {
87
A = "a",
@@ -11,8 +10,6 @@ type.ts(7,28): error TS2464: A computed property name must be of type 'string',
1110
}
1211
export type Type = { x?: { [Foo.Enum]: 0 } };
1312
~~~~~~~~~~
14-
!!! error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
15-
~~~~~~~~~~
1613
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
1714

1815
==== index.ts (0 errors) ====

testdata/baselines/reference/submodule/compiler/declarationEmitComputedPropertyNameEnum3.errors.txt.diff

Lines changed: 0 additions & 21 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/declarationEmitMultipleComputedNamesSameDomain.errors.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/declarationEmitMultipleComputedNamesSameDomain.errors.txt.diff

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)