Merge pull request #32893 from ajafff/classexpressionpropertymodifiers

report invalid modifiers on class expression properties
This commit is contained in:
Sheetal Nandi 2019-08-14 12:41:46 -07:00 committed by GitHub
commit 8f30c09d99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
}