Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Using --compress computed property names are replaced with original -> larger size than original #5965

Open
aayla-secura opened this issue Nov 30, 2024 · 0 comments

Comments

@aayla-secura
Copy link

aayla-secura commented Nov 30, 2024

This is not technically a bug as the code is valid, however it is the opposite of being minified (it's larger than original not counting whitespace).

When using the --compress option and using a local variable that holds a string literal as a computed property name in an object, it is replaced again with its literal value, which results in larger file even than the original.

Uglify version (uglifyjs -V)

uglify-js 3.19.3

JavaScript input

file.js:

const r = (c) => {
  const P = "foobar";
  return [
    { [P]: c[P] + 1 },
    { [P]: c[P] + 2 },
    { [P]: c[P] + 3 },
    { [P]: c[P] + 4 },
    { [P]: c[P] + 5 },
  ];
};

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

npx uglify-js file.js --compress

JavaScript output or error produced.
When running without --compress it correctly leaves the computed property:

$ npx uglify-js file.js

const r=c=>{const P="foobar";return[{[P]:c[P]+1},{[P]:c[P]+2},{[P]:c[P]+3},{[P]:c[P]+4},{[P]:c[P]+5}]};

However, when enabling --compress it strangely replaces the computed property with its literal, resulting in larger input:

$ npx uglify-js file.js --compress

let r=c=>{var P="foobar";return[{foobar:c[P]+1},{foobar:c[P]+2},{foobar:c[P]+3},{foobar:c[P]+4},{foobar:c[P]+5}]};

It's interesting to note that if the property definition P is made at the top level, then even --compress leaves the computed property names. So I see the issue only when using --compress with local variables in computed properties.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant