UglifyJS/test/compress/hoist_props.js
2017-10-25 00:44:37 +08:00

207 lines
3.8 KiB
JavaScript

issue_2377_1: {
options = {
evaluate: true,
inline: true,
hoist_props: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var obj = {
foo: 1,
bar: 2,
square: function(x) {
return x * x;
},
cube: function(x) {
return x * x * x;
},
};
console.log(obj.foo, obj.cube(3));
}
expect: {
var n = 1, o = function(n) {
return n * n * n;
};
console.log(n, o(3));
}
expect_stdout: "1 27"
}
issue_2377_2: {
options = {
evaluate: true,
inline: true,
hoist_props: true,
passes: 2,
reduce_vars: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var obj = {
foo: 1,
bar: 2,
square: function(x) {
return x * x;
},
cube: function(x) {
return x * x * x;
},
};
console.log(obj.foo, obj.cube(3));
}
expect: {
console.log(1, function(n) {
return n * n * n;
}(3));
}
expect_stdout: "1 27"
}
issue_2377_3: {
options = {
evaluate: true,
inline: true,
hoist_props: true,
passes: 3,
reduce_vars: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var obj = {
foo: 1,
bar: 2,
square: function(x) {
return x * x;
},
cube: function(x) {
return x * x * x;
},
};
console.log(obj.foo, obj.cube(3));
}
expect: {
console.log(1, 27);
}
expect_stdout: "1 27"
}
direct_access_1: {
options = {
reduce_vars: true,
hoist_props: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var a = 0;
var obj = {
a: 1,
b: 2,
};
for (var k in obj) a++;
console.log(a, obj.a);
}
expect: {
var a = 0;
var o = {
a: 1,
b: 2,
};
for (var r in o) a++;
console.log(a, o.a);
}
expect_stdout: "2 1"
}
direct_access_2: {
options = {
reduce_vars: true,
hoist_props: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var o = { a: 1 };
var f = function(k) {
if (o[k]) return "PASS";
};
console.log(f("a"));
}
expect: {
var n = { a: 1 };
console.log(function(o) {
if (n[o]) return "PASS";
}("a"));
}
expect_stdout: "PASS"
}
direct_access_3: {
options = {
reduce_vars: true,
hoist_props: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var o = { a: 1 };
o.b;
console.log(o.a);
}
expect: {
var a = { a: 1 };
a.b;
console.log(a.a);
}
expect_stdout: "1"
}
single_use: {
options = {
reduce_vars: true,
hoist_props: true,
toplevel: true,
unused: true,
}
mangle = {
toplevel: true,
}
input: {
var obj = {
bar: function() {
return 42;
},
};
console.log(obj.bar());
}
expect: {
console.log({
bar: function() {
return 42;
},
}.bar());
}
}