Missing parenthesis for await assignment expression argument
mischnic opened this issue · comments
Motivation
Parenthesis need to be inserted around the await
argument if it's an assignment expression
Input
Input:
var obj;
async function main() {
return await (obj = Promise.resolve(1));
}
Script
const acorn = require("acorn");
const astring = require("astring");
const code = `var obj;
async function main() {
return await (obj = Promise.resolve(1));
}
`;
const ast = acorn.parse(code, { ecmaVersion: 2020 });
const formattedCode = astring.generate(ast);
console.log(formattedCode);
/*
undefined:3
return await obj = Promise.resolve(1);
^^^^^^^^^
SyntaxError: Invalid left-hand side in assignment
*/
eval(formattedCode);
Expected behavior
= same as input
var obj;
async function main() {
return await (obj = Promise.resolve(1));
}
Actual behavior
var obj;
async function main() {
return await obj = Promise.resolve(1);
}
I guess the fix would be the identical to this
Lines 690 to 694 in 00690ab
@mischnic Thanks for reporting this, I'm fixing it now.
Well, actually, the yield operator has a very low precedence. Fixed in d3af2fc.