UglifyJS icon indicating copy to clipboard operation
UglifyJS copied to clipboard

array literal initializers, index assignments, aren't optimized

Open bulk88 opened this issue 2 years ago • 0 comments

uglify-js 3.17.4

input

(function() {
var a = [];
a[0] = 1;
a[1] = 2;
a[2] = 3;
console.log(a);
})() 

commandline

uglifyjs --config-file u.json status.js

config

{
    "compress": {
      "inline": true,
      "passes": 3,
      "reduce_funcs": true,
      "reduce_vars": true,
      "side_effects": true,
      "toplevel": true,
      "unsafe": true,
      "unused": true
    },
    "ie": true,
    "mangle": {
      "eval": true,
      "reserved": ["x", "y"],
      "toplevel": true
    },
    "nameCache": {}
  }

output

var o;(o=[])[0]=1,o[1]=2,o[2]=3,console.log(o);

Why wasn't this optimized to

console.log([1,2,3])

?

My goal is to use an ARRAY indexed JSON storage schema instead of object keys, to save space in the JSON string. I'd rather not do this optimization by hand writing array literals with heavy comments.

(function() {
function NAME () {return 0;}
function ADDRESS() {return 1;}
function TELEPHONE() {return 2;}
var a = [];
a[NAME()] = 1;
a[ADDRESS()] = 2;
a[TELEPHONE()] = 3;
console.log(a);
})()
 ```

bulk88 avatar Apr 07 '23 23:04 bulk88