Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Variable declarations inside direct eval is not taken into account #4055

Closed
sapphi-red opened this issue Jan 28, 2025 · 0 comments
Closed

Variable declarations inside direct eval is not taken into account #4055

sapphi-red opened this issue Jan 28, 2025 · 0 comments

Comments

@sapphi-red
Copy link
Contributor

For input,

const variable = false
;(function () {
  eval("var variable = true")
  console.log(variable)
})()

esbuild outputs

const variable=!1;(function(){eval("var variable = true"),console.log(!1)})();

when minified.
esbuild try

This changes the behavior of the code (true is output before minification, but false is output after minification). I guess it's because the fact that variable declarations inside direct eval leaks to the outside scope in non-strict mode is not taken into account when replacing constants.

(Note: this is not what I encountered in a real world usage. I found it when trying to know about the direct eval support in esbuild.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant