Move missing argument checks to the grammar walker.
This commit is contained in:
parent
7a414fc308
commit
76f88392a4
|
@ -2376,25 +2376,18 @@ module ts {
|
|||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic: DiagnosticMessage): Expression {
|
||||
if (token === SyntaxKind.CommaToken) {
|
||||
if (omittedExpressionDiagnostic) {
|
||||
var errorStart = scanner.getTokenPos();
|
||||
var errorLength = scanner.getTextPos() - errorStart;
|
||||
grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic);
|
||||
}
|
||||
return createNode(SyntaxKind.OmittedExpression);
|
||||
}
|
||||
|
||||
return parseAssignmentExpression();
|
||||
function parseAssignmentExpressionOrOmittedExpression(): Expression {
|
||||
return token === SyntaxKind.CommaToken
|
||||
? createNode(SyntaxKind.OmittedExpression)
|
||||
: parseAssignmentExpression();
|
||||
}
|
||||
|
||||
function parseArrayLiteralElement(): Expression {
|
||||
return parseAssignmentExpressionOrOmittedExpression(/*omittedExpressionDiagnostic*/ undefined);
|
||||
return parseAssignmentExpressionOrOmittedExpression();
|
||||
}
|
||||
|
||||
function parseArgumentExpression(): Expression {
|
||||
return parseAssignmentExpressionOrOmittedExpression(Diagnostics.Argument_expression_expected);
|
||||
return parseAssignmentExpressionOrOmittedExpression();
|
||||
}
|
||||
|
||||
function parseArrayLiteral(): ArrayLiteral {
|
||||
|
@ -3922,7 +3915,12 @@ module ts {
|
|||
|
||||
function visitCallExpression(node: CallExpression) {
|
||||
checkTypeArguments(node.typeArguments) ||
|
||||
checkForTrailingComma(node.arguments);
|
||||
checkArguments(node.arguments);
|
||||
}
|
||||
|
||||
function checkArguments(arguments: NodeArray<Expression>) {
|
||||
return checkForTrailingComma(arguments) ||
|
||||
checkForOmittedArgument(arguments);
|
||||
}
|
||||
|
||||
function checkTypeArguments(typeArguments: NodeArray<TypeNode>) {
|
||||
|
@ -3931,6 +3929,17 @@ module ts {
|
|||
checkForMissingTypeArgument(typeArguments);
|
||||
}
|
||||
|
||||
function checkForOmittedArgument(arguments: NodeArray<Expression>) {
|
||||
if (arguments) {
|
||||
for (var i = 0, n = arguments.length; i < n; i++) {
|
||||
var arg = arguments[i];
|
||||
if (arg.kind === SyntaxKind.OmittedExpression) {
|
||||
return grammarErrorAtPos(arg.pos, 0, Diagnostics.Argument_expression_expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkForMissingTypeArgument(typeArguments: NodeArray<TypeNode>) {
|
||||
if (typeArguments) {
|
||||
for (var i = 0, n = typeArguments.length; i < n; i++) {
|
||||
|
@ -4203,7 +4212,7 @@ module ts {
|
|||
|
||||
function visitNewExpression(node: NewExpression): void {
|
||||
checkTypeArguments(node.typeArguments) ||
|
||||
checkForTrailingComma(node.arguments);
|
||||
checkArguments(node.arguments);
|
||||
}
|
||||
|
||||
function visitObjectLiteral(node: ObjectLiteral): void {
|
||||
|
|
16
tests/baselines/reference/missingArgument1.errors.txt
Normal file
16
tests/baselines/reference/missingArgument1.errors.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
tests/cases/compiler/missingArgument1.ts(1,7): error TS1135: Argument expression expected.
|
||||
tests/cases/compiler/missingArgument1.ts(1,1): error TS2304: Cannot find name 'foo'.
|
||||
tests/cases/compiler/missingArgument1.ts(1,5): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/compiler/missingArgument1.ts(1,8): error TS2304: Cannot find name 'b'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/missingArgument1.ts (4 errors) ====
|
||||
foo(a,,b);
|
||||
|
||||
!!! error TS1135: Argument expression expected.
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'foo'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
|
@ -1,12 +1,9 @@
|
|||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts(1,5): error TS1135: Argument expression expected.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts(1,6): error TS1005: ')' expected.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts(1,1): error TS2304: Cannot find name 'Foo'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts (3 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts (2 errors) ====
|
||||
Foo(,
|
||||
~
|
||||
!!! error TS1135: Argument expression expected.
|
||||
|
||||
!!! error TS1005: ')' expected.
|
||||
~~~
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,7): error TS1135: Argument expression expected.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,8): error TS1005: ')' expected.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,1): error TS2304: Cannot find name 'Foo'.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts(1,5): error TS2304: Cannot find name 'a'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts (4 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts (3 errors) ====
|
||||
Foo(a,,
|
||||
~
|
||||
!!! error TS1135: Argument expression expected.
|
||||
|
||||
!!! error TS1005: ')' expected.
|
||||
~~~
|
||||
|
|
1
tests/cases/compiler/missingArgument1.ts
Normal file
1
tests/cases/compiler/missingArgument1.ts
Normal file
|
@ -0,0 +1 @@
|
|||
foo(a,,b);
|
Loading…
Reference in a new issue