[Pkg-javascript-commits] [uglifyjs] 335/491: inline single-use `function` across loop (#2594)
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 90313875f75f68fecfc23c6c6f96f921da730301
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu Dec 14 19:24:54 2017 +0800
inline single-use `function` across loop (#2594)
---
lib/compress.js | 7 +++--
test/compress/functions.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 2 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 96ed24a..9b0a535 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3862,12 +3862,15 @@ merge(Compressor.prototype, {
}
}
if (fn instanceof AST_Function) {
+ var def;
if (compressor.option("inline")
- && exp === fn
- && !fn.name
&& !fn.uses_arguments
&& !fn.uses_eval
&& fn.body.length == 1
+ && (exp === fn ? !fn.name
+ : compressor.option("unused")
+ && (def = exp.definition()).references.length == 1
+ && !recursive_ref(compressor, def))
&& !fn.contains_this()
&& all(fn.argnames, function(arg) {
return arg.__unused;
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 7e87692..c4281d5 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -672,3 +672,78 @@ empty_body: {
}
}
}
+
+inline_loop_1: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f() {
+ return x();
+ }
+ for (;;) f();
+ }
+ expect: {
+ for (;;) x();
+ }
+}
+
+inline_loop_2: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ for (;;) f();
+ function f() {
+ return x();
+ }
+ }
+ expect: {
+ for (;;) x();
+ }
+}
+
+inline_loop_3: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var f = function() {
+ return x();
+ };
+ for (;;) f();
+ }
+ expect: {
+ for (;;) x();
+ }
+}
+
+inline_loop_4: {
+ options = {
+ inline: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ for (;;) f();
+ var f = function() {
+ return x();
+ };
+ }
+ expect: {
+ for (;;) f();
+ var f = function() {
+ return x();
+ };
+ }
+}
--
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