[Pkg-javascript-commits] [uglifyjs] 222/491: collapse `a.b` whenever safe (#2350)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:38 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 1abe14296e9a11d30935dba3f27682a3e67885f8
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Oct 8 13:17:48 2017 +0800
collapse `a.b` whenever safe (#2350)
---
lib/compress.js | 2 +-
test/compress/collapse_vars.js | 71 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index d4a72d7..33b4ef0 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -812,7 +812,7 @@ merge(Compressor.prototype, {
var sym;
if (node instanceof AST_Call
|| node instanceof AST_Exit
- || node instanceof AST_PropAccess
+ || node instanceof AST_PropAccess && node.has_side_effects(compressor)
|| node instanceof AST_SymbolRef
&& (lvalues[node.name]
|| side_effects && !references_in_scope(node.definition()))
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index ecd1861..631f5b2 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1834,9 +1834,9 @@ issue_1858: {
}
expect: {
console.log(function(x) {
- var a = {}, b = a.b = x;
+ var a = {}, b = a.b = 1;
return a.b + b;
- }(1));
+ }());
}
expect_stdout: "2"
}
@@ -2521,3 +2521,70 @@ issue_2319_3: {
}
expect_stdout: "true"
}
+
+prop_side_effects_1: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ pure_getters: "strict",
+ reduce_vars: true,
+ toplevel: true,
+ unsafe: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ console.log(C);
+ var obj = {
+ bar: function() {
+ return C + C;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect: {
+ console.log(1);
+ console.log({
+ bar: function() {
+ return 2;
+ }
+ }.bar());
+ }
+ expect_stdout: [
+ "1",
+ "2",
+ ]
+}
+
+prop_side_effects_2: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ pure_getters: "strict",
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unsafe: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ console.log(C);
+ var obj = {
+ bar: function() {
+ return C + C;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect: {
+ console.log(1);
+ console.log(2);
+ }
+ expect_stdout: [
+ "1",
+ "2",
+ ]
+}
--
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