aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-04-02 22:31:23 +0800
committerGitHub <noreply@github.com>2018-04-02 22:31:23 +0800
commite67553fa550ad355aa1946b5da5051434259a6ba (patch)
treee7bd61ee1fe98d79d291c0082bfe69af2eb96412
parentfcf542f262f73f45f13681f5af2745bea0898fb9 (diff)
downloadtracifyjs-e67553fa550ad355aa1946b5da5051434259a6ba.tar.gz
tracifyjs-e67553fa550ad355aa1946b5da5051434259a6ba.zip
fix tree traversal on `AST_Do` (#3047)
fixes #3046
-rw-r--r--lib/compress.js15
-rw-r--r--lib/transform.js7
-rw-r--r--test/compress/hoist_props.js26
3 files changed, 34 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 477fa307..444b1d05 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -530,12 +530,11 @@ merge(Compressor.prototype, {
tw.safe_ids = save_ids;
return true;
});
- def(AST_Do, function(tw) {
+ def(AST_DWLoop, function(tw, descend) {
var saved_loop = tw.in_loop;
tw.in_loop = this;
push(tw);
- this.body.walk(tw);
- this.condition.walk(tw);
+ descend();
pop(tw);
tw.in_loop = saved_loop;
return true;
@@ -714,16 +713,6 @@ merge(Compressor.prototype, {
}
}
});
- def(AST_While, function(tw) {
- var saved_loop = tw.in_loop;
- tw.in_loop = this;
- push(tw);
- this.condition.walk(tw);
- this.body.walk(tw);
- pop(tw);
- tw.in_loop = saved_loop;
- return true;
- });
})(function(node, func){
node.DEFMETHOD("reduce_vars", func);
});
diff --git a/lib/transform.js b/lib/transform.js
index dcde62c2..41b24c54 100644
--- a/lib/transform.js
+++ b/lib/transform.js
@@ -93,7 +93,12 @@ TreeTransformer.prototype = new TreeWalker;
self.body = do_list(self.body, tw);
});
- _(AST_DWLoop, function(self, tw){
+ _(AST_Do, function(self, tw){
+ self.body = self.body.transform(tw);
+ self.condition = self.condition.transform(tw);
+ });
+
+ _(AST_While, function(self, tw){
self.condition = self.condition.transform(tw);
self.body = self.body.transform(tw);
});
diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js
index 90a7f1d8..b16f7425 100644
--- a/test/compress/hoist_props.js
+++ b/test/compress/hoist_props.js
@@ -716,3 +716,29 @@ issue_3021: {
}
expect_stdout: "2 2"
}
+
+issue_3046: {
+ options = {
+ hoist_props: true,
+ reduce_vars: true,
+ }
+ input: {
+ console.log(function(a) {
+ do {
+ var b = {
+ c: a++
+ };
+ } while (b.c && a);
+ return a;
+ }(0));
+ }
+ expect: {
+ console.log(function(a) {
+ do {
+ var b_c = a++;
+ } while (b_c && a);
+ return a;
+ }(0));
+ }
+ expect_stdout: "1"
+}