Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c0a0fd0

Browse files
fix: Correctly analyze ParenthesizedExpression and FunctionExpression in parser (#2605) (#2620)
1 parent 849a13c commit c0a0fd0

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

‎src/parser.ts‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,23 @@ export class Parser extends DiagnosticEmitter {
514514
if (signature) {
515515
if (isInnerParenthesized) {
516516
if (!tn.skip(Token.CloseParen)) {
517-
this.error(
518-
DiagnosticCode._0_expected,
519-
tn.range(), ")"
520-
);
517+
if (!suppressErrors) {
518+
this.error(
519+
DiagnosticCode._0_expected,
520+
tn.range(), ")"
521+
);
522+
}
521523
return null;
522524
}
523525
}
524526
type = signature;
525527
} else if (isInnerParenthesized || this.tryParseSignatureIsSignature) {
526-
this.error(
527-
DiagnosticCode.Unexpected_token,
528-
tn.range()
529-
);
528+
if (!suppressErrors) {
529+
this.error(
530+
DiagnosticCode.Unexpected_token,
531+
tn.range()
532+
);
533+
}
530534
return null;
531535
// Type (',' Type)* ')'
532536
} else if (acceptParenthesized) {
@@ -545,10 +549,12 @@ export class Parser extends DiagnosticEmitter {
545549
type.range.start = startPos;
546550
type.range.end = tn.pos;
547551
} else {
548-
this.error(
549-
DiagnosticCode.Unexpected_token,
550-
tn.range()
551-
);
552+
if (!suppressErrors) {
553+
this.error(
554+
DiagnosticCode.Unexpected_token,
555+
tn.range()
556+
);
557+
}
552558
return null;
553559
}
554560

@@ -3780,10 +3786,15 @@ export class Parser extends DiagnosticEmitter {
37803786

37813787
// if we got here, check for arrow
37823788
case Token.CloseParen: {
3783-
if (
3784-
!tn.skip(Token.Colon) &&
3785-
!tn.skip(Token.Equals_GreaterThan)
3786-
) {
3789+
// `Identifier):Type =>` is function expression
3790+
if (tn.skip(Token.Colon)) {
3791+
let type = this.parseType(tn, true, true);
3792+
if (type == null) {
3793+
again = false;
3794+
break;
3795+
}
3796+
}
3797+
if (!tn.skip(Token.Equals_GreaterThan)) {
37873798
again = false;
37883799
break;
37893800
}

‎tests/parser/arrow-functions.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ x => x;
99

1010
// not an array function
1111
(b ? x : y);
12+
b ? (x) : y;
13+
b ? (x):i32=>1 : y;
1214
(b ? f : g)();

‎tests/parser/arrow-functions.ts.fixture.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
x => x;
77
() => {};
88
(b ? x : y);
9+
b ? (x) : y;
10+
b ? (x): i32 => 1 : y;
911
(b ? f : g)();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /