Skip to content

Commit

Permalink
enhance side_effects (#3384)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Apr 25, 2019
1 parent cfde686 commit e5436ca
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/compress.js
Expand Up @@ -4172,10 +4172,8 @@ merge(Compressor.prototype, {
var right = this.right.drop_side_effect_free(compressor, first_in_statement);
if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement);
if (lazy_op[this.operator]) {
var node;
if (right === this.right) {
node = this;
} else {
var node = this;
if (right !== node.right) {
node = this.clone();
node.right = right.drop_side_effect_free(compressor);
}
Expand Down Expand Up @@ -4559,14 +4557,14 @@ merge(Compressor.prototype, {
operator : "||",
left : negated,
right : self.body.body
})
}).transform(compressor)
}).optimize(compressor);
return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Binary, self, {
operator : "&&",
left : self.condition,
right : self.body.body
})
}).transform(compressor)
}).optimize(compressor);
}
if (self.body instanceof AST_EmptyStatement
Expand All @@ -4576,7 +4574,7 @@ merge(Compressor.prototype, {
operator : "||",
left : self.condition,
right : self.alternative.body
})
}).transform(compressor)
}).optimize(compressor);
}
if (self.body instanceof AST_Exit
Expand Down
36 changes: 36 additions & 0 deletions test/compress/conditionals.js
Expand Up @@ -1435,3 +1435,39 @@ iife_condition: {
}
expect_stdout: "PASS"
}

angularjs_chain: {
options = {
conditionals: true,
passes: 2,
side_effects: true,
}
input: {
function nonComputedMember(left, right, context, create) {
var lhs = left();
if (create && create !== 1) {
if (lhs && lhs[right] == null) {
lhs[right] = {};
}
}
var value = lhs != null ? lhs[right] : undefined;
if (context) {
return { context: lhs, name: right, value: value };
} else {
return value;
}
}
}
expect: {
function nonComputedMember(left, right, context, create) {
var lhs = left();
create && 1 !== create && lhs && null == lhs[right] && (lhs[right] = {});
var value = null != lhs ? lhs[right] : void 0;
return context ? {
context: lhs,
name: right,
value: value
} : value;
}
}
}
36 changes: 36 additions & 0 deletions test/compress/sequences.js
Expand Up @@ -964,3 +964,39 @@ missing_link: {
console.log(a);
}
}

angularjs_chain: {
options = {
conditionals: true,
sequences: true,
side_effects: true,
}
input: {
function nonComputedMember(left, right, context, create) {
var lhs = left();
if (create && create !== 1) {
if (lhs && lhs[right] == null) {
lhs[right] = {};
}
}
var value = lhs != null ? lhs[right] : undefined;
if (context) {
return { context: lhs, name: right, value: value };
} else {
return value;
}
}
}
expect: {
function nonComputedMember(left, right, context, create) {
var lhs = left();
create && 1 !== create && lhs && null == lhs[right] && (lhs[right] = {});
var value = null != lhs ? lhs[right] : void 0;
return context ? {
context: lhs,
name: right,
value: value
} : value;
}
}
}

0 comments on commit e5436ca

Please sign in to comment.