mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Error on 'const' in class expression (#25125)
This commit is contained in:
@@ -27349,7 +27349,7 @@ namespace ts {
|
||||
}
|
||||
switch (modifier.kind) {
|
||||
case SyntaxKind.ConstKeyword:
|
||||
if (node.kind !== SyntaxKind.EnumDeclaration && node.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (node.kind !== SyntaxKind.EnumDeclaration) {
|
||||
return grammarErrorOnNode(node, Diagnostics.A_class_member_cannot_have_the_0_keyword, tokenToString(SyntaxKind.ConstKeyword));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/constInClassExpression.ts(2,11): error TS1248: A class member cannot have the 'const' keyword.
|
||||
|
||||
|
||||
==== tests/cases/compiler/constInClassExpression.ts (1 errors) ====
|
||||
let C = class {
|
||||
const a = 4;
|
||||
~
|
||||
!!! error TS1248: A class member cannot have the 'const' keyword.
|
||||
};
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [constInClassExpression.ts]
|
||||
let C = class {
|
||||
const a = 4;
|
||||
};
|
||||
|
||||
|
||||
//// [constInClassExpression.js]
|
||||
var C = /** @class */ (function () {
|
||||
function class_1() {
|
||||
this.a = 4;
|
||||
}
|
||||
return class_1;
|
||||
}());
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/constInClassExpression.ts ===
|
||||
let C = class {
|
||||
>C : Symbol(C, Decl(constInClassExpression.ts, 0, 3))
|
||||
|
||||
const a = 4;
|
||||
>a : Symbol(C.a, Decl(constInClassExpression.ts, 0, 15))
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/constInClassExpression.ts ===
|
||||
let C = class {
|
||||
>C : typeof C
|
||||
>class { const a = 4;} : typeof C
|
||||
|
||||
const a = 4;
|
||||
>a : number
|
||||
>4 : 4
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
let C = class {
|
||||
const a = 4;
|
||||
};
|
||||
Reference in New Issue
Block a user