Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of async and import in comma expression #254

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/parser.ts
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,18 @@ 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 Expand Up @@ -2688,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]
Expand Down Expand Up @@ -3574,6 +3581,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given your change on line 1114, should this line be added before line 2694?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems not needed here, added a couple more test-cases to cover it

return expr;
}

Expand Down
2 changes: 2 additions & 0 deletions test/parser/declarations/functions.ts
Expand Up @@ -397,6 +397,8 @@ 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() {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;}',
Expand Down
2 changes: 2 additions & 0 deletions test/parser/miscellaneous/pass.ts
Expand Up @@ -2834,6 +2834,8 @@ after = err;
'x = await(y);',
'class X { await() {} }',
'let async = await;',
'async = 1, b = 2;',
'b = 2, async = 1;',
'x = { await: false }',
'yield[100]',
`async
Expand Down
6 changes: 6 additions & 0 deletions test/parser/next/import-meta.ts
Expand Up @@ -100,6 +100,12 @@ 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.url = 1, import.meta.url = 2;',
'import.meta, import.meta.url = 1;',
'import.meta;'
]) {
it(`${arg}`, () => {
Expand Down