8000 Addressed code review feedback. · wheercool/TypeScript@b76c13c · GitHub
[go: up one dir, main page]

Skip to content

Commit b76c13c

Browse files
Addressed code review feedback.
1 parent 57d7cf5 commit b76c13c

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/compiler/parser.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,14 @@ module ts {
14681468

14691469
// *Maybe* we had an arrow function and we need to try to parse it out,
14701470
// rolling back and trying other parses if we fail.
1471-
var sig = tryParse(parseSignatureIfArrowOrBraceFollows);
1472-
if (sig === undefined) {
1473-
return undefined;
1474-
}
1475-
else {
1471+
var sig = tryParseSignatureIfArrowOrBraceFollows();
1472+
if (sig) {
14761473
parseExpected(SyntaxKind.EqualsGreaterThanToken);
14771474
return parseArrowExpressionTail(pos, sig, /*noIn:*/ false);
14781475
}
1476+
else {
1477+
return undefined;
1478+
}
14791479
}
14801480

14811481
// True -> We definitely expect a parenthesized arrow function here.
@@ -1549,22 +1549,24 @@ module ts {
15491549
return Tristate.False;
15501550
}
15511551

1552-
10000 function parseSignatureIfArrowOrBraceFollows(): ParsedSignature {
1553-
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
1552+
function tryParseSignatureIfArrowOrBraceFollows(): ParsedSignature {
1553+
return tryParse(() => {
1554+
var sig = parseSignature(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
15541555

1555-
// Parsing a signature isn't enough.
1556-
// Parenthesized arrow signatures often look like other valid expressions.
1557-
// For instance:
1558-
// - "(x = 10)" is an assignment expression parsed as a signature with a default parameter value.
1559-
// - "(x,y)" is a comma expression parsed as a signature with two parameters.
1560-
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
1561-
//
1562-
// So we need just a bit of lookahead to ensure that it can only be a signature.
1563-
if (token === SyntaxKind.EqualsGreaterThanToken || token === SyntaxKind.OpenBraceToken) {
1564-
return sig;
1565-
}
1556+
// Parsing a signature isn't enough.
1557+
// Parenthesized arrow signatures often look like other valid expressions.
1558+
// For instance:
1559+
// - "(x = 10)" is an assignment expression parsed as a signature with a default parameter value.
1560+
// - "(x,y)" is a comma expression parsed as a signature with two parameters.
1561+
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
1562+
//
1563+
// So we need just a bit of lookahead to ensure that it can only be a signature.
1564+
if (token === SyntaxKind.EqualsGreaterThanToken || token === SyntaxKind.OpenBraceToken) {
1565+
return sig;
1566+
}
15661567

1567-
return undefined;
1568+
return undefined;
1569+
});
15681570
}
15691571

15701572
function parseArrowExpressionTail(pos: number, sig: ParsedSignature, noIn: boolean): FunctionExpression {

tests/baselines/reference/arrowFunctionsMissingTokens.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
~
8181
!!! Declaration or statement expected.
8282

83-
module ceci_nEst_pas_une_arrow_function {
83+
module ce_nEst_pas_une_arrow_function {
8484
var a = ();
8585
~
8686
!!! Expression expected.

tests/cases/compiler/arrowFunctionsMissingTokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module missingCurliesWithArrow {
4141
}
4242
}
4343

44-
module ceci_nEst_pas_une_arrow_function {
44+
module ce_nEst_pas_une_arrow_function {
4545
var a = ();
4646

4747
var b = (): void;

0 commit comments

Comments
 (0)
0