[Pkg-javascript-commits] [uglifyjs] 151/491: fix loss of context in `collapse_vars` & `cascade` (#2112)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:30 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 931daa85bf72f6799dca83c1e1ac9b339d85b70b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Jun 16 21:18:43 2017 +0800
fix loss of context in `collapse_vars` & `cascade` (#2112)
fixes #2110
---
lib/compress.js | 2 ++
test/compress/pure_getters.js | 63 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/lib/compress.js b/lib/compress.js
index 3bf54da..309b87c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -722,6 +722,7 @@ merge(Compressor.prototype, {
// Stop immediately if these node types are encountered
var parent = tt.parent();
if (node instanceof AST_Assign && node.operator != "=" && lhs.equivalent_to(node.left)
+ || node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression)
|| node instanceof AST_Debugger
|| node instanceof AST_IterationStatement && !(node instanceof AST_For)
|| node instanceof AST_SymbolRef && node.undeclared()
@@ -3349,6 +3350,7 @@ merge(Compressor.prototype, {
field = "left";
}
} else if (cdr instanceof AST_Call
+ && !(left instanceof AST_PropAccess && cdr.expression.equivalent_to(left))
|| cdr instanceof AST_PropAccess
|| cdr instanceof AST_Unary && !unary_side_effects(cdr.operator)) {
field = "expression";
diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js
index 0ca6a80..81a96b7 100644
--- a/test/compress/pure_getters.js
+++ b/test/compress/pure_getters.js
@@ -178,3 +178,66 @@ impure_getter_2: {
}
expect: {}
}
+
+issue_2110_1: {
+ options = {
+ cascade: true,
+ pure_getters: "strict",
+ sequences: true,
+ side_effects: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function f() {
+ function f() {}
+ function g() {
+ return this;
+ }
+ f.g = g;
+ return f.g();
+ }
+ console.log(typeof f());
+ }
+ expect: {
+ function f() {
+ function f() {}
+ return f.g = function() {
+ return this;
+ }, f.g();
+ }
+ console.log(typeof f());
+ }
+ expect_stdout: "function"
+}
+
+issue_2110_2: {
+ options = {
+ collapse_vars: true,
+ pure_getters: "strict",
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function f() {
+ function f() {}
+ function g() {
+ return this;
+ }
+ f.g = g;
+ return f.g();
+ }
+ console.log(typeof f());
+ }
+ expect: {
+ function f() {
+ function f() {}
+ f.g = function() {
+ return this;
+ };
+ return f.g();
+ }
+ console.log(typeof f());
+ }
+ expect_stdout: "function"
+}
--
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