You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason why esbuild does this is because function hoisting semantics depends on strict mode. If this code is followed by console.log(foo) and evaluated, it will print foo in non-strict mode but it will throw an error in strict mode. The transformation that esbuild does here is intended to preserve the original semantics of the input (which was in non-strict mode) even when the output is evaluated in strict mode.
It might be impossible to preserve the original semantics of the input like this while also preserving the names of these symbols for direct eval. So perhaps the answer here is to not do this transformation when direct eval is present. This means that direct eval will be able to reference foo but the final code may end up behaving differently from the original code since the original function hoisting semantics were not preserved.
When this code
is transformed with default settings in esbuild 0.16.10, esbuild produces the following invalid output
=> Identifier 'foo' has already been declared
To reproduce, just call the transform API like this:
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.
The text was updated successfully, but these errors were encountered: