Skip to content

Commit

Permalink
Merge pull request #254 from DimaIT/fix-async-assign
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Mar 29, 2024
2 parents 9b9aacc + 578a388 commit 9b12d05
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
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;
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

0 comments on commit 9b12d05

Please sign in to comment.