fix non-string property key
avoid unused variable
This commit is contained in:
parent
1282206db3
commit
1eea65e82e
|
|
@ -2693,7 +2693,10 @@ merge(Compressor.prototype, {
|
|||
self.enclosed.forEach(function(def) {
|
||||
var_names[def.name] = true;
|
||||
});
|
||||
var tt = new TreeTransformer(function(node) {
|
||||
self.variables.each(function(def, name) {
|
||||
var_names[name] = true;
|
||||
});
|
||||
return self.transform(new TreeTransformer(function(node) {
|
||||
if (node instanceof AST_VarDef) {
|
||||
var sym = node.name, def, value;
|
||||
if (sym.scope === self
|
||||
|
|
@ -2731,7 +2734,7 @@ merge(Compressor.prototype, {
|
|||
}
|
||||
|
||||
function make_sym(key) {
|
||||
var prefix = sym.name + "_" + key.replace(/[^a-z_$]+/ig, "_");
|
||||
var prefix = sym.name + "_" + key.toString().replace(/[^a-z_$]+/ig, "_");
|
||||
var name = prefix;
|
||||
for (var i = 0; var_names[name]; i++) name = prefix + "$" + i;
|
||||
var new_var = make_node(sym.CTOR, sym, {
|
||||
|
|
@ -2744,8 +2747,7 @@ merge(Compressor.prototype, {
|
|||
var_names[name] = true;
|
||||
return new_var;
|
||||
}
|
||||
});
|
||||
return self.transform(tt);
|
||||
}));
|
||||
});
|
||||
|
||||
// drop_side_effect_free()
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ single_use: {
|
|||
}
|
||||
}
|
||||
|
||||
name_collision: {
|
||||
name_collision_1: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
hoist_props: true,
|
||||
|
|
@ -220,3 +220,69 @@ name_collision: {
|
|||
}
|
||||
expect_stdout: "1 3 4 5 6 7"
|
||||
}
|
||||
|
||||
name_collision_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
hoist_props: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
p: 1,
|
||||
0: function(x) {
|
||||
return x;
|
||||
},
|
||||
1: function(x) {
|
||||
return x + 1;
|
||||
}
|
||||
}, o__$0 = 2, o__$1 = 3;
|
||||
console.log(o.p === o.p, o[0](4), o[1](5), o__$0, o__$1);
|
||||
}
|
||||
expect: {
|
||||
var o_p = 1,
|
||||
o__ = function(x) {
|
||||
return x;
|
||||
},
|
||||
o__$2 = function(x) {
|
||||
return x + 1;
|
||||
},
|
||||
o__$0 = 2,
|
||||
o__$1 = 3;
|
||||
console.log(o_p === o_p, o__(4), o__$2(5), o__$0, o__$1);
|
||||
}
|
||||
expect_stdout: "true 4 6 2 3"
|
||||
}
|
||||
|
||||
name_collision_3: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
hoist_props: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
p: 1,
|
||||
0: function(x) {
|
||||
return x;
|
||||
},
|
||||
1: function(x) {
|
||||
return x + 1;
|
||||
}
|
||||
}, o__$0 = 2, o__$1 = 3;
|
||||
console.log(o.p === o.p, o[0](4), o[1](5));
|
||||
}
|
||||
expect: {
|
||||
var o_p = 1,
|
||||
o__ = function(x) {
|
||||
return x;
|
||||
},
|
||||
o__$2 = function(x) {
|
||||
return x + 1;
|
||||
},
|
||||
o__$0 = 2,
|
||||
o__$1 = 3;
|
||||
console.log(o_p === o_p, o__(4), o__$2(5));
|
||||
}
|
||||
expect_stdout: "true 4 6"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user