From fd6dea634e6aec39066b9ebc408342feeb141a99 Mon Sep 17 00:00:00 2001 From: DimaIT Date: Mon, 25 Mar 2024 13:01:57 +0100 Subject: [PATCH 1/4] 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 From a8a3f92c1309561d46c4e6e929ae98d5b6b253b3 Mon Sep 17 00:00:00 2001 From: DimaIT Date: Mon, 25 Mar 2024 19:05:09 +0100 Subject: [PATCH 2/4] fix(parser): fix async assignment in sequence --- src/parser.ts | 2 ++ test/parser/declarations/functions.ts | 1 + test/parser/miscellaneous/pass.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/src/parser.ts b/src/parser.ts index c42f2baf..a7f361cc 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -3671,6 +3671,8 @@ export function parseAsyncExpression( if (inNew) report(parser, Errors.InvalidAsyncArrow); return parseArrowFromIdentifier(parser, context, parser.tokenValue, expr, inNew, canAssign, 0, start, line, column); } + + parser.assignable = AssignmentKind.Assignable; return expr; } diff --git a/test/parser/declarations/functions.ts b/test/parser/declarations/functions.ts index 23d27437..4aad839f 100644 --- a/test/parser/declarations/functions.ts +++ b/test/parser/declarations/functions.ts @@ -398,6 +398,7 @@ describe('Declarations - Function', () => { 'function f() { const await = 10; }', 'function f(a = async function (x) { await x; }) { a(); } f();', 'function f() {async = 1, a = 2;}', + 'function f() {a = 1, async = 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 d6852cc8..b94f9c79 100644 --- a/test/parser/miscellaneous/pass.ts +++ b/test/parser/miscellaneous/pass.ts @@ -2835,6 +2835,7 @@ after = err; 'class X { await() {} }', 'let async = await;', 'async = 1, b = 2;', + 'b = 2, async = 1;', 'x = { await: false }', 'yield[100]', `async From 8febffb1047534d7430737d1bf987fb626de3649 Mon Sep 17 00:00:00 2001 From: DimaIT Date: Mon, 25 Mar 2024 19:33:14 +0100 Subject: [PATCH 3/4] fix(parser): fix `import.meta` in sequence --- src/parser.ts | 8 +++++++- test/parser/next/import-meta.ts | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index a7f361cc..1b1a511d 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1137,7 +1137,9 @@ export function parseAsyncArrowOrAsyncFunctionDeclaration( * https://github.com/estree/estree/blob/master/es5.md#sequenceexpression * */ - if (parser.token === Token.Comma) expr = parseSequenceExpression(parser, context, 0, start, line, column, expr); + if (parser.token === Token.Comma) { + expr = parseSequenceExpression(parser, context, 0, start, line, column, expr); + } /** * ExpressionStatement[Yield, Await]: @@ -2766,6 +2768,10 @@ export function parseImportMetaDeclaration( expr = parseAssignmentExpression(parser, context, 0, 0, start, line, column, expr as ESTree.Expression); + 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/next/import-meta.ts b/test/parser/next/import-meta.ts index 49249d2f..93202325 100644 --- a/test/parser/next/import-meta.ts +++ b/test/parser/next/import-meta.ts @@ -100,6 +100,10 @@ describe('Next - Import Meta', () => { '(a?.import("string")?.import.meta??(a))', 'import.meta?.(a?.import("string")?.import.meta??(a))', 'var a = import.meta;', + 'import.meta, 1;', + '1, import.meta;', + 'import.meta, a = 1;', + 'a = 1, import.meta;', 'import.meta;' ]) { it(`${arg}`, () => { From b333d8ae68b29c1ba26342b2e29b2c1750b257c8 Mon Sep 17 00:00:00 2001 From: DimaIT Date: Mon, 25 Mar 2024 19:37:02 +0100 Subject: [PATCH 4/4] update meriyah bundle --- dist/meriyah.umd.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dist/meriyah.umd.js b/dist/meriyah.umd.js index be02fa9f..97465845 100644 --- a/dist/meriyah.umd.js +++ b/dist/meriyah.umd.js @@ -5119,10 +5119,11 @@ parser.assignable = 1; } expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, start, line, column); - if (parser.token === 18) - expr = parseSequenceExpression(parser, context, 0, start, line, column, expr); expr = parseAssignmentExpression(parser, context, 0, 0, start, line, column, expr); parser.assignable = 1; + if (parser.token === 18) { + expr = parseSequenceExpression(parser, context, 0, start, line, column, expr); + } return parseExpressionStatement(parser, context, expr, start, line, column); } function parseDirective(parser, context, expression, token, start, line, column) { @@ -5782,6 +5783,9 @@ }), start, line, column); expr = parseMemberOrUpdateExpression(parser, context, expr, 0, 0, start, line, column); expr = parseAssignmentExpression(parser, context, 0, 0, start, line, column, expr); + if (parser.token === 18) { + expr = parseSequenceExpression(parser, context, 0, start, line, column, expr); + } return parseExpressionStatement(parser, context, expr, start, line, column); } function parseImportCallDeclaration(parser, context, start, line, column) { @@ -6125,6 +6129,7 @@ report(parser, 49); return parseArrowFromIdentifier(parser, context, parser.tokenValue, expr, inNew, canAssign, 0, start, line, column); } + parser.assignable = 1; return expr; } function parseYieldExpression(parser, context, inGroup, canAssign, start, line, column) {