Enhancement new expression with type arguments without parenthesized argument list error message (#37576)

* Enhancement new expression with type arguments without parenthesized argument list error message

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* add baselines

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* use parseErrorAt

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* refine code

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

* Space before paren

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
Rustin
2020-03-26 03:37:46 +08:00
committed by GitHub
parent b7b2c333a9
commit 8615eecfc1
12 changed files with 30 additions and 23 deletions

View File

@@ -1147,6 +1147,10 @@
"category": "Error",
"code": 1383
},
"A 'new' expression with type arguments must always be followed by a parenthesized argument list.": {
"category": "Error",
"code": 1384
},
"The types of '{0}' are incompatible between these types.": {
"category": "Error",

View File

@@ -5199,9 +5199,12 @@ namespace ts {
const node = <NewExpression>createNode(SyntaxKind.NewExpression, fullStart);
node.expression = expression;
node.typeArguments = typeArguments;
if (node.typeArguments || token() === SyntaxKind.OpenParenToken) {
if (token() === SyntaxKind.OpenParenToken) {
node.arguments = parseArgumentList();
}
else if (node.typeArguments) {
parseErrorAt(fullStart, scanner.getStartPos(), Diagnostics.A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list);
}
return finishNode(node);
}

View File

@@ -1,5 +1,5 @@
tests/cases/compiler/genericCallsWithoutParens.ts(2,18): error TS1005: '(' expected.
tests/cases/compiler/genericCallsWithoutParens.ts(7,22): error TS1005: '(' expected.
tests/cases/compiler/genericCallsWithoutParens.ts(7,8): error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
==== tests/cases/compiler/genericCallsWithoutParens.ts (2 errors) ====
@@ -12,7 +12,7 @@ tests/cases/compiler/genericCallsWithoutParens.ts(7,22): error TS1005: '(' expec
foo: T;
}
var c = new C<number>; // parse error
~
!!! error TS1005: '(' expected.
~~~~~~~~~~~~~~
!!! error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.

View File

@@ -17,4 +17,4 @@ var C = /** @class */ (function () {
}
return C;
}());
var c = new C(); // parse error
var c = new C; // parse error

View File

@@ -1,4 +1,4 @@
tests/cases/compiler/genericConstructExpressionWithoutArgs.ts(10,1): error TS1005: '(' expected.
tests/cases/compiler/genericConstructExpressionWithoutArgs.ts(9,9): error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
==== tests/cases/compiler/genericConstructExpressionWithoutArgs.ts (1 errors) ====
@@ -11,6 +11,6 @@ tests/cases/compiler/genericConstructExpressionWithoutArgs.ts(10,1): error TS100
var c = new C // C<any>
var c2 = new C<number> // error, type params are actually part of the arg list so you need both
!!! error TS1005: '(' expected.
~~~~~~~~~~~~~~
!!! error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.

View File

@@ -23,4 +23,4 @@ var C = /** @class */ (function () {
return C;
}());
var c = new C; // C<any>
var c2 = new C(); // error, type params are actually part of the arg list so you need both
var c2 = new C; // error, type params are actually part of the arg list so you need both

View File

@@ -1,4 +1,4 @@
tests/cases/compiler/genericObjectCreationWithoutTypeArgs.ts(6,26): error TS1005: '(' expected.
tests/cases/compiler/genericObjectCreationWithoutTypeArgs.ts(6,9): error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
==== tests/cases/compiler/genericObjectCreationWithoutTypeArgs.ts (1 errors) ====
@@ -8,8 +8,8 @@ tests/cases/compiler/genericObjectCreationWithoutTypeArgs.ts(6,26): error TS1005
var x1 = new SS<number>(); // OK
var x2 = new SS < number>; // Correctly give error
~
!!! error TS1005: '(' expected.
~~~~~~~~~~~~~~~~~
!!! error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
var x3 = new SS(); // OK
var x4 = new SS; // Should be allowed, but currently give error ('supplied parameters do not match any signature of the call target')

View File

@@ -16,6 +16,6 @@ var SS = /** @class */ (function () {
return SS;
}());
var x1 = new SS(); // OK
var x2 = new SS(); // Correctly give error
var x2 = new SS; // Correctly give error
var x3 = new SS(); // OK
var x4 = new SS; // Should be allowed, but currently give error ('supplied parameters do not match any signature of the call target')

View File

@@ -1,6 +1,6 @@
tests/cases/conformance/expressions/newOperator/newOperatorErrorCases.ts(26,16): error TS1005: ',' expected.
tests/cases/conformance/expressions/newOperator/newOperatorErrorCases.ts(26,16): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/expressions/newOperator/newOperatorErrorCases.ts(31,23): error TS1005: '(' expected.
tests/cases/conformance/expressions/newOperator/newOperatorErrorCases.ts(31,9): error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
tests/cases/conformance/expressions/newOperator/newOperatorErrorCases.ts(36,9): error TS2350: Only a void function can be called with the 'new' keyword.
@@ -40,8 +40,8 @@ tests/cases/conformance/expressions/newOperator/newOperatorErrorCases.ts(36,9):
var c1 = new T;
var c1: T<{}>;
var c2 = new T<string>; // Parse error
~
!!! error TS1005: '(' expected.
~~~~~~~~~~~~~~
!!! error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
// Construct expression of non-void returning function

View File

@@ -62,7 +62,7 @@ var b = new C0;
// Generic construct expression with no parentheses
var c1 = new T;
var c1;
var c2 = new T(); // Parse error
var c2 = new T; // Parse error
// Construct expression of non-void returning function
function fnNumber() { return 32; }
var s = new fnNumber(); // Error

View File

@@ -1,13 +1,13 @@
tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,1): error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,10): error TS2304: Cannot find name 'A'.
tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,10): error TS2558: Expected 0 type arguments, but got 1.
tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts(1,12): error TS1005: '(' expected.
==== tests/cases/conformance/parser/ecmascript5/Generics/parserConstructorAmbiguity3.ts (3 errors) ====
new Date<A>
~~~~~~~~~~~
!!! error TS1384: A 'new' expression with type arguments must always be followed by a parenthesized argument list.
~
!!! error TS2304: Cannot find name 'A'.
~
!!! error TS2558: Expected 0 type arguments, but got 1.
!!! error TS1005: '(' expected.
!!! error TS2558: Expected 0 type arguments, but got 1.

View File

@@ -2,4 +2,4 @@
new Date<A>
//// [parserConstructorAmbiguity3.js]
new Date();
new Date;