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
It doesn't happen when (1) --format=esm is not set or (2) export {} is appended or (3) 'use strict' is prepended.
This seems to happen from at least v0.9.0.
Interesting example, it seems that var f = function(){} does not act the same as function f(){} in nested blocks. The latter tries to pollute the outer block but silently fail if there's name conflicting in non-strict mode:
// code below are tested in node.js non-strict mode,// it may output different in other runtimesconstfoo=1;// same result as `let foo = 1`if(true){functionfoo(){}}console.log(foo);// 1if(true){functionbar(){}}console.log(bar);// [Function: bar]varbuzz=1if(true){functionbuzz(){}}console.log(buzz);// [Function: buzz]
So the problem is --minify-identifiers does not take outer block names into account in non-strict context. esbuild does var f = n simply for keeping non-strict behaviors as much as possible, since vars can pollute out of current block, but it will throw error when the pollution fails.
What if we keep the function declaration but only re-assign it to another let variable?
// original outputletn=function(){};varf=n;// new outputfunctionf(){};letn=f;
When this code is input,
esbuild outputs (
--minify-identifiers --format=esm
)This code redeclares
f
and throwsSyntaxError: Identifier 'f' has already been declared
.repl
It doesn't happen when (1)
--format=esm
is not set or (2)export {}
is appended or (3)'use strict'
is prepended.This seems to happen from at least v0.9.0.
Original issue: vitejs/vite#11642
The text was updated successfully, but these errors were encountered: