Remove isSemicolon (fix #200)

This commit is contained in:
Jason Freeman 2014-07-25 16:17:30 -07:00
parent c1be793a04
commit 61731eefdf
9 changed files with 29 additions and 8 deletions

View File

@ -676,11 +676,6 @@ module ts {
return token === SyntaxKind.Identifier || (isInStrictMode ? token > SyntaxKind.LastFutureReservedWord : token > SyntaxKind.LastReservedWord);
}
function isSemicolon(): boolean {
// True if real or automatic semicolon
return token === SyntaxKind.SemicolonToken || token === SyntaxKind.CloseBraceToken || scanner.hasPrecedingLineBreak();
}
function parseExpected(t: SyntaxKind): boolean {
if (token === t) {
nextToken();
@ -2361,7 +2356,7 @@ module ts {
var keywordStart = scanner.getTokenPos();
var keywordLength = scanner.getTextPos() - keywordStart;
parseExpected(kind === SyntaxKind.BreakStatement ? SyntaxKind.BreakKeyword : SyntaxKind.ContinueKeyword);
if (!isSemicolon()) node.label = parseIdentifier();
if (!canParseSemicolon()) node.label = parseIdentifier();
parseSemicolon();
finishNode(node);
@ -2444,7 +2439,7 @@ module ts {
var returnTokenLength = scanner.getTextPos() - returnTokenStart;
parseExpected(SyntaxKind.ReturnKeyword);
if (!isSemicolon()) node.expression = parseExpression();
if (!canParseSemicolon()) node.expression = parseExpression();
parseSemicolon();
// In an ambient context, we will already give an error for having a statement.
@ -2727,7 +2722,7 @@ module ts {
}
return body;
}
if (isSemicolon()) {
if (canParseSemicolon()) {
parseSemicolon();
return undefined;
}

View File

@ -0,0 +1,4 @@
//// [asiAmbientFunctionDeclaration.ts]
declare function foo()
//// [asiAmbientFunctionDeclaration.js]

View File

@ -0,0 +1,6 @@
//// [asiBreak.ts]
while (true) break
//// [asiBreak.js]
while (true)
break;

View File

@ -0,0 +1,6 @@
//// [asiContinue.ts]
while (true) continue
//// [asiContinue.js]
while (true)
continue;

View File

@ -0,0 +1,5 @@
==== tests/cases/compiler/asiReturn.ts (1 errors) ====
// This should be an error for using a return outside a function, but ASI should work properly
return
~~~~~~
!!! A 'return' statement can only be used within a function body.

View File

@ -0,0 +1 @@
declare function foo()

View File

@ -0,0 +1 @@
while (true) break

View File

@ -0,0 +1 @@
while (true) continue

View File

@ -0,0 +1,2 @@
// This should be an error for using a return outside a function, but ASI should work properly
return