fix usage accounting within assignment

This commit is contained in:
alexlamsl 2017-04-07 00:48:13 +08:00
parent 1d1a8575dd
commit 874beea90a
2 changed files with 34 additions and 3 deletions

View File

@ -283,10 +283,16 @@ merge(Compressor.prototype, {
if (node instanceof AST_VarDef) {
var d = node.name.definition();
if (d.fixed == null) {
d.fixed = node.value && function() {
if (node.value) {
d.fixed = function() {
return node.value;
};
descend();
} else {
d.fixed = null;
}
mark_as_safe(d);
return true;
} else if (node.value) {
d.fixed = false;
}
@ -1167,6 +1173,9 @@ merge(Compressor.prototype, {
def(AST_UnaryPrefix, function() {
return this.operator == "void";
});
def(AST_Seq, function(compressor) {
return this.cdr.may_eq_null(compressor);
});
def(AST_PropAccess, function(compressor) {
return !compressor.option("unsafe");
});

View File

@ -1916,3 +1916,25 @@ side_effects_assign: {
}
expect_stdout: "undefined"
}
pure_getters: {
options = {
pure_getters: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
try {
var a = (a.b, 2);
} catch (e) {}
console.log(a);
}
expect: {
try {
var a = (a.b, 2);
} catch (e) {}
console.log(a);
}
expect_stdout: "undefined"
}