From 9652602728cca827ebabcdcf3ed8f240ec125c7f 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 9e0d3cb0..52a9944e 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -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 : * @@ -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] 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 223936ec62b3b4f008a351075f25c466ca89e9da 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 52a9944e..4ab4c5e2 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -3575,6 +3575,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 15ea395a1dc59a253c99d57e4697c3a33147e3a8 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 4ab4c5e2..6186d70a 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1119,7 +1119,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]: @@ -2689,6 +2691,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 578a38837bd9fd0fc3c49ff39bd549927929c1db Mon Sep 17 00:00:00 2001 From: DimaIT Date: Thu, 28 Mar 2024 15:51:49 +0100 Subject: [PATCH 4/4] test: add more cases with `import.meta` assignment --- test/parser/next/import-meta.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parser/next/import-meta.ts b/test/parser/next/import-meta.ts index 93202325..61440348 100644 --- a/test/parser/next/import-meta.ts +++ b/test/parser/next/import-meta.ts @@ -104,6 +104,8 @@ describe('Next - Import Meta', () => { '1, import.meta;', 'import.meta, a = 1;', 'a = 1, import.meta;', + 'import.meta.url = 1, import.meta.url = 2;', + 'import.meta, import.meta.url = 1;', 'import.meta;' ]) { it(`${arg}`, () => {