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
When running code through minify (BABEL_ENV=prod npx babel --no-comments --out-file dst src), a local variable gets "reduced" (i.e. from navx to c) as expected but a later reference (within a string expression) uses the original name (i.e. navx) resulting in a 'not defined' error upon execution.
Input Code
(function(){consttotItems=71;// REQUIRED for error: if commented out, NO ERROR!!!varstart=1,navx='';while(start<71){navx+='a';start+=10;}constpages='b'+navx;console.log(pages);})();
looking for a workaround (for our real code), I noticed that the babel REPL is working properly on the same test code. It seems to use Babel 6.26.0, same as us, but Env 1.6.2 (we have babel-preset-env v1.6.1). Not sure which or which version of minify they use on that repl site.
When running code through minify (BABEL_ENV=prod npx babel --no-comments --out-file dst src), a local variable gets "reduced" (i.e. from navx to c) as expected but a later reference (within a string expression) uses the original name (i.e. navx) resulting in a 'not defined' error upon execution.
Input Code
.babelrc Setup:
Minified code
Using
BABEL_ENV=prod npx babel --out-file dst.js src.js
to build it:Actual Output
Using
node dst
to test run this code:Expected Output
Using
node src
to run:Details
Something interesting (?): if I remove the unused
totItems
declaration (definition? :-)), the code builds and runs properly.Is this a hoisting issue? (not a clue: just said that to sound smart! :-))
MORE IMPORTANTLY: if I remove the enclosing IIFE (i.e.
(function(){})()
), the code also runs properly.The text was updated successfully, but these errors were encountered: