[Pkg-javascript-commits] [uglifyjs] 148/491: enforce `inline` scope restriction (#2106)
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 33405bb24b9a5933badf146a9576953b8b456aad
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Jun 16 03:21:38 2017 +0800
enforce `inline` scope restriction (#2106)
fixes #2105
---
lib/compress.js | 34 +++++++++++++++++-----------------
test/compress/drop-unused.js | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 17 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index f598934..e14e63a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2944,18 +2944,18 @@ merge(Compressor.prototype, {
OPT(AST_Call, function(self, compressor){
var exp = self.expression;
- if (compressor.option("reduce_vars") && exp instanceof AST_SymbolRef) {
- var fixed = exp.fixed_value();
- if (fixed instanceof AST_Function) exp = fixed;
- }
+ var fn = exp;
if (compressor.option("unused")
- && exp instanceof AST_Function
- && !exp.uses_arguments
- && !exp.uses_eval) {
+ && (fn instanceof AST_Function
+ || compressor.option("reduce_vars")
+ && fn instanceof AST_SymbolRef
+ && (fn = fn.fixed_value()) instanceof AST_Function)
+ && !fn.uses_arguments
+ && !fn.uses_eval) {
var pos = 0, last = 0;
for (var i = 0, len = self.args.length; i < len; i++) {
- var trim = i >= exp.argnames.length;
- if (trim || exp.argnames[i].__unused) {
+ var trim = i >= fn.argnames.length;
+ if (trim || fn.argnames[i].__unused) {
var node = self.args[i].drop_side_effect_free(compressor);
if (node) {
self.args[pos++] = node;
@@ -3156,15 +3156,15 @@ merge(Compressor.prototype, {
}
}
}
- if (exp instanceof AST_Function) {
- var stat = exp.body[0];
- if (compressor.option("inline") && stat instanceof AST_Return) {
- var value = stat && stat.value;
- if (!value || value.is_constant_expression()) {
- var args = self.args.concat(value || make_node(AST_Undefined, self));
- return make_sequence(self, args).transform(compressor);
- }
+ var stat = fn instanceof AST_Function && fn.body[0];
+ if (compressor.option("inline") && stat instanceof AST_Return) {
+ var value = stat.value;
+ if (!value || value.is_constant_expression()) {
+ var args = self.args.concat(value || make_node(AST_Undefined, self));
+ return make_sequence(self, args).transform(compressor);
}
+ }
+ if (exp instanceof AST_Function) {
if (compressor.option("inline")
&& !exp.name
&& exp.body.length == 1
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index af792bf..08fc7b1 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1108,3 +1108,47 @@ var_catch_toplevel: {
}();
}
}
+
+issue_2105: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ !function(factory) {
+ factory();
+ }( function() {
+ return function(fn) {
+ fn()().prop();
+ }( function() {
+ function bar() {
+ var quux = function() {
+ console.log("PASS");
+ }, foo = function() {
+ console.log;
+ quux();
+ };
+ return { prop: foo };
+ }
+ return bar;
+ } );
+ });
+ }
+ expect: {
+ !void function() {
+ var quux = function() {
+ console.log("PASS");
+ };
+ return {
+ prop: function() {
+ console.log;
+ quux();
+ }
+ };
+ }().prop();
+ }
+ expect_stdout: "PASS"
+}
--
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