[Pkg-javascript-commits] [uglifyjs] 333/491: improve `reduce_vars` (#2592)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:50 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 02a6ce07eba11223518a22bce18e209371f78f39
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu Dec 14 15:32:13 2017 +0800
improve `reduce_vars` (#2592)
- account for hoisting nature of `var`
---
lib/compress.js | 11 +++++----
test/compress/reduce_vars.js | 54 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 05e0e1a..4166909 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -381,7 +381,10 @@ merge(Compressor.prototype, {
&& node.operator == "="
&& node.left instanceof AST_SymbolRef) {
var d = node.left.definition();
- if (safe_to_assign(d, node.right)) {
+ if (safe_to_assign(d, node.right)
+ || d.fixed === undefined && all(d.orig, function(sym) {
+ return sym instanceof AST_SymbolVar;
+ })) {
d.references.push(node.left);
d.fixed = function() {
return node.right;
@@ -561,9 +564,9 @@ merge(Compressor.prototype, {
if (!safe_to_read(def)) return false;
if (def.fixed === false) return false;
if (def.fixed != null && (!value || def.references.length > 0)) return false;
- return !def.orig.some(function(sym) {
- return sym instanceof AST_SymbolDefun
- || sym instanceof AST_SymbolLambda;
+ return all(def.orig, function(sym) {
+ return !(sym instanceof AST_SymbolDefun
+ || sym instanceof AST_SymbolLambda);
});
}
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 504ce6f..108dc0e 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -4784,3 +4784,57 @@ escape_local_throw: {
}
expect_stdout: "PASS"
}
+
+inverted_var: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 3,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ console.log(function() {
+ var a = 1;
+ return a;
+ }(), function() {
+ var b;
+ b = 2;
+ return b;
+ }(), function() {
+ c = 3;
+ return c;
+ var c;
+ }(), function(c) {
+ c = 4;
+ return c;
+ }(), function (c) {
+ c = 5;
+ return c;
+ var c;
+ }(), function c() {
+ c = 6;
+ return c;
+ }(), function c() {
+ c = 7;
+ return c;
+ var c;
+ }(), function() {
+ c = 8;
+ return c;
+ var c = "foo";
+ }());
+ }
+ expect: {
+ console.log(1, 2, 3, 4, 5, function c() {
+ c = 6;
+ return c;
+ }(), 7, function() {
+ c = 8;
+ return c;
+ var c = "foo";
+ }());
+ }
+ expect_stdout: true
+}
--
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