Add errors for break and continue statements
This commit is contained in:
Родитель
e2617750b1
Коммит
76804eb1f9
|
@ -5276,9 +5276,6 @@ module ts {
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.return_statement_has_no_containing_function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -394,13 +394,17 @@ module ts {
|
|||
|
||||
var lookAheadMode = LookAheadMode.NotLookingAhead;
|
||||
var inAmbientContext = false;
|
||||
var inModuleBody = false;
|
||||
var inFunctionBody = false;
|
||||
var inSwitchStatement = ControlBlockContext.NotNested;
|
||||
var inIterationStatement = ControlBlockContext.NotNested;
|
||||
|
||||
var labelledStatementInfo = (() => {
|
||||
// TODO(jfreeman): Implement a data structure for tracking labels
|
||||
var functionBoundarySentinel = <LabelledStatement>{};
|
||||
var labelledStatementStack: LabelledStatement[];
|
||||
|
||||
// TODO(jfreeman): Fill in these stubs
|
||||
return {
|
||||
getLength: (): number => 0,
|
||||
enqueueFunctionBoundary: () => { },
|
||||
|
@ -2072,12 +2076,56 @@ module ts {
|
|||
|
||||
function parseBreakOrContinueStatement(kind: SyntaxKind): BreakOrContinueStatement {
|
||||
var node = <BreakOrContinueStatement>createNode(kind);
|
||||
var errorCountBeforeStatement = file.syntacticErrors.length;
|
||||
var keywordStart = scanner.getTokenPos();
|
||||
var keywordLength = scanner.getTextPos() - keywordStart;
|
||||
parseExpected(kind === SyntaxKind.BreakStatement ? SyntaxKind.BreakKeyword : SyntaxKind.ContinueKeyword);
|
||||
if (!isSemicolon()) node.label = parseIdentifier();
|
||||
parseSemicolon();
|
||||
|
||||
// In an ambient context, we will already give an error for having a statement.
|
||||
if (!inAmbientContext && errorCountBeforeStatement === file.syntacticErrors.length) {
|
||||
if (!node.label) {
|
||||
checkAnonymousBreakOrContinueStatement(kind, keywordStart, keywordLength);
|
||||
}
|
||||
}
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function checkAnonymousBreakOrContinueStatement(kind: SyntaxKind, errorStart: number, errorLength: number): void {
|
||||
if (kind === SyntaxKind.BreakStatement) {
|
||||
if (inIterationStatement === ControlBlockContext.Nested
|
||||
|| inSwitchStatement === ControlBlockContext.Nested) {
|
||||
return;
|
||||
}
|
||||
else if (inIterationStatement === ControlBlockContext.NotNested
|
||||
&& inSwitchStatement === ControlBlockContext.NotNested) {
|
||||
grammarErrorAtPos(errorStart, errorLength,
|
||||
Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement);
|
||||
return;
|
||||
}
|
||||
// Fall through
|
||||
}
|
||||
else if (kind === SyntaxKind.ContinueStatement) {
|
||||
if (inIterationStatement === ControlBlockContext.Nested) {
|
||||
return;
|
||||
}
|
||||
else if (inIterationStatement === ControlBlockContext.NotNested) {
|
||||
grammarErrorAtPos(errorStart, errorLength,
|
||||
Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement);
|
||||
return;
|
||||
}
|
||||
// Fall through
|
||||
}
|
||||
else {
|
||||
Debug.fail("checkAnonymousBreakOrContinueStatement");
|
||||
}
|
||||
|
||||
Debug.assert(inIterationStatement === ControlBlockContext.CrossingFunctionBoundary
|
||||
|| inSwitchStatement === ControlBlockContext.CrossingFunctionBoundary);
|
||||
grammarErrorAtPos(errorStart, errorLength, Diagnostics.Jump_target_cannot_cross_function_boundary);
|
||||
}
|
||||
|
||||
function parseReturnStatement(): ReturnStatement {
|
||||
var node = <ReturnStatement>createNode(SyntaxKind.ReturnStatement);
|
||||
var errorCountBeforeReturnStatement = file.syntacticErrors.length;
|
||||
|
@ -2088,7 +2136,7 @@ module ts {
|
|||
if (!isSemicolon()) node.expression = parseExpression();
|
||||
parseSemicolon();
|
||||
|
||||
if (!inFunctionBody && errorCountBeforeReturnStatement === file.syntacticErrors.length) {
|
||||
if (!inFunctionBody && !inModuleBody && errorCountBeforeReturnStatement === file.syntacticErrors.length) {
|
||||
grammarErrorAtPos(returnTokenStart, returnTokenLength, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
|
||||
}
|
||||
return finishNode(node);
|
||||
|
@ -2827,7 +2875,11 @@ module ts {
|
|||
function parseModuleBody(): Block {
|
||||
var node = <Block>createNode(SyntaxKind.ModuleBlock);
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken)) {
|
||||
var saveInModuleBody = inModuleBody;
|
||||
inModuleBody = true;
|
||||
node.statements = parseList(ParsingContext.ModuleElements, parseModuleElement);
|
||||
inModuleBody = saveInModuleBody;
|
||||
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -407,12 +407,10 @@ module ts {
|
|||
}
|
||||
|
||||
export interface DoStatement extends IterationStatement {
|
||||
statement: Statement;
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
export interface WhileStatement extends IterationStatement {
|
||||
statement: Statement;
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
|
@ -421,14 +419,12 @@ module ts {
|
|||
initializer?: Expression;
|
||||
condition?: Expression;
|
||||
iterator?: Expression;
|
||||
statement: Statement;
|
||||
}
|
||||
|
||||
export interface ForInStatement extends IterationStatement {
|
||||
declaration?: VariableDeclaration;
|
||||
variable?: Expression;
|
||||
expression: Expression;
|
||||
statement: Statement;
|
||||
}
|
||||
|
||||
export interface BreakOrContinueStatement extends Statement {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
==== tests/cases/compiler/breakNotInIterationOrSwitchStatement1.ts (1 errors) ====
|
||||
break;
|
||||
~~~~~
|
||||
!!! A 'break' statement can only be used within an enclosing iteration or switch statement.
|
|
@ -1,5 +0,0 @@
|
|||
//// [breakNotInIterationOrSwitchStatement1.ts]
|
||||
break;
|
||||
|
||||
//// [breakNotInIterationOrSwitchStatement1.js]
|
||||
break;
|
|
@ -0,0 +1,8 @@
|
|||
==== tests/cases/compiler/breakNotInIterationOrSwitchStatement2.ts (1 errors) ====
|
||||
while (true) {
|
||||
function f() {
|
||||
break;
|
||||
~~~~~
|
||||
!!! Jump target cannot cross function boundary.
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
//// [breakNotInIterationOrSwitchStatement2.ts]
|
||||
while (true) {
|
||||
function f() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//// [breakNotInIterationOrSwitchStatement2.js]
|
||||
while (true) {
|
||||
function f() {
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
==== tests/cases/compiler/continueNotInIterationStatement1.ts (1 errors) ====
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
|
@ -1,5 +0,0 @@
|
|||
//// [continueNotInIterationStatement1.ts]
|
||||
continue;
|
||||
|
||||
//// [continueNotInIterationStatement1.js]
|
||||
continue;
|
|
@ -0,0 +1,8 @@
|
|||
==== tests/cases/compiler/continueNotInIterationStatement2.ts (1 errors) ====
|
||||
while (true) {
|
||||
function f() {
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! Jump target cannot cross function boundary.
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
//// [continueNotInIterationStatement2.ts]
|
||||
while (true) {
|
||||
function f() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//// [continueNotInIterationStatement2.js]
|
||||
while (true) {
|
||||
function f() {
|
||||
continue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
==== tests/cases/compiler/continueNotInIterationStatement3.ts (1 errors) ====
|
||||
switch (0) {
|
||||
default:
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
//// [continueNotInIterationStatement3.ts]
|
||||
switch (0) {
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
//// [continueNotInIterationStatement3.js]
|
||||
switch (0) {
|
||||
default:
|
||||
continue;
|
||||
}
|
|
@ -19,8 +19,8 @@
|
|||
return 1;
|
||||
~~~~~~
|
||||
!!! Property or signature expected.
|
||||
~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
};
|
||||
~
|
||||
!!! Declaration or statement expected.
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
==== tests/cases/conformance/statements/breakStatements/invalidDoWhileBreakStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
~~~~~
|
||||
!!! A 'break' statement can only be used within an enclosing iteration or switch statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
do break TWO; while (true)
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
do {
|
||||
var x = () => {
|
||||
break TWO;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
THREE:
|
||||
do {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
// break forward
|
||||
do {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
do { } while (true)
|
||||
}while (true)
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
do {
|
||||
break NINE;
|
||||
}while (true)
|
|
@ -1,64 +0,0 @@
|
|||
//// [invalidDoWhileBreakStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
do break TWO; while (true)
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
do {
|
||||
var x = () => {
|
||||
break TWO;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
THREE:
|
||||
do {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
// break forward
|
||||
do {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
do { } while (true)
|
||||
}while (true)
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
do {
|
||||
break NINE;
|
||||
}while (true)
|
||||
|
||||
//// [invalidDoWhileBreakStatements.js]
|
||||
break;
|
||||
ONE: do
|
||||
break TWO;
|
||||
while (true);
|
||||
TWO: do {
|
||||
var x = function () {
|
||||
break TWO;
|
||||
};
|
||||
} while (true);
|
||||
THREE: do {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
};
|
||||
} while (true);
|
||||
do {
|
||||
break FIVE;
|
||||
FIVE: do {
|
||||
} while (true);
|
||||
} while (true);
|
||||
NINE: var y = 12;
|
||||
do {
|
||||
break NINE;
|
||||
} while (true);
|
|
@ -0,0 +1,41 @@
|
|||
==== tests/cases/conformance/statements/continueStatements/invalidDoWhileContinueStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
do continue TWO; while (true)
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
do {
|
||||
var x = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
THREE:
|
||||
do {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
// continue forward
|
||||
do {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
do { } while (true)
|
||||
}while (true)
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
do {
|
||||
continue NINE;
|
||||
}while (true)
|
|
@ -1,64 +0,0 @@
|
|||
//// [invalidDoWhileContinueStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
do continue TWO; while (true)
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
do {
|
||||
var x = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
THREE:
|
||||
do {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}while (true)
|
||||
|
||||
// continue forward
|
||||
do {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
do { } while (true)
|
||||
}while (true)
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
do {
|
||||
continue NINE;
|
||||
}while (true)
|
||||
|
||||
//// [invalidDoWhileContinueStatements.js]
|
||||
continue;
|
||||
ONE: do
|
||||
continue TWO;
|
||||
while (true);
|
||||
TWO: do {
|
||||
var x = function () {
|
||||
continue TWO;
|
||||
};
|
||||
} while (true);
|
||||
THREE: do {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
};
|
||||
} while (true);
|
||||
do {
|
||||
continue FIVE;
|
||||
FIVE: do {
|
||||
} while (true);
|
||||
} while (true);
|
||||
NINE: var y = 12;
|
||||
do {
|
||||
continue NINE;
|
||||
} while (true);
|
|
@ -0,0 +1,40 @@
|
|||
==== tests/cases/conformance/statements/breakStatements/invalidForBreakStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
~~~~~
|
||||
!!! A 'break' statement can only be used within an enclosing iteration or switch statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for(;;) break TWO;
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
for(;;) {
|
||||
var x = () => {
|
||||
break TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for(;;) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// break forward
|
||||
for(;;) {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
for (; ;) { }
|
||||
}
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for(;;) {
|
||||
break NINE;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//// [invalidForBreakStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for(;;) break TWO;
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
for(;;) {
|
||||
var x = () => {
|
||||
break TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for(;;) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// break forward
|
||||
for(;;) {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
for (; ;) { }
|
||||
}
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for(;;) {
|
||||
break NINE;
|
||||
}
|
||||
|
||||
//// [invalidForBreakStatements.js]
|
||||
break;
|
||||
ONE: for (;;)
|
||||
break TWO;
|
||||
TWO: for (;;) {
|
||||
var x = function () {
|
||||
break TWO;
|
||||
};
|
||||
}
|
||||
THREE: for (;;) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
};
|
||||
}
|
||||
for (;;) {
|
||||
break FIVE;
|
||||
FIVE: for (;;) {
|
||||
}
|
||||
}
|
||||
NINE: var y = 12;
|
||||
for (;;) {
|
||||
break NINE;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
==== tests/cases/conformance/statements/continueStatements/invalidForContinueStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for(;;) continue TWO;
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
for(;;) {
|
||||
var x = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for(;;) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// continue forward
|
||||
for(;;) {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
for (; ;) { }
|
||||
}
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for(;;) {
|
||||
continue NINE;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//// [invalidForContinueStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for(;;) continue TWO;
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
for(;;) {
|
||||
var x = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for(;;) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// continue forward
|
||||
for(;;) {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
for (; ;) { }
|
||||
}
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for(;;) {
|
||||
continue NINE;
|
||||
}
|
||||
|
||||
//// [invalidForContinueStatements.js]
|
||||
continue;
|
||||
ONE: for (;;)
|
||||
continue TWO;
|
||||
TWO: for (;;) {
|
||||
var x = function () {
|
||||
continue TWO;
|
||||
};
|
||||
}
|
||||
THREE: for (;;) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
};
|
||||
}
|
||||
for (;;) {
|
||||
continue FIVE;
|
||||
FIVE: for (;;) {
|
||||
}
|
||||
}
|
||||
NINE: var y = 12;
|
||||
for (;;) {
|
||||
continue NINE;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
==== tests/cases/conformance/statements/breakStatements/invalidForInBreakStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
~~~~~
|
||||
!!! A 'break' statement can only be used within an enclosing iteration or switch statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for (var x in {}) break TWO;
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
for (var x in {}) {
|
||||
var fn = () => {
|
||||
break TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for (var x in {}) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// break forward
|
||||
for (var x in {}) {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
for (var x in {}) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for (var x in {}) {
|
||||
break NINE;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
//// [invalidForInBreakStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for (var x in {}) break TWO;
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
for (var x in {}) {
|
||||
var fn = () => {
|
||||
break TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for (var x in {}) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// break forward
|
||||
for (var x in {}) {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
for (var x in {}) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for (var x in {}) {
|
||||
break NINE;
|
||||
}
|
||||
|
||||
//// [invalidForInBreakStatements.js]
|
||||
break;
|
||||
ONE: for (var x in {})
|
||||
break TWO;
|
||||
TWO: for (var x in {}) {
|
||||
var fn = function () {
|
||||
break TWO;
|
||||
};
|
||||
}
|
||||
THREE: for (var x in {}) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
};
|
||||
}
|
||||
for (var x in {}) {
|
||||
break FIVE;
|
||||
FIVE: for (var x in {}) {
|
||||
}
|
||||
}
|
||||
NINE: var y = 12;
|
||||
for (var x in {}) {
|
||||
break NINE;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
==== tests/cases/conformance/statements/continueStatements/invalidForInContinueStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for (var x in {}) continue TWO;
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
for (var x in {}) {
|
||||
var fn = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for (var x in {}) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// continue forward
|
||||
for (var x in {}) {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
for (var x in {}) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for (var x in {}) {
|
||||
continue NINE;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
//// [invalidForInContinueStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
for (var x in {}) continue TWO;
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
for (var x in {}) {
|
||||
var fn = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
for (var x in {}) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// continue forward
|
||||
for (var x in {}) {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
for (var x in {}) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
for (var x in {}) {
|
||||
continue NINE;
|
||||
}
|
||||
|
||||
//// [invalidForInContinueStatements.js]
|
||||
continue;
|
||||
ONE: for (var x in {})
|
||||
continue TWO;
|
||||
TWO: for (var x in {}) {
|
||||
var fn = function () {
|
||||
continue TWO;
|
||||
};
|
||||
}
|
||||
THREE: for (var x in {}) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
};
|
||||
}
|
||||
for (var x in {}) {
|
||||
continue FIVE;
|
||||
FIVE: for (var x in {}) {
|
||||
}
|
||||
}
|
||||
NINE: var y = 12;
|
||||
for (var x in {}) {
|
||||
continue NINE;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
==== tests/cases/conformance/statements/continueStatements/invalidSwitchContinueStatement.ts (1 errors) ====
|
||||
// continue is not allowed in a switch statement
|
||||
|
||||
switch (12) {
|
||||
case 5:
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
//// [invalidSwitchContinueStatement.ts]
|
||||
// continue is not allowed in a switch statement
|
||||
|
||||
switch (12) {
|
||||
case 5:
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//// [invalidSwitchContinueStatement.js]
|
||||
switch (12) {
|
||||
case 5:
|
||||
continue;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
==== tests/cases/conformance/statements/breakStatements/invalidWhileBreakStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
~~~~~
|
||||
!!! A 'break' statement can only be used within an enclosing iteration or switch statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
while (true) break TWO;
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
while (true){
|
||||
var x = () => {
|
||||
break TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
while (true) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// break forward
|
||||
while (true) {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
while (true) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
while (true) {
|
||||
break NINE;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
//// [invalidWhileBreakStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked break not allowed
|
||||
break;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
while (true) break TWO;
|
||||
|
||||
// break from inside function
|
||||
TWO:
|
||||
while (true){
|
||||
var x = () => {
|
||||
break TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
while (true) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// break forward
|
||||
while (true) {
|
||||
break FIVE;
|
||||
FIVE:
|
||||
while (true) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
while (true) {
|
||||
break NINE;
|
||||
}
|
||||
|
||||
//// [invalidWhileBreakStatements.js]
|
||||
break;
|
||||
ONE: while (true)
|
||||
break TWO;
|
||||
TWO: while (true) {
|
||||
var x = function () {
|
||||
break TWO;
|
||||
};
|
||||
}
|
||||
THREE: while (true) {
|
||||
var fn = function () {
|
||||
break THREE;
|
||||
};
|
||||
}
|
||||
while (true) {
|
||||
break FIVE;
|
||||
FIVE: while (true) {
|
||||
}
|
||||
}
|
||||
NINE: var y = 12;
|
||||
while (true) {
|
||||
break NINE;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
==== tests/cases/conformance/statements/continueStatements/invalidWhileContinueStatements.ts (1 errors) ====
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
~~~~~~~~
|
||||
!!! A 'continue' statement can only be used within an enclosing iteration statement.
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
while (true) continue TWO;
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
while (true){
|
||||
var x = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
while (true) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// continue forward
|
||||
while (true) {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
while (true) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
while (true) {
|
||||
continue NINE;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
//// [invalidWhileContinueStatements.ts]
|
||||
// All errors
|
||||
|
||||
// naked continue not allowed
|
||||
continue;
|
||||
|
||||
// non-existent label
|
||||
ONE:
|
||||
while (true) continue TWO;
|
||||
|
||||
// continue from inside function
|
||||
TWO:
|
||||
while (true){
|
||||
var x = () => {
|
||||
continue TWO;
|
||||
}
|
||||
}
|
||||
|
||||
THREE:
|
||||
while (true) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
}
|
||||
}
|
||||
|
||||
// continue forward
|
||||
while (true) {
|
||||
continue FIVE;
|
||||
FIVE:
|
||||
while (true) { }
|
||||
}
|
||||
|
||||
// label on non-loop statement
|
||||
NINE:
|
||||
var y = 12;
|
||||
|
||||
while (true) {
|
||||
continue NINE;
|
||||
}
|
||||
|
||||
//// [invalidWhileContinueStatements.js]
|
||||
continue;
|
||||
ONE: while (true)
|
||||
continue TWO;
|
||||
TWO: while (true) {
|
||||
var x = function () {
|
||||
continue TWO;
|
||||
};
|
||||
}
|
||||
THREE: while (true) {
|
||||
var fn = function () {
|
||||
continue THREE;
|
||||
};
|
||||
}
|
||||
while (true) {
|
||||
continue FIVE;
|
||||
FIVE: while (true) {
|
||||
}
|
||||
}
|
||||
NINE: var y = 12;
|
||||
while (true) {
|
||||
continue NINE;
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
var f: (x: 'hi') => number = ('hi') => { return 1; };
|
||||
~~
|
||||
!!! ';' expected.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! Specialized overload signature is not assignable to any non-specialized signature.
|
||||
~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
!!! Specialized overload signature is not assignable to any non-specialized signature.
|
|
@ -1,13 +1,13 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ModuleElements/parserErrorRecovery_ModuleElement1.ts (4 errors) ====
|
||||
return foo;
|
||||
~~~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
}
|
||||
~
|
||||
!!! Declaration or statement expected.
|
||||
return bar;
|
||||
~~~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
}
|
||||
~
|
||||
!!! Declaration or statement expected.
|
|
@ -1,5 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (1 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (2 errors) ====
|
||||
var a,
|
||||
~
|
||||
!!! Trailing comma not allowed.
|
||||
return;
|
||||
return;
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
|
@ -4,6 +4,6 @@
|
|||
!!! Cannot find name 'a'.
|
||||
{
|
||||
return true;
|
||||
~~~~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
//// [parserNotRegex1.ts]
|
||||
if (a.indexOf(-(4/3))) // We should not get a regex here becuase of the / in the comment.
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//// [parserNotRegex1.js]
|
||||
if (a.indexOf(-(4 / 3))) {
|
||||
return true;
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts (1 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts (2 errors) ====
|
||||
public break;
|
||||
~~~~~~
|
||||
!!! Declaration or statement expected.
|
||||
~~~~~
|
||||
!!! A 'break' statement can only be used within an enclosing iteration or switch statement.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts (1 errors) ====
|
||||
return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
|
@ -1,5 +0,0 @@
|
|||
//// [parserRegularExpression1.ts]
|
||||
return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g;
|
||||
|
||||
//// [parserRegularExpression1.js]
|
||||
return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g;
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserReturnStatement1.d.ts (1 errors) ====
|
||||
return;
|
||||
~~~~~~
|
||||
!!! Statements are not allowed in ambient contexts.
|
||||
!!! A 'return' statement can only be used within a function body.
|
|
@ -0,0 +1,4 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/ReturnStatements/parserReturnStatement1.ts (1 errors) ====
|
||||
return;
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
|
@ -1,5 +0,0 @@
|
|||
//// [parserReturnStatement1.ts]
|
||||
return;
|
||||
|
||||
//// [parserReturnStatement1.js]
|
||||
return;
|
|
@ -0,0 +1,6 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/ReturnStatements/parserReturnStatement2.ts (1 errors) ====
|
||||
{
|
||||
return;
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
//// [parserReturnStatement2.ts]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//// [parserReturnStatement2.js]
|
||||
{
|
||||
return;
|
||||
}
|
|
@ -1,22 +1,13 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (1 errors) ====
|
||||
return {
|
||||
~~~~~~~~
|
||||
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
|
||||
"set": function (key, value) {
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
// 'private' should not be considered a member variable here.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
private[key] = value;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
}
|
||||
~~~
|
||||
|
||||
|
||||
};
|
||||
~~
|
||||
!!! 'return' statement has no containing function.
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
//// [parserStatementIsNotAMemberVariableDeclaration1.ts]
|
||||
return {
|
||||
|
||||
"set": function (key, value) {
|
||||
|
||||
// 'private' should not be considered a member variable here.
|
||||
private[key] = value;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//// [parserStatementIsNotAMemberVariableDeclaration1.js]
|
||||
return {
|
||||
"set": function (key, value) {
|
||||
private[key] = value;
|
||||
}
|
||||
};
|
|
@ -1,5 +1,7 @@
|
|||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts (1 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts (2 errors) ====
|
||||
with (1)
|
||||
~
|
||||
!!! All symbols within a 'with' block will be resolved to 'any'.
|
||||
return;
|
||||
return;
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
|
@ -1,7 +0,0 @@
|
|||
//// [parserWithStatement2.ts]
|
||||
with (1)
|
||||
return;
|
||||
|
||||
//// [parserWithStatement2.js]
|
||||
with (1)
|
||||
return;
|
|
@ -1,5 +0,0 @@
|
|||
//// [parser_breakNotInIterationOrSwitchStatement1.ts]
|
||||
break;
|
||||
|
||||
//// [parser_breakNotInIterationOrSwitchStatement1.js]
|
||||
break;
|
|
@ -1,13 +0,0 @@
|
|||
//// [parser_breakNotInIterationOrSwitchStatement2.ts]
|
||||
while (true) {
|
||||
function f() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//// [parser_breakNotInIterationOrSwitchStatement2.js]
|
||||
while (true) {
|
||||
function f() {
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
//// [parser_continueNotInIterationStatement1.ts]
|
||||
continue;
|
||||
|
||||
//// [parser_continueNotInIterationStatement1.js]
|
||||
continue;
|
|
@ -1,13 +0,0 @@
|
|||
//// [parser_continueNotInIterationStatement2.ts]
|
||||
while (true) {
|
||||
function f() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//// [parser_continueNotInIterationStatement2.js]
|
||||
while (true) {
|
||||
function f() {
|
||||
continue;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
//// [parser_continueNotInIterationStatement3.ts]
|
||||
switch (0) {
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
//// [parser_continueNotInIterationStatement3.js]
|
||||
switch (0) {
|
||||
default:
|
||||
continue;
|
||||
}
|
|
@ -26,8 +26,8 @@
|
|||
!!! Cannot find name 'baz'.
|
||||
|
||||
return this.bar; // doesn't get rewritten to Foo.bar.
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! 'return' statement has no containing function.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (8 errors) ====
|
||||
==== tests/cases/compiler/switchStatementsWithMultipleDefaults.ts (9 errors) ====
|
||||
|
||||
var x = 10;
|
||||
|
||||
|
@ -39,6 +39,8 @@
|
|||
default: return;
|
||||
~~~~~~~~
|
||||
!!! A 'default' clause cannot appear more than once in a 'switch' statement.
|
||||
~~~~~~
|
||||
!!! A 'return' statement can only be used within a function body.
|
||||
default: default:
|
||||
~~~~~~~~
|
||||
!!! A 'default' clause cannot appear more than once in a 'switch' statement.
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
break;
|
|
@ -1,5 +0,0 @@
|
|||
while (true) {
|
||||
function f() {
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
continue;
|
|
@ -1,5 +0,0 @@
|
|||
while (true) {
|
||||
function f() {
|
||||
continue;
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
switch (0) {
|
||||
default:
|
||||
continue;
|
||||
}
|
Загрузка…
Ссылка в новой задаче