!function(e,t){"object"==typeof exports&&"object"==typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e.tern||(e.tern={})).signal={})}(this,function(e){function t(e,t){var r=this._handlers||(this._handlers=Object.create(null));(r[e]||(r[e]=[])).push(t)}function r(e,t){var r=this._handlers&&this._handlers[e];if(r)for(var n=0;n"!=e&&h(e,t,r)}),!c.length&&2<=l.length&&!1!==s.guess)for(var P in i.cx.props)h(P,i.cx.props[P][0],0);p="memberCompletion"}else T.forAllLocalsAt(e.ast,r,e.scope,h),s.includeKeywords&&(6<=i.options.ecmaVersion?I:k).forEach(function(e){h(e,null,0,function(e){e.isKeyword=!0})}),p="variableCompletion";i.signal(p,e,r,n,h),!1!==s.sort&&c.sort(S);return i.cx.completingProperty=null,{start:F(s,e,r),end:F(s,e,n),isProperty:!!P,isObjectKey:!!f,completions:c}}},properties:{run:function(e,t){var r=t.prefix,n=[];for(var o in e.cx.props)""==o||r&&0!==o.indexOf(r)||n.push(o);!1!==t.sort&&n.sort(S);return{completions:n}}},type:{takesFile:!0,run:function(e,t,r){var n,o,i,s=L(r,t),a=H(e,t,r,s);(n=a[0])||(s=q(r,t),a=H(e,t,r,s),n=a[0]);o=a[1],i=a[2];var p={guess:T.didGuess(),type:T.toString(i,t.depth),name:n&&n.name,exprName:o,doc:i.doc,url:i.url};n&&$(t,n,p);return w(p)}},documentation:{takesFile:!0,run:function(e,t,r){var n=L(r,t),o=V(e,t,r,n),i=o.getType();i||(n=q(r,t),o=V(e,t,r,n),i=o.getType());var s={url:o.url,doc:B(t,o.doc),type:T.toString(o)};i&&$(t,i,s);return w(s)}},definition:{takesFile:!0,run:function(e,t,r){var n=L(r,t),o=V(e,t,r,n);if(T.didGuess())return{};var i=G(o),s={url:o.url,doc:B(t,o.doc),origin:o.origin};if(o.types)for(var a=o.types.length-1;0<=a;--a){var p=o.types[a];$(t,p,s),i=i||G(p)}{var u,f,l,c;i&&i.node?(u=i.node.sourceFile||e.fileMap[i.origin],f=F(t,u,i.node.start),l=F(t,u,i.node.end),s.start=f,s.end=l,s.file=i.origin,c=Math.max(0,i.node.start-50),s.contextOffset=i.node.start-c,s.context=u.text.slice(c,c+50)):i&&(s.file=i.origin,z(e,t,i,s))}return w(s)}},refs:{takesFile:!0,fullFile:!0,run:function(e,t,r){var n=R(r,t,!0);{if(n&&"Identifier"==n.node.type)return W(e,t,r,n);if(n&&"MemberExpression"==n.node.type&&!n.node.computed){var o=n.node.property;return n.node=n.node.object,U(e,t,r,n,o)}if(n&&"ObjectExpression"==n.node.type)for(var i=N(r,t.end),s=0;s=i)return U(e,t,r,n,a)}else if(n&&"MethodDefinition"==n.node.type){o=n.node.key;return U(e,t,r,n,o)}}throw j("Not at a variable or property name.")}},rename:{takesFile:!0,fullFile:!0,run:function(e,t,r){if("string"!=typeof t.newName)throw j(".query.newName should be a string");var n=R(r,t);if(!n||"Identifier"!=n.node.type)throw j("Not at a variable.");var o=W(e,t,r,n,t.newName),i=o.refs;delete o.refs,o.files=e.files.map(function(e){return e.name});for(var s=o.changes=[],a=0;ag(r,t)&&(o.parent=t,o.excluded&&(o.excluded=null)));var i=new s(e,t);r.files.push(i),r.fileMap[e]=i,null!=n?a(i,n,r):r.options.async?(r.startAsyncAction(),r.options.getFile(e,function(e,t){a(i,t||"",r),r.finishAsyncAction(e)})):a(i,r.options.getFile(e)||"",r)}function c(e,t,r){var n=function(){e.off("everythingFetched",n),clearTimeout(o),h(e,t,r)};e.on("everythingFetched",n);var o=setTimeout(n,e.options.fetchTimeout)}function h(r,e,t){if(r.pending)return c(r,e,t);var n=r.fetchError;if(n)return r.fetchError=null,t(n);0Math.abs(i-r))&&(o=i),n=i+e.length}return o}(b,m.text,n),x=null==w?Math.max(0,m.text.lastIndexOf("\n",n)):w;return T.withContext(g.cx,function(){T.purge(d.name,x,x+d.text.length);var e,t,r=d.text;if(!(e=r.match(/(?:"([^"]*)"|([\w$]+))\s*:\s*function\b/))||(t=P.findNodeAround(d.backing.ast,x,"ObjectExpression"))&&t.node.objType&&(y={type:t.node.objType,prop:e[2]||e[1]}),w&&(e=b.match(/^(.*?)\bfunction\b/))){for(var n=e[1].length,o="",i=0;ie.text.length){if(!r)throw j("Position "+t+" is outside of file.");t=e.text.length}return t};function m(e,t,r){var n,o=r-t;if(e.hasAstral)for(i.lastIndex=t;(n=i.exec(e.text))&&n.index=t)return n}}var k="break do instanceof typeof case else new var catch finally return void continue for switch while debugger function this with default if throw delete in try".split(" "),I=k.concat("export class extends const super yield import let static".split(" ")),D=e.addCompletion=function(e,t,r,n,o){for(var i=e.types||e.docs||e.urls||e.origins,s=i||e.depths,a=0;a ")?(a=this.pos,(p=this.parseType(!0)).call&&!d&&(o=p,p=P.ANull,i=a)):p=P.ANull,d?(u=t,f=h,l=p,c=n,function(e,t){for(var r=[],n=0;n$!:]/)||this.error();return r.apply?function(e,t){return o(r(e,t),n)}:o(r,n)},parseTypeInner:function(e,t,r){var n,i,s,o,a;if(this.eat("fn(")||(n=this.eat("fn*(")))return this.parseFnType(e,t,r,n);if(this.eat("[")){for(var p=this.parseType(e),u=p.call;this.eat(", ");){l=l||[p];var f=this.parseType(e);l.push(f),u=u||f.call}return this.eat("]")||this.error(),u?l?(a=l,function(t,r){return new P.Arr(a.map(function(e){return T(e,t,r)}))}):(o=p,function(e,t){return new P.Arr(o(e,t))}):r&&this.base?(P.Arr.call(this.base,l||p),this.base):new P.Arr(l||p)}if(this.eat("{")){var l=[],c=[],u=!1;if(!this.eat("}"))for(;;0){var h,g=this.spec.indexOf(": ",this.pos);-1!=g&&(h=this.spec.slice(this.pos,g),/^[$\w?]+$/.test(h)?this.pos=g+2:h=null);var d=this.parseType(e);if(d.call&&(u=!0),c.push(h),l.push(d),!this.eat(", ")){this.eat("}")||this.error();break}}if(u)return i=c,s=l,function(r,n){var o=new P.Obj;return i.forEach(function(e,t){o.defProp(e).addType(T(s[t],r,n))}),o};var y=new P.Obj;return c.forEach(function(e,t){y.defProp(e).addType(l[t])}),y}if(this.eat("+")){var v=this.word(/[\w$<>\.:!]/),m=P.cx().localDefs[v+".prototype"];if(!m){if(!((m=O(v))instanceof P.Obj))return m;var b=A(m,["prototype"]);(b=b&&b.getObjType())&&(m=b)}return e&&this.eat("[")?this.parsePoly(m):r&&this.base?((t=(this.base.proto=m).hasCtor&&m.hasCtor.name||m.name)&&(this.base.name=t),this.base):r&&this.forceNew?new P.Obj(m):P.getInstance(m)}if(this.eat(":")){t=this.word(/[\w$\.]/);return P.getSymbol(t)}if(e&&this.eat("!")){var w=this.word(/\d/);if(w)return w=Number(w),function(e,t){return t[w]||P.ANull};if(this.eat("this"))return function(e){return e};if(this.eat("custom:")){var x=this.word(/[\w$]/);return E[x]||function(){return P.ANull}}return this.fromWord("!"+this.word(/[\w$<>\.!:]/))}return this.eat("?")?P.ANull:this.fromWord(this.word(/[\w$<>\.!:`]/))},fromWord:function(e){var t=P.cx();switch(e){case"number":return t.num;case"string":return t.str;case"bool":return t.bool;case"":return t.topScope}return t.localDefs&&e in t.localDefs?t.localDefs[e]:O(e)},parsePoly:function(n){var e,o="";(e=this.spec.slice(this.pos).match(/^\s*([\w$:]+)\s*=\s*/))&&(o=e[1],this.pos+=e[0].length);var i=this.parseType(!0);if(this.eat("]")||this.error(),i.call)return function(e,t){var r=new P.Obj(n);return i(e,t).propagate(r.defProp(o)),r};var t=new P.Obj(n);return i.propagate(t.defProp(o)),t}};var p,d=e.parseEffect=function(e,t){var r;if(0==e.indexOf("propagate ")){var n=(s=new h(e,10)).parseType(!0);s.eat(" ")||s.error();var o=s.parseType(!0);g(t,function(e,t){T(n,e,t).propagate(T(o,e,t))})}else if(0==e.indexOf("call ")){var a=5==e.indexOf("and return ",5),p=(s=new h(e,a?16:5)).parseType(!0),u=null,f=[];for(s.eat(" this=")&&(u=s.parseType(!0));s.eat(" ");)f.push(s.parseType(!0));g(t,function(e,t){for(var r=T(p,e,t),n=u?T(u,e,t):P.ANull,o=[],i=0;i"!=e&&n.propagate(new P.DefProp(e,t))})})}},O=e.parsePath=function(e,t){var r=P.cx(),n=r.paths[e],o=e;if(null!=n)return n;r.paths[e]=P.ANull;var i=t||p||r.topScope;if(r.localDefs)for(var s in r.localDefs)if(0==e.indexOf(s)){if(e==s)return r.paths[e]=r.localDefs[e];if("."==e.charAt(s.length)){i=r.localDefs[s],e=e.slice(s.length+1);break}}var a=A(i,e.split("."));return r.paths[o]=a==P.ANull?null:a,a};function A(e,t){for(var r=0;r"),o=0;o").getType(!1);if(!a)return r;var p=r.getProp("").getType(!1);return!p||c(a,p,n+1)?r:void 0}d.prototype=t(g,{addType:function(r,n){if(n=n||100,this.maxWeightn||-1"!=t){var o=e.hasProp("");if(o)return o.getType()}else if(e.props[""]!=this)for(var i in e.props){var s=e.props[i];if(!s.isEmpty())return s.getType()}},makeupType:function(){var e=this.propertyOf&&this.makeupPropType(this.propertyOf);if(e)return e;if(!this.forward)return null;for(var t=this.forward.length-1;0<=t;--t){var r=this.forward[t].typeHint();if(r&&!r.isEmpty())return ke=!0,r}for(var n=Object.create(null),o=null,t=0;t"!=p&&"✖"!=p&&p!=H.completingProperty&&(n[p]=!0,o=p)}if(!o)return null;var i=_(o);if(i){var s=[];e:for(t=0;t").isEmpty()?1:2;else if(r){u=1;for(var f=0;f"==this.prop||!/[^\w_]/.test(this.prop))return{target:this.target,pathExt:"."+this.prop}}}),v=u.PropHasSubset=u.DefProp=r({construct:function(e,t,r){this.prop=e,this.type=t,this.originNode=r},addType:function(e,t){var r;e instanceof I&&((r=e.defProp(this.prop,this.originNode)).origin||(r.origin=this.origin),this.type.propagate(r,t))},propHint:function(){return this.prop}}),m=r({construct:function(e){this.c=e},addType:function(e){e instanceof I&&e.forAllProps(this.c)}});var b=u.IsCallee=r({construct:function(e,t,r,n){this.self=e,this.args=t,this.argNodes=r,this.retval=n,this.disabled=H.disabledComputing},addType:function(e,t){if(e instanceof L){for(var r=0;r"!=n){if(5"},broadcastProp:function(e,t,r){var n,o;if(r&&(this.signal("addProp",e,t),this instanceof W||(n=e,o=this,(H.props[n]||(H.props[n]=[])).push(o))),this.onNewProp)for(var i=0;i"!=r&&":"!=r.charAt(0)&&e(r,this,t);this.proto&&this.proto.gatherProperties(e,t+1)},getObjType:function(){return this}});var D="undefined"!=typeof StopIteration;function M(e){return"__proto__"==e||"✖"==e||D&&"__iterator__"==e}var L=u.Fn=function(e,t,r,n,o,i,s){I.call(this,H.protos.Function,e),this.self=t,this.args=r,this.argNames=n,this.retval=o,this.generator=i,this.async=s};L.prototype=t(I.prototype,{constructor:L,toString:function(e){null==e&&(e=0);for(var t=this.generator?"fn*(":"fn(",r=0;r");if(Array.isArray(e)){this.tuple=e.length;for(var r=0;r"),e-1,this);return"["+t+"]"},normalizeIntegerProp:function(e){return+e"}});var R=u.Sym=function(e,t){C.call(this,H.protos.Symbol,"Symbol"),this.symName=e,this.originNode=t};function _(e){return H.props[e]}R.prototype=t(C.prototype,{constructor:R,asPropName:function(){return":"+this.symName},getSymbolType:function(){return this}}),u.getSymbol=function(e,t){var r=e.replace(/[^\w$\.]/g,"_"),n=H.symbols[r];return n?(t&&!n.originNode&&(n.originNode=t),n):H.symbols[r]=new R(r,t)},u.Context=function(t,e){this.parent=e,this.props=Object.create(null),this.protos=Object.create(null),this.origins=[],this.curOrigin="ecmascript",this.paths=Object.create(null),this.definitions=Object.create(null),this.purgeGen=0,this.workList=null,this.disabledComputing=null,this.curSuperCtor=this.curSuper=null,this.symbols=Object.create(null),u.withContext(this,function(){if(H.protos.Object=new I(null,"Object.prototype"),H.topScope=new W,H.topScope.name="",H.protos.Array=new I(!0,"Array.prototype"),H.protos.Function=new L("Function.prototype",g,[],[],g),H.protos.Function.proto=H.protos.Object,H.protos.RegExp=new I(!0,"RegExp.prototype"),H.protos.String=new I(!0,"String.prototype"),H.protos.Number=new I(!0,"Number.prototype"),H.protos.Boolean=new I(!0,"Boolean.prototype"),H.protos.Symbol=new I(!0,"Symbol.prototype"),H.str=new C(H.protos.String,"string"),H.bool=new C(H.protos.Boolean,"bool"),H.num=new C(H.protos.Number,"number"),H.curOrigin=null,t)for(var e=0;e=V)throw new u.TimedOut;o=n[r+3]+1,n[r+1].addType(n[r],n[r+2])}return H.workList=null,t}function z(e,t,r){var n=H.curSuperCtor,o=H.curSuper;H.curSuperCtor=e,H.curSuper=t;var i=r();return H.curSuperCtor=n,H.curSuper=o,i}var W=u.Scope=function(e,t,r,n){I.call(this,e||!0),this.prev=e,this.originNode=t,this.isBlock=!!r,this.isCatch=!!n};function U(e,t){for(;e.isBlock||e.isCatch||!1===t&&e.fnType&&e.fnType.isArrowFn();)e=e.prev;return e}function K(e,t){var r=U(e).fnType;r&&(r.instantiateScore=(r.instantiateScore||0)+t)}W.prototype=t(I.prototype,{constructor:W,defVar:function(e,t){for(var r=this;;r=r.proto){var n=r.props[e];if(n)return n;if(!r.prev)return r.defProp(e,t)}}});var Z={};function J(e,t){var r=t.instantiateScore;if(!H.disabledComputing&&r&&t.args.length&&function(e,t){try{return h.simple(e,{Expression:function(){if(--t<=0)throw Z}}),1}catch(e){if(e==Z)return;throw e}}(e,5*r))return K(U(t.originNode.scope.prev),r/2),function(f,l){for(var c=f.scope,e=0;e"));for(var n=u(e.self,"!this",0),o=0;!n&&o"};function se(e){var t=e.getSymbolType();if(t)return t.asPropName()}function ae(e){switch(e){case"+":case"-":case"~":return H.num;case"!":return H.bool;case"typeof":return H.str;case"void":case"delete":return g}}function pe(e){switch(e){case"==":case"!=":case"===":case"!==":case"<":case">":case">=":case"<=":case"in":case"instanceof":return 1}}function ue(e){if(e.regex)return P(H.protos.RegExp);switch(typeof e.value){case"boolean":return H.bool;case"number":return H.num;case"string":return H.str;case"object":case"function":return e.value?P(H.protos.RegExp):g}}function fe(e,t){for(var r=0;r"==(s=ie(p,f))||"set"==p.kind?i=g:((i=(p.static?n:c).defProp(s,p.key)).initializer=!0,"get"==p.kind&&(i=new b(o,[],null,i))),we(p.value,f,i),(a=i.getFunctionType())&&a.self.addType(o))}return n})}function ye(e,t,r){var n=1"==(t=ie(o,a))||"set"==o.kind?r=g:((n=r=u.defProp(t,i)).initializer=!0,"get"==o.kind&&(r=new b(u,[],null,n))),we(o.value,a,r,t),"FunctionExpression"==o.value.type&&o.value.scope.fnType.self.addType(u,2))}}),u}),FunctionExpression:ve(function(e,t,r){var n=e.scope,o=n.fnType;return r&&!o.name&&(o.name=r),fe(e,n),e.expression?we(e.body,n,n.fnType.retval=new d):h.recursive(e.body,n,null,Pe,"Statement"),"ArrowFunctionExpression"==e.type&&ge(t).propagate(o.self),J(e,o)||Q(o),e.id&&n.getProp(e.id.name).addType(o),o}),ClassExpression:ve(de),SequenceExpression:ve(function(e,t){for(var r=0,n=e.expressions.length-1;r"==o){var s=e.left.property.name,a=t.props[s],p=a&&a.iteratesOver;if(p){K(t,20);var u="MemberExpression"==e.right.type&&e.right.computed&&e.right.property.name==s;return p.forAllProps(function(e,t,r){r&&"prototype"!=e&&""!=e&&i.propagate(new v(e,u?t:g))}),n}}i.propagate(new v(o,n,e.left.property)),function e(t){t.isEmpty()&&t.propertyOf&&(t.propertyOf.getProp(t.propertyName).addType(new I,f),e(t.propertyOf))}(i),"FunctionExpression"==e.right.type&&i.propagate(e.right.scope.fnType.self,2)}else he(e.left,t,n);return n}),LogicalExpression:me(function(e,t,r){we(e.left,t,r),we(e.right,t,r)}),ConditionalExpression:me(function(e,t,r){we(e.test,t,g),we(e.consequent,t,r),we(e.alternate,t,r)}),NewExpression:me(function(e,t,r,n){"Identifier"==e.callee.type&&e.callee.name in t.props&&K(t,20);for(var o=0,i=[];o"==s&&((i=se(o=we(e.property,t)))?s=e.propName=i:o.hasType(H.num)||(n=6)),we(e.object,t).getProp(s).propagate(r,n)}),Identifier:ve(function(e,t){var r;return"arguments"==e.name&&(!(r=U(t,!1)).fnType||e.name in r.props||r.defProp(e.name,r.fnType.originNode).addType(new q(r.fnType.arguments=new d))),t.getProp(e.name)}),ThisExpression:ve(function(e,t){return ge(t)}),Super:ve(function(e){return e.superType=H.curSuper||g}),Literal:ve(ue),TemplateLiteral:ve(function(e,t){for(var r=0;r").propagate(le(n,t))):he(n,t,o.getProp(""))),r(e.body,t,"Statement")},ForOfStatement:function(e,t,r){var n,o=xe(e.left);"Identifier"==o.type?n=le(o,t):he(o,t,n=new d),e.await?we(e.right,t,new w(":Symbol.asyncIterator",[],null,new w("next",[],null,new p(":t",new p("value",n))))):we(e.right,t,new w(":Symbol.iterator",[],null,new w("next",[],null,new p("value",n)))),r(e.body,t,"Statement")}}),Te=u.parse=function(t,r,e){var n;r&&!Array.isArray(r)||(r=e);try{n=o.parse(t,r)}catch(e){n=i.parse(t,r)}return n};function Oe(e,t,r){var n=H.definitions.ecmascript,o=new I(!0);o.defProp("done").addType(H.bool),t.propagate(o.defProp("value"));var i=o;r&&n&&(i=new I(n["Promise.prototype"])).getType().propagate(new v(":t",o));var s=new L(null,g,e?[e]:[],e?["?"]:[],i),a=new I(!n||(r?n.async_generator_prototype:n.generator_prototype));return a.defProp("next").addType(s),a}function Ae(e,t){return e.generator?e.computeRet?Oe(e.yieldval,t,e.async):(!0===e.generator&&(e.generator=Oe(e.yieldval,t,e.async)),e.generator):t}function Ee(e,t,r){var n=Ne(e,r).getFunctionType();if(!n)return g;var o=n.retval;if(n.computeRet){for(var i=0,s=[];i=n&&t.end<=o&&-1=n&&t.end<=o&&e.origin==r}}(e,t,r);for(var o in++H.purgeGen,H.topScope.purge(n),H.props){for(var i=H.props[o],s=0;s"==r?g:function(e){ke=!0;var t=_(e);if(t)for(var r=0;rr)&&(("Identifier"!=t.type||"✖"!=t.name)&&je.hasOwnProperty(t.type))};return h.findNodeAround(e,t,i,Se,n||H.topScope)},u.findExpressionAround=function(e,r,t,n,o){var i=o||function(e,t){return!(null!=r&&t.start>r)&&(("Identifier"!=t.type||"✖"!=t.name)&&je.hasOwnProperty(t.type))};return h.findNodeAround(e,t,i,Fe,n||H.topScope)},u.expressionType=function(e){return Ne(e.node,e.state)},u.parentNode=function(i,e){var s=[];try{!function e(t,r,n){if(t.start<=i.start&&t.end>=i.end){var o=s[s.length-1];if(t==i)throw{found:o};o!=t&&s.push(t),h.base[n||t.type](t,r,e),o!=t&&s.pop()}}(e,null)}catch(e){if(e.found)return e.found;throw e}};var Ce=u.findTypeFromContext={ArrayExpression:function(e,t,r){return r(e,!0).getProp("")},ObjectExpression:function(e,t,r){for(var n=0;ni.length&&0==p.indexOf(i)&&(t.types||t.docs||t.urls||t.origins?(o={name:JSON.stringify(p),displayName:p},s.push(o),t.types&&(o.type="string"),t.origins&&(o.origin=a[p])):s.push(JSON.stringify(p)))}return s.length?{start:f.outputPos(t,e,n.node.start),end:f.outputPos(t,e,r+(e.text.charAt(r)==e.text.charAt(n.node.start)?1:0)),isProperty:!1,completions:s}:void 0}}f.registerPlugin("complete_strings",function(e,t){e.mod.completeStrings={maxLen:t&&t.maxLength||15,seen:Object.create(null)},e.on("reset",function(){e.mod.completeStrings.seen=Object.create(null)}),e.on("postParse",r),e.on("completion",n)})});