Skip to content

Commit 858cca5

Browse files
authored
Fix arrow function body parsing precedence (AssemblyScript#546)
1 parent fd99589 commit 858cca5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/parser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,14 @@ export class Parser extends DiagnosticEmitter {
14371437
tn.range(signatureStart, tn.pos)
14381438
);
14391439

1440-
var body: Statement | null;
1440+
var body: Statement | null = null;
14411441
if (arrowKind) {
1442-
body = this.parseStatement(tn, false);
1442+
if (tn.skip(Token.OPENBRACE)) {
1443+
body = this.parseBlockStatement(tn, false);
1444+
} else {
1445+
let bodyExpression = this.parseExpression(tn, Precedence.COMMA + 1);
1446+
if (bodyExpression) body = Node.createExpressionStatement(bodyExpression);
1447+
}
14431448
} else {
14441449
if (!tn.skip(Token.OPENBRACE)) {
14451450
this.error(

0 commit comments

Comments
 (0)