fix unknown property access

This commit is contained in:
alexlamsl 2017-10-25 00:44:37 +08:00
parent 1893abd2cb
commit cf75ccbce9
2 changed files with 53 additions and 3 deletions

View File

@ -611,8 +611,9 @@ merge(Compressor.prototype, {
} else if (parent instanceof AST_Array || parent instanceof AST_Object) {
mark_escaped(d, parent, parent, level + 1);
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
mark_escaped(d, parent, read_property(value, parent.property), level + 1);
return;
value = read_property(value, parent.property);
mark_escaped(d, parent, value, level + 1);
if (value) return;
}
if (level == 0) d.direct_access = true;
}

View File

@ -98,7 +98,7 @@ issue_2377_3: {
expect_stdout: "1 27"
}
direct_access: {
direct_access_1: {
options = {
reduce_vars: true,
hoist_props: true,
@ -129,6 +129,55 @@ direct_access: {
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,