"use strict";function SymbolDef(d,a,b){this.name=a.name,this.orig=[a],this.init=b,this.eliminated=0,this.scope=d,this.references=[],this.replaced=0,this.global=!1,this.export=!1,this.mangled_name=null,this.undeclared=!1,this.id=SymbolDef.next_id++}SymbolDef.next_id=1,SymbolDef.prototype={unmangleable:function(b){return b||(b={}),this.global&&!b.toplevel||this.export||this.undeclared||!b.eval&&(this.scope.uses_eval||this.scope.uses_with)||b.keep_fnames&&(this.orig[0]instanceof AST_SymbolLambda||this.orig[0]instanceof AST_SymbolDefun)||this.orig[0]instanceof AST_SymbolMethod||b.keep_classnames&&(this.orig[0]instanceof AST_SymbolClass||this.orig[0]instanceof AST_SymbolDefClass)},mangle:function(f){var a=f.cache&&f.cache.props;if(this.global&&a&&a.has(this.name))this.mangled_name=a.get(this.name);else if(!this.mangled_name&&!this.unmangleable(f)){var b=this.scope,c=this.orig[0];f.ie8&&c instanceof AST_SymbolLambda&&(b=b.parent_scope);var d;this.mangled_name=(d=this.redefined())?d.mangled_name||d.name:b.next_mangled(f,this),this.global&&a&&a.set(this.name,this.mangled_name)}},redefined:function(){return this.defun&&this.defun.variables.get(this.name)}},AST_Toplevel.DEFMETHOD("figure_out_scope",function(l){l=defaults(l,{cache:null,ie8:!1,safari10:!1});var a=this,r=a.parent_scope=null,c=new Dictionary,d=null,e=null,f=[],g=new TreeWalker(function(h,a){function b(f,a){if(e){var b=0;do a++;while(g.parent(b++)!==e)}var c=g.parent(a);f.export=c instanceof AST_Export}if(h.is_block_scope()){var i=r;return h.block_scope=r=new AST_Scope(h),r.init_scope_vars(i),h instanceof AST_Scope||(r.uses_with=i.uses_with,r.uses_eval=i.uses_eval,r.directives=i.directives),l.safari10&&(h instanceof AST_For||h instanceof AST_ForIn)&&f.push(r),a(),r=i,!0}if(h instanceof AST_Destructuring)return e=h,a(),e=null,!0;if(h instanceof AST_Scope){h.init_scope_vars(r);var i=r,j=d,k=c;return d=r=h,c=new Dictionary,a(),r=i,d=j,c=k,!0}if(h instanceof AST_LabeledStatement){var m=h.label;if(c.has(m.name))throw new Error(string_template("Label {name} defined twice",m));return c.set(m.name,m),a(),c.del(m.name),!0}if(h instanceof AST_With){for(var n=r;n;n=n.parent_scope)n.uses_with=!0;return}if(h instanceof AST_Symbol&&(h.scope=r),h instanceof AST_Label&&(h.thedef=h,h.references=[]),h instanceof AST_SymbolLambda)d.def_function(h,"arguments"==h.name?void 0:d);else if(h instanceof AST_SymbolDefun)b((h.scope=d.parent_scope.get_defun_scope()).def_function(h,d),1);else if(h instanceof AST_SymbolClass)b(d.def_variable(h,d),1);else if(h instanceof AST_SymbolImport)r.def_variable(h);else if(h instanceof AST_SymbolDefClass)b((h.scope=d.parent_scope).def_function(h,d),1);else if(h instanceof AST_SymbolVar||h instanceof AST_SymbolLet||h instanceof AST_SymbolConst){var o;if(o=h instanceof AST_SymbolBlockDeclaration?r.def_variable(h,null):d.def_variable(h,"SymbolVar"==h.TYPE?null:void 0),all(o.orig,function(b){return b===h||(h instanceof AST_SymbolBlockDeclaration?b instanceof AST_SymbolLambda:!(b instanceof AST_SymbolLet||b instanceof AST_SymbolConst))})||js_error(h.name+" redeclared",h.start.file,h.start.line,h.start.col,h.start.pos),h instanceof AST_SymbolFunarg||b(o,2),o.destructuring=e,d!==r){h.mark_enclosed(l);var o=r.find_variable(h);h.thedef!==o&&(h.thedef=o,h.reference(l))}}else if(h instanceof AST_SymbolCatch)r.def_variable(h).defun=d;else if(h instanceof AST_LabelRef){var p=c.get(h.name);if(!p)throw new Error(string_template("Undefined label {name} [{line},{col}]",{name:h.name,line:h.start.line,col:h.start.col}));h.thedef=p}!(r instanceof AST_Toplevel)&&(h instanceof AST_Export||h instanceof AST_Import)&&js_error(h.TYPE+" statement may only appear at top level",h.start.file,h.start.line,h.start.col,h.start.pos)});a.walk(g),a.globals=new Dictionary;var g=new TreeWalker(function(b){if(b instanceof AST_LoopControl&&b.label)return b.label.thedef.references.push(b),!0;if(b instanceof AST_SymbolRef){var c=b.name;if("eval"==c&&g.parent()instanceof AST_Call)for(var d=b.scope;d&&!d.uses_eval;d=d.parent_scope)d.uses_eval=!0;var e;return g.parent()instanceof AST_NameMapping&&g.parent(1).module_name||!(e=b.scope.find_variable(c))?e=a.def_global(b):e.scope instanceof AST_Lambda&&"arguments"==c&&(e.scope.uses_arguments=!0),b.thedef=e,b.reference(l),b.scope.is_block_scope()&&!(e.orig[0]instanceof AST_SymbolBlockDeclaration)&&(b.scope=b.scope.get_defun_scope()),!0}var f;if(b instanceof AST_SymbolCatch&&(f=b.definition().redefined()))for(var d=b.scope;d&&(push_uniq(d.enclosed,f),d!==f.scope);)d=d.parent_scope});if(a.walk(g),l.ie8&&a.walk(new TreeWalker(function(b){if(b instanceof AST_SymbolCatch){var c=b.name,d=b.thedef.references,e=b.thedef.defun,f=e.find_variable(c)||a.globals.get(c)||e.def_variable(b);return d.forEach(function(a){a.thedef=f,a.reference(l)}),b.thedef=f,b.reference(l),!0}})),l.safari10)for(var r,b=0;b