Input:
let o = {
foo: "foo",
bar: "bar"
};
let {foo, bar} = o;
Output with --mangle-props=1 --beautify:
let o = {
a: "foo",
b: "bar"
};
let {foo, bar} = o; // oops - both are assigned undefined
The syntax let {foo, bar} = o needs to consider foo and bar as candidates for property mangling since they implicitly read object properties. This probably needs special consideration to avoid colliding with other local variable names.
The harmony branch is a work in progress and has known problems related to mangling. It's advisable to disable mangle and compress for the time being.
Could you please put an [ES6] prefix in this issue title?
In few days I guess I can start looking in these kinds of issues without internet trouble.
See #1286. Should work fine with 'unused' (a compression option) disabled. And there is a proposed fix there as well, though some additional testing is still welcome.
Is still an issue?
@avdg no idea - can you reproduce the results with the command line as specified in https://github.com/mishoo/UglifyJS2/issues/1315#issue-180924062 on harmony?
If not, then I'll close this.
https://avdg.github.io/uglify/#ref_harmony-editor_let_s0o_s0_x3d_s0_x7b_r_n_s3foo_x3a_s0_x22foo_x22_x2c_r_n_s3bar_x3a_s0_x22bar_x22_r_n_x7d_x3b_r_n_r_nlet_s0_x7bfoo_x2c_s0bar_x7d_s0_x3d_s0o_x3b-bool_beautify0
I've got SCRIPT5009: 'Promise' is undefined so I don't think the linked page works for me at all.
oh, something I can't use I guess...
is that on a recent browser?
IE11 on Win10, so it's as recent as I can get my hands on.
oh, yeah, I see that... You should be fine with edge though... at least if you want to be a daredevil :-)
Edge is not available for the Stable Branch - and for good reasons :wink:
uh I will look for a fallback library I guess :-)
@alexlamsl I've implemented support for ie 11 on my online uglify editor. Enjoy :-)
The bug at the top of this ticket appears to have been addressed:
$ bin/uglifyjs -V
uglify-es 3.0.12
$ cat 1315.js
let o = {
foo: "foo",
bar: "bar"
};
let {foo, bar} = o;
console.log(foo, bar);
md5-7c09a15dae0cf9d30faa396a937ea1bc
$ node 1315.js
foo bar
md5-7c09a15dae0cf9d30faa396a937ea1bc
$ bin/uglifyjs 1315.js --mangle-props | node
foo bar
$ bin/uglifyjs 1315.js --mangle-props
let o={o:"foo",l:"bar"};let{o:foo,l:bar}=o;console.log(foo,bar);
md5-7c09a15dae0cf9d30faa396a937ea1bc
$ bin/uglifyjs 1315.js --mangle-props -c -m --toplevel | node
foo bar
$ bin/uglifyjs 1315.js --mangle-props -c -m --toplevel
let o={o:"foo",l:"bar"},{o:a,l:b}=o;console.log(a,b);
Good to be looking after self-healing software :angel: