Move grammar checking: returnStatement; there are still error from incomplet grammar migration

This commit is contained in:
Yui T 2014-12-14 15:18:54 -08:00
parent e852f3379c
commit eadcc06fa3
4 changed files with 31 additions and 3 deletions

View file

@ -8126,6 +8126,20 @@ module ts {
}
function checkReturnStatement(node: ReturnStatement) {
// Grammar checking
var parent = node.parent;
var inFunctionBlock = false;
while (parent && parent.kind !== SyntaxKind.SourceFile) {
inFunctionBlock = isFunctionBlock(parent);
if (inFunctionBlock) {
break;
}
parent = parent.parent;
}
if (!inFunctionBlock) {
grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
}
if (node.expression) {
var func = getContainingFunction(node);
if (func) {
@ -8149,6 +8163,20 @@ module ts {
}
function checkWithStatement(node: WithStatement) {
// Grammar checking
if (node.statement.kind === SyntaxKind.ReturnStatement) {
// Grammar check for invalid use of return statement
grammarErrorOnFirstToken(node.statement, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
}
else if (node.statement.kind === SyntaxKind.Block) {
forEach((<Block>node.statement).statements, statement => {
if (statement.kind === SyntaxKind.ReturnStatement) {
// Grammar check for invalid use of return statement
grammarErrorOnFirstToken(node.statement, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
}
});
}
checkExpression(node.expression);
error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
}

View file

@ -4665,7 +4665,7 @@ module ts {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
return checkProperty(<PropertyDeclaration>node);
case SyntaxKind.ReturnStatement: return checkReturnStatement(<ReturnStatement>node);
//case SyntaxKind.ReturnStatement: return checkReturnStatement(<ReturnStatement>node);
case SyntaxKind.SetAccessor: return checkSetAccessor(<MethodDeclaration>node);
case SyntaxKind.SourceFile: return checkSourceFile(<SourceFile>node);
case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);

View file

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts(3,5): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts(1,7): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts(3,5): error TS1108: A 'return' statement can only be used within a function body.
==== tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts (2 errors) ====

View file

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts(2,3): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts(1,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'.
tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts(2,3): error TS1108: A 'return' statement can only be used within a function body.
==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts (2 errors) ====