Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

array literal initializers, index assignments, aren't optimized #5790

Open
bulk88 opened this issue Apr 7, 2023 · 0 comments
Open

array literal initializers, index assignments, aren't optimized #5790

bulk88 opened this issue Apr 7, 2023 · 0 comments

Comments

@bulk88
Copy link

bulk88 commented Apr 7, 2023

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);
})()
 ```

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

No branches or pull requests

1 participant