diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-12-14 02:59:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-14 02:59:59 +0800 |
commit | 9a137e8613e49066a54f2a1b734a559c05338f11 (patch) | |
tree | d621147814d38dfd20a97c25d287e12b739b3dde /lib | |
parent | ef618332ea92db57e59f90f166035a0e7cf8a509 (diff) | |
download | tracifyjs-9a137e8613e49066a54f2a1b734a559c05338f11.tar.gz tracifyjs-9a137e8613e49066a54f2a1b734a559c05338f11.zip |
drop local assign-only variable in `return` (#2587)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 6e984ffa..559fb51a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4666,6 +4666,24 @@ merge(Compressor.prototype, { var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ]; var ASSIGN_OPS_COMMUTATIVE = [ '*', '|', '^', '&' ]; OPT(AST_Assign, function(self, compressor){ + if (compressor.option("dead_code") + && self.left instanceof AST_SymbolRef + && self.left.definition().scope === compressor.find_parent(AST_Lambda)) { + var level = 0, node, parent = self; + do { + node = parent; + parent = compressor.parent(level++); + if (parent instanceof AST_Exit) { + if (self.operator == "=") return self.right; + return make_node(AST_Binary, self, { + operator: self.operator.slice(0, -1), + left: self.left, + right: self.right + }).optimize(compressor); + } + } while (parent instanceof AST_Binary && parent.right === node + || parent instanceof AST_Sequence && parent.tail_node() === node); + } self = self.lift_sequences(compressor); if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) { // x = expr1 OP expr2 |