aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mozilla-ast.js2
-rw-r--r--lib/output.js2
-rw-r--r--lib/scope.js9
-rw-r--r--test/compress/rename.js128
4 files changed, 135 insertions, 6 deletions
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index dace808a..b6fb29bf 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -403,7 +403,7 @@
var def = M.definition();
return {
type: "Identifier",
- name: def ? def.mangled_name || def.name : M.name
+ name: def && def.mangled_name || M.name
};
});
diff --git a/lib/output.js b/lib/output.js
index af0cdc4b..827fa43a 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1355,7 +1355,7 @@ function OutputStream(options) {
});
DEFPRINT(AST_Symbol, function(self, output) {
var def = self.definition();
- output.print_name(def ? def.mangled_name || def.name : self.name);
+ output.print_name(def && def.mangled_name || self.name);
});
DEFPRINT(AST_Hole, noop);
DEFPRINT(AST_This, function(self, output) {
diff --git a/lib/scope.js b/lib/scope.js
index 7da982a0..01a67b7d 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -511,13 +511,14 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
if (def.global && options.cache) return;
if (def.unmangleable(options)) return;
if (options.reserved.has[def.name]) return;
- var d = def.redefined();
- def.name = d ? d.name : next_name();
+ var redef = def.redefined();
+ var name = redef ? redef.rename || redef.name : next_name();
+ def.rename = name;
def.orig.forEach(function(sym) {
- sym.name = def.name;
+ sym.name = name;
});
def.references.forEach(function(sym) {
- sym.name = def.name;
+ sym.name = name;
});
}
});
diff --git a/test/compress/rename.js b/test/compress/rename.js
index 08429d7c..c654e00e 100644
--- a/test/compress/rename.js
+++ b/test/compress/rename.js
@@ -611,3 +611,131 @@ function_do_catch_ie8: {
}
expect_stdout: "0 1"
}
+
+issue_3480: {
+ rename = true,
+ mangle = {
+ ie8: false,
+ toplevel: false,
+ }
+ input: {
+ var d, a, b, c = "FAIL";
+ (function b() {
+ (function() {
+ try {
+ c = "PASS";
+ } catch (b) {
+ }
+ })();
+ })();
+ console.log(c);
+ }
+ expect: {
+ var d, a, b, c = "FAIL";
+ (function n() {
+ (function() {
+ try {
+ c = "PASS";
+ } catch (c) {}
+ })();
+ })();
+ console.log(c);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3480_ie8: {
+ rename = true,
+ mangle = {
+ ie8: true,
+ toplevel: false,
+ }
+ input: {
+ var d, a, b, c = "FAIL";
+ (function b() {
+ (function() {
+ try {
+ c = "PASS";
+ } catch (b) {
+ }
+ })();
+ })();
+ console.log(c);
+ }
+ expect: {
+ var d, a, b, c = "FAIL";
+ (function b() {
+ (function() {
+ try {
+ c = "PASS";
+ } catch (b) {}
+ })();
+ })();
+ console.log(c);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3480_toplevel: {
+ rename = true,
+ mangle = {
+ ie8: false,
+ toplevel: true,
+ }
+ input: {
+ var d, a, b, c = "FAIL";
+ (function b() {
+ (function() {
+ try {
+ c = "PASS";
+ } catch (b) {
+ }
+ })();
+ })();
+ console.log(c);
+ }
+ expect: {
+ var c, n, o, t = "FAIL";
+ (function c() {
+ (function() {
+ try {
+ t = "PASS";
+ } catch (c) {}
+ })();
+ })();
+ console.log(t);
+ }
+ expect_stdout: "PASS"
+}
+
+issue_3480_ie8_toplevel: {
+ rename = true,
+ mangle = {
+ ie8: true,
+ toplevel: true,
+ }
+ input: {
+ var d, a, b, c = "FAIL";
+ (function b() {
+ (function() {
+ try {
+ c = "PASS";
+ } catch (b) {
+ }
+ })();
+ })();
+ console.log(c);
+ }
+ expect: {
+ var c, n, o, t = "FAIL";
+ (function o() {
+ (function() {
+ try {
+ t = "PASS";
+ } catch (o) {}
+ })();
+ })();
+ console.log(t);
+ }
+ expect_stdout: "PASS"
+}