+
Skip to content

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

@sapphi-red

Description

@sapphi-red

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载