32
lib/scope.js
32
lib/scope.js
@@ -419,7 +419,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
if (options.cache && node instanceof AST_Toplevel) {
|
if (options.cache && node instanceof AST_Toplevel) {
|
||||||
node.globals.each(mangle);
|
node.globals.each(mangle);
|
||||||
}
|
}
|
||||||
node.variables.each(mangle);
|
node.variables.each(function(def) {
|
||||||
|
if (!defer_redef(def)) mangle(def);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
@@ -432,22 +434,11 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
}
|
}
|
||||||
if (!options.ie8 && node instanceof AST_Catch) {
|
if (!options.ie8 && node instanceof AST_Catch) {
|
||||||
var def = node.argname.definition();
|
var def = node.argname.definition();
|
||||||
var redef = def.redefined();
|
var redef = defer_redef(def, node.argname);
|
||||||
if (redef) {
|
|
||||||
redefined.push(def);
|
|
||||||
reference(node.argname);
|
|
||||||
def.references.forEach(reference);
|
|
||||||
}
|
|
||||||
descend();
|
descend();
|
||||||
if (!redef) mangle(def);
|
if (!redef) mangle(def);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reference(sym) {
|
|
||||||
sym.thedef = redef;
|
|
||||||
sym.reference(options);
|
|
||||||
sym.thedef = def;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
redefined.forEach(mangle);
|
redefined.forEach(mangle);
|
||||||
@@ -456,6 +447,21 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
if (options.reserved.has[def.name]) return;
|
if (options.reserved.has[def.name]) return;
|
||||||
def.mangle(options);
|
def.mangle(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defer_redef(def, node) {
|
||||||
|
var redef = def.redefined();
|
||||||
|
if (!redef) return false;
|
||||||
|
redefined.push(def);
|
||||||
|
def.references.forEach(reference);
|
||||||
|
if (node) reference(node);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
function reference(sym) {
|
||||||
|
sym.thedef = redef;
|
||||||
|
sym.reference(options);
|
||||||
|
sym.thedef = def;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
||||||
|
|||||||
@@ -1321,3 +1321,243 @@ issue_3475_ie8_toplevel: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3478_1: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var a;
|
||||||
|
console.log(typeof f);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function a() {
|
||||||
|
(function a() {
|
||||||
|
var o;
|
||||||
|
console.log(typeof a);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_1_ie8: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var a;
|
||||||
|
console.log(typeof f);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var a;
|
||||||
|
console.log(typeof f);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_1_toplevel: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var a;
|
||||||
|
console.log(typeof f);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function a() {
|
||||||
|
(function a() {
|
||||||
|
var o;
|
||||||
|
console.log(typeof a);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_1_ie8_toplevel: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var a;
|
||||||
|
console.log(typeof f);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
(function o() {
|
||||||
|
(function o() {
|
||||||
|
var a;
|
||||||
|
console.log(typeof o);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_2: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var c = "FAIL";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var b = function g() {
|
||||||
|
f && (c = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var c = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function n() {
|
||||||
|
var b = function b() {
|
||||||
|
n && (c = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_2_ie8: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var c = "FAIL";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var b = function g() {
|
||||||
|
f && (c = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var c = "FAIL";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var b = function n() {
|
||||||
|
f && (c = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_2_toplevel: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var c = "FAIL";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var b = function g() {
|
||||||
|
f && (c = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var o = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function n() {
|
||||||
|
var b = function b() {
|
||||||
|
n && (o = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3478_2_ie8_toplevel: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var c = "FAIL";
|
||||||
|
(function f() {
|
||||||
|
(function f() {
|
||||||
|
var b = function g() {
|
||||||
|
f && (c = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"bbbbbbb";
|
||||||
|
var o = "FAIL";
|
||||||
|
(function c() {
|
||||||
|
(function c() {
|
||||||
|
var b = function n() {
|
||||||
|
c && (o = "PASS");
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user