2017-10-24 08:58:31 +00:00
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 16:44:37 +00:00
|
|
|
direct_access_1: {
|
2017-10-24 08:58:31 +00:00
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 16:44:37 +00:00
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 08:58:31 +00:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|