mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-06 23:59:42 -05:00
Improve parse error for double comma somewhere inside a call expression (#20399)
This commit is contained in:
@@ -1429,9 +1429,13 @@ namespace ts {
|
||||
return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isIdentifierOrPattern();
|
||||
case ParsingContext.TypeParameters:
|
||||
return isIdentifier();
|
||||
case ParsingContext.ArgumentExpressions:
|
||||
case ParsingContext.ArrayLiteralMembers:
|
||||
return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isStartOfExpression();
|
||||
if (token() === SyntaxKind.CommaToken) {
|
||||
return true;
|
||||
}
|
||||
// falls through
|
||||
case ParsingContext.ArgumentExpressions:
|
||||
return token() === SyntaxKind.DotDotDotToken || isStartOfExpression();
|
||||
case ParsingContext.Parameters:
|
||||
return isStartOfParameter();
|
||||
case ParsingContext.TypeArguments:
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS2307: Cannot find module 'pathToModule'.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1324: Dynamic import must have one specifier as an argument.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS2307: Cannot find module 'pathToModule'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ====
|
||||
==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ====
|
||||
declare function getSpecifier(): string;
|
||||
declare var whatToLoad: boolean;
|
||||
|
||||
@@ -22,11 +20,6 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,19)
|
||||
const p2 = import();
|
||||
~~~~~~~~
|
||||
!!! error TS1324: Dynamic import must have one specifier as an argument.
|
||||
const p3 = import(,);
|
||||
|
||||
!!! error TS1135: Argument expression expected.
|
||||
|
||||
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'.
|
||||
const p4 = import("pathToModule", "secondModule");
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic import must have one specifier as an argument.
|
||||
|
||||
@@ -7,7 +7,6 @@ import(...["PathModule"]);
|
||||
|
||||
var p1 = import(...a);
|
||||
const p2 = import();
|
||||
const p3 = import(,);
|
||||
const p4 = import("pathToModule", "secondModule");
|
||||
|
||||
//// [importCallExpressionGrammarError.js]
|
||||
@@ -15,5 +14,4 @@ var a = ["./0"];
|
||||
Promise.resolve().then(() => require(...["PathModule"]));
|
||||
var p1 = Promise.resolve().then(() => require(...a));
|
||||
const p2 = Promise.resolve().then(() => require());
|
||||
const p3 = Promise.resolve().then(() => require());
|
||||
const p4 = Promise.resolve().then(() => require("pathToModule"));
|
||||
|
||||
@@ -17,9 +17,6 @@ var p1 = import(...a);
|
||||
const p2 = import();
|
||||
>p2 : Symbol(p2, Decl(importCallExpressionGrammarError.ts, 7, 5))
|
||||
|
||||
const p3 = import(,);
|
||||
>p3 : Symbol(p3, Decl(importCallExpressionGrammarError.ts, 8, 5))
|
||||
|
||||
const p4 = import("pathToModule", "secondModule");
|
||||
>p4 : Symbol(p4, Decl(importCallExpressionGrammarError.ts, 9, 5))
|
||||
>p4 : Symbol(p4, Decl(importCallExpressionGrammarError.ts, 8, 5))
|
||||
|
||||
|
||||
@@ -26,11 +26,6 @@ const p2 = import();
|
||||
>p2 : Promise<any>
|
||||
>import() : Promise<any>
|
||||
|
||||
const p3 = import(,);
|
||||
>p3 : Promise<any>
|
||||
>import(,) : Promise<any>
|
||||
> : undefined
|
||||
|
||||
const p4 = import("pathToModule", "secondModule");
|
||||
>p4 : Promise<any>
|
||||
>import("pathToModule", "secondModule") : Promise<any>
|
||||
|
||||
@@ -10,7 +10,7 @@ tests/cases/compiler/missingArgument1.ts(1,8): error TS2304: Cannot find name 'b
|
||||
!!! error TS2304: Cannot find name 'foo'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
|
||||
~
|
||||
!!! error TS1135: Argument expression expected.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'b'.
|
||||
@@ -2,4 +2,4 @@
|
||||
foo(a,,b);
|
||||
|
||||
//// [missingArgument1.js]
|
||||
foo(a, , b);
|
||||
foo(a, b);
|
||||
|
||||
@@ -3,6 +3,5 @@ foo(a,,b);
|
||||
>foo(a,,b) : any
|
||||
>foo : any
|
||||
>a : any
|
||||
> : undefined
|
||||
>b : any
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/parseErrorDoubleCommaInCall.ts(2,10): error TS1136: Property assignment expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/parseErrorDoubleCommaInCall.ts (1 errors) ====
|
||||
Boolean({
|
||||
x: 0,,
|
||||
~
|
||||
!!! error TS1136: Property assignment expected.
|
||||
});
|
||||
|
||||
10
tests/baselines/reference/parseErrorDoubleCommaInCall.js
Normal file
10
tests/baselines/reference/parseErrorDoubleCommaInCall.js
Normal file
@@ -0,0 +1,10 @@
|
||||
//// [parseErrorDoubleCommaInCall.ts]
|
||||
Boolean({
|
||||
x: 0,,
|
||||
});
|
||||
|
||||
|
||||
//// [parseErrorDoubleCommaInCall.js]
|
||||
Boolean({
|
||||
x: 0
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/parseErrorDoubleCommaInCall.ts ===
|
||||
Boolean({
|
||||
>Boolean : Symbol(Boolean, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
x: 0,,
|
||||
>x : Symbol(x, Decl(parseErrorDoubleCommaInCall.ts, 0, 9))
|
||||
|
||||
});
|
||||
|
||||
12
tests/baselines/reference/parseErrorDoubleCommaInCall.types
Normal file
12
tests/baselines/reference/parseErrorDoubleCommaInCall.types
Normal file
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/parseErrorDoubleCommaInCall.ts ===
|
||||
Boolean({
|
||||
>Boolean({ x: 0,,}) : boolean
|
||||
>Boolean : BooleanConstructor
|
||||
>{ x: 0,,} : { x: number; }
|
||||
|
||||
x: 0,,
|
||||
>x : number
|
||||
>0 : 0
|
||||
|
||||
});
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
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(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 (2 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList6.ts (3 errors) ====
|
||||
Foo(,
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'Foo'.
|
||||
~
|
||||
!!! error TS1135: Argument expression expected.
|
||||
|
||||
!!! error TS1005: ')' expected.
|
||||
@@ -2,5 +2,4 @@
|
||||
Foo(,
|
||||
>Foo(, : any
|
||||
>Foo : any
|
||||
> : undefined
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
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(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 (3 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList7.ts (4 errors) ====
|
||||
Foo(a,,
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'Foo'.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
~
|
||||
!!! error TS1135: Argument expression expected.
|
||||
|
||||
!!! error TS1005: ')' expected.
|
||||
@@ -2,4 +2,4 @@
|
||||
Foo(a,,
|
||||
|
||||
//// [parserErrorRecovery_ArgumentList7.js]
|
||||
Foo(a, );
|
||||
Foo(a);
|
||||
|
||||
@@ -3,5 +3,4 @@ Foo(a,,
|
||||
>Foo(a,, : any
|
||||
>Foo : any
|
||||
>a : any
|
||||
> : undefined
|
||||
|
||||
|
||||
3
tests/cases/compiler/parseErrorDoubleCommaInCall.ts
Normal file
3
tests/cases/compiler/parseErrorDoubleCommaInCall.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
Boolean({
|
||||
x: 0,,
|
||||
});
|
||||
@@ -10,5 +10,4 @@ import(...["PathModule"]);
|
||||
|
||||
var p1 = import(...a);
|
||||
const p2 = import();
|
||||
const p3 = import(,);
|
||||
const p4 = import("pathToModule", "secondModule");
|
||||
@@ -13,14 +13,14 @@ verify.currentSignatureHelpIs("f(): any");
|
||||
verify.currentSignatureParameterCountIs(0);
|
||||
verify.signatureHelpArgumentCountIs(0);
|
||||
|
||||
edit.insert(", ");
|
||||
edit.insert("x, ");
|
||||
verify.signatureHelpCountIs(4);
|
||||
verify.currentSignatureHelpIs("f(s: string, b: boolean): any");
|
||||
verify.currentSignatureParameterCountIs(2);
|
||||
verify.currentParameterHelpArgumentNameIs("b");
|
||||
verify.currentParameterSpanIs("b: boolean");
|
||||
|
||||
edit.insert(", ");
|
||||
edit.insert("x, ");
|
||||
verify.signatureHelpCountIs(4);
|
||||
verify.currentSignatureHelpIs("f(s: string, b: boolean): any");
|
||||
verify.currentSignatureParameterCountIs(2);
|
||||
Reference in New Issue
Block a user