Skip to content

Fix checkGrammarForInvalidDynamicName #1063

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

Merged
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
12 changes: 11 additions & 1 deletion internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,17 @@ func (c *Checker) checkGrammarTypeOperatorNode(node *ast.TypeOperatorNode) bool
}

func (c *Checker) checkGrammarForInvalidDynamicName(node *ast.DeclarationName, message *diagnostics.Message) bool {
if c.isNonBindableDynamicName(node) {
if !c.isNonBindableDynamicName(node) {
return false
}
var expression *ast.Node
if ast.IsElementAccessExpression(node) {
expression = ast.SkipParentheses(node.AsElementAccessExpression().ArgumentExpression)
} else {
expression = node.Expression()
}

if !ast.IsEntityNameExpression(expression) {
return c.grammarErrorOnNode(node, message)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
capturedParametersInInitializers2.ts(3,20): error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.
capturedParametersInInitializers2.ts(4,14): error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.
capturedParametersInInitializers2.ts(6,10): error TS2373: Parameter 'y' cannot reference identifier 'z' declared after it.
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.
capturedParametersInInitializers2.ts(13,27): error TS2373: Parameter 'y' cannot reference identifier 'x' declared after it.


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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
complicatedPrivacy.ts(11,24): error TS1054: A 'get' accessor cannot have parameters.
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.
complicatedPrivacy.ts(35,6): error TS2693: 'number' only refers to a type, but is being used as a value here.
complicatedPrivacy.ts(73,55): error TS2694: Namespace 'mglo5' has no exported member 'i6'.


==== complicatedPrivacy.ts (4 errors) ====
==== complicatedPrivacy.ts (3 errors) ====
module m1 {
export module m2 {

Expand Down Expand Up @@ -42,8 +41,6 @@ complicatedPrivacy.ts(73,55): error TS2694: Namespace 'mglo5' has no exported me
export function f4(arg1:
{
[number]: C1; // Used to be indexer, now it is a computed property
~~~~~~~~
!!! 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.
~~~~~~
!!! error TS2693: 'number' only refers to a type, but is being used as a value here.
}) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
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.
type.ts(1,29): error TS2304: Cannot find name 'Enum'.


==== type.ts (2 errors) ====
==== type.ts (1 errors) ====
export type Type = { x?: { [Enum.A]: 0 } };
~~~~~~~~
!!! 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.
~~~~
!!! error TS2304: Cannot find name 'Enum'.

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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.
type.ts(7,28): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.


==== type.ts (2 errors) ====
==== type.ts (1 errors) ====
export namespace Foo {
export enum Enum {
A = "a",
Expand All @@ -11,8 +10,6 @@ type.ts(7,28): error TS2464: A computed property name must be of type 'string',
}
export type Type = { x?: { [Foo.Enum]: 0 } };
~~~~~~~~~~
!!! 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.
~~~~~~~~~~
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.

==== index.ts (0 errors) ====
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading