Skip to content

Commit

Permalink
fix(parser): rejects "await 2**2"
Browse files Browse the repository at this point in the history
closes #187
  • Loading branch information
3cp committed Apr 8, 2021
1 parent da41eba commit 9a75bf6
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,8 @@ export function parseAwaitExpression(
parser.colPos
);

if (parser.token === Token.Exponentiate) report(parser, Errors.InvalidExponentiationLHS);

parser.assignable = AssignmentKind.CannotAssign;

return finishNode(parser, context, start, line, column, {
Expand Down
119 changes: 118 additions & 1 deletion test/parser/expressions/exponentiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('Expressions - Exponentiation', () => {
['(!3 ** 2)', Context.None],
['(+x ** 2)', Context.None],
['(a * +a ** a ** 3)', Context.None],
['for (var import.meta of [1]) {}', Context.None]
['for (var import.meta of [1]) {}', Context.None],
['async function f() { await 2 ** 2; }', Context.None]
]);

for (const arg of [
Expand Down Expand Up @@ -675,6 +676,122 @@ describe('Expressions - Exponentiation', () => {
}
]
}
],
[
'(+1) ** 2',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'UnaryExpression',
operator: '+',
argument: {
type: 'Literal',
value: 1
},
prefix: true
},
right: {
type: 'Literal',
value: 2
},
operator: '**'
}
}
]
}
],
[
'async function f() { (await 2) ** 2; }',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'FunctionDeclaration',
id: {
type: 'Identifier',
name: 'f'
},
params: [],
body: {
type: 'BlockStatement',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'BinaryExpression',
left: {
type: 'AwaitExpression',
argument: {
type: 'Literal',
value: 2
}
},
right: {
type: 'Literal',
value: 2
},
operator: '**'
}
}
]
},
async: true,
generator: false
}
]
}
],
[
'async function f() { await (2 ** 2); }',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'FunctionDeclaration',
id: {
type: 'Identifier',
name: 'f'
},
params: [],
body: {
type: 'BlockStatement',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'AwaitExpression',
argument: {
type: 'BinaryExpression',
left: {
type: 'Literal',
value: 2
},
right: {
type: 'Literal',
value: 2
},
operator: '**'
}
}
}
]
},
async: true,
generator: false
}
]
}
]
]);
});

0 comments on commit 9a75bf6

Please sign in to comment.