diff --git a/hook.min.js b/hook.min.js index 565a21bd..5bbff40e 100644 --- a/hook.min.js +++ b/hook.min.js @@ -117,6 +117,12 @@ * homepage: https://github.com/Gozala/events#readme * version: 1.1.1 * + * he: + * license: MIT (http://opensource.org/licenses/MIT) + * author: Mathias Bynens + * homepage: https://mths.be/he + * version: 1.1.1 + * * htmlparser2: * license: MIT (http://opensource.org/licenses/MIT) * author: Felix Boehm @@ -201,4 +207,4 @@ * * This header is generated by licensify (https://github.com/twada/licensify) */ -(function(f){if(typeof exports==='object'&&typeof module!=='undefined'){module.exports=f();}else if(typeof define==='function'&&define.amd){define([],f);}else{var g;if(typeof window!=='undefined'){g=window;}else if(typeof global!=='undefined'){g=global;}else if(typeof self!=='undefined'){g=self;}else{g=this;}Object.defineProperty(g,'hook',{configurable:false,enumerable:false,writable:false,value:f()});Object.defineProperty(g,'$hook$',{configurable:false,enumerable:false,writable:false,value:g.hook});if(g.constructor.name==='ServiceWorkerGlobalScope'){for(let h in hook.serviceWorkerHandlers){g.addEventListener(h,hook.serviceWorkerHandlers[h]);}}if(g.constructor.name==='Window'){hook.registerServiceWorker();}}}(function(){var define,module,exports;return function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=='function'&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error('Cannot find module \''+o+'\'');throw f.code='MODULE_NOT_FOUND',f;}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e);},l,l.exports,e,t,n,r);}return n[o].exports;}var i=typeof require=='function'&&require;for(var o=0;onode&&node.type?'['+path+']'+node.type+(node.id&&node.id.name?':'+node.id.name:node.key&&node.key.name?':'+(node.kind==='get'||node.kind==='set'?node.kind+' ':node.static?'static ':'')+node.key.name:''):path).join(',');}function generateOldMethodContext(astPath){return astPath.map(([path,node],index)=>node&&node.type?node.id&&node.id.name?node.id.name:node.key&&node.key.name?(node.kind==='get'||node.kind==='set'?node.kind+' ':node.static?'static ':'')+node.key.name:'':index===0?path:'').filter(p=>p).join(',');}function generateMethodContext(astPath){let result;let i;let p,n,l=astPath.length;for(i=l-1;i>=0;i--){p=astPath[i];n=p[1];result=p[3];if(result){break;}else{p[2]=i>0?n.id&&n.id.name?n.__moved__?'':n.id.name:n.key&&(n.key.name||n.key.value)&&(!n.computed||n.computed&&(n.key.type==='Identifier'||n.key.type==='Literal'))?(n.kind==='get'||n.kind==='set'?n.kind+' ':n.static?'static ':'')+(n.key.name||n.key.value):'':p[0];}}if(!result){i=0;result=astPath[0][3]=astPath[0][2];}for(i++;i'','astPath':generateAstPathContext,'method':generateMethodContext,'cachedMethod':generateMethodContext,'cachedMethodDebug':generateCachedMethodDebugContext,'oldMethod':generateOldMethodContext}};};},{}],3:[function(require,module,exports){module.exports=function(hook,preprocess){function __hook_except_properties__(f,thisArg,args,context,newTarget){return newTarget?Reflect.construct(f,args):thisArg?f.apply(thisArg,args):f(...args);}const _global=new Function('return this')();class StrictModeWrapper{static['#.'](o,p){return o[p];}static['#[]'](o,p){return o[p];}static['#*'](o){return o;}static['#in'](o,p){return p in o;}static['#()'](o,p,a){return o[p](...a);}static['#p++'](o,p){return o[p]++;}static['#++p'](o,p){return++o[p];}static['#p--'](o,p){return o[p]--;}static['#--p'](o,p){return--o[p];}static['#delete'](o,p){return delete o[p];}static['#='](o,p,v){return o[p]=v;}static['#+='](o,p,v){return o[p]+=v;}static['#-='](o,p,v){return o[p]-=v;}static['#*='](o,p,v){return o[p]*=v;}static['#/='](o,p,v){return o[p]/=v;}static['#%='](o,p,v){return o[p]%=v;}static['#**='](o,p,v){return o[p]**=v;}static['#<<='](o,p,v){return o[p]<<=v;}static['#>>='](o,p,v){return o[p]>>=v;}static['#>>>='](o,p,v){return o[p]>>>=v;}static['#&='](o,p,v){return o[p]&=v;}static['#^='](o,p,v){return o[p]^=v;}static['#|='](o,p,v){return o[p]|=v;}static['#.='](o,p){return{set ['='](v){o[p]=v;},get ['='](){return o[p];}};}}function __hook__(f,thisArg,args,context,newTarget){let normalizedThisArg=thisArg;if(newTarget===false){let varName=args[0];let __with__=thisArg;let scope=_global;let _scope;let i;for(i=0;i<__with__.length;i++){_scope=__with__[i];if(Reflect.has(_scope,varName)){if(_scope[Symbol.unscopables]&&_scope[Symbol.unscopables][varName]){continue;}else{scope=_scope;break;}}}thisArg=normalizedThisArg=scope;}let result;let args1=args[1];function*gen(){}async function asf(){}let GeneratorFunction=gen.constructor;let AsyncFunction=asf.constructor;switch(f){case Function:args=hook.FunctionArguments('__hook__',[[context,{}]],'method',args);break;case AsyncFunction:args=hook.FunctionArguments('__hook__',[[context,{}]],'method',args,false,true);break;case GeneratorFunction:args=hook.FunctionArguments('__hook__',[[context,{}]],'method',args,true,false);break;case'()':case'#()':switch(thisArg){case Reflect:switch(args[0]){case'construct':if(args[1]){switch(args[1][0]){case Function:args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1])];if(args[1][2]){args1.push(args[1][2]);}break;case AsyncFunction:args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1],false,true)];if(args[1][2]){args1.push(args[1][2]);}break;case GeneratorFunction:args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1],true,false)];if(args[1][2]){args1.push(args[1][2]);}break;default:if(Function.isPrototypeOf(args[1][0])){args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1],GeneratorFunction.isPrototypeOf(args[1][0]),AsyncFunction.isPrototypeOf(args[1][0]))];if(args[1][2]){args1.push(args[1][2]);}}break;}}break;case'apply':if(args[1]){switch(args[1][0]){case Function:args1=[args[1][0],args[1][1],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][2])];break;case AsyncFunction:args1=[args[1][0],args[1][1],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][2],false,true)];break;case GeneratorFunction:args1=[args[1][0],args[1][1],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][2],true,false)];break;default:if(Function.isPrototypeOf(args[1][0])){args1=[args[1][0],args[1][1],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][2],GeneratorFunction.isPrototypeOf(args[1][0]),AsyncFunction.isPrototypeOf(args[1][0]))];}break;}}break;default:break;}break;case Function:switch(args[0]){case'apply':args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1])];break;case'call':args1=[args[1][0],...hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1].slice(1))];break;default:break;}break;case AsyncFunction:switch(args[0]){case'apply':args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1],false,true)];break;case'call':args1=[args[1][0],...hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1].slice(1),false,true)];break;default:break;}break;case GeneratorFunction:switch(args[0]){case'apply':args1=[args[1][0],hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1][1],true,false)];break;case'call':args1=[args[1][0],...hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1].slice(1),true,false)];break;default:break;}break;case undefined:break;default:if(args[0]==='constructor'){if(thisArg instanceof GeneratorFunction){args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1],true,false);}else if(thisArg instanceof AsyncFunction){args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1],false,true);}else if(thisArg instanceof Function){args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1]);}}else{switch(thisArg[args[0]]){case Function:args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1]);break;case AsyncFunction:args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1],false,true);break;case GeneratorFunction:args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1],true,false);break;default:break;}}break;}break;case's()':switch(args[2](args[0])){case Function:args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1]);break;case AsyncFunction:args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1],false,true);break;case GeneratorFunction:args1=hook.FunctionArguments('__hook__',[[context,{}]],'method',args[1],true,false);break;default:break;}break;default:if(typeof f==='function'){if(Function.isPrototypeOf(f)&&newTarget){args=hook.FunctionArguments('__hook__',[[context,{}]],'method',args,GeneratorFunction.isPrototypeOf(f),AsyncFunction.isPrototypeOf(f));}else if(newTarget===''){if(Function.isPrototypeOf(args[0])){args=[args[0],...hook.FunctionArguments('__hook__',[[context,{}]],'method',args.slice(1),GeneratorFunction.isPrototypeOf(args[0]),AsyncFunction.isPrototypeOf(args[0]))];}}}break;}if(typeof f!=='string'){result=newTarget?Reflect.construct(f,args):thisArg?f.apply(thisArg,args):f(...args);}else{switch(f){case'.':case'[]':result=thisArg[args[0]];break;case'*':result=thisArg;break;case'in':result=args[0]in thisArg;break;case'()':result=thisArg[args[0]](...args1);break;case'p++':result=thisArg[args[0]]++;break;case'++p':result=++thisArg[args[0]];break;case'p--':result=thisArg[args[0]]--;break;case'--p':result=--thisArg[args[0]];break;case'delete':result=delete thisArg[args[0]];break;case'=':result=thisArg[args[0]]=args[1];break;case'+=':result=thisArg[args[0]]+=args[1];break;case'-=':result=thisArg[args[0]]-=args[1];break;case'*=':result=thisArg[args[0]]*=args[1];break;case'/=':result=thisArg[args[0]]/=args[1];break;case'%=':result=thisArg[args[0]]%=args[1];break;case'**=':result=thisArg[args[0]]**=args[1];break;case'<<=':result=thisArg[args[0]]<<=args[1];break;case'>>=':result=thisArg[args[0]]>>=args[1];break;case'>>>=':result=thisArg[args[0]]>>>=args[1];break;case'&=':result=thisArg[args[0]]&=args[1];break;case'^=':result=thisArg[args[0]]^=args[1];break;case'|=':result=thisArg[args[0]]|=args[1];break;case'.=':result={set ['='](v){thisArg[args[0]]=v;},get ['='](){return thisArg[args[0]];}};break;case'#.':case'#[]':result=StrictModeWrapper['#.'](thisArg,args[0]);break;case'#*':result=StrictModeWrapper['#*'](thisArg);break;case'#in':result=StrictModeWrapper['#in'](thisArg,args[0]);break;case'#()':result=StrictModeWrapper['#()'](thisArg,args[0],args1);break;case'#p++':result=StrictModeWrapper['#p++'](thisArg,args[0]);break;case'#++p':result=StrictModeWrapper['#++p'](thisArg,args[0]);break;case'#p--':result=StrictModeWrapper['#p--'](thisArg,args[0]);break;case'#--p':result=StrictModeWrapper['#--p'](thisArg,args[0]);break;case'#delete':result=StrictModeWrapper['#delete'](thisArg,args[0]);break;case'#=':result=StrictModeWrapper['#='](thisArg,args[0],args[1]);break;case'#+=':result=StrictModeWrapper['#+='](thisArg,args[0],args[1]);break;case'#-=':result=StrictModeWrapper['#-='](thisArg,args[0],args[1]);break;case'#*=':result=StrictModeWrapper['#*='](thisArg,args[0],args[1]);break;case'#/=':result=StrictModeWrapper['#/='](thisArg,args[0],args[1]);break;case'#%=':result=StrictModeWrapper['#%='](thisArg,args[0],args[1]);break;case'#**=':result=StrictModeWrapper['#**='](thisArg,args[0],args[1]);break;case'#<<=':result=StrictModeWrapper['#<<='](thisArg,args[0],args[1]);break;case'#>>=':result=StrictModeWrapper['#>>='](thisArg,args[0],args[1]);break;case'#>>>=':result=StrictModeWrapper['#>>>='](thisArg,args[0],args[1]);break;case'#&=':result=StrictModeWrapper['#&='](thisArg,args[0],args[1]);break;case'#^=':result=StrictModeWrapper['#^='](thisArg,args[0],args[1]);break;case'#|=':result=StrictModeWrapper['#|='](thisArg,args[0],args[1]);break;case'#.=':result=StrictModeWrapper['#.='](thisArg,args[0]);break;case's.':case's[]':result=args[1](args[0]);break;case's()':result=args[2](args[0]).apply(thisArg,args1);break;case's++':case'++s':case's--':case'--s':result=args[1].apply(thisArg,args);break;case's=':case's+=':case's-=':case's*=':case's/=':case's%=':case's**=':case's<<=':case's>>=':case's>>>=':case's&=':case's^=':case's|=':result=args[2].apply(thisArg,args);break;case'w.':case'w[]':result=args[1]();break;case'w()':result=args[2](...args[1]);break;case'wnew':result=args[2](...args[1]);break;case'w++':case'++w':case'w--':case'--w':result=args[1]();break;case'wtypeof':case'wdelete':result=args[1]();break;case'w.=':result=args[1];break;case'w=':case'w+=':case'w-=':case'w*=':case'w/=':case'w%=':case'w**=':case'w<<=':case'w>>=':case'w>>>=':case'w&=':case'w^=':case'w|=':result=args[2](args[1]);break;default:f();result=null;break;}}return result;}function hookCallbackCompatibilityTest(hookCallback=_global[preprocess.getHookNameForServiceWorker()],throwError=true,checkTypeError=true){let result=true;let reason='Unknown';let value;let error;do{if(!hookCallback){result=false;reason='hook: hook callback is undefined';break;}if(typeof hookCallback!=='function'){result=false;reason='hook: hook callback is not a function';break;}const c='hook.hookCallbackCompatibilityTest';let tests=[[()=>[(a,b)=>a+b],p=>[p[0],null,[1,2],c],(v,p)=>v===3],[()=>[function f1(a,b){return this.a+a+b;},{a:2}],p=>[p[0],p[1],[2,3],c],(v,p)=>v===7],[()=>[class c1{constructor(a,b){this.r=a+b;}}],p=>[p[0],null,[2,3],c,true],(v,p)=>v instanceof p[0]&&v.r===5],[()=>[{a:2}],p=>['.',p[0],['a'],c],(v,p)=>v.a===p.a],[()=>[{a:2}],p=>['*',p[0],[],c],(v,p)=>v===p[0]],[()=>[{a:2}],p=>['in',p[0],['a'],c],(v,p)=>v===true],[()=>[class c2{static m(a,b){return a+b;}}],p=>['()',p[0],['m',[1,3]],c],(v,p)=>v===4],[()=>[{a:2}],p=>['p++',p[0],['a'],c],(v,p)=>v===2&&p[0].a===3],[()=>[{a:2}],p=>['++p',p[0],['a'],c],(v,p)=>v===3&&p[0].a===3],[()=>[{a:2}],p=>['p--',p[0],['a'],c],(v,p)=>v===2&&p[0].a===1],[()=>[{a:2}],p=>['--p',p[0],['a'],c],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['delete',p[0],['a'],c],(v,p)=>v===true&&!Reflect.has(p[0],'a')],[()=>[{a:2}],p=>['=',p[0],['a',5],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:2}],p=>['+=',p[0],['a',5],c],(v,p)=>v===7&&p[0].a===7],[()=>[{a:2}],p=>['-=',p[0],['a',5],c],(v,p)=>v===-3&&p[0].a===-3],[()=>[{a:2}],p=>['*=',p[0],['a',5],c],(v,p)=>v===10&&p[0].a===10],[()=>[{a:10}],p=>['/=',p[0],['a',2],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['%=',p[0],['a',3],c],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['**=',p[0],['a',3],c],(v,p)=>v===8&&p[0].a===8],[()=>[{a:2}],p=>['<<=',p[0],['a',3],c],(v,p)=>v===16&&p[0].a===16],[()=>[{a:16}],p=>['>>=',p[0],['a',2],c],(v,p)=>v===4&&p[0].a===4],[()=>[{a:-1}],p=>['>>>=',p[0],['a',1],c],(v,p)=>v===2147483647&&p[0].a===2147483647],[()=>[{a:10}],p=>['&=',p[0],['a',7],c],(v,p)=>v===2&&p[0].a===2],[()=>[{a:10}],p=>['^=',p[0],['a',15],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['|=',p[0],['a',7],c],(v,p)=>v===15&&p[0].a===15],[()=>[{a:2}],p=>['s.',p[0],['a',prop=>p[0][prop]],c],(v,p)=>v===2],[()=>[{a:2,m(a,b){return this.a+a+b;}}],p=>['s()',p[0],['m',[2,3],prop=>p[0][prop]],c],(v,p)=>v===7],[()=>[{a:2}],p=>['s++',p[0],['a',prop=>p[0][prop]++],c],(v,p)=>v===2&&p[0].a===3],[()=>[{a:2}],p=>['++s',p[0],['a',prop=>++p[0][prop]],c],(v,p)=>v===3&&p[0].a===3],[()=>[{a:2}],p=>['s--',p[0],['a',prop=>p[0][prop]--],c],(v,p)=>v===2&&p[0].a===1],[()=>[{a:2}],p=>['--s',p[0],['a',prop=>--p[0][prop]],c],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['s=',p[0],['a',5,(prop,value)=>p[0][prop]=value],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:2}],p=>['+=',p[0],['a',5,(prop,value)=>p[0][prop]+=value],c],(v,p)=>v===7&&p[0].a===7],[()=>[{a:2}],p=>['-=',p[0],['a',5,(prop,value)=>p[0][prop]-=value],c],(v,p)=>v===-3&&p[0].a===-3],[()=>[{a:2}],p=>['*=',p[0],['a',5,(prop,value)=>p[0][prop]*=value],c],(v,p)=>v===10&&p[0].a===10],[()=>[{a:10}],p=>['/=',p[0],['a',2],c,(prop,value)=>p[0][prop]/=value],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['%=',p[0],['a',3],c,(prop,value)=>p[0][prop]%=value],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['**=',p[0],['a',3],c,(prop,value)=>p[0][prop]**=value],(v,p)=>v===8&&p[0].a===8],[()=>[{a:2}],p=>['<<=',p[0],['a',3],c,(prop,value)=>p[0][prop]<<=value],(v,p)=>v===16&&p[0].a===16],[()=>[{a:16}],p=>['>>=',p[0],['a',2],c,(prop,value)=>p[0][prop]>>=value],(v,p)=>v===4&&p[0].a===4],[()=>[{a:-1}],p=>['>>>=',p[0],['a',1],c,(prop,value)=>p[0][prop]>>>=value],(v,p)=>v===2147483647&&p[0].a===2147483647],[()=>[{a:10}],p=>['&=',p[0],['a',7,(prop,value)=>p[0][prop]&=value],c],(v,p)=>v===2&&p[0].a===2],[()=>[{a:10}],p=>['^=',p[0],['a',15,(prop,value)=>p[0][prop]^=value],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['|=',p[0],['a',7,(prop,value)=>p[0][prop]|=value],c],(v,p)=>v===15&&p[0].a===15],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w.',p[0],['b',()=>p[1].b],c,false],(v,p)=>v===3],[()=>[[{a:true},{m:true}],{a:2,m(a,b){return a+b;}}],p=>['w()',p[0],['m',[2,3],(...args)=>p[1].m(...args)],c,false],(v,p)=>v===5],[()=>[[{a:true},{m:true}],class c2{constructor(a,b){this.r=a+b;}}],p=>['wnew',p[0],['m',[2,3],(...args)=>new p[1](...args)],c,false],(v,p)=>v.r===5],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w++',p[0],['b',()=>p[1].b++],c,false],(v,p)=>v===3&&p[1].b===4],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['++w',p[0],['b',()=>++p[1].b],c,false],(v,p)=>v===4&&p[1].b===4],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w--',p[0],['b',()=>p[1].b--],c,false],(v,p)=>v===3&&p[1].b===2],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['--w',p[0],['b',()=>--p[1].b],c,false],(v,p)=>v===2&&p[1].b===2],[()=>[[{a:true},{b:true}],{a:2,b:true}],p=>['wtypeof',p[0],['b',()=>typeof p[1].b],c,false],(v,p)=>v==='boolean'],[()=>[[{a:true},{b:true}],{a:2,b:true}],p=>['wdelete',p[0],['b',()=>delete p[1].b],c,false],(v,p)=>v===true&&!Reflect.has(p[1],'b')],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w.=',p[0],['b',{set ['='](v){p[1].b=v;},get ['='](){return p[1].b;}}],c,false],(v,p)=>(v['=']=4)===4&&v['=']===4&&p[1].b===4],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w=',p[0],['b',5,v=>p[1].b=v],c,false],(v,p)=>v===5&&p[1].b===5],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w+=',p[0],['b',5,v=>p[1].b+=v],c,false],(v,p)=>v===8&&p[1].b===8],[()=>[[{a:true},{b:true}],{a:2,b:3}],p=>['w-=',p[0],['b',5,v=>p[1].b-=v],c,false],(v,p)=>v===-2&&p[1].b===-2],[()=>[[{a:true},{b:true}],{a:2,b:10}],p=>['w/=',p[0],['b',2,v=>p[1].b/=v],c,false],(v,p)=>v===5&&p[1].b===5],[()=>[[{a:true},{b:true}],{a:2,b:10}],p=>['w%=',p[0],['b',3,v=>p[1].b%=v],c,false],(v,p)=>v===1&&p[1].b===1],[()=>[[{a:true},{b:true}],{a:2,b:2}],p=>['w%=',p[0],['b',3,v=>p[1].b**=v],c,false],(v,p)=>v===8&&p[1].b===8],[()=>[[{a:true},{b:true}],{a:2,b:2}],p=>['w<<=',p[0],['b',3,v=>p[1].b<<=v],c,false],(v,p)=>v===16&&p[1].b===16],[()=>[[{a:true},{b:true}],{a:2,b:16}],p=>['w>>=',p[0],['b',2,v=>p[1].b>>=v],c,false],(v,p)=>v===4&&p[1].b===4],[()=>[[{a:true},{b:true}],{a:2,b:-1}],p=>['w>>>=',p[0],['b',1,v=>p[1].b>>>=v],c,false],(v,p)=>v===2147483647&&p[1].b===2147483647],[()=>[[{a:true},{b:true}],{a:2,b:10}],p=>['w&=',p[0],['b',7,v=>p[1].b&=v],c,false],(v,p)=>v===2&&p[1].b===2],[()=>[[{a:true},{b:true}],{a:2,b:10}],p=>['w^=',p[0],['b',15,v=>p[1].b^=v],c,false],(v,p)=>v===5&&p[1].b===5],[()=>[[{a:true},{b:true}],{a:2,b:10}],p=>['w|=',p[0],['b',7,v=>p[1].b|=v],c,false],(v,p)=>v===15&&p[1].b===15],[()=>[{a:2,b:3}],p=>['.=',p[0],['b'],c],(v,p)=>(v['=']=4)===4&&v['=']===4&&p[0].b===4],[()=>[{a:2}],p=>['#.',p[0],['a'],c],(v,p)=>v.a===p.a],[()=>[{a:2}],p=>['#*',p[0],[],c],(v,p)=>v===p[0]],[()=>[{a:2}],p=>['#in',p[0],['a'],c],(v,p)=>v===true],[()=>[class c2{static m(a,b){return a+b;}}],p=>['#()',p[0],['m',[1,3]],c],(v,p)=>v===4],[()=>[{a:2}],p=>['#p++',p[0],['a'],c],(v,p)=>v===2&&p[0].a===3],[()=>[{a:2}],p=>['#++p',p[0],['a'],c],(v,p)=>v===3&&p[0].a===3],[()=>[{a:2}],p=>['#p--',p[0],['a'],c],(v,p)=>v===2&&p[0].a===1],[()=>[{a:2}],p=>['#--p',p[0],['a'],c],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['#delete',p[0],['a'],c],(v,p)=>v===true&&!Reflect.has(p[0],'a')],[()=>[{a:2}],p=>['#=',p[0],['a',5],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:2}],p=>['#+=',p[0],['a',5],c],(v,p)=>v===7&&p[0].a===7],[()=>[{a:2}],p=>['#-=',p[0],['a',5],c],(v,p)=>v===-3&&p[0].a===-3],[()=>[{a:2}],p=>['#*=',p[0],['a',5],c],(v,p)=>v===10&&p[0].a===10],[()=>[{a:10}],p=>['#/=',p[0],['a',2],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['#%=',p[0],['a',3],c],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['#**=',p[0],['a',3],c],(v,p)=>v===8&&p[0].a===8],[()=>[{a:2}],p=>['#<<=',p[0],['a',3],c],(v,p)=>v===16&&p[0].a===16],[()=>[{a:16}],p=>['#>>=',p[0],['a',2],c],(v,p)=>v===4&&p[0].a===4],[()=>[{a:-1}],p=>['#>>>=',p[0],['a',1],c],(v,p)=>v===2147483647&&p[0].a===2147483647],[()=>[{a:10}],p=>['#&=',p[0],['a',7],c],(v,p)=>v===2&&p[0].a===2],[()=>[{a:10}],p=>['#^=',p[0],['a',15],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['#|=',p[0],['a',7],c],(v,p)=>v===15&&p[0].a===15],[()=>[{a:2}],p=>['#+=',p[0],['a',5,(prop,value)=>p[0][prop]+=value],c],(v,p)=>v===7&&p[0].a===7],[()=>[{a:2}],p=>['#-=',p[0],['a',5,(prop,value)=>p[0][prop]-=value],c],(v,p)=>v===-3&&p[0].a===-3],[()=>[{a:2}],p=>['#*=',p[0],['a',5,(prop,value)=>p[0][prop]*=value],c],(v,p)=>v===10&&p[0].a===10],[()=>[{a:10}],p=>['#/=',p[0],['a',2],c,(prop,value)=>p[0][prop]/=value],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['#%=',p[0],['a',3],c,(prop,value)=>p[0][prop]%=value],(v,p)=>v===1&&p[0].a===1],[()=>[{a:2}],p=>['#**=',p[0],['a',3],c,(prop,value)=>p[0][prop]**=value],(v,p)=>v===8&&p[0].a===8],[()=>[{a:2}],p=>['#<<=',p[0],['a',3],c,(prop,value)=>p[0][prop]<<=value],(v,p)=>v===16&&p[0].a===16],[()=>[{a:16}],p=>['#>>=',p[0],['a',2],c,(prop,value)=>p[0][prop]>>=value],(v,p)=>v===4&&p[0].a===4],[()=>[{a:-1}],p=>['#>>>=',p[0],['a',1],c,(prop,value)=>p[0][prop]>>>=value],(v,p)=>v===2147483647&&p[0].a===2147483647],[()=>[{a:10}],p=>['#&=',p[0],['a',7,(prop,value)=>p[0][prop]&=value],c],(v,p)=>v===2&&p[0].a===2],[()=>[{a:10}],p=>['#^=',p[0],['a',15,(prop,value)=>p[0][prop]^=value],c],(v,p)=>v===5&&p[0].a===5],[()=>[{a:10}],p=>['#|=',p[0],['a',7,(prop,value)=>p[0][prop]|=value],c],(v,p)=>v===15&&p[0].a===15],[()=>[{a:2,b:3}],p=>['#.=',p[0],['b'],c],(v,p)=>(v['=']=4)===4&&v['=']===4&&p[0].b===4]];for(let i=0;i=1){let params=args.slice(0,args.length-1).join(',');let original=args[args.length-1];let match=original.match(new RegExp('^[s]*(\'use strict\';)?[s]*void ?\'params=([^\']*)\';[s]*void ?\'original=([^\']*)\''));let skip=false;if(match){if(match[2]===params){skip=true;}else{original=decodeURIComponent(atob(match[3]));}}if(!skip){let context=initialContext[0][0];let hooked=hook('('+(isAsync?'async ':'')+'function '+(isGenerator?'*':'')+'('+(args.length?args.slice(0,args.length-1).join(','):'')+') {'+original+'})',hookName,initialContext,contextGenerator,true,preprocess.getHookProperty(),null,false,preprocess.getCompact(),preprocess.getHookGlobal(),preprocess.getHookPrefix(),{arguments:true});let useStrict=hooked.indexOf('\'use strict\';');let firstReturn=isGenerator?hooked.indexOf('yield*'):hooked.indexOf('return ');hooked=(useStrict>=0&&useStrict=1){let params=args.slice(0,args.length-1).join(',');let original=args[args.length-1];let match=original.match(new RegExp('^[s]*(\'use strict\';)?[s]*void ?\'params=([^\']*)\';[s]*void ?\'original=([^\']*)\''));let skip=false;if(match){if(match[2]===params){skip=true;}else{original=decodeURIComponent(atob(match[3]));}}if(!skip){let context=initialContext[0][0];let hooked=hook('('+(isAsync?'async ':'')+'function* ('+(args.length?args.slice(0,args.length-1).join(','):'')+') {'+original+'})',hookName,initialContext,contextGenerator,true,preprocess.getHookProperty(),null,false,preprocess.getCompact(),preprocess.getHookGlobal(),preprocess.getHookPrefix(),{arguments:true});let useStrict=hooked.indexOf('\'use strict\';');let firstReturn=hooked.indexOf('yield*');hooked=(useStrict>=0&&useStrict=1){let params=args.slice(0,args.length-1).join(',');let original=args[args.length-1];let match=original.match(new RegExp('^[s]*(\'use strict\';)?[s]*void ?\'params=([^\']*)\';[s]*void ?\'original=([^\']*)\''));let skip=false;if(match){if(match[2]===params){skip=true;}else{original=decodeURIComponent(atob(match[3]));}}if(!skip){let context=initialContext[0][0];let hooked=hook('('+(isAsync?'async ':'')+'function ('+(args.length?args.slice(0,args.length-1).join(','):'')+') {'+original+'})',hookName,initialContext,contextGenerator,true,preprocess.getHookProperty(),null,false,preprocess.getCompact(),preprocess.getHookGlobal(),preprocess.getHookPrefix(),{arguments:true});let useStrict=hooked.indexOf('\'use strict\';');let firstReturn=hooked.indexOf('return ');hooked=(useStrict>=0&&useStrict _eval(script)')()){if(!evalWrapper||typeof evalWrapper!=='function'||evalWrapper.toString().replace(/ /g,'')!=='(script,eval)=>eval(script)'&&evalWrapper.toString().replace(/ /g,'')!=='(script,_eval)=>_eval(script)'){console.error('hook.eval: invalid eval wrapper function "'+evalWrapper.toString()+'"');evalWrapper=(script,_eval)=>_eval(script);script='/* invalidated eval script due to invalid eval wrapper function */';}else if(typeof script==='string'){if(initialScope['$use_strict$']){script='\'use strict\';'+script;}script=hook(script,hookName,initialContext,contextGenerator,true,preprocess.getHookProperty(),null,false,preprocess.getCompact(),preprocess.getHookGlobal(),preprocess.getHookPrefix(),initialScope);}return _global[hookName](evalWrapper,this,[script,_native.eval],'eval');};Object.defineProperty(_eval,'name',{configurable:false,writable:false,enumerable:false,value:'eval'});return _eval;}function hookSetTimeout(hookName,initialContext=[['setTimeout',{}]],contextGenerator){return function setTimeout(...args){if(typeof args[0]==='string'){args[0]=hook('(() => { '+args[0]+' })()',hookName,initialContext,contextGenerator);}return _global[hookName](_native.setTimeout,_global,args,'setTimeout');};}function hookSetInterval(hookName,initialContext=[['setInterval',{}]],contextGenerator){return function setInterval(...args){if(typeof args[0]==='string'){args[0]=hook('(() => { '+args[0]+' })()',hookName,initialContext,contextGenerator);}return _global[hookName](_native.setInterval,_global,args,'setInterval');};}function hookImportScripts(){return function importScripts(...args){let _args=args.map(arg=>{let path=(''+arg).trim();if(path.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*[.]m?js)(\?([^#]*))?(#(.*))?$/)){return arg;}else{return'!!! invalid url !!!';}});return _global[preprocess.getHookNameForServiceWorker()](_native.importScripts,_global,_args,'importScripts');};}const jsMimeTypes=['','application/ecmascript','application/javascript','application/x-ecmascript','application/x-javascript','text/ecmascript','text/javascript','text/javascript1.0','text/javascript1.1','text/javascript1.2','text/javascript1.3','text/javascript1.4','text/javascript1.5','text/jscript','text/livescript','text/x-ecmascript','text/x-javascript','module'];const hookedScripts=new Set();function hookNode(hookName,initialContext=[['Node',{}]],contextGenerator){if(_native.Node&&Object.getOwnPropertyDescriptor(_native.Node.prototype,'textContent').configurable){Object.defineProperty(_native.Node.prototype,'textContent',{configurable:false,enumerable:_nativeMethods.Node.proto.textContent.enumerable,get:_nativeMethods.Node.proto.textContent.get,set:function(value){if(this instanceof _native.HTMLScriptElement){if(!hookedScripts.has(value)){value=hook(value,hookName,initialContext,contextGenerator);hookedScripts.add(value);}}return _global[hookName](_nativeMethods.Node.proto.textContent.set,this,[value],this.constructor.name+',set textContent');}});}return _native.Node;}function hookElement(hookName,initialContext=[['Element',{}]],contextGenerator){if(_native.Element&&Object.getOwnPropertyDescriptor(_native.Element.prototype,'setAttribute').configurable){Object.defineProperty(_native.Element.prototype,'setAttribute',{configurable:false,enumerable:_nativeMethods.Element.proto.setAttribute.enumerable,writable:false,value:function setAttribute(name,value){let doHook=false;let _name=name?name.toLowerCase():'';let _value=typeof value==='string'?value.trim():'';switch(_name){case'type':if(this instanceof _native.HTMLScriptElement&&jsMimeTypes.indexOf(_value.toLowerCase())>=0&&jsMimeTypes.indexOf(this.type?this.type.toLowerCase():'')<0){doHook=true;}break;case'src':if(this instanceof _native.HTMLScriptElement){if(_value){let srcUrl=new URL(_value,'https://localhost/');if(!srcUrl.pathname.match(/[.]m?js$/)){value='';}}}break;case'href':if(_value.startsWith('javascript:')){value='javascript:'+hook('(() => { '+_value.substr(11)+' })()',hookName,[[this.constructor.name+',setAttribute,'+_name,{}]],contextGenerator);}break;default:if(_name.match(/^on[a-z]{1,}$/)){value='return '+hook('(() => { '+value+' })()',hookName,[[this.constructor.name+',setAttribute,'+_name,{}]],contextGenerator);}break;}let result=_global[hookName](_nativeMethods.Element.proto.setAttribute.value,this,[name,value],this.constructor.name+',setAttribute');if(doHook){this.textContent=this.textContent;}return result;}});}if(_native.Element&&Object.getOwnPropertyDescriptor(_native.Element.prototype,'innerHTML').configurable){Object.defineProperty(_native.Element.prototype,'innerHTML',{configurable:false,enumerable:_nativeMethods.Element.proto.innerHTML.enumerable,get:_nativeMethods.Element.proto.innerHTML.get,set:function(value){let processed=preprocess._preprocessHtml(value,hookName,new URL(document.location),_global.location.hostname!==document.location.hostname,contextGenerator,[],false,true,0,preprocess.getHookProperty());return _global[hookName](_nativeMethods.Element.proto.innerHTML.set,this,[processed],this.constructor.name+',set innerHTML');}});}return _native.Element;}function hookHTMLScriptElement(hookName,initialContext=[['HTMLScriptElement',{}]],contextGenerator){hookNode(hookName,initialContext,contextGenerator);hookElement(hookName,initialContext,contextGenerator);if(_native.HTMLScriptElement&&Object.getOwnPropertyDescriptor(_native.HTMLScriptElement.prototype,'type').configurable){Object.defineProperty(_native.HTMLScriptElement.prototype,'type',{configurable:false,enumerable:_nativeMethods.HTMLScriptElement.proto.type.enumerable,get:_nativeMethods.HTMLScriptElement.proto.type.get,set:function(value){let doHook=false;if(this instanceof _native.HTMLScriptElement&&jsMimeTypes.indexOf(value?value.toLowerCase():'')>=0&&jsMimeTypes.indexOf(this.type?this.type.toLowerCase():'')<0){doHook=true;}let result=_global[hookName](_nativeMethods.HTMLScriptElement.proto.type.set,this,[value],this.constructor.name+',set type');if(doHook){this.textContent=this.textContent;}return result;}});}if(_native.HTMLScriptElement&&Object.getOwnPropertyDescriptor(_native.HTMLScriptElement.prototype,'src').configurable){Object.defineProperty(_native.HTMLScriptElement.prototype,'src',{configurable:false,enumerable:_nativeMethods.HTMLScriptElement.proto.type.enumerable,get:_nativeMethods.HTMLScriptElement.proto.src.get,set:function(value){let doHook=false;if(this instanceof _native.HTMLScriptElement){let _value=typeof value==='string'?value.trim():'';if(_value){let srcUrl=new URL(_value,'https://localhost/');if(!srcUrl.pathname.match(/[.]m?js$/)){value='';}}}let result=_global[hookName](_nativeMethods.HTMLScriptElement.proto.src.set,this,[value],this.constructor.name+',set src');return result;}});}return _native.HTMLScriptElement;}function hookHrefProperty(hookName,target,contextGenerator){if(_native[target]&&Object.getOwnPropertyDescriptor(_native[target].prototype,'href').configurable){Object.defineProperty(_native[target].prototype,'href',{configurable:false,enumerable:_nativeMethods[target].proto.href.enumerable,get:_nativeMethods[target].proto.href.get,set:function href(value){let doHook=false;let _value=typeof value==='string'?value.trim():'';if(_value.startsWith('javascript:')){value='javascript:'+hook('(() => { '+_value.substr(11)+' })()',hookName,[[this.constructor.name+',set href',{}]],contextGenerator);}return _global[hookName](_nativeMethods[target].proto.href.set,this,[value],this.constructor.name+',set href');}});}return _native[target];}function hookHTMLAnchorElement(hookName,initialContext=[['HTMLAnchorElement',{}]],contextGenerator){return hookHrefProperty(hookName,'HTMLAnchorElement',contextGenerator);}function hookHTMLAreaElement(hookName,initialContext=[['HTMLAreaElement',{}]],contextGenerator){return hookHrefProperty(hookName,'HTMLAreaElement',contextGenerator);}function hookDocument(hookName,initialContext=[['Document',{}]],contextGenerator,calculateScriptOffset=false){if(_native.Document&&Object.getOwnPropertyDescriptor(_native.Document.prototype,'write').configurable){Object.defineProperty(_native.Document.prototype,'write',{configurable:false,enumerable:_nativeMethods.Document.proto.write.enumerable,writable:false,value:function write(markup){let scriptOffset=0;if(calculateScriptOffset){for(let i=0;i{_freezeProperty(target,prop);});_freeze[target.name]&&_freeze[target.name].proto&&_freeze[target.name].proto.forEach(prop=>{_freezeProperty(target.prototype,prop);});}function hookPlatform(...targets){let platform=_global;targets.forEach(target=>{switch(target.name){case'setTimeout':case'setInterval':Object.defineProperty(target,'toString',{value:function toString(){return'function '+target.name+'() { [native code] }';},configurable:false,enumerable:false,writable:false});_freezeProperties(target);Object.defineProperty(platform,target.name,{value:target,configurable:false,enumerable:false,writable:false});break;case'HTMLScriptElement':_freezeProperties(target);Object.defineProperty(platform,target.name,{value:target,configurable:false,enumerable:false,writable:false});break;case'eval':_freezeProperties(target);Object.defineProperty(platform,target.name,{value:target,configurable:false,enumerable:false,writable:false});break;case'importScripts':_freezeProperties(target);Object.defineProperty(platform,target.name,{value:target,configurable:false,enumerable:false,writable:false});break;case'write':default:break;}});}return{hook:hookPlatform,global:hookGlobal,Function:hookFunction,FunctionArguments:hookFunctionArguments,eval:hookEval,setTimeout:hookSetTimeout,setInterval:hookSetInterval,Node:hookNode,Element:hookElement,HTMLAnchorElement:hookHTMLAnchorElement,HTMLAreaElement:hookHTMLAreaElement,HTMLScriptElement:hookHTMLScriptElement,Document:hookDocument,with:hookWith,importScripts:hookImportScripts};};}.call(this,typeof global!=='undefined'?global:typeof self!=='undefined'?self:typeof window!=='undefined'?window:{}));},{}],5:[function(require,module,exports){module.exports=function(espree,escodegen,htmlparser,createHash,convert){const espreeOptionsForTarget={loc:true,range:true,tokens:true,comment:true,ecmaVersion:9,ecmaFeatures:{experimentalObjectRestSpread:true}};const espreeOptionsForTargetCompact={loc:false,range:false,tokens:false,comment:false,ecmaVersion:9,ecmaFeatures:{experimentalObjectRestSpread:true}};const espreeOptions={loc:false,range:false,tokens:false,comment:false,ecmaVersion:9,ecmaFeatures:{experimentalObjectRestSpread:true}};const espreeModuleOptions={loc:true,range:true,tokens:true,comment:true,ecmaVersion:9,sourceType:'module',ecmaFeatures:{experimentalObjectRestSpread:true}};const espreeModuleOptionsCompact={loc:false,range:false,tokens:false,comment:false,ecmaVersion:9,sourceType:'module',ecmaFeatures:{experimentalObjectRestSpread:true}};let configurationsJSON='{"hookNameForServiceWorker":"__hook__","contextGeneratorName":"method","discardHookErrors":true,"hookProperty":true,"hookGlobal":true,"hookPrefix":"_p_","compact":false,"noHookAuthorizationPreValidated":[],"contextGeneratorScripts":[]}';let configurations=JSON.parse(configurationsJSON);function getConfigurations(){return configurations;}function setConfigurations(_configurations){return configurations=_configurations;}function getHookNameForServiceWorker(){return configurations.hookNameForServiceWorker;}function setHookNameForServiceWorker(_hookName){return configurations.hookNameForServiceWorker=_hookName;}function getHookWith(){return'__with__';}function setHookWith(_hookWith){return'__with__';}function getContextGeneratorName(){return configurations.contextGeneratorName;}function setContextGeneratorName(_contextGeneratorName){return configurations.contextGeneratorName=_contextGeneratorName;}function getDiscardHookErrors(){return configurations.discardHookErrors;}function setDiscardHookErrors(_discardHookErrors){return configurations.discardHookErrors=_discardHookErrors;}function getHookProperty(){return configurations.hookProperty;}function setHookProperty(_hookProperty){return configurations.hookProperty=_hookProperty;}function getHookGlobal(){return configurations.hookGlobal;}function setHookGlobal(_hookGlobal){return configurations.hookGlobal=_hookGlobal;}function getHookPrefix(){return configurations.hookPrefix;}function setHookPrefix(_hookPrefix){return configurations.hookPrefix=_hookPrefix;}function getCompact(){return configurations.compact;}function setCompact(_compact){return configurations.compact=_compact;}function getNoHookAuthorizationPreValidated(){return configurations.noHookAuthorizationPreValidated;}function setNoHookAuthorizationPreValidated(_noHookAuthorizationPreValidated){return configurations.noHookAuthorizationPreValidated=_noHookAuthorizationPreValidated;}function getContextGeneratorScripts(){return configurations.contextGeneratorScripts;}let hookWorkers=[];let hookWorkerCount=4;function getHookId(seed){let hash=hook.utils.createHash('sha256');hash.update(Math.random()+seed);return hash.digest('hex');}function getHookWorkers(){return hookWorkers;}function setHookWorkers(_hookWorkers){hookWorkers=_hookWorkers;console.log('setHookWorkers',hookWorkers);hookWorkers.forEach(function(worker){worker.tasks={};worker.port.onmessage=function(event){let message=JSON.parse(event.data);let id=message[0];let status=message[1];if(typeof worker.tasks[id]==='object'){if(status==='success'){let result=message[2];worker.tasks[id].status=status;worker.tasks[id].result=result;worker.tasks[id].callback(worker.tasks[id]);}else{let error=message[2];worker.tasks[id].status=status;worker.tasks[id].error=error;console.error('response from Hook Worker for '+id+':'+status+':'+error);worker.tasks[id].callback(worker.tasks[id]);}}else{console.error('response with unknown id '+id+' from Hook Worker');}};});}function setupHookWorkers(){if(hookWorkers.length===0&&hook.parameters.hookWorker){let transferChannels=[];for(let i=0;i0){let minIndex=0;let minTaskQueueSize=hookWorkers[minIndex].taskQueueSize;for(let i=minIndex;i0){ast=stack[--cursor];_ast=stack[--cursor];for(prop in ast){value=ast[prop];if(Array.isArray(value)){stack[cursor++]=_ast[prop]=[];stack[cursor++]=value;}else if(value&&typeof value==='object'){stack[cursor++]=_ast[prop]={};stack[cursor++]=value;}else if(value===baseHookName){_ast[prop]=hookName;}else if(value===baseContext){_ast[prop]=context;}else{_ast[prop]=value;}}}return result;}function _clone(sourceAst){let result={};let stack=[result,sourceAst];let cursor=stack.length;let ast,_ast;let prop,value;while(cursor>0){ast=stack[--cursor];_ast=stack[--cursor];for(prop in ast){value=ast[prop];if(Array.isArray(value)){stack[cursor++]=_ast[prop]=[];stack[cursor++]=value;}else if(value&&typeof value==='object'){stack[cursor++]=_ast[prop]={};stack[cursor++]=value;}else{_ast[prop]=value;}}}return result;}const functionScopeTypes={FunctionDeclaration:true,FunctionExpression:true,ArrowFunctionExpression:true,ClassDeclaration:true,VariableDeclaration_var:true,ImportDeclaration:true};const scopes={$block$:true,$function$:true};const S_STRICT=Symbol('use strict');const parameterTypes={Identifier:true,AssignmentPattern:true,ArrayPattern:true,ObjectPattern:true,RestElement:true};const arrayPatternElementTypes={Identifier:true,AssignmentPattern:true,ArrayPattern:true,ObjectPattern:true,RestElement:true,MemberExpression:true};const objectPatternValueTypes={Identifier:true,AssignmentPattern:true,ArrayPattern:true,ObjectPattern:true,MemberExpression:true};const variableDeclaratorIdTypes={Identifier:true,ArrayPattern:true,ObjectPattern:true};const nonOverridableIdentifiers=new Map();['undefined','NaN','Infinity'].forEach(v=>{nonOverridableIdentifiers.set(v,'__unexpected_overridden_declaration_of_'+v+'__');});function _analyzeScope(ast,blockScope,functionScope,moduleScope,hookName,hookWith){let target,child,t,index,i,l,item,type,scope,params;type=ast.type;switch(type){case'FunctionDeclaration':case'FunctionExpression':case'ArrowFunctionExpression':case'CatchClause':switch(type){case'FunctionDeclaration':if(ast.id&&ast.id.name){if(nonOverridableIdentifiers.has(ast.id.name)){ast.id.name=nonOverridableIdentifiers.get(ast.id.name);}blockScope[ast.id.name]=type;}blockScope=Object.create(blockScope);functionScope=blockScope;blockScope.arguments='VariableDeclaration_var';params=ast.params;if(ast.body&&Array.isArray(ast.body.body)&&ast.body.body.length>0&&(item=ast.body.body[0])&&Reflect.has(item,'type')&&item.type==='ExpressionStatement'&&item.expression&&item.expression.type==='Literal'&&item.expression.value==='use strict'){functionScope[S_STRICT]='Literal';}break;case'FunctionExpression':blockScope=Object.create(blockScope);functionScope=blockScope;if(ast.id&&ast.id.name){if(nonOverridableIdentifiers.has(ast.id.name)){ast.id.name=nonOverridableIdentifiers.get(ast.id.name);}functionScope[ast.id.name]=type;}blockScope.arguments='VariableDeclaration_var';params=ast.params;if(ast.body&&Array.isArray(ast.body.body)&&ast.body.body.length>0&&(item=ast.body.body[0])&&Reflect.has(item,'type')&&item.type==='ExpressionStatement'&&item.expression&&item.expression.type==='Literal'&&item.expression.value==='use strict'){functionScope[S_STRICT]='Literal';}break;case'ArrowFunctionExpression':blockScope=Object.create(blockScope);functionScope=blockScope;if(ast.id&&ast.id.name){if(nonOverridableIdentifiers.has(ast.id.name)){ast.id.name=nonOverridableIdentifiers.get(ast.id.name);}functionScope[ast.id.name]=type;}blockScope.arguments='VariableDeclaration_var';params=ast.params;break;case'CatchClause':blockScope=Object.create(blockScope);functionScope=blockScope;if(ast.param){params=[ast.param];}else{params=[];}break;default:break;}for(index=0;index0&&(item=ast.body[0])&&typeof item==='object'&&Reflect.has(item,'type')&&item.type==='ExpressionStatement'&&item.expression&&item.expression.type==='Literal'&&item.expression.value==='use strict'){functionScope[S_STRICT]='Literal';}break;default:break;}ast.$block$=blockScope;ast.$function$=functionScope;for(target in ast){if(scopes[target]){continue;}child=ast[target];if(child){if(Array.isArray(child)){for(t=child,index=0,l=t.length;indexk+'('+v+')').join(',')+']';o=Object.getPrototypeOf(o);}console.log(ast.type,ast.name||'',scope);}function _nonGlobalScope(blockScope,globalScope){let o=blockScope;let list={};while(o&&o!==globalScope){Object.assign(list,o);o=Object.getPrototypeOf(o);}return list;}function _nonGlobalWithScope(blockScope,globalScope,hookWith){let o=blockScope;let list={};while(o&&o!==globalScope){Object.assign(list,o);if(o.hasOwnProperty(hookWith)){break;}o=Object.getPrototypeOf(o);}return list;}function _logScope(ast){let target,child,t,index,i,l,item,type,scope;_logAst(ast);for(target in ast){if(scopes[target]){continue;}child=ast[target];if(child){if(Array.isArray(child)){for(t=child,index=0,l=t.length;index0&&globalScope===(ast.kind==='var'?functionScope:blockScope)){if(ast.__for__&&ast.declarations.length===1&&(ast.declarations[0].id.type==='Identifier'||ast.declarations[0].id.type==='ArrayPattern'||ast.declarations[0].id.type==='ObjectPattern')&&!ast.declarations[0].init){switch(ast.declarations[0].id.type){case'Identifier':if(!blockScope[ast.declarations[0].id.name]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');body=ast.declarations[0].id;t=functionScope[S_STRICT];template=_espreeParse(t?'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'name\', \'#var\').name':'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'name\', \'var\').name',hookName,context).expression;template.object.arguments[2].value=body.name;template.object.arguments[3].value=ast.kind;template.object.__hooked__=true;template.object.callee.__hooked__=true;template.object.callee.object.__hooked__=true;template.object.callee.property.__hooked__=true;if(t){template.property.name='S'+_hookPrefix+body.name;}else{template.property.name=_hookPrefix+body.name;}template.__hooked__=true;ast.declarations=undefined;ast.kind=undefined;objectAssign(ast,template);}break;case'ArrayPattern':template=ast.declarations[0].id;template.__global__=ast.kind;template.__LHS__=true;ast.declarations=undefined;ast.kind=undefined;objectAssign(ast,template);for(index=0,l=ast.elements.length;index super[p]], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;if(ast.computed){params[0]=ast.property;}else{params[0].value=ast.property.name;if(_sourceMap){params[0].start=ast.property.start;params[0].end=ast.property.end;}params[0].raw=undefined;}params[1].__hooked__=true;params[1].body.__hooked__=true;params[1].$block$=params[1].$function$=Object.create(blockScope);params[1].$block$.p=true;ast.object=undefined;ast.property=undefined;ast.computed=undefined;objectAssign(ast,f);}else{if(hookWith&&blockScope[hookWith]){if(ast.object.type==='Identifier'){ast.object.__with__='get';}}if(ast.__LHS__){context=contextGenerator(astPath).replace(/\'/g,'\\\'');t=functionScope[S_STRICT];template=_espreeParse(t?'_X_hookName_X_(\'#.=\', o, [\'p\'], \'X_X_XcontextX_X_X\')[\'=\']':'_X_hookName_X_(\'.=\', o, [\'p\'], \'X_X_XcontextX_X_X\')[\'=\']',hookName,context);f=template.expression.object;params=f.arguments[2].elements;f.arguments[1]=ast.object;if(ast.computed){params[0]=ast.property;}else{params[0].value=ast.property.name;if(_sourceMap){params[0].start=ast.property.start;params[0].end=ast.property.end;}params[0].raw=undefined;}template.expression.__hooked__=true;f.callee.__hooked__=true;f.__hooked__=true;ast.object=undefined;ast.property=undefined;ast.computed=undefined;ast.__LHS__=undefined;objectAssign(ast,template.expression);}else{context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse(functionScope[S_STRICT]?'_X_hookName_X_(\'#.\', o, [\'p\'], \'X_X_XcontextX_X_X\')':'_X_hookName_X_(\'.\', o, [\'p\'], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[1]=ast.object;if(ast.computed){params[0]=ast.property;}else{params[0].value=ast.property.name;if(_sourceMap){params[0].start=ast.property.start;params[0].end=ast.property.end;}params[0].raw=undefined;}ast.object=undefined;ast.property=undefined;ast.computed=undefined;objectAssign(ast,f);}}}break;case'UpdateExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else if(_hookProperty&&typeof ast.operator==='string'&&typeof ast.prefix==='boolean'&&typeof ast.argument==='object'){switch(ast.argument.type){case'MemberExpression':if(ast.argument.object.type==='Super'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', this, [\'p\', p => super[p]++], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[0].value=ast.prefix?ast.operator+'s':'s'+ast.operator;if(ast.argument.computed){params[0]=ast.argument.property;}else{params[0].value=ast.argument.property.name;params[0].raw=undefined;}params[1].body.operator=ast.operator;params[1].body.prefix=ast.prefix;params[1].body.argument.__hooked__=true;params[1].body.__hooked__=true;params[1].__hooked__=true;params[1].$block$=params[1].$function$=Object.create(blockScope);params[1].$block$.p=true;ast.operator=undefined;ast.prefix=undefined;ast.argument=undefined;objectAssign(ast,f);}else{if(hookWith&&blockScope[hookWith]){if(ast.argument.object.type==='Identifier'){ast.argument.object.__with__='get';}}context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', o, [\'p\'], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;if(functionScope[S_STRICT]){f.arguments[0].value=ast.prefix?'#'+ast.operator+'p':'#p'+ast.operator;}else{f.arguments[0].value=ast.prefix?ast.operator+'p':'p'+ast.operator;}f.arguments[1]=ast.argument.object;if(ast.argument.computed){params[0]=ast.argument.property;}else{params[0].value=ast.argument.property.name;params[0].raw=undefined;}ast.operator=undefined;ast.prefix=undefined;ast.argument=undefined;objectAssign(ast,f);}break;case'Identifier':if(hookWith&&blockScope[hookWith]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', '+hookWith+', [\'p\', () => foo++], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[0].value=ast.prefix?ast.operator+'w':'w'+ast.operator;f.arguments[1].__hooked__=true;params[0].value=ast.argument.name;params[1].body.argument.name=ast.argument.name;params[1].body.operator=ast.operator;params[1].body.prefix=ast.prefix;params[1].body.__hooked__=true;params[1].__hooked__=true;ast.operator=undefined;ast.prefix=undefined;ast.argument=undefined;objectAssign(ast,f);}else if(_hookGlobal&&ast.argument.name&&!blockScope[ast.argument.name]){ast.argument.__global__='set';}break;default:break;}}break;case'UnaryExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else if(_hookProperty&&typeof ast.argument==='object'){switch(ast.argument.type){case'MemberExpression':if(ast.operator==='delete'){if(hookWith&&blockScope[hookWith]){if(ast.argument.object.type==='Identifier'){ast.argument.object.__with__='get';}}context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', o, [\'p\'], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;if(functionScope[S_STRICT]){f.arguments[0].value='#'+ast.operator;}else{f.arguments[0].value=ast.operator;}f.arguments[1]=ast.argument.object;if(ast.argument.computed){params[0]=ast.argument.property;}else{params[0].value=ast.argument.property.name;params[0].raw=undefined;}ast.operator=undefined;ast.prefix=undefined;ast.argument=undefined;objectAssign(ast,f);}break;case'Identifier':switch(ast.operator){case'delete':if(hookWith&&blockScope[hookWith]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'wdelete\', '+hookWith+', [\'p\', () => delete p], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[1].__hooked__=true;params[0].value=ast.argument.name;params[1].body.argument.name=ast.argument.name;params[1].body.argument.__hooked__=true;params[1].body.__hooked__=true;params[1].__hooked__=true;ast.argument=undefined;ast.operator=undefined;ast.prefix=undefined;objectAssign(ast,f);}else if(_hookGlobal&&ast.argument.name&&!blockScope[ast.argument.name]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse(functionScope[S_STRICT]?'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'name\', \'#delete\')':'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'name\', \'delete\')',hookName,context);template.expression.arguments[2].value=ast.argument.name;template.expression.__hooked__=true;template.expression.callee.__hooked__=true;ast.argument=undefined;objectAssign(ast,template.expression);}break;case'typeof':if(hookWith&&blockScope[hookWith]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'wtypeof\', '+hookWith+', [\'p\', () => typeof p], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[1].__hooked__=true;params[0].value=ast.argument.name;params[1].body.argument.name=ast.argument.name;params[1].body.argument.__hooked__=true;params[1].body.__hooked__=true;params[1].__hooked__=true;ast.argument=undefined;ast.operator=undefined;ast.prefix=undefined;objectAssign(ast,f);}else if(_hookGlobal&&ast.argument.name&&!blockScope[ast.argument.name]){ast.argument.__global__='typeof';}break;default:if(hookWith&&blockScope[hookWith]){ast.argument.__with__='get';}else if(_hookGlobal&&ast.argument.name&&!blockScope[ast.argument.name]){ast.argument.__global__='get';}break;}break;default:break;}}break;case'AssignmentExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else if(_hookProperty&&typeof ast.operator==='string'&&typeof ast.left==='object'&&typeof ast.right==='object'){if(ast.right.type==='Identifier'){if(hookWith&&blockScope[hookWith]){ast.right.__with__='get';}else if(_hookGlobal&&!blockScope[ast.right.name]){ast.right.__global__='get';}}switch(ast.left.type){case'MemberExpression':if(ast.left.object.type==='Super'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', this, [\'p\', v, (p, v) => super[p] = v], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[0].value='s'+ast.operator;f.arguments[0].raw=undefined;if(ast.left.computed){params[0]=ast.left.property;}else{params[0].value=ast.left.property.name;if(_sourceMap){params[0].start=ast.left.property.start;params[0].end=ast.left.property.end;}params[0].raw=undefined;}params[1]=ast.right;params[2].body.operator=ast.operator;params[2].body.left.__hooked__=true;params[2].body.__hooked__=true;params[2].__hooked__=true;params[2].$block$=params[2].$function$=Object.create(blockScope);params[2].$block$.p=true;params[2].$block$.v=true;if(_sourceMap){f.callee.start=ast.left.start;f.callee.end=ast.left.end;f.callee.loc=ast.left.loc;f.callee.range=ast.left.range;}ast.operator=undefined;ast.left=undefined;ast.right=undefined;objectAssign(ast,f);}else{context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', o, [\'p\', v], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[0].value=functionScope[S_STRICT]?'#'+ast.operator:ast.operator;f.arguments[0].raw=undefined;f.arguments[1]=ast.left.object;if(ast.left.computed){params[0]=ast.left.property;}else{params[0].value=ast.left.property.name;if(_sourceMap){params[0].start=ast.left.property.start;params[0].end=ast.left.property.end;}params[0].raw=undefined;}params[1]=ast.right;if(_sourceMap){f.callee.start=ast.left.start;f.callee.end=ast.left.end;f.callee.loc=ast.left.loc;f.callee.range=ast.left.range;}ast.operator=undefined;ast.left=undefined;ast.right=undefined;objectAssign(ast,f);}break;case'Identifier':if(hookWith&&blockScope[hookWith]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'op\', '+hookWith+', [\'p\', v, (v) => p = v], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[0].value='w'+ast.operator;f.arguments[0].raw=undefined;params[0].value=ast.left.name;params[0].raw=undefined;params[1]=ast.right;params[2].body.left.name=ast.left.name;params[2].body.left.__hooked__=true;params[2].body.operator=ast.operator;params[2].body.__hooked__=true;params[2].__hooked__=true;params[2].$block$=params[2].$function$=Object.create(blockScope);params[2].$block$.v=true;if(_sourceMap){params[0].start=ast.start;params[0].end=ast.end;f.callee.start=ast.left.start;f.callee.end=ast.left.end;f.callee.loc=ast.left.loc;f.callee.range=ast.left.range;}ast.operator=undefined;ast.left=undefined;ast.right=undefined;objectAssign(ast,f);}else if(_hookGlobal&&!blockScope[ast.left.name]){ast.left.__global__='set';}break;case'ArrayPattern':case'ObjectPattern':ast.left.__LHS__=true;if(hookWith&&blockScope[hookWith]){ast.left.__with__='set';}else if(_hookGlobal){ast.left.__global__='set';}break;default:break;}}break;case'MethodDefinition':if(_hookProperty){if(ast.computed&&ast.key&&ast.key.type==='Identifier'&&ast.key.name){if(hookWith&&blockScope[hookWith]){ast.key.__with__='get';}else if(_hookGlobal&&!blockScope[ast.key.name]){ast.key.__global__='get';}}}break;case'FunctionDeclaration':case'FunctionExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else if(typeof ast.body==='object'&&!Array.isArray(ast.body)&&ast.body.type==='BlockStatement'&&ast.body.body&&Array.isArray(ast.body.body)){params=ast.params;body=ast.body.body;if(body[0]&&body[0].type==='ExpressionStatement'&&body[0].expression&&body[0].expression.type==='Literal'&&body[0].expression.value==='use strict'){useStrict=body.shift();}else{useStrict=null;}context=contextGenerator(astPath).replace(/\'/g,'\\\'');t=ast.params[0]&&ast.params[0].type==='ArrayPattern';template=_espreeParse(t?ast.generator?'function * f(...args) { yield * _X_hookName_X_(function * () {}, this, args, \'X_X_XcontextX_X_X\'); }':'function f(...args) { return _X_hookName_X_(() => {}, null, args, \'X_X_XcontextX_X_X\'); }':ast.generator?'function * f() { yield * _X_hookName_X_(function * () {}, this, arguments, \'X_X_XcontextX_X_X\'); }':'function f() { return _X_hookName_X_(() => {}, null, arguments, \'X_X_XcontextX_X_X\'); }',hookName,context);f=ast.generator?template.body.body[0].expression.argument.arguments[0]:template.body.body[0].argument.arguments[0];f.async=ast.async;f.params=ast.params;f.body.body=body;f.__hooked__=true;if(ast.generator){template.body.body[0].expression.argument.callee.__hooked__=true;template.body.body[0].expression.argument.__hooked__=true;}else{template.body.body[0].argument.callee.__hooked__=true;template.body.body[0].argument.__hooked__=true;}if(useStrict){template.body.body.unshift(useStrict);}ast.params=t?template.params:params.map(function _trim(param){return param&&(param.type==='ArrayPattern'?{type:param.type,elements:param.elements.map(element=>_trim(element))}:param.type==='AssignmentPattern'?param.left:param.type==='ObjectPattern'?{type:'ObjectPattern',properties:param.properties.map(prop=>prop.value&&prop.value.type==='AssignmentPattern'?((p,v)=>(p.value=v,p))(objectAssign({},prop),prop.value.left):prop.value&&prop.value.type==='ObjectPattern'?((p,v)=>(p.value=v,p))(objectAssign({},prop),_trim(prop.value)):prop)}:param);});if(_sourceMap){template.body.start=ast.body.start;template.body.end=ast.body.end;template.body.loc=ast.body.loc;template.body.range=ast.body.range;}ast.body=template.body;if(_hookProperty&&_hookGlobal&&ast.type==='FunctionDeclaration'&&Object.getPrototypeOf(functionScope)===globalScope){t=functionScope[S_STRICT];template=_espreeParse(t?'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'fname\', \'#function\').fname = function fname() {}':'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'fname\', \'function\').fname = function fname() {}',hookName,context);template.expression.left.object.arguments[2].value=ast.id.name;template.expression.left.object.__hooked__=true;template.expression.left.object.callee.__hooked__=true;if(t){template.expression.left.property.name='S'+_hookPrefix+ast.id.name;}else{template.expression.left.property.name=_hookPrefix+ast.id.name;}template.expression.left.__hooked__=true;objectAssign(template.expression.right,ast);template.expression.right.type='FunctionExpression';template.expression.right.__hooked__=true;template.expression.right.__moved__=true;template.expression.__hooked__=true;ast.id=undefined;ast.generator=undefined;ast.expression=undefined;ast.async=undefined;ast.params=undefined;ast.body=undefined;objectAssign(ast,template);}}break;case'ArrowFunctionExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else{if(typeof ast.body==='object'&&!Array.isArray(ast.body)){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse(ast.body.type==='BlockStatement'?'(...args) => _X_hookName_X_(p => { return p; }, null, args, \'X_X_XcontextX_X_X\')':ast.body.type==='ObjectExpression'?'(...args) => _X_hookName_X_(p => ({ p: p }), null, args, \'X_X_XcontextX_X_X\')':'(...args) => _X_hookName_X_(p => p, null, args, \'X_X_XcontextX_X_X\')',hookName,context).expression;f=template.body.arguments[0];f.async=ast.async;f.params=ast.params;f.body=ast.body;f.__hooked__=true;template.body.__hooked__=true;template.body.callee.__hooked__=true;ast.params=template.params;ast.body=template.body;}}break;case'NewExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else if(_hookProperty){if(hookWith&&blockScope[hookWith]){if(ast.callee.type==='Identifier'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'wnew\', '+hookWith+', [\'p\', [], (...args) => new p(...args)], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;params[0].value=ast.callee.name;params[1].elements=ast.arguments;params[2].body.callee.name=ast.callee.name;f.arguments[1].__hooked__=true;params[2].params[0].__hooked__=true;params[2].params[0].argument.__hooked__=true;params[2].body.callee.__hooked__=true;params[2].body.arguments[0].__hooked__=true;params[2].body.arguments[0].argument.__hooked__=true;params[2].body.__hooked__=true;params[2].__hooked__=true;params[2].$block$=params[2].$function$=Object.create(blockScope);params[2].$block$.args=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}}else{context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(ctor, null, [], \'X_X_XcontextX_X_X\', true)',hookName,context);f=template.expression;f.arguments[0]=ast.callee;f.arguments[2].elements=ast.arguments;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}}break;case'CallExpression':if(ast.__hooked__){ast.__hooked__=undefined;}else if(metaHooking&&ast.callee&&ast.callee.type==='Identifier'&&(ast.callee.name==='setTimeout'||ast.callee.name==='setInterval')&&ast.arguments&&ast.arguments[0]&&ast.arguments[0].type!=='FunctionExpression'&&ast.arguments[0].type!=='ArrowFunctionExpression'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('$hook$.'+ast.callee.name+'(\'_X_hookName_X_\', [[\'X_X_XcontextX_X_X\', {}]], \''+contextGeneratorName+'\')',hookName,context).expression;template.callee.__hooked__=true;template.__hooked__=true;ast.callee=template;}else if(metaHooking&&ast.callee&&ast.callee.type==='Identifier'&&ast.callee.name==='eval'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('$hook$.'+ast.callee.name+'(\'_X_hookName_X_\', [[\'X_X_XcontextX_X_X\', {}]], \''+contextGeneratorName+'\', {v:true})',hookName,context).expression;wrapper=functionScope[S_STRICT]?_espreeParse('(script, _eval) => _eval(script)',hookName,context).expression:_espreeParse('(script, eval) => eval(script)',hookName,context).expression;t=template.arguments[3].properties.pop();let nonGlobalScope=_nonGlobalScope(blockScope,globalScope);for(let v in nonGlobalScope){item=_clone(t);item.key.name=v;template.arguments[3].properties.push(item);}if(functionScope[S_STRICT]){item=_clone(t);item.key.name='$use_strict$';template.arguments[3].properties.push(item);}if(_sourceMap){_trimStartEndRaw(template);}template.callee.__hooked__=true;template.__hooked__=true;ast.callee=template;if(ast.arguments.length===1){wrapper.__hooked__=true;wrapper.body.__hooked__=true;ast.arguments.push(wrapper);}}else if(_hookProperty&&ast.callee&&ast.callee.type==='MemberExpression'){if(ast.callee.object.type==='Super'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'s()\', this, [\'p\', [], p => super[p]], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;if(ast.callee.computed){params[0]=ast.callee.property;}else{params[0].value=ast.callee.property.name;params[0].raw=undefined;}params[1]={'type':'ArrayExpression','elements':ast.arguments};params[2].__hooked__=true;params[2].body.__hooked__=true;params[2].$block$=params[1].$function$=Object.create(blockScope);params[2].$block$.p=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}else{if(hookWith&&blockScope[hookWith]){if(ast.callee.object.type==='Identifier'){ast.callee.object.__with__='get';}}context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse(functionScope[S_STRICT]?'_X_hookName_X_(\'#()\', o, [\'p\', args], \'X_X_XcontextX_X_X\')':'_X_hookName_X_(\'()\', o, [\'p\', args], \'X_X_XcontextX_X_X\')',hookName,context);f=template.expression;params=f.arguments[2].elements;f.arguments[1]=ast.callee.object;if(ast.callee.computed){params[0]=ast.callee.property;}else{params[0].value=ast.callee.property.name;params[0].raw=undefined;}params[1]={'type':'ArrayExpression','elements':ast.arguments};if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}}else if(_hookProperty){if(ast.callee.type==='Super'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_((newTarget,...args) => super(...args), null, [], \'X_X_XcontextX_X_X\', \'\')',hookName,context);f=template.expression;ast.arguments.unshift({type:'MetaProperty',meta:{type:'Identifier',name:'new'},property:{type:'Identifier',name:'target'}});f.arguments[2].elements=ast.arguments;f.__hooked__=true;f.callee.__hooked__=true;f.arguments[0].__hooked__=true;f.arguments[0].body.__hooked__=true;f.arguments[0].body.callee.__hooked__=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}else if(ast.callee.type==='Import'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_((Import,ImportSpecifier) => import(ImportSpecifier), null, [], \'X_X_XcontextX_X_X\', NaN)',hookName,context);f=template.expression;ast.arguments.unshift({type:'Literal',value:'import()'});f.arguments[2].elements=ast.arguments;f.__hooked__=true;f.callee.__hooked__=true;f.arguments[0].__hooked__=true;f.arguments[0].body.__hooked__=true;f.arguments[0].body.callee.__hooked__=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}else{let isInitialImportScripts=ast.callee.name==='importScripts'&&ast.arguments[0]&&ast.arguments[0].type==='Literal'&&typeof ast.arguments[0].value==='string'&&ast.arguments[0].value.indexOf('/hook.min.js?')>=0;if(isInitialImportScripts){for(let i=0;i p(...args)], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;params[0].value=ast.callee.name;params[1].elements=ast.arguments;f.arguments[1].__hooked__=true;params[2].body.callee.name=ast.callee.name;params[2].body.callee.__hooked__=true;params[2].params[0].__hooked__=true;params[2].params[0].argument.__hooked__=true;params[2].body.arguments[0].__hooked__=true;params[2].body.arguments[0].argument.__hooked__=true;params[2].body.__hooked__=true;params[2].__hooked__=true;params[2].$block$=params[2].$function$=Object.create(blockScope);params[2].$block$.args=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}}else if(ast.callee.name==='require'&&Reflect.has(blockScope,'require')&&ast.arguments[0]&&ast.arguments[0].type==='Literal'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');let targetContext=ast.arguments[0].value;let targetContextIndex=context.indexOf('|');if(targetContextIndex>0){targetContext=context.substring(targetContextIndex+1);context=context.substring(0,targetContextIndex);}template=_espreeParse('_X_hookName_X_(() => require(\'module.js\'), null, [], \'X_X_XcontextX_X_X\', NaN)',hookName,context);f=template.expression;f.arguments[0].body.arguments[0].value=ast.arguments[0].value;ast.arguments.unshift({type:'Literal',value:'require'});ast.arguments[2]={type:'Literal',value:targetContext};f.arguments[2].elements=ast.arguments;f.__hooked__=true;f.callee.__hooked__=true;f.arguments[0].__hooked__=true;f.arguments[0].body.__hooked__=true;f.arguments[0].body.callee.__hooked__=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}else{context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(f, null, [], \'X_X_XcontextX_X_X\', 0)',hookName,context);f=template.expression;f.arguments[0]=ast.callee;f.arguments[2].elements=ast.arguments;f.__hooked__=true;f.callee.__hooked__=true;if(_sourceMap){f.callee.start=ast.callee.start;f.callee.end=ast.callee.end;f.callee.loc=ast.callee.loc;f.callee.range=ast.callee.range;}ast.callee=undefined;ast.arguments=undefined;objectAssign(ast,f);}}}}break;case'MetaProperty':ast.meta=ast.meta.name;ast.property=ast.property.name;if(ast.__hooked__){ast.__hooked__=undefined;}else{if(ast.meta==='import'&&ast.property==='meta'){context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(() => import.meta, null, [\'import.meta\'], \'X_X_XcontextX_X_X\', NaN)',hookName,context);f=template.expression;f.__hooked__=true;f.callee.__hooked__=true;f.arguments[0].__hooked__=true;f.arguments[0].body.__hooked__=true;if(_sourceMap){f.callee.start=ast.start;f.callee.end=ast.end;f.callee.loc=ast.loc;f.callee.range=ast.range;}ast.meta=undefined;ast.property=undefined;objectAssign(ast,f);}}break;case'Identifier':if(ast.__hooked__){ast.__hooked__=undefined;}else if(_hookProperty){if(ast.__with__){switch(ast.__with__){case'get':context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'w.\', '+hookWith+', [\'p\', () => p], \'X_X_XcontextX_X_X\', false)',hookName,context);f=template.expression;params=f.arguments[2].elements;params[0].value=ast.name;params[0].raw=undefined;params[1].body.name=ast.name;params[1].body.__hooked__=true;params[1].__hooked__=true;params[1].$block$=params[1].$function$=Object.create(blockScope);f.arguments[1].__hooked__=true;f.__hooked__=true;if(_sourceMap){params[0].start=ast.start;params[0].end=ast.end;f.callee.start=ast.start;f.callee.end=ast.end;f.callee.loc=ast.loc;f.callee.range=ast.range;}ast.name=undefined;ast.__with__=undefined;objectAssign(ast,f);break;case'set':context=contextGenerator(astPath).replace(/\'/g,'\\\'');template=_espreeParse('_X_hookName_X_(\'w.=\', '+hookWith+', [\'p\', { set [\'=\'](v) { p = v; }, get [\'=\']() { return p; } }], \'X_X_XcontextX_X_X\', false)[\'=\']',hookName,context);f=template.expression.object;params=f.arguments[2].elements;params[0].value=ast.name;params[0].raw=undefined;params[1].properties[0].value.body.body[0].expression.left.name=ast.name;params[1].properties[0].value.body.body[0].expression.left.__hooked__=true;params[1].properties[0].value.body.body[0].expression.right.__hooked__=true;params[1].properties[0].value.body.body[0].expression.__hooked__=true;params[1].properties[0].value.params[0].__hooked__=true;params[1].properties[0].value.__hooked__=true;params[1].properties[0].value.$block$=params[1].properties[0].value.$function$=Object.create(blockScope);params[1].properties[0].value.$block$.v=true;params[1].properties[1].value.body.body[0].argument.name=ast.name;params[1].properties[1].value.body.body[0].argument.__hooked__=true;params[1].properties[1].value.__hooked__=true;params[1].properties[1].value.$block$=params[1].properties[1].value.$function$=Object.create(blockScope);params[1].__hooked__=true;template.expression.__hooked__=true;template.expression.object.__hooked__=true;if(_sourceMap){params[0].start=ast.start;params[0].end=ast.end;f.callee.start=ast.start;f.callee.end=ast.end;f.callee.loc=ast.loc;f.callee.range=ast.range;}ast.name=undefined;ast.__with__=undefined;objectAssign(ast,template.expression);break;default:ast.__with__=undefined;break;}}else if(_hookGlobal&&ast.__global__&&ast.name&&!blockScope[ast.name]){context=contextGenerator(astPath).replace(/\'/g,'\\\'');t=functionScope[S_STRICT];template=_espreeParse(t?'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'name\', \'#var\').name':'$hook$.global(_X_hookName_X_, \'X_X_XcontextX_X_X\', \'name\', \'var\').name',hookName,context);template.expression.object.arguments[2].value=ast.name;template.expression.object.arguments[3].value=t?'#'+ast.__global__:ast.__global__;template.expression.object.__hooked__=true;template.expression.object.callee.__hooked__=true;template.expression.object.callee.object.__hooked__=true;template.expression.object.callee.property.__hooked__=true;template.expression.property.name=t?'S'+_hookPrefix+ast.name:_hookPrefix+ast.name;template.expression.__hooked__=true;ast.name=undefined;ast.__global__=undefined;objectAssign(ast,template.expression);}}break;case'ArrayPattern':if(_hookProperty){for(index=0,l=ast.elements.length;index';},onopentag(name,attributes){let attrs='';let attrNoHook=typeof attributes['no-hook']==='string';for(let attr in attributes){if(attr.match(/^on[a-z]{1,}$/)&&attributes[attr]){let _attrNoHook=attrNoHook;if(_attrNoHook){let originalScript=attributes[attr];attributes[attr]=_validateNoHookScript(originalScript,url);_attrNoHook=originalScript===attributes[attr];}if(!_attrNoHook){attributes[attr]='return '+hook('(() => { '+attributes[attr]+'})()',hookName,[[(cors?url.href:url.pathname)+','+name+(attributes.id?'#'+attributes.id:attributes.class?'.'+attributes.class:'')+','+attr+'@'+(scriptOffset+processed.length),{}]],contextGenerator,metaHooking,_hookProperty);}}else if(attributes[attr]&&attributes[attr].indexOf('javascript:')===0){let _attrNoHook=attrNoHook;if(_attrNoHook){let originalScript=attributes[attr].substr(11);attributes[attr]='javascript:'+_validateNoHookScript(originalScript,url);_attrNoHook=originalScript===attributes[attr];}if(!_attrNoHook){attributes[attr]='javascript:'+hook('(() => { '+attributes[attr].substr(11)+'})()',hookName,[[(cors?url.href:url.pathname)+','+name+(attributes.id?'#'+attributes.id:attributes.class?'.'+attributes.class:'')+','+attr+'@'+(scriptOffset+processed.length),{}]],contextGenerator,metaHooking,_hookProperty);}}else if(attr==='src'&&name==='script'&&attributes[attr]){if(!attributes[attr].trim().match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*[.]m?js)(\?([^#]*))?(#(.*))?$/)){continue;}}attrs+=' '+attr+(attributes[attr]?attributes[attr].indexOf('"')>=0?'=\''+attributes[attr]+'\'':'="'+attributes[attr]+'"':'');}processed+='<'+name+attrs+'>';if(name==='script'){inScript=true;noHook=attrNoHook;src=attributes.src;inlineScript='';contextGeneratorAttr=attributes['context-generator'];if(src&&src.match(/\/hook[.]min[.]js\?/)){let srcUrl=new URL(src,'https://host/');if(srcUrl.searchParams.has('hook-name')){setHookNameForServiceWorker(srcUrl.searchParams.get('hook-name')||'__hook__');}if(srcUrl.searchParams.has('context-generator-name')){setContextGeneratorName(srcUrl.searchParams.get('context-generator-name')||'method');}if(srcUrl.searchParams.has('discard-hook-errors')){setDiscardHookErrors(srcUrl.searchParams.get('discard-hook-errors')==='true');}if(srcUrl.searchParams.has('hook-property')){setHookProperty(srcUrl.searchParams.get('hook-property')==='true');}if(srcUrl.searchParams.has('hook-global')){setHookGlobal(srcUrl.searchParams.get('hook-global')==='true');}if(srcUrl.searchParams.has('hook-prefix')){setHookPrefix(srcUrl.searchParams.get('hook-prefix'));}if(srcUrl.searchParams.has('compact')){setCompact(srcUrl.searchParams.get('compact')==='true');}if(srcUrl.searchParams.has('no-hook-authorization')){let noHookAuthorization=srcUrl.searchParams.get('no-hook-authorization').split(/,/);hook.parameters.noHookAuthorizationPreValidated=hook.parameters.noHookAuthorizationPreValidated||{};noHookAuthorization.forEach(ticket=>{hook.parameters.noHookAuthorizationPreValidated[ticket]=true;});setNoHookAuthorizationPreValidated(noHookAuthorization);}}if(isDecoded&&typeof contextGeneratorAttr==='string'&&src){contextGeneratorScripts.push(new URL(src,url));}}},ontext(text){if(inScript){inlineScript+=text;}else{processed+=text;}},onclosetag(name){if(name==='script'&&inScript){if(isDecoded&&typeof contextGeneratorAttr==='string'&&inlineScript){contextGeneratorScripts.push(inlineScript);}if(inlineScript){if(noHook){let originalScript=inlineScript;inlineScript=_validateNoHookScript(originalScript,url);noHook=originalScript===inlineScript;}if(!noHook){inlineScript=hook(inlineScript,hookName,[[(cors?url.href:url.pathname)+',script@'+(scriptOffset+processed.length),{}]],contextGenerator,metaHooking,_hookProperty);}}processed+=inlineScript;inScript=false;noHook=false;src='';}processed+='';},oncomment(data){processed+='';},onerror(error){throw error;}});stream.write(html.replace(/\n/g,'\0').replace(/(<\/[\s]{1,})script([\s]*>)/g,'$1-closing-script-in-process-$2').replace(/\0/g,'\n'));stream.end();processed=processed.replace(/\n/g,'\0').replace(/(<\/[\s]{1,})-closing-script-in-process-([\s]*>)/g,'$1script$2').replace(/\0/g,'\n');return processed;}}const escodegenOptions={format:{indent:{style:' '}},comment:true};const escodegenOptionsCompact={format:{compact:true},comment:false};const escodegenOptionsWithSourceMap={format:{indent:{style:' ',base:0,adjustMultilineComment:false},newline:'\n',space:' ',json:false,renumber:false,hexadecimal:false,quotes:'single',escapeless:false,compact:false,parentheses:true,semicolons:true,safeConcatenation:false},moz:{starlessGenerator:false,parenthesizedComprehensionBlock:false,comprehensionExpressionStartsWithAssignment:false},parse:null,comment:true,sourceMap:'source.js',sourceMapRoot:'src',sourceMapWithCode:true,file:'source.js.map',sourceContent:'',directive:false,verbatim:undefined};function hook(code,hookName='__hook__',initialContext=[],contextGeneratorName='method',metaHooking=true,_hookProperty=getHookProperty(),_sourceMap=null,asynchronous=false,_compact=getCompact(),_hookGlobal=getHookGlobal(),_hookPrefix=getHookPrefix(),initialScope=null){let hookWith=getHookWith();if(asynchronous){let worker=getBestHookWorker();if(worker){return new Promise(function(resolve,reject){let id=getHookId(code);let size=code.length;worker.tasks[id]={status:'requesting'};worker.taskQueueSize+=size;worker.tasks[id].callback=function callback(task){delete worker.tasks[id];worker.taskQueueSize-=size;if(task.status==='success'){resolve(task.result);}else{reject(task.error);}};let message=[id,'text/javascript',code,hookName,initialContext,contextGeneratorName,metaHooking,_hookProperty,_sourceMap,false,_compact,_hookGlobal,_hookPrefix,initialScope];worker.port.postMessage(JSON.stringify(message,null,0));});}else{return new Promise(function(resolve,reject){try{resolve(hook(code,hookName,initialContext,contextGeneratorName,metaHooking,_hookProperty,_sourceMap,false,_compact,_hookGlobal,_hookPrefix,initialScope));}catch(e){reject(e);}});}}else{let targetAst;try{targetAst=espree.parse(code,_compact?espreeOptionsForTargetCompact:espreeOptionsForTarget);}catch(e){if(e.name==='SyntaxError'&&e.message.match(/'import' and 'export' may appear only with 'sourceType: module'/)){targetAst=espree.parse(code,_compact?espreeModuleOptionsCompact:espreeModuleOptions);}else{throw e;}}let astWithComments=_compact?targetAst:escodegen.attachComments(targetAst,targetAst.comments,targetAst.tokens);targetAst={type:astWithComments.type,sourceType:astWithComments.sourceType,body:astWithComments.body};contextGeneratorName=hook.contextGenerators[contextGeneratorName]?contextGeneratorName:'method';let contextGenerator=hook.contextGenerators[contextGeneratorName];initialContext.push(['root',targetAst]);let globalScope={};let globalObjectScope={};let globalClassScope={};let blockScope=globalScope;let functionScope=globalScope;if(initialScope instanceof Object){blockScope=Object.create(globalScope);functionScope=blockScope;Object.assign(blockScope,initialScope);}_analyzeScope(targetAst,blockScope,functionScope,globalScope,hookName,hookWith);for(let globalProperty in globalScope){switch(globalScope[globalProperty]){case'FunctionDeclaration':case'VariableDeclaration_var':globalObjectScope[globalProperty]=globalScope[globalProperty];break;default:globalClassScope[globalProperty]=globalScope[globalProperty];break;}globalScope[globalProperty]=false;}globalScope[hookName]=true;_preprocess(targetAst,hookName,initialContext,contextGeneratorName,contextGenerator,metaHooking,_hookProperty,_sourceMap,_hookGlobal,_hookPrefix,hookWith,blockScope,functionScope,globalScope,globalObjectScope,globalClassScope);if(!_compact&&_sourceMap&&typeof _sourceMap==='object'&&_sourceMap.pathname){let sourcePath=_sourceMap.pathname.split(/\//).pop();escodegenOptionsWithSourceMap.code=code;escodegenOptionsWithSourceMap.sourceMap=sourcePath;escodegenOptionsWithSourceMap.file=sourcePath+'.map';let output=escodegen.generate(astWithComments,escodegenOptionsWithSourceMap);output.map.setSourceContent(sourcePath,code);let mapComment=convert.fromJSON(output.map.toString()).toComment();return output.code+'\n'+mapComment;}else{return escodegen.generate(astWithComments,_compact?escodegenOptionsCompact:escodegenOptions);}}}return{hook:hook,_preprocessHtml:_preprocessHtml,_validateNoHookScript:_validateNoHookScript,getConfigurations:getConfigurations,setConfigurations:setConfigurations,getHookNameForServiceWorker:getHookNameForServiceWorker,setHookNameForServiceWorker:setHookNameForServiceWorker,getHookWith:getHookWith,setHookWith:setHookWith,getContextGeneratorName:getContextGeneratorName,setContextGeneratorName:setContextGeneratorName,getDiscardHookErrors:getDiscardHookErrors,setDiscardHookErrors:setDiscardHookErrors,getHookProperty:getHookProperty,setHookProperty:setHookProperty,getHookGlobal:getHookGlobal,setHookGlobal:setHookGlobal,getHookPrefix:getHookPrefix,setHookPrefix:setHookPrefix,mutateScriptConfigurationsJSON:mutateScriptConfigurationsJSON,getCompact:getCompact,setCompact:setCompact,getNoHookAuthorizationPreValidated:getNoHookAuthorizationPreValidated,setNoHookAuthorizationPreValidated:setNoHookAuthorizationPreValidated,getContextGeneratorScripts:getContextGeneratorScripts,getHookWorkers:getHookWorkers,setHookWorkers:setHookWorkers,setupHookWorkers:setupHookWorkers,public:{hookHtml:_preprocessHtml}};};},{}],6:[function(require,module,exports){module.exports=function(hook,preprocess){const DEFAULT_VERSION='1';const UNINITIALIZED_VERSION='uninitialized';let version=UNINITIALIZED_VERSION;const CONFIGURATIONS_PSEUDO_URL='https://thin-hook.localhost.localdomain/configurations.json';function onInstall(event){version=new URL(location.href).searchParams.get('version')||DEFAULT_VERSION;}function onActivate(event){preprocess.setHookWorkers([]);event.waitUntil(caches.keys().then(keys=>Promise.all(keys.map(key=>key==='version_'+version||caches.delete(key)))));}function onMessage(event){if(event.data==='channel'){let hookWorkers=[];for(let i=0;i{hook.parameters.noHookAuthorizationPreValidated[ticket]=true;});preprocess.getContextGeneratorScripts().forEach(script=>{new Function(script)();});return cache.match(event.request);});}else{console.error('onFetch configurations not found');return cache.match(event.request);}}):cache.match(event.request)).then(function(response){let cors=false;let request;if(!response){if(event.request.method==='GET'&&event.request.url.indexOf('cors=true')>=0){cors=true;request=new Request(event.request.url.replace(/&cors=true/,'').replace(/\?cors=true$/,'').replace(/\?cors=true&/,'?'),{mode:'cors'});}else if(event.request.method==='GET'&&Array.isArray(hook.parameters.cors)&&hook.parameters.cors.filter(pattern=>typeof pattern==='string'?pattern===event.request.url:typeof pattern==='function'?pattern(event.request.url):false).reduce((prev,curr)=>prev||curr,false)){cors=true;request=new Request(event.request.url,{mode:'cors'});}else{request=event.request.clone();}}return response||fetch(request).then(function(response){if(response.type==='opaque'){if(request&&response.status===0&&Array.isArray(hook.parameters.opaque)&&hook.parameters.opaque.filter(pattern=>typeof pattern==='string'?pattern===request.url:typeof pattern==='function'?pattern(request.url):false).reduce((prev,curr)=>prev||curr,false)){}else{response=null;}}else if(response.status===200){if(response.url){let url=new URL(response.url);let noHook=url.searchParams.get('no-hook')==='true'||Array.isArray(hook.parameters.noHook)&&hook.parameters.noHook.filter(pattern=>typeof pattern==='string'?pattern===url.href:typeof pattern==='function'?pattern(url):false).reduce((prev,curr)=>prev||curr,false);if(url.pathname.match(/[.]m?js$/)){return response.text().then(async function(result){let sourceMap=Array.isArray(hook.parameters.sourceMap)&&hook.parameters.sourceMap.filter(pattern=>typeof pattern==='string'?pattern===url.href:typeof pattern==='function'?pattern(url):false).reduce((prev,curr)=>prev||curr,false)?{pathname:url.pathname}:null;try{if(noHook){let originalScript=result;result=preprocess._validateNoHookScript(originalScript,url);noHook=originalScript===result;if(noHook){result=preprocess.mutateScriptConfigurationsJSON(result,url);}}if(!noHook){result=await hook(result,preprocess.getHookNameForServiceWorker(),[[cors?response.url:url.pathname,{}]],preprocess.getContextGeneratorName(),true,preprocess.getHookProperty(),sourceMap,true);}}catch(e){if(preprocess.getDiscardHookErrors()){console.log(e);}else{result='/* Empty script due to a hook error */';console.error(e);throw e;}}finally{let processedResponse=new Response(result,{headers:{'Content-Type':'text/javascript'}});cache.put(event.request,processedResponse.clone());return processedResponse;}});}else if(url.pathname.match(/(\/|[.]html?)$/)){let original;let decoded;let contextGeneratorScripts=[];return response.text().then(async function(result){try{result=decoded=hook.serviceWorkerTransformers.decodeHtml(original=result);result=await preprocess._preprocessHtml(decoded,preprocess.getHookNameForServiceWorker(),url,cors,preprocess.getContextGeneratorName(),contextGeneratorScripts,original!==decoded,true,0,preprocess.getHookProperty(),true);}catch(e){if(preprocess.getDiscardHookErrors()){console.log(e);}else{result='';console.error(e);throw e;}}finally{let processedResponse=new Response(result,{headers:{'Content-Type':'text/html'}});if(decoded===original){cache.put(event.request,processedResponse.clone());}else{let match=decoded.replace(/\n/g,'\0').match(/