#5965·UglifyJS

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

Author: aayla-securaCreated Nov 30, 2024Updated Aug 21, 2025

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:

javascript
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.