Skip to content

Commit 8eeb763

Browse files
committed
report invalid modifiers on class expression properties
Fixes: microsoft#32532
1 parent 2483803 commit 8eeb763

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32406,7 +32406,7 @@ namespace ts {
3240632406
else if (flags & ModifierFlags.Async) {
3240732407
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "export", "async");
3240832408
}
32409-
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
32409+
else if (isClassLike(node.parent)) {
3241032410
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
3241132411
}
3241232412
else if (node.kind === SyntaxKind.Parameter) {
@@ -32429,7 +32429,7 @@ namespace ts {
3242932429
else if (flags & ModifierFlags.Async) {
3243032430
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
3243132431
}
32432-
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
32432+
else if (isClassLike(node.parent)) {
3243332433
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
3243432434
}
3243532435
else if (node.kind === SyntaxKind.Parameter) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/compiler/classExpressionPropertyModifiers.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element.
2+
tests/cases/compiler/classExpressionPropertyModifiers.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element.
3+
4+
5+
==== tests/cases/compiler/classExpressionPropertyModifiers.ts (2 errors) ====
6+
const a = class Cat {
7+
declare [Symbol.toStringTag] = "uh";
8+
~~~~~~~
9+
!!! error TS1031: 'declare' modifier cannot appear on a class element.
10+
export foo = 1;
11+
~~~~~~
12+
!!! error TS1031: 'export' modifier cannot appear on a class element.
13+
}
14+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @noEmit: true
2+
// @noTypesAndSymbols: true
3+
// @lib: es6
4+
5+
const a = class Cat {
6+
declare [Symbol.toStringTag] = "uh";
7+
export foo = 1;
8+
}

0 commit comments

Comments
 (0)