Skip to content

Commit df5c254

Browse files
Support automatic semicolon insertion in class member declarations.
1 parent 0f7de96 commit df5c254

File tree

5 files changed

+55
-36
lines changed

5 files changed

+55
-36
lines changed

src/compiler/parser.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,11 +2373,15 @@ module ts {
23732373
case SyntaxKind.LessThanToken: // Generic Method declaration
23742374
case SyntaxKind.ColonToken: // Type Annotation for declaration
23752375
case SyntaxKind.EqualsToken: // Initializer for declaration
2376-
case SyntaxKind.SemicolonToken: // Declaration termination
2377-
case SyntaxKind.CloseBraceToken: // End-of-class, must be declaration.
2378-
case SyntaxKind.EndOfFileToken: // Not valid, but permitted so that it gets caught later on.
23792376
case SyntaxKind.QuestionToken: // Not valid, but permitted so that it gets caught later on.
23802377
return true;
2378+
default:
2379+
// Covers
2380+
// - Semicolons (declaration termination)
2381+
// - Closing braces (end-of-class, must be declaration)
2382+
// - End-of-files (not valid, but permitted so that it gets caught later on)
2383+
// - Line-breaks (enabling *automatic semicolon insertion*)
2384+
return canParseSemicolon();
23812385
}
23822386
}
23832387

tests/baselines/reference/parserClassDeclaration26.errors.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [parserClassDeclaration26.ts]
2+
class C {
3+
var
4+
public
5+
}
6+
7+
//// [parserClassDeclaration26.js]
8+
var C = (function () {
9+
function C() {
10+
}
11+
return C;
12+
})();

tests/baselines/reference/varAsID.errors.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/baselines/reference/varAsID.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [varAsID.ts]
2+
3+
class Foo {
4+
var; // ok
5+
x=1;
6+
}
7+
8+
var f = new Foo();
9+
10+
11+
class Foo2 {
12+
var // not an error, because of ASI.
13+
x=1;
14+
}
15+
16+
var f2 = new Foo2();
17+
18+
19+
20+
21+
22+
//// [varAsID.js]
23+
var Foo = (function () {
24+
function Foo() {
25+
this.x = 1;
26+
}
27+
return Foo;
28+
})();
29+
var f = new Foo();
30+
var Foo2 = (function () {
31+
function Foo2() {
32+
this.x = 1;
33+
}
34+
return Foo2;
35+
})();
36+
var f2 = new Foo2();

0 commit comments

Comments
 (0)