[Pkg-javascript-commits] [uglifyjs] 341/491: account for `catch` variable when `inline` (#2605)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:51 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 21794c9b8d0102ed00a15d1e54314908c92e4a24
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sat Dec 16 15:21:09 2017 +0800
account for `catch` variable when `inline` (#2605)
fixes #2604
---
lib/compress.js | 14 +++++++--
test/compress/functions.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 8c17422..ebcae48 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3924,10 +3924,20 @@ merge(Compressor.prototype, {
return self;
function can_flatten_args(fn) {
- var scope = compressor.find_parent(AST_Scope);
+ var scope, level = 0;
+ var catches = Object.create(null);
+ do {
+ scope = compressor.parent(level++);
+ if (scope instanceof AST_Catch) {
+ catches[scope.argname.name] = true;
+ }
+ } while (!(scope instanceof AST_Scope));
var safe_to_inject = compressor.toplevel.vars || !(scope instanceof AST_Toplevel);
return all(fn.argnames, function(arg) {
- return arg.__unused || safe_to_inject && !scope.var_names()[arg.name];
+ return arg.__unused
+ || safe_to_inject
+ && !catches[arg.name]
+ && !scope.var_names()[arg.name];
}) && scope;
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 8e67bc3..5f7fba6 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -847,3 +847,79 @@ issue_2601_2: {
}
expect_stdout: "PASS"
}
+
+issue_2604_1: {
+ options = {
+ inline: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function() {
+ try {
+ throw 1;
+ } catch (b) {
+ (function f(b) {
+ b && b();
+ })();
+ b && (a = "PASS");
+ }
+ })();
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ (function() {
+ try {
+ throw 1;
+ } catch (b) {
+ (function(b) {
+ b && b();
+ })();
+ b && (a = "PASS");
+ }
+ })();
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_2604_2: {
+ rename = true
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 3,
+ reduce_vars: true,
+ side_effects: true,
+ unused: true,
+ }
+ mangle = {}
+ input: {
+ var a = "FAIL";
+ (function() {
+ try {
+ throw 1;
+ } catch (b) {
+ (function f(b) {
+ b && b();
+ })();
+ b && (a = "PASS");
+ }
+ })();
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ (function() {
+ try {
+ throw 1;
+ } catch (o) {
+ o && (a = "PASS");
+ }
+ })();
+ console.log(a);
+ }
+ 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