mishoo / UglifyJS

JavaScript parser / mangler / compressor / beautifier toolkit
http://lisperator.net/uglifyjs/
Other
13.16k stars 1.25k forks source link

Part of expression containing global definition missing from minified output #4010

Closed jameswilddev closed 4 years ago

jameswilddev commented 4 years ago

Bug report or feature request?

Bug report.

Uglify version (uglifyjs -V)

uglify-js 3.10.0

JavaScript input

Given that testConstantA is 47:

testConstantA * 10 + testConstantB.join('::')

The uglifyjs CLI command executed or minify() options used.

echo "testConstantA * 10 + testConstantB.join('::')" | uglifyjs -d testConstantA=47

JavaScript output or error produced.

testConstantB.join("::");
jameswilddev commented 4 years ago

I've written a test for this but it doesn't fail? Very strange. https://github.com/mishoo/UglifyJS/compare/master...jameswilddev:issue-4010

alexlamsl commented 4 years ago

By default uglify-js treats input as complete statements, i.e. in your example the evaluated value of testConstantA * 10 + testConstantB.join('::') will be discarded since it is not being fed into any function arguments or variable assignments etc.

I assume what you want here is the --compress expression:

$ echo "testConstantA * 10 + testConstantB.join('::')" | uglifyjs -d testConstantA=47
testConstantB.join("::");

$ echo "testConstantA * 10 + testConstantB.join('::')" | uglifyjs -d testConstantA=47 -c expression
470+testConstantB.join("::");
jameswilddev commented 4 years ago

Ah, ok, I think I understand where the code which led to this example is going wrong. Thanks for the help!