[Pkg-javascript-commits] [uglifyjs] 179/228: fix catch symbol mangling (#1734)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit c595b84032b3083b87a976c8387010bf6074ad93
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Fri Mar 31 02:57:47 2017 +0800
fix catch symbol mangling (#1734)
Only need to look up the immediate non-block/catch scope for the same-name special case.
fixes #1733
---
lib/scope.js | 8 ++--
test/compress/issue-1733.js | 97 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 100 insertions(+), 5 deletions(-)
diff --git a/lib/scope.js b/lib/scope.js
index 025d4ca..df0a7e0 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -79,9 +79,7 @@ SymbolDef.prototype = {
if (!options.screw_ie8 && sym instanceof AST_SymbolLambda)
s = s.parent_scope;
var def;
- if (options.screw_ie8
- && sym instanceof AST_SymbolCatch
- && (def = s.parent_scope.find_variable(sym))) {
+ if (this.defun && (def = this.defun.variables.get(this.name))) {
this.mangled_name = def.mangled_name || def.name;
} else
this.mangled_name = s.next_mangled(options, this);
@@ -171,7 +169,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
}
}
else if (node instanceof AST_SymbolCatch) {
- scope.def_variable(node);
+ scope.def_variable(node).defun = defun;
}
else if (node instanceof AST_LabelRef) {
var sym = labels.get(node.name);
@@ -227,7 +225,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
if (node instanceof AST_SymbolCatch) {
var name = node.name;
var refs = node.thedef.references;
- var scope = node.thedef.scope.parent_scope;
+ var scope = node.thedef.defun;
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
refs.forEach(function(ref) {
ref.thedef = def;
diff --git a/test/compress/issue-1733.js b/test/compress/issue-1733.js
new file mode 100644
index 0000000..3a940c9
--- /dev/null
+++ b/test/compress/issue-1733.js
@@ -0,0 +1,97 @@
+function_iife_catch: {
+ mangle = {
+ screw_ie8: true,
+ }
+ input: {
+ function f(n) {
+ !function() {
+ try {
+ throw 0;
+ } catch (n) {
+ var a = 1;
+ console.log(n, a);
+ }
+ }();
+ }
+ f();
+ }
+ expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
+ expect_stdout: "0 1"
+}
+
+function_iife_catch_ie8: {
+ mangle = {
+ screw_ie8: false,
+ }
+ input: {
+ function f(n) {
+ !function() {
+ try {
+ throw 0;
+ } catch (n) {
+ var a = 1;
+ console.log(n, a);
+ }
+ }();
+ }
+ f();
+ }
+ expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
+ expect_stdout: "0 1"
+}
+
+function_catch_catch: {
+ mangle = {
+ screw_ie8: true,
+ }
+ input: {
+ var o = 0;
+ function f() {
+ try {
+ throw 1;
+ } catch (c) {
+ try {
+ throw 2;
+ } catch (o) {
+ var o = 3;
+ console.log(o);
+ }
+ }
+ console.log(o);
+ }
+ f();
+ }
+ expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
+ expect_stdout: [
+ "3",
+ "undefined",
+ ]
+}
+
+function_catch_catch_ie8: {
+ mangle = {
+ screw_ie8: false,
+ }
+ input: {
+ var o = 0;
+ function f() {
+ try {
+ throw 1;
+ } catch (c) {
+ try {
+ throw 2;
+ } catch (o) {
+ var o = 3;
+ console.log(o);
+ }
+ }
+ console.log(o);
+ }
+ f();
+ }
+ expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
+ expect_stdout: [
+ "3",
+ "undefined",
+ ]
+}
--
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