aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-11-14 12:21:43 +0200
committerMihai Bazon <mihai@bazon.net>2012-11-14 12:21:43 +0200
commitbdfcbf496b1b7be16dfd8a55c72bad8e5a33cf82 (patch)
treeaacb35f73e4c551d77d0ff6765cff0c37980e3a0 /lib/compress.js
parentdba8da48005956e151a097e85896b161b4224782 (diff)
downloadtracifyjs-bdfcbf496b1b7be16dfd8a55c72bad8e5a33cf82.tar.gz
tracifyjs-bdfcbf496b1b7be16dfd8a55c72bad8e5a33cf82.zip
better solution for the last test in constant switch folding
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js43
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 89be0cea..66375be8 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1368,7 +1368,8 @@ merge(Compressor.prototype, {
self.expression = exp[0];
if (!compressor.option("dead_code")) break out;
var value = exp[1];
- var in_substat = false;
+ var in_if = false;
+ var in_block = false;
var started = false;
var stopped = false;
var ruined = false;
@@ -1377,32 +1378,36 @@ merge(Compressor.prototype, {
// no need to descend these node types
return node;
}
- else if (node instanceof AST_Switch) {
- if (node === self) {
- node = node.clone();
- descend(node, this);
- return ruined ? node : make_node(AST_BlockStatement, node, {
- body: node.body.reduce(function(a, branch){
- return a.concat(branch.body);
- }, [])
- }).transform(compressor);
- }
+ else if (node instanceof AST_Switch && node === self) {
+ node = node.clone();
+ descend(node, this);
+ return ruined ? node : make_node(AST_BlockStatement, node, {
+ body: node.body.reduce(function(a, branch){
+ return a.concat(branch.body);
+ }, [])
+ }).transform(compressor);
}
- else if (node instanceof AST_StatementWithBody || node instanceof AST_Switch || node instanceof AST_Try) {
- var save_substat = in_substat;
- in_substat = true;
+ else if (node instanceof AST_If || node instanceof AST_Try) {
+ var save = in_if;
+ in_if = !in_block;
descend(node, this);
- in_substat = save_substat;
+ in_if = save;
+ return node;
+ }
+ else if (node instanceof AST_StatementWithBody || node instanceof AST_Switch) {
+ var save = in_block;
+ in_block = true;
+ descend(node, this);
+ in_block = save;
return node;
}
else if (node instanceof AST_Break && this.loopcontrol_target(node.label) === self) {
- if (in_substat) {
- // won't handle situations like if (foo) break;
+ if (in_if) {
ruined = true;
return node;
- } else {
- stopped = true;
}
+ if (in_block) return node;
+ stopped = true;
return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);
}
else if (node instanceof AST_SwitchBranch && this.parent() === self) {