diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-07 09:25:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 17:25:04 +0800 |
commit | 4bde50ce851b9f3c06be99e45e87185cee00ea55 (patch) | |
tree | f428a066d55178c53e179e62fb57e2ed52282c9b /lib | |
parent | fbecedf94ca2c2f667de39dff2d7fbb77629eb40 (diff) | |
download | tracifyjs-4bde50ce851b9f3c06be99e45e87185cee00ea55.tar.gz tracifyjs-4bde50ce851b9f3c06be99e45e87185cee00ea55.zip |
fix corner case in `side_effects` (#4343)
fixes #4342
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/compress.js b/lib/compress.js index be38304a..21ecc5e5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6240,18 +6240,20 @@ merge(Compressor.prototype, { if (!exp.is_string(compressor)) return node; return exp.drop_side_effect_free(compressor, first_in_statement); } + function convert_spread(node) { + return node instanceof AST_Spread ? make_node(AST_Array, node, { + elements: [ node ] + }) : node; + } def(AST_Node, return_this); def(AST_Accessor, return_null); def(AST_Array, function(compressor, first_in_statement) { var values = trim(this.elements, compressor, first_in_statement, array_spread); if (!values) return null; - if (all(values, function(node) { - return !(node instanceof AST_Spread); - })) return make_sequence(this, values); - if (values === this.elements) return this; - var node = this.clone(); - node.elements = values; - return node; + if (values === this.elements && all(values, function(node) { + return node instanceof AST_Spread; + })) return this; + return make_sequence(this, values.map(convert_spread)); }); def(AST_Assign, function(compressor) { var left = this.left; @@ -6304,14 +6306,14 @@ merge(Compressor.prototype, { if (self.is_expr_pure(compressor)) { if (self.pure) AST_Node.warn("Dropping __PURE__ call [{file}:{line},{col}]", self.start); var args = trim(self.args, compressor, first_in_statement, array_spread); - return args && make_sequence(self, args); + return args && make_sequence(self, args.map(convert_spread)); } var exp = self.expression; if (self.is_call_pure(compressor)) { var exprs = self.args.slice(); exprs.unshift(exp.expression); exprs = trim(exprs, compressor, first_in_statement, array_spread); - return exprs && make_sequence(self, exprs); + return exprs && make_sequence(self, exprs.map(convert_spread)); } var def; if (exp instanceof AST_Function @@ -6342,7 +6344,7 @@ merge(Compressor.prototype, { var exprs = self.args.slice(); exprs.unshift(exp); exprs = trim(exprs, compressor, first_in_statement, array_spread); - return exprs && make_sequence(self, exprs); + return exprs && make_sequence(self, exprs.map(convert_spread)); } if (!fn.contains_this()) return make_node(AST_Call, self, self); } |