diff options
Diffstat (limited to 'lib/scope.js')
-rw-r--r-- | lib/scope.js | 109 |
1 files changed, 11 insertions, 98 deletions
diff --git a/lib/scope.js b/lib/scope.js index 74760e4f..2ffca25a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -76,7 +76,7 @@ SymbolDef.prototype = { else if (!this.mangled_name && !this.unmangleable(options)) { var s = this.scope; var sym = this.orig[0]; - if (!options.screw_ie8 && sym instanceof AST_SymbolLambda) + if (options.ie8 && sym instanceof AST_SymbolLambda) s = s.parent_scope; var def; if (this.defun && (def = this.defun.variables.get(this.name))) { @@ -93,7 +93,7 @@ SymbolDef.prototype = { AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ options = defaults(options, { cache: null, - screw_ie8: true, + ie8: false, }); // pass 1: setup scope chaining and handle definitions @@ -220,7 +220,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ self.walk(tw); // pass 3: fix up any scoping issue with IE8 - if (!options.screw_ie8) { + if (options.ie8) { self.walk(new TreeWalker(function(node, descend) { if (node instanceof AST_SymbolCatch) { var name = node.name; @@ -325,8 +325,8 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){ if (!is_identifier(m)) continue; // skip over "do" // https://github.com/mishoo/UglifyJS2/issues/242 -- do not - // shadow a name excepted from mangling. - if (options.except.indexOf(m) >= 0) continue; + // shadow a name reserved from mangling. + if (options.reserved.indexOf(m) >= 0) continue; // we must ensure that the mangled name does not shadow a name // from some parent scope that is referenced in this or in @@ -399,10 +399,9 @@ AST_Symbol.DEFMETHOD("global", function(){ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){ return defaults(options, { eval : false, - except : [], + ie8 : false, keep_fnames : false, - screw_ie8 : true, - sort : false, // Ignored. Flag retained for backwards compatibility. + reserved : [], toplevel : false, }); }); @@ -411,7 +410,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ options = this._default_mangler_options(options); // Never mangle arguments - options.except.push('arguments'); + options.reserved.push('arguments'); // We only need to mangle declaration nodes. Special logic wired // into the code generator will display the mangled name if it's @@ -422,7 +421,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ if (options.cache) { this.globals.each(function(symbol){ - if (options.except.indexOf(symbol.name) < 0) { + if (options.reserved.indexOf(symbol.name) < 0) { to_mangle.push(symbol); } }); @@ -439,7 +438,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ if (node instanceof AST_Scope) { var p = tw.parent(), a = []; node.variables.each(function(symbol){ - if (options.except.indexOf(symbol.name) < 0) { + if (options.reserved.indexOf(symbol.name) < 0) { a.push(symbol); } }); @@ -452,7 +451,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ node.mangled_name = name; return true; } - if (options.screw_ie8 && node instanceof AST_SymbolCatch) { + if (!options.ie8 && node instanceof AST_SymbolCatch) { to_mangle.push(node.definition()); return; } @@ -573,89 +572,3 @@ var base54 = (function() { }; return base54; })(); - -AST_Toplevel.DEFMETHOD("scope_warnings", function(options){ - options = defaults(options, { - assign_to_global : true, - eval : true, - func_arguments : true, - nested_defuns : true, - undeclared : false, // this makes a lot of noise - unreferenced : true, - }); - var tw = new TreeWalker(function(node){ - if (options.undeclared - && node instanceof AST_SymbolRef - && node.undeclared()) - { - // XXX: this also warns about JS standard names, - // i.e. Object, Array, parseInt etc. Should add a list of - // exceptions. - AST_Node.warn("Undeclared symbol: {name} [{file}:{line},{col}]", { - name: node.name, - file: node.start.file, - line: node.start.line, - col: node.start.col - }); - } - if (options.assign_to_global) - { - var sym = null; - if (node instanceof AST_Assign && node.left instanceof AST_SymbolRef) - sym = node.left; - else if (node instanceof AST_ForIn && node.init instanceof AST_SymbolRef) - sym = node.init; - if (sym - && (sym.undeclared() - || (sym.global() && sym.scope !== sym.definition().scope))) { - AST_Node.warn("{msg}: {name} [{file}:{line},{col}]", { - msg: sym.undeclared() ? "Accidental global?" : "Assignment to global", - name: sym.name, - file: sym.start.file, - line: sym.start.line, - col: sym.start.col - }); - } - } - if (options.eval - && node instanceof AST_SymbolRef - && node.undeclared() - && node.name == "eval") { - AST_Node.warn("Eval is used [{file}:{line},{col}]", node.start); - } - if (options.unreferenced - && (node instanceof AST_SymbolDeclaration || node instanceof AST_Label) - && !(node instanceof AST_SymbolCatch) - && node.unreferenced()) { - AST_Node.warn("{type} {name} is declared but not referenced [{file}:{line},{col}]", { - type: node instanceof AST_Label ? "Label" : "Symbol", - name: node.name, - file: node.start.file, - line: node.start.line, - col: node.start.col - }); - } - if (options.func_arguments - && node instanceof AST_Lambda - && node.uses_arguments) { - AST_Node.warn("arguments used in function {name} [{file}:{line},{col}]", { - name: node.name ? node.name.name : "anonymous", - file: node.start.file, - line: node.start.line, - col: node.start.col - }); - } - if (options.nested_defuns - && node instanceof AST_Defun - && !(tw.parent() instanceof AST_Scope)) { - AST_Node.warn("Function {name} declared in nested statement \"{type}\" [{file}:{line},{col}]", { - name: node.name.name, - type: tw.parent().TYPE, - file: node.start.file, - line: node.start.line, - col: node.start.col - }); - } - }); - this.walk(tw); -}); |