Add --screw-ie option

For now the implication is that UglifyJS will not leak a function
expression's name in the surrounding scope (IE < 9 does that).

(ref. mishoo/UglifyJS#485)
This commit is contained in:
Mihai Bazon
2013-03-02 14:28:34 +02:00
parent dac6efb43d
commit 26746ce316
2 changed files with 17 additions and 10 deletions

View File

@@ -67,7 +67,10 @@ SymbolDef.prototype = {
}
};
AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
options = defaults(options, {
screw_ie: false
});
// This does what ast_add_scope did in UglifyJS v1.
//
// Part of it could be done at parse time, but it would complicate
@@ -121,13 +124,15 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
node.init_scope_vars();
}
if (node instanceof AST_SymbolLambda) {
//scope.def_function(node);
//
// https://github.com/mishoo/UglifyJS2/issues/24 — MSIE
// leaks function expression names into the containing
// scope. Don't like this fix but seems we can't do any
// better. IE: please die. Please!
(node.scope = scope.parent_scope).def_function(node);
if (options.screw_ie) {
scope.def_function(node);
} else {
// https://github.com/mishoo/UglifyJS2/issues/24 — MSIE
// leaks function expression names into the containing
// scope. Don't like this fix but seems we can't do any
// better. IE: please die. Please!
(node.scope = scope.parent_scope).def_function(node);
}
}
else if (node instanceof AST_SymbolDefun) {
// Careful here, the scope where this should be defined is