From fd6dea634e6aec39066b9ebc408342feeb141a99 Mon Sep 17 00:00:00 2001 From: DimaIT Date: Mon, 25 Mar 2024 13:01:57 +0100 Subject: [PATCH] fix(parser): fix async assignment in comma expression --- src/parser.ts | 19 ++++++++++--------- test/parser/declarations/functions.ts | 1 + test/parser/miscellaneous/pass.ts | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index c69d41ec..c42f2baf 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1118,15 +1118,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 : * @@ -1138,6 +1129,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] diff --git a/test/parser/declarations/functions.ts b/test/parser/declarations/functions.ts index 819aa35d..23d27437 100644 --- a/test/parser/declarations/functions.ts +++ b/test/parser/declarations/functions.ts @@ -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;}', diff --git a/test/parser/miscellaneous/pass.ts b/test/parser/miscellaneous/pass.ts index 24bc3633..d6852cc8 100644 --- a/test/parser/miscellaneous/pass.ts +++ b/test/parser/miscellaneous/pass.ts @@ -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