Skip to content

Transform produces invalid code for sources containing direct eval #2761

@micschro

Description

@micschro

When this code

// source
if (true) { 
  function foo () {};
  eval(''); 
}

is transformed with default settings in esbuild 0.16.10, esbuild produces the following invalid output

// transformed
if (true) {
  let foo = function() {
  };
  var foo = foo;
  ;
  eval("");
}

=> Identifier 'foo' has already been declared

To reproduce, just call the transform API like this:

// index.js
console.log(require('esbuild').transformSync(`if (true) { function foo () {}; eval(''); }`).code)

I'm aware that direct eval should be avoided, but esbuild still should be able to produce valid output when it is used in the sources.

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