Error on 'const' in class expression (#25125)

This commit is contained in:
Andy
2018-06-21 09:57:52 -07:00
committed by GitHub
parent 3e50f502bb
commit 40899eaf5b
6 changed files with 47 additions and 1 deletions
+1 -1
View File
@@ -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;
};