Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,19 +514,23 @@ export class Parser extends DiagnosticEmitter {
if (signature) {
if (isInnerParenthesized) {
if (!tn.skip(Token.CloseParen)) {
this.error(
DiagnosticCode._0_expected,
tn.range(), ")"
);
if (!suppressErrors) {
this.error(
DiagnosticCode._0_expected,
tn.range(), ")"
);
}
return null;
}
}
type = signature;
} else if (isInnerParenthesized || this.tryParseSignatureIsSignature) {
this.error(
DiagnosticCode.Unexpected_token,
tn.range()
);
if (!suppressErrors) {
this.error(
DiagnosticCode.Unexpected_token,
tn.range()
);
}
return null;
// Type (',' Type)* ')'
} else if (acceptParenthesized) {
Expand All @@ -545,10 +549,12 @@ export class Parser extends DiagnosticEmitter {
type.range.start = startPos;
type.range.end = tn.pos;
} else {
this.error(
DiagnosticCode.Unexpected_token,
tn.range()
);
if (!suppressErrors) {
this.error(
DiagnosticCode.Unexpected_token,
tn.range()
);
}
return null;
}

Expand Down Expand Up @@ -3780,10 +3786,15 @@ export class Parser extends DiagnosticEmitter {

// if we got here, check for arrow
case Token.CloseParen: {
if (
!tn.skip(Token.Colon) &&
!tn.skip(Token.Equals_GreaterThan)
) {
// `Identifier):Type =>` is function expression
if (tn.skip(Token.Colon)) {
let type = this.parseType(tn, true, true);
if (type == null) {
again = false;
break;
}
}
if (!tn.skip(Token.Equals_GreaterThan)) {
again = false;
break;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/parser/arrow-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ x => x;

// not an array function
(b ? x : y);
b ? (x) : y;
b ? (x):i32=>1 : y;
(b ? f : g)();
2 changes: 2 additions & 0 deletions tests/parser/arrow-functions.ts.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
x => x;
() => {};
(b ? x : y);
b ? (x) : y;
b ? (x): i32 => 1 : y;
(b ? f : g)();