diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-05-12 03:52:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-12 03:52:46 +0800 |
commit | 54cb67805532667af50947cc3846d2cacc2a0a1d (patch) | |
tree | d707c4e63a4deb6c07afeaeb1c67e94c97a90c61 /lib/compress.js | |
parent | e88c439eacf0715991e50e1cc664e29af88ee7ab (diff) | |
download | tracifyjs-54cb67805532667af50947cc3846d2cacc2a0a1d.tar.gz tracifyjs-54cb67805532667af50947cc3846d2cacc2a0a1d.zip |
fix corner case in `assignments` (#3407)
fixes #3406
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/compress.js b/lib/compress.js index b63c0512..638fb7c0 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5395,7 +5395,8 @@ merge(Compressor.prototype, { OPT(AST_UnaryPrefix, function(self, compressor) { var e = self.expression; - if (self.operator == "delete" + if (compressor.option("evaluate") + && self.operator == "delete" && !(e instanceof AST_SymbolRef || e instanceof AST_PropAccess || is_identifier_atom(e))) { @@ -6254,6 +6255,7 @@ merge(Compressor.prototype, { if (compressor.option("dead_code") && self.left instanceof AST_SymbolRef && (def = self.left.definition()).scope === compressor.find_parent(AST_Lambda)) { + if (self.left.is_immutable()) return strip_assignment(); var level = 0, node, parent = self; do { node = parent; @@ -6261,16 +6263,12 @@ merge(Compressor.prototype, { if (parent instanceof AST_Exit) { if (in_try(level, parent)) break; if (is_reachable(def.scope, [ def ])) break; - if (self.operator == "=") return self.right.optimize(compressor); def.fixed = false; - return make_node(AST_Binary, self, { - operator: self.operator.slice(0, -1), - left: self.left, - right: self.right - }).optimize(compressor); + return strip_assignment(); } } while (parent instanceof AST_Binary && parent.right === node - || parent instanceof AST_Sequence && parent.tail_node() === node); + || parent instanceof AST_Sequence && parent.tail_node() === node + || parent instanceof AST_UnaryPrefix); } self = self.lift_sequences(compressor); if (!compressor.option("assignments")) return self; @@ -6302,13 +6300,6 @@ merge(Compressor.prototype, { expression: self.left }); } - if (!compressor.option("ie8") && self.left instanceof AST_Symbol && self.left.is_immutable()) { - return (self.operator == "=" ? self.right : make_node(AST_Binary, self, { - operator: self.operator.slice(0, -1), - left: self.left, - right: self.right - })).optimize(compressor); - } return self; function in_try(level, node) { @@ -6325,6 +6316,14 @@ merge(Compressor.prototype, { } } } + + function strip_assignment() { + return (self.operator != "=" ? make_node(AST_Binary, self, { + operator: self.operator.slice(0, -1), + left: self.left, + right: self.right + }) : maintain_this_binding(compressor, compressor.parent(), self, self.right)).optimize(compressor); + } }); OPT(AST_Conditional, function(self, compressor) { |