Move grammar checking: callExpression, newExpression

This commit is contained in:
Yui T 2014-12-11 12:06:21 -08:00
parent b31981c6e9
commit 907d1d001b
9 changed files with 64 additions and 26 deletions

View File

@ -6248,6 +6248,12 @@ module ts {
}
function checkCallExpression(node: CallExpression): Type {
// Grammar checking
var hasGrammarErrorFromCheckModifierOrTypeArguments = checkGrammarModifiers(node) ? true : checkGrammarTypeArguments(node, node.typeArguments);
if (!hasGrammarErrorFromCheckModifierOrTypeArguments) {
checkGrammarArguments(node, node.arguments);
}
var signature = getResolvedSignature(node);
if (node.expression.kind === SyntaxKind.SuperKeyword) {
return voidType;
@ -9876,6 +9882,37 @@ module ts {
}
}
function checkGrammarForAtLeastOneTypeArgument(node: CallExpression, typeArguments: NodeArray<TypeNode>): boolean {
if (typeArguments && typeArguments.length === 0) {
var sourceFile = getSourceFileOfNode(node);
var start = typeArguments.pos - "<".length;
var end = skipTrivia(sourceFile.text, typeArguments.end) + ">".length;
return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_argument_list_cannot_be_empty);
}
}
function checkGrammarTypeArguments(node: CallExpression, typeArguments: NodeArray<TypeNode>): boolean {
return checkGrammarForDisallowedTrailingComma(typeArguments) ||
checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
}
function checkGrammarForOmittedArgument(node: CallExpression, arguments: NodeArray<Expression>): boolean {
if (arguments) {
var sourceFile = getSourceFileOfNode(node);
for (var i = 0, n = arguments.length; i < n; i++) {
var arg = arguments[i];
if (arg.kind === SyntaxKind.OmittedExpression) {
return grammarErrorAtPos(sourceFile, arg.pos, 0, Diagnostics.Argument_expression_expected);
}
}
}
}
function checkGrammarArguments(node: CallExpression, arguments: NodeArray<Expression>): boolean {
return checkGrammarForDisallowedTrailingComma(arguments) ||
checkGrammarForOmittedArgument(node, arguments);
}
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
return sourceFile.parseDiagnostics.length > 0;
}

View File

@ -64,7 +64,7 @@ module ts {
An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: DiagnosticCategory.Error, key: "An index signature must have exactly one parameter.", isEarly: true },
_0_list_cannot_be_empty: { code: 1097, category: DiagnosticCategory.Error, key: "'{0}' list cannot be empty.", isEarly: true },
Type_parameter_list_cannot_be_empty: { code: 1098, category: DiagnosticCategory.Error, key: "Type parameter list cannot be empty.", isEarly: true },
Type_argument_list_cannot_be_empty: { code: 1099, category: DiagnosticCategory.Error, key: "Type argument list cannot be empty." },
Type_argument_list_cannot_be_empty: { code: 1099, category: DiagnosticCategory.Error, key: "Type argument list cannot be empty.", isEarly: true },
Invalid_use_of_0_in_strict_mode: { code: 1100, category: DiagnosticCategory.Error, key: "Invalid use of '{0}' in strict mode.", isEarly: true },
with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: DiagnosticCategory.Error, key: "'with' statements are not allowed in strict mode.", isEarly: true },
delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: DiagnosticCategory.Error, key: "'delete' cannot be called on an identifier in strict mode.", isEarly: true },

View File

@ -287,7 +287,8 @@
},
"Type argument list cannot be empty.": {
"category": "Error",
"code": 1099
"code": 1099,
"isEarly": true
},
"Invalid use of '{0}' in strict mode.": {
"category": "Error",

View File

@ -4629,9 +4629,9 @@ module ts {
case SyntaxKind.BreakStatement:
case SyntaxKind.ContinueStatement:
return checkBreakOrContinueStatement(<BreakOrContinueStatement>node);
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return checkCallOrNewExpression(<NewExpression>node);
//case SyntaxKind.CallExpression:
//case SyntaxKind.NewExpression:
//return checkCallOrNewExpression(<NewExpression>node);
case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(<EnumDeclaration>node);
case SyntaxKind.BinaryExpression: return checkBinaryExpression(<BinaryExpression>node);

View File

@ -1,11 +1,11 @@
tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty.
tests/cases/compiler/emptyTypeArgumentList.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty.
==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ====
function foo<T>() { }
foo<>();
~~
!!! error TS1099: Type argument list cannot be empty.
~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
!!! error TS2346: Supplied parameters do not match any signature of call target.
~~
!!! error TS1099: Type argument list cannot be empty.

View File

@ -1,11 +1,11 @@
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty.
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty.
==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ====
class foo<T> { }
new foo<>();
~~
!!! error TS1099: Type argument list cannot be empty.
~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
!!! error TS2346: Supplied parameters do not match any signature of call target.
~~
!!! error TS1099: Type argument list cannot be empty.

View File

@ -1,16 +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,7): error TS1135: Argument expression expected.
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 TS1135: Argument expression expected.
~
!!! error TS2304: Cannot find name 'b'.

View File

@ -1,16 +1,16 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,9): error TS1009: Trailing comma not allowed.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,4): error TS2304: Cannot find name 'bar'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,8): error TS2304: Cannot find name 'a'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,9): error TS1009: Trailing comma not allowed.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts (3 errors) ====
function foo() {
bar(a,)
~
!!! error TS1009: Trailing comma not allowed.
~~~
!!! error TS2304: Cannot find name 'bar'.
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS1009: Trailing comma not allowed.
return;
}

View File

@ -1,7 +1,7 @@
tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,7): error TS1009: Trailing comma not allowed.
tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,8): error TS1009: Trailing comma not allowed.
tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,1): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,7): error TS1009: Trailing comma not allowed.
tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,1): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,8): error TS1009: Trailing comma not allowed.
==== tests/cases/compiler/trailingSeparatorInFunctionCall.ts (4 errors) ====
@ -9,16 +9,16 @@ tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,1): error TS2346: Supp
}
f(1, 2, );
~
!!! error TS1009: Trailing comma not allowed.
~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
~
!!! error TS1009: Trailing comma not allowed.
function f2<T>(x: T, y: T) {
}
f2(1, 2, );
~
!!! error TS1009: Trailing comma not allowed.
~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
!!! error TS2346: Supplied parameters do not match any signature of call target.
~
!!! error TS1009: Trailing comma not allowed.