💻
How are you using Babel?
Babel REPL
Input code
const foo = () => (args) => class A {};
new (foo()`bar`)();
const baz = () => ({ qux: class A {} })
new (baz()?.qux)();
REPL link
Configuration file name
No response
Configuration
{} (no config)
Current and expected behavior
Current behavior: babel prints
const foo = () => args => class A {};
new foo()`bar`();
const baz = () => ({ qux: class A {} });
new baz()?.qux();
the parentheses around foo()`bar` and baz()?.qux are wrongly removed, which changes semantic due to the first () immediately ends NewExpression.
Expected behavior: print the source AS IS
Environment
- Babel version: v7.29.7
- Reproduced on REPL, Chrome version: 147
Possible solution
The check of wrapping parentheses around callee of new should consider TaggedTemplateExpression and ChainExpression.
Additional context
The related printer bugs was first observed from SvelteJS' esrap and we'd discovered same issue for Babel.
💻
How are you using Babel?
Babel REPL
Input code
REPL link
Configuration file name
No response
Configuration
{}(no config)Current and expected behavior
Current behavior: babel prints
the parentheses around
foo()`bar`andbaz()?.quxare wrongly removed, which changes semantic due to the first()immediately endsNewExpression.Expected behavior: print the source AS IS
Environment
Possible solution
The check of wrapping parentheses around callee of
newshould considerTaggedTemplateExpressionandChainExpression.Additional context
The related printer bugs was first observed from SvelteJS' esrap and we'd discovered same issue for Babel.