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 using the += operator first on a number and then on a string while the compress option is active, the output will be concatenated. This leads to unwanted results at runtime.
Please see 'additional context' for full explanation, as @swc/core is used via swc-loader, terser-webpack-plugin and webpack. I can not reproduce it on the playground, but maybe someone knows, whats going on. Thanks!
For example:
x=100;x+=dist;x+='px';shouldoutputx=100,x+=dist,x+='px'whichoutputs`150px`atruntime.Insteaditoutputsx=100,x+=dist+'px'Soatruntimetheresultistnot`150px`but`10050px`.
Config
No response
Playground link (or link to the minimal reproduction)
Operating System:
Platform: darwin
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
CPU: (10 cores)
Models: Apple M1 Pro
Terser CLI with command --compress --mangle --mangle-props -- node_modules/tiny-slider/src/tiny-slider.js. This does not output the same behavior, which leads me to think the plugin being the issue.
Checked Terser commits regarding this issue from 5.26.0 to 5.31.5.
Checked Webpack commits regarding this issue from 5.89.0 to 5.94.0.
@SeeSpring thanks for the working playground example! Additionally the problem especially occurs, when dist is provided with a negative value. Then the resulting string is not even a valid number.
Describe the bug
When using the
+=
operator first on a number and then on a string while thecompress
option is active, the output will be concatenated. This leads to unwanted results at runtime.Please see 'additional context' for full explanation, as
@swc/core
is used viaswc-loader
,terser-webpack-plugin
andwebpack
. I can not reproduce it on the playground, but maybe someone knows, whats going on. Thanks!Already tried it here: webpack-contrib/terser-webpack-plugin#610 (comment)
Input code
Config
No response
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.7.18&code=H4sIAAAAAAAAA31TUU%2FbMBB%2B51fcHkYcQC17JYoQGkziAYZapiGhPXjJpbXk2pF9adNB%2Fztnt0lKxxbJie9899133zlVYwpS1kAtzY%2B6lIQgMIWXI%2BBHVSA%2BLewSr5XDGHbT1rzBsouAkDcl6QhyqKT2mO38DqlxZmtt4ruQlXCyujUltmnWF%2BgAGBK6Ywbjrah25ET6MvBjehlswjrqMT7kCHmeQ3KZBOB%2FBMAM6e6jIxHx%2Fws%2FSBBlqh0u0dC0cFZrOD4G5R9tU8xvgpc5BxbvY3Ig12DfB7C57jG3qDiidR3GATHRj3ChSBwgwyUkFByhkwQuICmdnEXjDJSpbKjetcPD4EFQMRfoHAP3xZfSQRs5SeM163xrFJ31bABK5Wmr2DXvhJaeHqxXQZJQRvVWmu3rMrdO%2FbGGpIbXV6hUi%2BVPVdI8WLIhG410r%2B%2FxGCaocSkNgVYGPfxGbVf9eQuneSSTvXcldZtkfY%2FIV3EPNHRXoytYMTnDJ%2B7jcXJ1P%2F32fXLH8sXWTkARLjx%2Fv5yfwxiEWCpc1Zav9inMGiJkvU7Aa1XiV9sYusdVetHl7nL%2BTjlguUfikP%2FngX43lCIIxxq4kae1xuc4nMq6xRWR%2B9VNKzgeHLK2XDaswWs9sXv4CzdvSAKKdPADAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF95wCed1tu%2BgdcghEnYiIn2wiFUW5e4FA2%2BzwvDFP3oWUsLKGp9zLswxRESN950I4%2B6TehQBqp1iTiQluI125RrOyjA0dZwJJ0YKpbfG962BDYBx6Z854M%2Bf%2FQh1cJGS%2BilVVfrF4rRO9Elx4bS3sh6Qc8ax%2FwE8aZYm29i8YnsZiZeL4ADoI3bUTAQAA
SWC Info output
Operating System:
Platform: darwin
Arch: arm64
Machine Type: arm64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
CPU: (10 cores)
Models: Apple M1 Pro
Expected behavior
The output should be:
Actual behavior
The output is:
Version
1.3.101
Additional context
I came across this while working with https://github.com/ganlanyuan/tiny-slider, see https://github.com/ganlanyuan/tiny-slider/blob/4d709735c417c2483e77a22d017fc1b18c04f0d4/src/tiny-slider.js#L2606.
How Do We Reproduce?
Use the plugin to bundle the TinySlider code, with the following config:
What I already checked
--compress --mangle --mangle-props -- node_modules/tiny-slider/src/tiny-slider.js
. This does not output the same behavior, which leads me to think the plugin being the issue.Screenshot of the actual issue inside the project:
The text was updated successfully, but these errors were encountered: