Covered more cases for arrow functions omitting arrows.
Specifically where we have a full signature followed by an open curly brace.
This commit is contained in:
parent
5b6bb5b649
commit
5fc2792297
|
@ -1445,7 +1445,7 @@ module ts {
|
|||
function tryParseParenthesizedArrowFunctionExpression(): Expression {
|
||||
var pos = getNodePos();
|
||||
|
||||
// Whether we are certain that we should parse an arrow expression.
|
||||
// Indicates whether we are certain that we should parse an arrow expression.
|
||||
var triState = isParenthesizedArrowFunctionExpression();
|
||||
|
||||
// It is not a parenthesized arrow function.
|
||||
|
@ -1470,11 +1470,12 @@ module ts {
|
|||
|
||||
// Otherwise, *maybe* we had an arrow function and we need to *try* to parse it out
|
||||
// (which will ensure we rollback if we fail).
|
||||
var sig = tryParse(parseSignatureAndArrow);
|
||||
var sig = tryParse(parseSignatureIfArrowOrBraceFollows);
|
||||
if (sig === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
parseExpected(SyntaxKind.EqualsGreaterThanToken);
|
||||
return parseArrowExpressionTail(pos, sig, /*noIn:*/ false);
|
||||
}
|
||||
}
|
||||
|
@ -1512,8 +1513,9 @@ module ts {
|
|||
return Tristate.True;
|
||||
}
|
||||
|
||||
// We had "(" not followed by an identifier. This definitely doesn't
|
||||
// look like a lambda. Note: we could be a little more lenient and allow
|
||||
// If we had "(" followed by something that's not an identifier,
|
||||
// then this definitely doesn't look like a lambda.
|
||||
// Note: we could be a little more lenient and allow
|
||||
// "(public" or "(private". These would not ever actually be allowed,
|
||||
// but we could provide a good error message instead of bailing out.
|
||||
if (!isIdentifier()) {
|
||||
|
@ -1543,10 +1545,12 @@ module ts {
|
|||
return Tristate.False;
|
||||
}
|
||||
|
||||
function parseSignatureAndArrow(): ParsedSignature {
|
||||
function parseSignatureIfArrowOrBraceFollows(): ParsedSignature {
|
||||
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||
parseExpected(SyntaxKind.EqualsGreaterThanToken);
|
||||
return sig;
|
||||
if (token === SyntaxKind.EqualsGreaterThanToken || token === SyntaxKind.OpenBraceToken) {
|
||||
return sig;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseArrowExpressionTail(pos: number, sig: ParsedSignature, noIn: boolean): FunctionExpression {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/compiler/arrowFunctionsMissingTokens.ts (39 errors) ====
|
||||
==== tests/cases/compiler/arrowFunctionsMissingTokens.ts (31 errors) ====
|
||||
|
||||
module missingArrowsWithCurly {
|
||||
var a = () { };
|
||||
|
@ -11,31 +11,15 @@
|
|||
|
||||
var c = (x) { };
|
||||
~
|
||||
!!! ',' expected.
|
||||
~
|
||||
!!! Cannot find name 'x'.
|
||||
!!! '=>' expected.
|
||||
|
||||
var d = (x: number, y: string) { };
|
||||
~
|
||||
!!! ')' expected.
|
||||
~
|
||||
!!! ',' expected.
|
||||
~
|
||||
!!! Variable declaration expected.
|
||||
~
|
||||
!!! Cannot find name 'x'.
|
||||
!!! '=>' expected.
|
||||
|
||||
var e = (x: number, y: string): void { };
|
||||
~
|
||||
!!! ')' expected.
|
||||
~
|
||||
!!! ',' expected.
|
||||
~
|
||||
!!! Variable declaration expected.
|
||||
~~~~
|
||||
!!! Variable declaration expected.
|
||||
~
|
||||
!!! Cannot find name 'x'.
|
||||
~
|
||||
!!! '=>' expected.
|
||||
}
|
||||
|
||||
module missingCurliesWithArrow {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/compiler/fatarrowfunctionsErrors.ts (25 errors) ====
|
||||
==== tests/cases/compiler/fatarrowfunctionsErrors.ts (18 errors) ====
|
||||
foo((...Far:any[])=>{return 0;})
|
||||
~~~
|
||||
!!! Cannot find name 'foo'.
|
||||
|
@ -39,25 +39,11 @@
|
|||
~
|
||||
!!! '=>' expected.
|
||||
var x2 = (a:number) :void {};
|
||||
~
|
||||
!!! ')' expected.
|
||||
~
|
||||
!!! ',' expected.
|
||||
~
|
||||
!!! Variable declaration expected.
|
||||
~~~~
|
||||
!!! Variable declaration expected.
|
||||
~
|
||||
!!! Cannot find name 'a'.
|
||||
~
|
||||
!!! '=>' expected.
|
||||
var x3 = (a:number) {};
|
||||
~
|
||||
!!! ')' expected.
|
||||
~
|
||||
!!! ',' expected.
|
||||
~
|
||||
!!! Variable declaration expected.
|
||||
~
|
||||
!!! Cannot find name 'a'.
|
||||
!!! '=>' expected.
|
||||
var x4= (...a: any[]) { };
|
||||
~
|
||||
!!! '=>' expected.
|
|
@ -1,4 +1,4 @@
|
|||
==== tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts (5 errors) ====
|
||||
==== tests/cases/conformance/statements/tryStatements/invalidTryStatements2.ts (4 errors) ====
|
||||
function fn() {
|
||||
try {
|
||||
} catch { // syntax error, missing '(x)'
|
||||
|
@ -10,9 +10,7 @@
|
|||
~~~~~
|
||||
!!! Statement expected.
|
||||
~
|
||||
!!! ';' expected.
|
||||
~
|
||||
!!! Cannot find name 'x'.
|
||||
!!! '=>' expected.
|
||||
|
||||
finally{ } // error missing try
|
||||
~~~~~~~
|
||||
|
|
Loading…
Reference in a new issue