Parser/Codegen: should preserve parentheses around assignment target
Current Behavior
var fn;
(fn) = function() {};
The AST doesn't preserve the parentheses in (fn), which causes the codegen generates:
var fn;
fn = function() {};
Which has different runtime behavior: in the original code, fn.name is an empty string, but in the generated code, fn.name is "fn". Run this playground.
Expected behavior
Parentheses around assignment target should be preserved and printed.
Background
I encountered the problem when trying to pass this test262 case: https://github.com/tc39/test262/blob/main/test/language/expressions/assignment/fn-name-lhs-cover.js
https://oxc.rs/docs/learn/ecmascript/grammar.html#parenthesized-expression
Nobody uses this in the real world so I didn't spend the time fixing it. It'll be some ugly hacks in the parser and codegen ... but only to satisfy the spec?
This is a bug so I'll leave the issue open.
As it turns out none of the tools (esbuild, swc, prettier, babel with prettify) preserve this semantic. I'm unwilling to implement this :-(