report invalid modifiers on class expression properties

Fixes: #32532
This commit is contained in:
Klaus Meinhardt 2019-08-14 21:00:19 +02:00
parent 2483803398
commit 8eeb763cdd
3 changed files with 24 additions and 2 deletions

View File

@ -32406,7 +32406,7 @@ namespace ts {
else if (flags & ModifierFlags.Async) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "export", "async");
}
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
else if (isClassLike(node.parent)) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
}
else if (node.kind === SyntaxKind.Parameter) {
@ -32429,7 +32429,7 @@ namespace ts {
else if (flags & ModifierFlags.Async) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
}
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
else if (isClassLike(node.parent)) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
}
else if (node.kind === SyntaxKind.Parameter) {

View File

@ -0,0 +1,14 @@
tests/cases/compiler/classExpressionPropertyModifiers.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element.
tests/cases/compiler/classExpressionPropertyModifiers.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element.
==== tests/cases/compiler/classExpressionPropertyModifiers.ts (2 errors) ====
const a = class Cat {
declare [Symbol.toStringTag] = "uh";
~~~~~~~
!!! error TS1031: 'declare' modifier cannot appear on a class element.
export foo = 1;
~~~~~~
!!! error TS1031: 'export' modifier cannot appear on a class element.
}

View File

@ -0,0 +1,8 @@
// @noEmit: true
// @noTypesAndSymbols: true
// @lib: es6
const a = class Cat {
declare [Symbol.toStringTag] = "uh";
export foo = 1;
}