webpack-contrib / terser-webpack-plugin

Terser Plugin
MIT License
1.95k stars 157 forks source link

Behavior of minified code is altered: when dependencies have imported JSON, JSON has names mangled, uncontrollable by terser mangle options #603

Closed edmonl closed 5 months ago

edmonl commented 5 months ago

Bug report

A dependency package imports JSON in its code. Destructuring assignment is used to get values from the parsed JSON. Minification generates incorrect output by inconsistently mangling names from JSON.

Why do I feel this is the issue of the plugin instead of terser itself?

I used terser directly, i.e. npx terser ..., to minify code, including the individual files and/or the unminified bundle. The output was correct.

Plugins for other tool chains like gulp also generates correct output.

Actual Behavior

Minification mangles names from JSON and destructuring assignment inconsistently. Plugin options, including terserOptions, include/exclude, cannot stop name mangling in JSON.

Expected Behavior

Minification mangles names from JSON and destructuring assignment consistently. Plugin options can control name mangling in JSON.

How Do We Reproduce?

This is my reproduction repository https://github.com/edmonl/demo-webpack-terser-issue . See README.md.

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (6) x64 Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
    Memory: 9.98 GB / 15.59 GB
  Binaries:
    Node: 16.20.2 - ~/stow/node-v16.20.2-linux-x64/bin/node
    npm: 10.2.4 - ~/.npm-global/bin/npm
  Browsers:
    Chrome: 124.0.6367.207
  Packages:
    terser-webpack-plugin: ^5.3.10 => 5.3.10 
    webpack: ^5.91.0 => 5.91.0 
    webpack-cli: ^5.1.4 => 5.1.4 
alexander-akait commented 5 months ago

Duplicate of https://github.com/webpack/webpack/issues/18278, we have a PR, fix will be soon (hope this week)