[Pkg-javascript-commits] [uglifyjs] 326/491: improve `collapse_vars` on side-effect-free replacements (#2583)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:49 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 04cc395c353ac622d8e737c9099387d69b851d64
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Wed Dec 13 04:52:54 2017 +0800
improve `collapse_vars` on side-effect-free replacements (#2583)
---
lib/compress.js | 5 +++--
test/compress/collapse_vars.js | 48 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 00d03fd..6aee949 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -893,10 +893,11 @@ merge(Compressor.prototype, {
|| 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.is_declared(compressor)
|| node instanceof AST_Try
|| node instanceof AST_With
- || parent instanceof AST_For && node !== parent.init) {
+ || parent instanceof AST_For && node !== parent.init
+ || (side_effects || !replace_all)
+ && (node instanceof AST_SymbolRef && !node.is_declared(compressor))) {
abort = true;
return node;
}
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 330667d..5840580 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -3805,3 +3805,51 @@ may_throw: {
}
}
}
+
+side_effect_free_replacement: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var b;
+ (function(a) {
+ x(a);
+ })(b);
+ }
+ expect: {
+ var b;
+ x(b);
+ }
+}
+
+recursive_function_replacement: {
+ rename = true
+ options = {
+ collapse_vars: true,
+ inline: true,
+ passes: 2,
+ reduce_funcs: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ mangle = {}
+ input: {
+ function f(a) {
+ return x(g(a));
+ }
+ function g(a) {
+ return y(f(a));
+ }
+ console.log(f(c));
+ }
+ expect: {
+ function f(n) {
+ return x(y(f(n)));
+ }
+ console.log(f(c));
+ }
+}
--
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