mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-11 09:24:19 -06:00
Support automatic semicolon insertion in class member declarations.
This commit is contained in:
parent
0f7de96483
commit
df5c2547fa
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
12
tests/baselines/reference/parserClassDeclaration26.js
Normal file
12
tests/baselines/reference/parserClassDeclaration26.js
Normal file
@ -0,0 +1,12 @@
|
||||
//// [parserClassDeclaration26.ts]
|
||||
class C {
|
||||
var
|
||||
public
|
||||
}
|
||||
|
||||
//// [parserClassDeclaration26.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
})();
|
||||
@ -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();
|
||||
|
||||
|
||||
|
||||
|
||||
36
tests/baselines/reference/varAsID.js
Normal file
36
tests/baselines/reference/varAsID.js
Normal 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();
|
||||
Loading…
x
Reference in New Issue
Block a user