Skip to content

Commit

Permalink
Merge pull request #28 from surfly/fix-async-assign
Browse files Browse the repository at this point in the history
Fix usage of `async` and `import` in comma expression
  • Loading branch information
DimaIT authored Mar 26, 2024
2 parents fd6cd61 + b333d8a commit 117e84c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
9 changes: 7 additions & 2 deletions dist/meriyah.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 18 additions & 9 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
*
Expand All @@ -1138,6 +1129,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 @@ -2765,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]
Expand Down Expand Up @@ -3670,6 +3677,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;
}

Expand Down
2 changes: 2 additions & 0 deletions test/parser/declarations/functions.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
4 changes: 4 additions & 0 deletions test/parser/next/import-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, () => {
Expand Down

0 comments on commit 117e84c

Please sign in to comment.