Skip to content

Commit

Permalink
fix corner case in hoist_props (#3412)
Browse files Browse the repository at this point in the history
fixes #3411
  • Loading branch information
alexlamsl committed May 14, 2019
1 parent d538a73 commit f87caac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/compress.js
Expand Up @@ -519,7 +519,7 @@ merge(Compressor.prototype, {
if (parent instanceof AST_Call && node === parent.expression) return;
if (parent instanceof AST_Sequence && node !== parent.tail_node()) return;
if (parent instanceof AST_SimpleStatement) return;
if (parent instanceof AST_Unary) return;
if (parent instanceof AST_Unary && !unary_side_effects[parent.operator]) return;
d.direct_access = true;
}

Expand Down Expand Up @@ -4067,6 +4067,16 @@ merge(Compressor.prototype, {
}));
return make_sequence(node, assignments);
}
if (node instanceof AST_Unary
&& !unary_side_effects[node.operator]
&& node.expression instanceof AST_SymbolRef
&& node.expression.definition().id in defs_by_id) {
node = node.clone();
node.expression = make_node(AST_Object, node, {
properties: []
});
return node;
}
if (node instanceof AST_VarDef && can_hoist(node.name, node.value, 0)) {
descend(node, this);
var defs = new Dictionary();
Expand Down
24 changes: 24 additions & 0 deletions test/compress/hoist_props.js
Expand Up @@ -862,3 +862,27 @@ issue_3071_3: {
}
expect_stdout: "2"
}

issue_3411: {
options = {
hoist_props: true,
reduce_vars: true,
}
input: {
var c = 1;
!function f() {
var o = {
p: --c && f()
};
+o || console.log("PASS");
}();
}
expect: {
var c = 1;
!function f() {
var o_p = --c && f();
+{} || console.log("PASS");
}();
}
expect_stdout: "PASS"
}

0 comments on commit f87caac

Please sign in to comment.