[Pkg-javascript-commits] [uglifyjs] 314/491: fix escape analysis for `AST_Conditional` & `AST_Sequence` (#2563)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:48 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit e20935c3f2a03779b15ad225ae4616a1d80c2ec5
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Dec 8 01:50:38 2017 +0800
fix escape analysis for `AST_Conditional` & `AST_Sequence` (#2563)
fixes #2560
---
lib/compress.js | 4 ++-
test/compress/reduce_vars.js | 77 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/lib/compress.js b/lib/compress.js
index e59dce6..c80192d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -656,7 +656,9 @@ merge(Compressor.prototype, {
|| parent instanceof AST_VarDef && node === parent.value) {
d.escaped = true;
return;
- } else if (parent instanceof AST_Array) {
+ } else if (parent instanceof AST_Array
+ || parent instanceof AST_Conditional && node !== parent.condition
+ || parent instanceof AST_Sequence && node === parent.tail_node()) {
mark_escaped(d, scope, parent, parent, level + 1);
} else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
var obj = tw.parent(level + 1);
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 4a098f7..9a66d1c 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -4544,3 +4544,80 @@ issue_2455: {
}
}
}
+
+issue_2560_1: {
+ options = {
+ reduce_funcs: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function main() {
+ var thing = baz();
+ if (thing !== (thing = baz()))
+ console.log("FAIL");
+ else
+ console.log("PASS");
+ }
+ function baz(s) {
+ return s ? foo : bar;
+ }
+ function foo() {}
+ function bar() {}
+ main();
+ }
+ expect: {
+ function baz(s) {
+ return s ? foo : bar;
+ }
+ function foo() {}
+ function bar() {}
+ (function() {
+ var thing = baz();
+ if (thing !== (thing = baz()))
+ console.log("FAIL");
+ else
+ console.log("PASS");
+ })();
+ }
+ expect_stdout: "PASS"
+}
+
+issue_2560_2: {
+ options = {
+ reduce_funcs: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function main() {
+ var thing = baz();
+ if (thing !== (thing = baz()))
+ console.log("FAIL");
+ else
+ console.log("PASS");
+ }
+ function baz() {
+ return foo, bar;
+ }
+ function foo() {}
+ function bar() {}
+ main();
+ }
+ expect: {
+ function baz() {
+ return function() {}, bar;
+ }
+ function bar() {}
+ (function() {
+ var thing = baz();
+ if (thing !== (thing = baz()))
+ console.log("FAIL");
+ else
+ console.log("PASS");
+ })();
+ }
+ expect_stdout: "PASS"
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list