Skip to content

Commit

Permalink
fix(parser): fix async assignment in comma expression
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaIT committed Mar 25, 2024
1 parent 9b9aacc commit 9652602
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,15 +1100,6 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(
*/

expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, start, line, column);
/** Sequence expression
*
* Note: The comma operator leads to a sequence expression which is not equivalent
* to the ES Expression, but it's part of the ESTree specs:
*
* https://github.com/estree/estree/blob/master/es5.md#sequenceexpression
*
*/
if (parser.token === Token.Comma) expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);

/** AssignmentExpression :
*
Expand All @@ -1120,6 +1111,16 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration(

parser.assignable = AssignmentKind.Assignable;

/** Sequence expression
*
* Note: The comma operator leads to a sequence expression which is not equivalent
* to the ES Expression, but it's part of the ESTree specs:
*
* https://github.com/estree/estree/blob/master/es5.md#sequenceexpression
*
*/
if (parser.token === Token.Comma) expr = parseSequenceExpression(parser, context, 0, start, line, column, expr);

/**
* ExpressionStatement[Yield, Await]:
* [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }]Expression[+In, ?Yield, ?Await]
Expand Down
1 change: 1 addition & 0 deletions test/parser/declarations/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ describe('Declarations - Function', () => {
'function f() { function await() { } }',
'function f() { const await = 10; }',
'function f(a = async function (x) { await x; }) { a(); } f();',
'function f() {async = 1, a = 2;}',
'function f() {var async = 1; return async;}',
'function f() {let async = 1; return async;}',
'function f() {const async = 1; return async;}',
Expand Down
1 change: 1 addition & 0 deletions test/parser/miscellaneous/pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,7 @@ after = err;
'x = await(y);',
'class X { await() {} }',
'let async = await;',
'async = 1, b = 2;',
'x = { await: false }',
'yield[100]',
`async
Expand Down

0 comments on commit 9652602

Please sign in to comment.