Skip to content

Commit 5a4cd09

Browse files
authored
enhance inline (#5610)
1 parent c32fe26 commit 5a4cd09

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

lib/compress.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10825,7 +10825,7 @@ Compressor.prototype.compress = function(node) {
1082510825
var begin;
1082610826
var in_order = [];
1082710827
var side_effects = false;
10828-
value.walk(new TreeWalker(function(node, descend) {
10828+
var tw = new TreeWalker(function(node, descend) {
1082910829
if (abort) return true;
1083010830
if (node instanceof AST_Binary && lazy_op[node.operator]
1083110831
|| node instanceof AST_Conditional) {
@@ -10841,7 +10841,7 @@ Compressor.prototype.compress = function(node) {
1084110841
return;
1084210842
}
1084310843
if (def.init instanceof AST_LambdaDefinition) return abort = true;
10844-
if (is_lhs(node, this.parent())) return abort = true;
10844+
if (is_lhs(node, tw.parent())) return abort = true;
1084510845
var index = resolve_index(def);
1084610846
if (!(begin < index)) begin = index;
1084710847
if (!in_order) return;
@@ -10852,12 +10852,21 @@ Compressor.prototype.compress = function(node) {
1085210852
}
1085310853
return;
1085410854
}
10855+
if (side_effects) return;
10856+
if (node instanceof AST_Assign && node.left instanceof AST_PropAccess) {
10857+
node.left.expression.walk(tw);
10858+
if (node.left instanceof AST_Sub) node.left.property.walk(tw);
10859+
node.right.walk(tw);
10860+
side_effects = true;
10861+
return true;
10862+
}
1085510863
if (node.has_side_effects(compressor)) {
1085610864
descend();
1085710865
side_effects = true;
1085810866
return true;
1085910867
}
10860-
}));
10868+
});
10869+
value.walk(tw);
1086110870
if (abort) return;
1086210871
var end = self.args.length;
1086310872
if (in_order && fn.argnames.length >= end) {

test/compress/functions.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5512,6 +5512,40 @@ substitute_use_strict: {
55125512
]
55135513
}
55145514

5515+
substitute_assignment: {
5516+
options = {
5517+
evaluate: true,
5518+
inline: true,
5519+
passes: 2,
5520+
properties: true,
5521+
reduce_vars: true,
5522+
side_effects: true,
5523+
toplevel: true,
5524+
unused: true,
5525+
}
5526+
input: {
5527+
function f(a, b, c) {
5528+
a[b] = c;
5529+
}
5530+
var o = {};
5531+
f(o, 42, null);
5532+
f(o, "foo", "bar");
5533+
for (var k in o)
5534+
console.log(k, o[k]);
5535+
}
5536+
expect: {
5537+
var o = {};
5538+
o[42] = null;
5539+
o.foo = "bar";
5540+
for (var k in o)
5541+
console.log(k, o[k]);
5542+
}
5543+
expect_stdout: [
5544+
"42 null",
5545+
"foo bar",
5546+
]
5547+
}
5548+
55155549
issue_3833_1: {
55165550
options = {
55175551
inline: 3,

0 commit comments

Comments
 (0)