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
TLDR: babel-plugin-minify-dead-code seems to assume that var initializers are executed, but they're executed only if reached.
Longer version: var x = ydoes two things: it declares x at the function scope (no matter what), and sets x = ywhen that line gets reached. As a result, if (condition) var x = y declares x, but x will remain undefined if condition is false. babel-plugin-minify-dead-code seems to assume that the assignment happens though, and generates incorrect code.
To Reproduce
Demo link (please uncheck "Bug fixes" after loading)
Describe the bug
TLDR: babel-plugin-minify-dead-code seems to assume that
var
initializers are executed, but they're executed only if reached.Longer version:
var x = y
does two things: it declaresx
at the function scope (no matter what), and setsx = y
when that line gets reached. As a result,if (condition) var x = y
declaresx
, butx
will remainundefined
ifcondition
is false. babel-plugin-minify-dead-code seems to assume that the assignment happens though, and generates incorrect code.To Reproduce
Demo link (please uncheck "Bug fixes" after loading)
Actual Output
Expected Output
Configuration
How are you using babel-minify?
babel Node API
babel-minify version:
0.5.1
babel version :
7.15.5
babel-minify-config:
babelrc:
Additional context
This arose when minifying (a PR for) the CoffeeScript compiler.
The text was updated successfully, but these errors were encountered: