Skip to content

Commit

Permalink
enhance inline (#5610)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Aug 9, 2022
1 parent c32fe26 commit 5a4cd09
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10825,7 +10825,7 @@ Compressor.prototype.compress = function(node) {
var begin;
var in_order = [];
var side_effects = false;
value.walk(new TreeWalker(function(node, descend) {
var tw = new TreeWalker(function(node, descend) {
if (abort) return true;
if (node instanceof AST_Binary && lazy_op[node.operator]
|| node instanceof AST_Conditional) {
Expand All @@ -10841,7 +10841,7 @@ Compressor.prototype.compress = function(node) {
return;
}
if (def.init instanceof AST_LambdaDefinition) return abort = true;
if (is_lhs(node, this.parent())) return abort = true;
if (is_lhs(node, tw.parent())) return abort = true;
var index = resolve_index(def);
if (!(begin < index)) begin = index;
if (!in_order) return;
Expand All @@ -10852,12 +10852,21 @@ Compressor.prototype.compress = function(node) {
}
return;
}
if (side_effects) return;
if (node instanceof AST_Assign && node.left instanceof AST_PropAccess) {
node.left.expression.walk(tw);
if (node.left instanceof AST_Sub) node.left.property.walk(tw);
node.right.walk(tw);
side_effects = true;
return true;
}
if (node.has_side_effects(compressor)) {
descend();
side_effects = true;
return true;
}
}));
});
value.walk(tw);
if (abort) return;
var end = self.args.length;
if (in_order && fn.argnames.length >= end) {
Expand Down
34 changes: 34 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5512,6 +5512,40 @@ substitute_use_strict: {
]
}

substitute_assignment: {
options = {
evaluate: true,
inline: true,
passes: 2,
properties: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
function f(a, b, c) {
a[b] = c;
}
var o = {};
f(o, 42, null);
f(o, "foo", "bar");
for (var k in o)
console.log(k, o[k]);
}
expect: {
var o = {};
o[42] = null;
o.foo = "bar";
for (var k in o)
console.log(k, o[k]);
}
expect_stdout: [
"42 null",
"foo bar",
]
}

issue_3833_1: {
options = {
inline: 3,
Expand Down

0 comments on commit 5a4cd09

Please sign in to comment.