Support automatic semicolon insertion in class member declarations.

This commit is contained in:
Daniel Rosenwasser 2014-07-16 16:40:20 -07:00
parent 0f7de96483
commit df5c2547fa
5 changed files with 55 additions and 36 deletions

View File

@ -2373,11 +2373,15 @@ module ts {
case SyntaxKind.LessThanToken: // Generic Method declaration
case SyntaxKind.ColonToken: // Type Annotation for declaration
case SyntaxKind.EqualsToken: // Initializer for declaration
case SyntaxKind.SemicolonToken: // Declaration termination
case SyntaxKind.CloseBraceToken: // End-of-class, must be declaration.
case SyntaxKind.EndOfFileToken: // Not valid, but permitted so that it gets caught later on.
case SyntaxKind.QuestionToken: // Not valid, but permitted so that it gets caught later on.
return true;
default:
// Covers
// - Semicolons (declaration termination)
// - Closing braces (end-of-class, must be declaration)
// - End-of-files (not valid, but permitted so that it gets caught later on)
// - Line-breaks (enabling *automatic semicolon insertion*)
return canParseSemicolon();
}
}

View File

@ -1,9 +0,0 @@
==== tests/cases/conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclaration26.ts (2 errors) ====
class C {
var
~~~
!!! Unexpected token. A constructor, method, accessor, or property was expected.
public
}
~
!!! Declaration or statement expected.

View File

@ -0,0 +1,12 @@
//// [parserClassDeclaration26.ts]
class C {
var
public
}
//// [parserClassDeclaration26.js]
var C = (function () {
function C() {
}
return C;
})();

View File

@ -1,24 +0,0 @@
==== tests/cases/compiler/varAsID.ts (2 errors) ====
class Foo {
var; // ok
x=1;
}
var f = new Foo();
class Foo2 {
var // not an error, because of ASI.
~~~
!!! Unexpected token. A constructor, method, accessor, or property was expected.
x=1;
}
~
!!! Declaration or statement expected.
var f2 = new Foo2();

View File

@ -0,0 +1,36 @@
//// [varAsID.ts]
class Foo {
var; // ok
x=1;
}
var f = new Foo();
class Foo2 {
var // not an error, because of ASI.
x=1;
}
var f2 = new Foo2();
//// [varAsID.js]
var Foo = (function () {
function Foo() {
this.x = 1;
}
return Foo;
})();
var f = new Foo();
var Foo2 = (function () {
function Foo2() {
this.x = 1;
}
return Foo2;
})();
var f2 = new Foo2();