semantics: references created by direct eval in non-strict mode is not respected
Currently semantic does not track the existence of direct eval.
is_global_reference may return true even if that reference refers to a variable declared by direct eval (the declaration is only leaked outside in non-strict mode).
https://github.com/oxc-project/oxc/blob/e4d66e46360dbdec289e40319f8b2a335b25c099/crates/oxc_semantic/src/symbol.rs#L342-L346
This leads to minification errors for codes like:
function foo() {
eval('var Object = class { constructor() { console.log("Constructor") } }')
console.log(new Object())
}
foo()
I'd say just never use direct eval 😅 But leaving a note for reference. (This is not something I met with real world code)
All logic related to eval has not been implemented yet. We need to either implement them or warn about it. Note: esbuild bails minification and mangling for all parent scopes containing eval.
Direct eval disables the mangler.
https://github.com/oxc-project/oxc/blob/0b08159ee76120159694b39a159d9eb6272279aa/crates/oxc_mangler/src/lib.rs#L195-L198
It's not only the mangler. We need to disable all the compression that uses is_global_reference or relies on any information related to variables / functions. The reproduction in the OP is still broken.