aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-02 18:42:15 +0800
committerGitHub <noreply@github.com>2018-01-02 18:42:15 +0800
commit6dead95eb3e2566f157b9d776803ea8b7168356d (patch)
treeca9d068856eddb8aad70a81bde7736443265f316 /lib/compress.js
parentcc931b3ad85ff980e397d598f49fb649d08bc68c (diff)
downloadtracifyjs-6dead95eb3e2566f157b9d776803ea8b7168356d.tar.gz
tracifyjs-6dead95eb3e2566f157b9d776803ea8b7168356d.zip
enhance `collapse_vars` (#2704)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5da07f71..32212688 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1159,10 +1159,10 @@ merge(Compressor.prototype, {
if (!expr.left.has_side_effects(compressor)) {
candidates.push(hit_stack.slice());
}
- } else if (expr instanceof AST_Unary) {
- if (expr.operator == "++" || expr.operator == "--") {
- candidates.push(hit_stack.slice());
- }
+ extract_candidates(expr.right);
+ } else if (expr instanceof AST_Binary) {
+ extract_candidates(expr.left);
+ extract_candidates(expr.right);
} else if (expr instanceof AST_Call) {
extract_candidates(expr.expression);
expr.args.forEach(extract_candidates);
@@ -1187,14 +1187,22 @@ merge(Compressor.prototype, {
} else if (expr instanceof AST_Switch) {
extract_candidates(expr.expression);
expr.body.forEach(extract_candidates);
+ } else if (expr instanceof AST_Unary) {
+ if (expr.operator == "++" || expr.operator == "--") {
+ candidates.push(hit_stack.slice());
+ }
} else if (expr instanceof AST_VarDef) {
- if (expr.value) candidates.push(hit_stack.slice());
+ if (expr.value) {
+ candidates.push(hit_stack.slice());
+ extract_candidates(expr.value);
+ }
}
hit_stack.pop();
}
function find_stop(node, level) {
var parent = scanner.parent(level);
+ if (parent instanceof AST_Binary) return node;
if (parent instanceof AST_Call) return node;
if (parent instanceof AST_Case) return node;
if (parent instanceof AST_Conditional) return node;
@@ -1202,6 +1210,7 @@ merge(Compressor.prototype, {
if (parent instanceof AST_If) return node;
if (parent instanceof AST_Sequence) return find_stop(parent, level + 1);
if (parent instanceof AST_Switch) return node;
+ if (parent instanceof AST_VarDef) return node;
return null;
}