Skip to content

Commit

Permalink
enhance inline (#5655)
Browse files Browse the repository at this point in the history
- improve fix for #5653
  • Loading branch information
alexlamsl committed Sep 8, 2022
1 parent 02d966d commit 9dec612
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ Compressor.prototype = new TreeTransformer(function(node, descend, in_list) {
if (node._squeezed) return node;
var is_scope = node instanceof AST_Scope;
if (is_scope) {
if (this.option("arrows") && is_arrow(node) && node.value) {
node.body = [ node.first_statement() ];
node.value = null;
}
node.hoist_properties(this);
node.hoist_declarations(this);
node.process_returns(this);
Expand Down Expand Up @@ -8449,6 +8453,7 @@ Compressor.prototype.compress = function(node) {
AST_Scope.DEFMETHOD("hoist_properties", function(compressor) {
if (!compressor.option("hoist_props") || compressor.has_directive("use asm")) return;
var self = this;
if (is_arrow(self) && self.value) return;
var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
var defs_by_id = Object.create(null);
var tt = new TreeTransformer(function(node, descend) {
Expand Down Expand Up @@ -8486,18 +8491,9 @@ Compressor.prototype.compress = function(node) {
return make_sequence(node, assignments);
}
if (node instanceof AST_Scope) {
var parent;
if (node === self || (parent = tt.parent()).TYPE == "Call" && parent.expression === node) {
if (!(is_arrow(node) && node.value)) return;
var stat = node.first_statement();
node.body = [ stat ];
node.value = null;
descend(node, tt);
if (node.body.length == 1 && node.body[0] === stat) {
node.body.length = 0;
node.value = stat.value;
}
}
if (node === self) return;
var parent = tt.parent();
if (parent.TYPE == "Call" && parent.expression === node) return;
return node;
}
if (node instanceof AST_VarDef) {
Expand Down
22 changes: 22 additions & 0 deletions test/compress/arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,28 @@ single_use_recursive: {
node_version: ">=4"
}

inline_iife_within_arrow: {
options = {
arrows: true,
inline: true,
}
input: {
var f = () => console.log(function(a) {
return Math.ceil(a);
}(Math.random()));
f();
}
expect: {
var f = () => {
return console.log((a = Math.random(), Math.ceil(a)));
var a;
};
f();
}
expect_stdout: "1"
node_version: ">=4"
}

issue_4388: {
options = {
inline: true,
Expand Down

0 comments on commit 9dec612

Please sign in to comment.