esquery.esm.js 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418
  1. function _arrayLikeToArray(r, a) {
  2. (null == a || a > r.length) && (a = r.length);
  3. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  4. return n;
  5. }
  6. function _arrayWithHoles(r) {
  7. if (Array.isArray(r)) return r;
  8. }
  9. function _arrayWithoutHoles(r) {
  10. if (Array.isArray(r)) return _arrayLikeToArray(r);
  11. }
  12. function _iterableToArray(r) {
  13. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  14. }
  15. function _iterableToArrayLimit(r, l) {
  16. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  17. if (null != t) {
  18. var e,
  19. n,
  20. i,
  21. u,
  22. a = [],
  23. f = !0,
  24. o = !1;
  25. try {
  26. if (i = (t = t.call(r)).next, 0 === l) {
  27. if (Object(t) !== t) return;
  28. f = !1;
  29. } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  30. } catch (r) {
  31. o = !0, n = r;
  32. } finally {
  33. try {
  34. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  35. } finally {
  36. if (o) throw n;
  37. }
  38. }
  39. return a;
  40. }
  41. }
  42. function _nonIterableRest() {
  43. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  44. }
  45. function _nonIterableSpread() {
  46. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  47. }
  48. function _slicedToArray(r, e) {
  49. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  50. }
  51. function _toConsumableArray(r) {
  52. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  53. }
  54. function _typeof(o) {
  55. "@babel/helpers - typeof";
  56. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  57. return typeof o;
  58. } : function (o) {
  59. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  60. }, _typeof(o);
  61. }
  62. function _unsupportedIterableToArray(r, a) {
  63. if (r) {
  64. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  65. var t = {}.toString.call(r).slice(8, -1);
  66. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  67. }
  68. }
  69. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  70. function createCommonjsModule(fn, module) {
  71. return module = { exports: {} }, fn(module, module.exports), module.exports;
  72. }
  73. var estraverse = createCommonjsModule(function (module, exports) {
  74. /*
  75. Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
  76. Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
  77. Redistribution and use in source and binary forms, with or without
  78. modification, are permitted provided that the following conditions are met:
  79. * Redistributions of source code must retain the above copyright
  80. notice, this list of conditions and the following disclaimer.
  81. * Redistributions in binary form must reproduce the above copyright
  82. notice, this list of conditions and the following disclaimer in the
  83. documentation and/or other materials provided with the distribution.
  84. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  85. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  86. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  87. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  88. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  90. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  91. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  92. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  93. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  94. */
  95. /*jslint vars:false, bitwise:true*/
  96. /*jshint indent:4*/
  97. /*global exports:true*/
  98. (function clone(exports) {
  99. var Syntax, VisitorOption, VisitorKeys, BREAK, SKIP, REMOVE;
  100. function deepCopy(obj) {
  101. var ret = {},
  102. key,
  103. val;
  104. for (key in obj) {
  105. if (obj.hasOwnProperty(key)) {
  106. val = obj[key];
  107. if (typeof val === 'object' && val !== null) {
  108. ret[key] = deepCopy(val);
  109. } else {
  110. ret[key] = val;
  111. }
  112. }
  113. }
  114. return ret;
  115. }
  116. // based on LLVM libc++ upper_bound / lower_bound
  117. // MIT License
  118. function upperBound(array, func) {
  119. var diff, len, i, current;
  120. len = array.length;
  121. i = 0;
  122. while (len) {
  123. diff = len >>> 1;
  124. current = i + diff;
  125. if (func(array[current])) {
  126. len = diff;
  127. } else {
  128. i = current + 1;
  129. len -= diff + 1;
  130. }
  131. }
  132. return i;
  133. }
  134. Syntax = {
  135. AssignmentExpression: 'AssignmentExpression',
  136. AssignmentPattern: 'AssignmentPattern',
  137. ArrayExpression: 'ArrayExpression',
  138. ArrayPattern: 'ArrayPattern',
  139. ArrowFunctionExpression: 'ArrowFunctionExpression',
  140. AwaitExpression: 'AwaitExpression',
  141. // CAUTION: It's deferred to ES7.
  142. BlockStatement: 'BlockStatement',
  143. BinaryExpression: 'BinaryExpression',
  144. BreakStatement: 'BreakStatement',
  145. CallExpression: 'CallExpression',
  146. CatchClause: 'CatchClause',
  147. ChainExpression: 'ChainExpression',
  148. ClassBody: 'ClassBody',
  149. ClassDeclaration: 'ClassDeclaration',
  150. ClassExpression: 'ClassExpression',
  151. ComprehensionBlock: 'ComprehensionBlock',
  152. // CAUTION: It's deferred to ES7.
  153. ComprehensionExpression: 'ComprehensionExpression',
  154. // CAUTION: It's deferred to ES7.
  155. ConditionalExpression: 'ConditionalExpression',
  156. ContinueStatement: 'ContinueStatement',
  157. DebuggerStatement: 'DebuggerStatement',
  158. DirectiveStatement: 'DirectiveStatement',
  159. DoWhileStatement: 'DoWhileStatement',
  160. EmptyStatement: 'EmptyStatement',
  161. ExportAllDeclaration: 'ExportAllDeclaration',
  162. ExportDefaultDeclaration: 'ExportDefaultDeclaration',
  163. ExportNamedDeclaration: 'ExportNamedDeclaration',
  164. ExportSpecifier: 'ExportSpecifier',
  165. ExpressionStatement: 'ExpressionStatement',
  166. ForStatement: 'ForStatement',
  167. ForInStatement: 'ForInStatement',
  168. ForOfStatement: 'ForOfStatement',
  169. FunctionDeclaration: 'FunctionDeclaration',
  170. FunctionExpression: 'FunctionExpression',
  171. GeneratorExpression: 'GeneratorExpression',
  172. // CAUTION: It's deferred to ES7.
  173. Identifier: 'Identifier',
  174. IfStatement: 'IfStatement',
  175. ImportExpression: 'ImportExpression',
  176. ImportDeclaration: 'ImportDeclaration',
  177. ImportDefaultSpecifier: 'ImportDefaultSpecifier',
  178. ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
  179. ImportSpecifier: 'ImportSpecifier',
  180. Literal: 'Literal',
  181. LabeledStatement: 'LabeledStatement',
  182. LogicalExpression: 'LogicalExpression',
  183. MemberExpression: 'MemberExpression',
  184. MetaProperty: 'MetaProperty',
  185. MethodDefinition: 'MethodDefinition',
  186. ModuleSpecifier: 'ModuleSpecifier',
  187. NewExpression: 'NewExpression',
  188. ObjectExpression: 'ObjectExpression',
  189. ObjectPattern: 'ObjectPattern',
  190. PrivateIdentifier: 'PrivateIdentifier',
  191. Program: 'Program',
  192. Property: 'Property',
  193. PropertyDefinition: 'PropertyDefinition',
  194. RestElement: 'RestElement',
  195. ReturnStatement: 'ReturnStatement',
  196. SequenceExpression: 'SequenceExpression',
  197. SpreadElement: 'SpreadElement',
  198. Super: 'Super',
  199. SwitchStatement: 'SwitchStatement',
  200. SwitchCase: 'SwitchCase',
  201. TaggedTemplateExpression: 'TaggedTemplateExpression',
  202. TemplateElement: 'TemplateElement',
  203. TemplateLiteral: 'TemplateLiteral',
  204. ThisExpression: 'ThisExpression',
  205. ThrowStatement: 'ThrowStatement',
  206. TryStatement: 'TryStatement',
  207. UnaryExpression: 'UnaryExpression',
  208. UpdateExpression: 'UpdateExpression',
  209. VariableDeclaration: 'VariableDeclaration',
  210. VariableDeclarator: 'VariableDeclarator',
  211. WhileStatement: 'WhileStatement',
  212. WithStatement: 'WithStatement',
  213. YieldExpression: 'YieldExpression'
  214. };
  215. VisitorKeys = {
  216. AssignmentExpression: ['left', 'right'],
  217. AssignmentPattern: ['left', 'right'],
  218. ArrayExpression: ['elements'],
  219. ArrayPattern: ['elements'],
  220. ArrowFunctionExpression: ['params', 'body'],
  221. AwaitExpression: ['argument'],
  222. // CAUTION: It's deferred to ES7.
  223. BlockStatement: ['body'],
  224. BinaryExpression: ['left', 'right'],
  225. BreakStatement: ['label'],
  226. CallExpression: ['callee', 'arguments'],
  227. CatchClause: ['param', 'body'],
  228. ChainExpression: ['expression'],
  229. ClassBody: ['body'],
  230. ClassDeclaration: ['id', 'superClass', 'body'],
  231. ClassExpression: ['id', 'superClass', 'body'],
  232. ComprehensionBlock: ['left', 'right'],
  233. // CAUTION: It's deferred to ES7.
  234. ComprehensionExpression: ['blocks', 'filter', 'body'],
  235. // CAUTION: It's deferred to ES7.
  236. ConditionalExpression: ['test', 'consequent', 'alternate'],
  237. ContinueStatement: ['label'],
  238. DebuggerStatement: [],
  239. DirectiveStatement: [],
  240. DoWhileStatement: ['body', 'test'],
  241. EmptyStatement: [],
  242. ExportAllDeclaration: ['source'],
  243. ExportDefaultDeclaration: ['declaration'],
  244. ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
  245. ExportSpecifier: ['exported', 'local'],
  246. ExpressionStatement: ['expression'],
  247. ForStatement: ['init', 'test', 'update', 'body'],
  248. ForInStatement: ['left', 'right', 'body'],
  249. ForOfStatement: ['left', 'right', 'body'],
  250. FunctionDeclaration: ['id', 'params', 'body'],
  251. FunctionExpression: ['id', 'params', 'body'],
  252. GeneratorExpression: ['blocks', 'filter', 'body'],
  253. // CAUTION: It's deferred to ES7.
  254. Identifier: [],
  255. IfStatement: ['test', 'consequent', 'alternate'],
  256. ImportExpression: ['source'],
  257. ImportDeclaration: ['specifiers', 'source'],
  258. ImportDefaultSpecifier: ['local'],
  259. ImportNamespaceSpecifier: ['local'],
  260. ImportSpecifier: ['imported', 'local'],
  261. Literal: [],
  262. LabeledStatement: ['label', 'body'],
  263. LogicalExpression: ['left', 'right'],
  264. MemberExpression: ['object', 'property'],
  265. MetaProperty: ['meta', 'property'],
  266. MethodDefinition: ['key', 'value'],
  267. ModuleSpecifier: [],
  268. NewExpression: ['callee', 'arguments'],
  269. ObjectExpression: ['properties'],
  270. ObjectPattern: ['properties'],
  271. PrivateIdentifier: [],
  272. Program: ['body'],
  273. Property: ['key', 'value'],
  274. PropertyDefinition: ['key', 'value'],
  275. RestElement: ['argument'],
  276. ReturnStatement: ['argument'],
  277. SequenceExpression: ['expressions'],
  278. SpreadElement: ['argument'],
  279. Super: [],
  280. SwitchStatement: ['discriminant', 'cases'],
  281. SwitchCase: ['test', 'consequent'],
  282. TaggedTemplateExpression: ['tag', 'quasi'],
  283. TemplateElement: [],
  284. TemplateLiteral: ['quasis', 'expressions'],
  285. ThisExpression: [],
  286. ThrowStatement: ['argument'],
  287. TryStatement: ['block', 'handler', 'finalizer'],
  288. UnaryExpression: ['argument'],
  289. UpdateExpression: ['argument'],
  290. VariableDeclaration: ['declarations'],
  291. VariableDeclarator: ['id', 'init'],
  292. WhileStatement: ['test', 'body'],
  293. WithStatement: ['object', 'body'],
  294. YieldExpression: ['argument']
  295. };
  296. // unique id
  297. BREAK = {};
  298. SKIP = {};
  299. REMOVE = {};
  300. VisitorOption = {
  301. Break: BREAK,
  302. Skip: SKIP,
  303. Remove: REMOVE
  304. };
  305. function Reference(parent, key) {
  306. this.parent = parent;
  307. this.key = key;
  308. }
  309. Reference.prototype.replace = function replace(node) {
  310. this.parent[this.key] = node;
  311. };
  312. Reference.prototype.remove = function remove() {
  313. if (Array.isArray(this.parent)) {
  314. this.parent.splice(this.key, 1);
  315. return true;
  316. } else {
  317. this.replace(null);
  318. return false;
  319. }
  320. };
  321. function Element(node, path, wrap, ref) {
  322. this.node = node;
  323. this.path = path;
  324. this.wrap = wrap;
  325. this.ref = ref;
  326. }
  327. function Controller() {}
  328. // API:
  329. // return property path array from root to current node
  330. Controller.prototype.path = function path() {
  331. var i, iz, j, jz, result, element;
  332. function addToPath(result, path) {
  333. if (Array.isArray(path)) {
  334. for (j = 0, jz = path.length; j < jz; ++j) {
  335. result.push(path[j]);
  336. }
  337. } else {
  338. result.push(path);
  339. }
  340. }
  341. // root node
  342. if (!this.__current.path) {
  343. return null;
  344. }
  345. // first node is sentinel, second node is root element
  346. result = [];
  347. for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
  348. element = this.__leavelist[i];
  349. addToPath(result, element.path);
  350. }
  351. addToPath(result, this.__current.path);
  352. return result;
  353. };
  354. // API:
  355. // return type of current node
  356. Controller.prototype.type = function () {
  357. var node = this.current();
  358. return node.type || this.__current.wrap;
  359. };
  360. // API:
  361. // return array of parent elements
  362. Controller.prototype.parents = function parents() {
  363. var i, iz, result;
  364. // first node is sentinel
  365. result = [];
  366. for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
  367. result.push(this.__leavelist[i].node);
  368. }
  369. return result;
  370. };
  371. // API:
  372. // return current node
  373. Controller.prototype.current = function current() {
  374. return this.__current.node;
  375. };
  376. Controller.prototype.__execute = function __execute(callback, element) {
  377. var previous, result;
  378. result = undefined;
  379. previous = this.__current;
  380. this.__current = element;
  381. this.__state = null;
  382. if (callback) {
  383. result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
  384. }
  385. this.__current = previous;
  386. return result;
  387. };
  388. // API:
  389. // notify control skip / break
  390. Controller.prototype.notify = function notify(flag) {
  391. this.__state = flag;
  392. };
  393. // API:
  394. // skip child nodes of current node
  395. Controller.prototype.skip = function () {
  396. this.notify(SKIP);
  397. };
  398. // API:
  399. // break traversals
  400. Controller.prototype['break'] = function () {
  401. this.notify(BREAK);
  402. };
  403. // API:
  404. // remove node
  405. Controller.prototype.remove = function () {
  406. this.notify(REMOVE);
  407. };
  408. Controller.prototype.__initialize = function (root, visitor) {
  409. this.visitor = visitor;
  410. this.root = root;
  411. this.__worklist = [];
  412. this.__leavelist = [];
  413. this.__current = null;
  414. this.__state = null;
  415. this.__fallback = null;
  416. if (visitor.fallback === 'iteration') {
  417. this.__fallback = Object.keys;
  418. } else if (typeof visitor.fallback === 'function') {
  419. this.__fallback = visitor.fallback;
  420. }
  421. this.__keys = VisitorKeys;
  422. if (visitor.keys) {
  423. this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
  424. }
  425. };
  426. function isNode(node) {
  427. if (node == null) {
  428. return false;
  429. }
  430. return typeof node === 'object' && typeof node.type === 'string';
  431. }
  432. function isProperty(nodeType, key) {
  433. return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
  434. }
  435. function candidateExistsInLeaveList(leavelist, candidate) {
  436. for (var i = leavelist.length - 1; i >= 0; --i) {
  437. if (leavelist[i].node === candidate) {
  438. return true;
  439. }
  440. }
  441. return false;
  442. }
  443. Controller.prototype.traverse = function traverse(root, visitor) {
  444. var worklist, leavelist, element, node, nodeType, ret, key, current, current2, candidates, candidate, sentinel;
  445. this.__initialize(root, visitor);
  446. sentinel = {};
  447. // reference
  448. worklist = this.__worklist;
  449. leavelist = this.__leavelist;
  450. // initialize
  451. worklist.push(new Element(root, null, null, null));
  452. leavelist.push(new Element(null, null, null, null));
  453. while (worklist.length) {
  454. element = worklist.pop();
  455. if (element === sentinel) {
  456. element = leavelist.pop();
  457. ret = this.__execute(visitor.leave, element);
  458. if (this.__state === BREAK || ret === BREAK) {
  459. return;
  460. }
  461. continue;
  462. }
  463. if (element.node) {
  464. ret = this.__execute(visitor.enter, element);
  465. if (this.__state === BREAK || ret === BREAK) {
  466. return;
  467. }
  468. worklist.push(sentinel);
  469. leavelist.push(element);
  470. if (this.__state === SKIP || ret === SKIP) {
  471. continue;
  472. }
  473. node = element.node;
  474. nodeType = node.type || element.wrap;
  475. candidates = this.__keys[nodeType];
  476. if (!candidates) {
  477. if (this.__fallback) {
  478. candidates = this.__fallback(node);
  479. } else {
  480. throw new Error('Unknown node type ' + nodeType + '.');
  481. }
  482. }
  483. current = candidates.length;
  484. while ((current -= 1) >= 0) {
  485. key = candidates[current];
  486. candidate = node[key];
  487. if (!candidate) {
  488. continue;
  489. }
  490. if (Array.isArray(candidate)) {
  491. current2 = candidate.length;
  492. while ((current2 -= 1) >= 0) {
  493. if (!candidate[current2]) {
  494. continue;
  495. }
  496. if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
  497. continue;
  498. }
  499. if (isProperty(nodeType, candidates[current])) {
  500. element = new Element(candidate[current2], [key, current2], 'Property', null);
  501. } else if (isNode(candidate[current2])) {
  502. element = new Element(candidate[current2], [key, current2], null, null);
  503. } else {
  504. continue;
  505. }
  506. worklist.push(element);
  507. }
  508. } else if (isNode(candidate)) {
  509. if (candidateExistsInLeaveList(leavelist, candidate)) {
  510. continue;
  511. }
  512. worklist.push(new Element(candidate, key, null, null));
  513. }
  514. }
  515. }
  516. }
  517. };
  518. Controller.prototype.replace = function replace(root, visitor) {
  519. var worklist, leavelist, node, nodeType, target, element, current, current2, candidates, candidate, sentinel, outer, key;
  520. function removeElem(element) {
  521. var i, key, nextElem, parent;
  522. if (element.ref.remove()) {
  523. // When the reference is an element of an array.
  524. key = element.ref.key;
  525. parent = element.ref.parent;
  526. // If removed from array, then decrease following items' keys.
  527. i = worklist.length;
  528. while (i--) {
  529. nextElem = worklist[i];
  530. if (nextElem.ref && nextElem.ref.parent === parent) {
  531. if (nextElem.ref.key < key) {
  532. break;
  533. }
  534. --nextElem.ref.key;
  535. }
  536. }
  537. }
  538. }
  539. this.__initialize(root, visitor);
  540. sentinel = {};
  541. // reference
  542. worklist = this.__worklist;
  543. leavelist = this.__leavelist;
  544. // initialize
  545. outer = {
  546. root: root
  547. };
  548. element = new Element(root, null, null, new Reference(outer, 'root'));
  549. worklist.push(element);
  550. leavelist.push(element);
  551. while (worklist.length) {
  552. element = worklist.pop();
  553. if (element === sentinel) {
  554. element = leavelist.pop();
  555. target = this.__execute(visitor.leave, element);
  556. // node may be replaced with null,
  557. // so distinguish between undefined and null in this place
  558. if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
  559. // replace
  560. element.ref.replace(target);
  561. }
  562. if (this.__state === REMOVE || target === REMOVE) {
  563. removeElem(element);
  564. }
  565. if (this.__state === BREAK || target === BREAK) {
  566. return outer.root;
  567. }
  568. continue;
  569. }
  570. target = this.__execute(visitor.enter, element);
  571. // node may be replaced with null,
  572. // so distinguish between undefined and null in this place
  573. if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
  574. // replace
  575. element.ref.replace(target);
  576. element.node = target;
  577. }
  578. if (this.__state === REMOVE || target === REMOVE) {
  579. removeElem(element);
  580. element.node = null;
  581. }
  582. if (this.__state === BREAK || target === BREAK) {
  583. return outer.root;
  584. }
  585. // node may be null
  586. node = element.node;
  587. if (!node) {
  588. continue;
  589. }
  590. worklist.push(sentinel);
  591. leavelist.push(element);
  592. if (this.__state === SKIP || target === SKIP) {
  593. continue;
  594. }
  595. nodeType = node.type || element.wrap;
  596. candidates = this.__keys[nodeType];
  597. if (!candidates) {
  598. if (this.__fallback) {
  599. candidates = this.__fallback(node);
  600. } else {
  601. throw new Error('Unknown node type ' + nodeType + '.');
  602. }
  603. }
  604. current = candidates.length;
  605. while ((current -= 1) >= 0) {
  606. key = candidates[current];
  607. candidate = node[key];
  608. if (!candidate) {
  609. continue;
  610. }
  611. if (Array.isArray(candidate)) {
  612. current2 = candidate.length;
  613. while ((current2 -= 1) >= 0) {
  614. if (!candidate[current2]) {
  615. continue;
  616. }
  617. if (isProperty(nodeType, candidates[current])) {
  618. element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
  619. } else if (isNode(candidate[current2])) {
  620. element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
  621. } else {
  622. continue;
  623. }
  624. worklist.push(element);
  625. }
  626. } else if (isNode(candidate)) {
  627. worklist.push(new Element(candidate, key, null, new Reference(node, key)));
  628. }
  629. }
  630. }
  631. return outer.root;
  632. };
  633. function traverse(root, visitor) {
  634. var controller = new Controller();
  635. return controller.traverse(root, visitor);
  636. }
  637. function replace(root, visitor) {
  638. var controller = new Controller();
  639. return controller.replace(root, visitor);
  640. }
  641. function extendCommentRange(comment, tokens) {
  642. var target;
  643. target = upperBound(tokens, function search(token) {
  644. return token.range[0] > comment.range[0];
  645. });
  646. comment.extendedRange = [comment.range[0], comment.range[1]];
  647. if (target !== tokens.length) {
  648. comment.extendedRange[1] = tokens[target].range[0];
  649. }
  650. target -= 1;
  651. if (target >= 0) {
  652. comment.extendedRange[0] = tokens[target].range[1];
  653. }
  654. return comment;
  655. }
  656. function attachComments(tree, providedComments, tokens) {
  657. // At first, we should calculate extended comment ranges.
  658. var comments = [],
  659. comment,
  660. len,
  661. i,
  662. cursor;
  663. if (!tree.range) {
  664. throw new Error('attachComments needs range information');
  665. }
  666. // tokens array is empty, we attach comments to tree as 'leadingComments'
  667. if (!tokens.length) {
  668. if (providedComments.length) {
  669. for (i = 0, len = providedComments.length; i < len; i += 1) {
  670. comment = deepCopy(providedComments[i]);
  671. comment.extendedRange = [0, tree.range[0]];
  672. comments.push(comment);
  673. }
  674. tree.leadingComments = comments;
  675. }
  676. return tree;
  677. }
  678. for (i = 0, len = providedComments.length; i < len; i += 1) {
  679. comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
  680. }
  681. // This is based on John Freeman's implementation.
  682. cursor = 0;
  683. traverse(tree, {
  684. enter: function (node) {
  685. var comment;
  686. while (cursor < comments.length) {
  687. comment = comments[cursor];
  688. if (comment.extendedRange[1] > node.range[0]) {
  689. break;
  690. }
  691. if (comment.extendedRange[1] === node.range[0]) {
  692. if (!node.leadingComments) {
  693. node.leadingComments = [];
  694. }
  695. node.leadingComments.push(comment);
  696. comments.splice(cursor, 1);
  697. } else {
  698. cursor += 1;
  699. }
  700. }
  701. // already out of owned node
  702. if (cursor === comments.length) {
  703. return VisitorOption.Break;
  704. }
  705. if (comments[cursor].extendedRange[0] > node.range[1]) {
  706. return VisitorOption.Skip;
  707. }
  708. }
  709. });
  710. cursor = 0;
  711. traverse(tree, {
  712. leave: function (node) {
  713. var comment;
  714. while (cursor < comments.length) {
  715. comment = comments[cursor];
  716. if (node.range[1] < comment.extendedRange[0]) {
  717. break;
  718. }
  719. if (node.range[1] === comment.extendedRange[0]) {
  720. if (!node.trailingComments) {
  721. node.trailingComments = [];
  722. }
  723. node.trailingComments.push(comment);
  724. comments.splice(cursor, 1);
  725. } else {
  726. cursor += 1;
  727. }
  728. }
  729. // already out of owned node
  730. if (cursor === comments.length) {
  731. return VisitorOption.Break;
  732. }
  733. if (comments[cursor].extendedRange[0] > node.range[1]) {
  734. return VisitorOption.Skip;
  735. }
  736. }
  737. });
  738. return tree;
  739. }
  740. exports.Syntax = Syntax;
  741. exports.traverse = traverse;
  742. exports.replace = replace;
  743. exports.attachComments = attachComments;
  744. exports.VisitorKeys = VisitorKeys;
  745. exports.VisitorOption = VisitorOption;
  746. exports.Controller = Controller;
  747. exports.cloneEnvironment = function () {
  748. return clone({});
  749. };
  750. return exports;
  751. })(exports);
  752. /* vim: set sw=4 ts=4 et tw=80 : */
  753. });
  754. var parser = createCommonjsModule(function (module) {
  755. /*
  756. * Generated by PEG.js 0.10.0.
  757. *
  758. * http://pegjs.org/
  759. */
  760. (function (root, factory) {
  761. if ( module.exports) {
  762. module.exports = factory();
  763. }
  764. })(commonjsGlobal, function () {
  765. function peg$subclass(child, parent) {
  766. function ctor() {
  767. this.constructor = child;
  768. }
  769. ctor.prototype = parent.prototype;
  770. child.prototype = new ctor();
  771. }
  772. function peg$SyntaxError(message, expected, found, location) {
  773. this.message = message;
  774. this.expected = expected;
  775. this.found = found;
  776. this.location = location;
  777. this.name = "SyntaxError";
  778. if (typeof Error.captureStackTrace === "function") {
  779. Error.captureStackTrace(this, peg$SyntaxError);
  780. }
  781. }
  782. peg$subclass(peg$SyntaxError, Error);
  783. peg$SyntaxError.buildMessage = function (expected, found) {
  784. var DESCRIBE_EXPECTATION_FNS = {
  785. literal: function literal(expectation) {
  786. return "\"" + literalEscape(expectation.text) + "\"";
  787. },
  788. "class": function _class(expectation) {
  789. var escapedParts = "",
  790. i;
  791. for (i = 0; i < expectation.parts.length; i++) {
  792. escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
  793. }
  794. return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
  795. },
  796. any: function any(expectation) {
  797. return "any character";
  798. },
  799. end: function end(expectation) {
  800. return "end of input";
  801. },
  802. other: function other(expectation) {
  803. return expectation.description;
  804. }
  805. };
  806. function hex(ch) {
  807. return ch.charCodeAt(0).toString(16).toUpperCase();
  808. }
  809. function literalEscape(s) {
  810. return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
  811. return '\\x0' + hex(ch);
  812. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  813. return '\\x' + hex(ch);
  814. });
  815. }
  816. function classEscape(s) {
  817. return s.replace(/\\/g, '\\\\').replace(/\]/g, '\\]').replace(/\^/g, '\\^').replace(/-/g, '\\-').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
  818. return '\\x0' + hex(ch);
  819. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  820. return '\\x' + hex(ch);
  821. });
  822. }
  823. function describeExpectation(expectation) {
  824. return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
  825. }
  826. function describeExpected(expected) {
  827. var descriptions = new Array(expected.length),
  828. i,
  829. j;
  830. for (i = 0; i < expected.length; i++) {
  831. descriptions[i] = describeExpectation(expected[i]);
  832. }
  833. descriptions.sort();
  834. if (descriptions.length > 0) {
  835. for (i = 1, j = 1; i < descriptions.length; i++) {
  836. if (descriptions[i - 1] !== descriptions[i]) {
  837. descriptions[j] = descriptions[i];
  838. j++;
  839. }
  840. }
  841. descriptions.length = j;
  842. }
  843. switch (descriptions.length) {
  844. case 1:
  845. return descriptions[0];
  846. case 2:
  847. return descriptions[0] + " or " + descriptions[1];
  848. default:
  849. return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
  850. }
  851. }
  852. function describeFound(found) {
  853. return found ? "\"" + literalEscape(found) + "\"" : "end of input";
  854. }
  855. return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
  856. };
  857. function peg$parse(input, options) {
  858. options = options !== void 0 ? options : {};
  859. var peg$FAILED = {},
  860. peg$startRuleFunctions = {
  861. start: peg$parsestart
  862. },
  863. peg$startRuleFunction = peg$parsestart,
  864. peg$c0 = function peg$c0(ss) {
  865. return ss.length === 1 ? ss[0] : {
  866. type: 'matches',
  867. selectors: ss
  868. };
  869. },
  870. peg$c1 = function peg$c1() {
  871. return void 0;
  872. },
  873. peg$c2 = " ",
  874. peg$c3 = peg$literalExpectation(" ", false),
  875. peg$c4 = /^[^ [\],():#!=><~+.]/,
  876. peg$c5 = peg$classExpectation([" ", "[", "]", ",", "(", ")", ":", "#", "!", "=", ">", "<", "~", "+", "."], true, false),
  877. peg$c6 = function peg$c6(i) {
  878. return i.join('');
  879. },
  880. peg$c7 = ">",
  881. peg$c8 = peg$literalExpectation(">", false),
  882. peg$c9 = function peg$c9() {
  883. return 'child';
  884. },
  885. peg$c10 = "~",
  886. peg$c11 = peg$literalExpectation("~", false),
  887. peg$c12 = function peg$c12() {
  888. return 'sibling';
  889. },
  890. peg$c13 = "+",
  891. peg$c14 = peg$literalExpectation("+", false),
  892. peg$c15 = function peg$c15() {
  893. return 'adjacent';
  894. },
  895. peg$c16 = function peg$c16() {
  896. return 'descendant';
  897. },
  898. peg$c17 = ",",
  899. peg$c18 = peg$literalExpectation(",", false),
  900. peg$c19 = function peg$c19(s, ss) {
  901. return [s].concat(ss.map(function (s) {
  902. return s[3];
  903. }));
  904. },
  905. peg$c20 = function peg$c20(op, s) {
  906. if (!op) return s;
  907. return {
  908. type: op,
  909. left: {
  910. type: 'exactNode'
  911. },
  912. right: s
  913. };
  914. },
  915. peg$c21 = function peg$c21(a, ops) {
  916. return ops.reduce(function (memo, rhs) {
  917. return {
  918. type: rhs[0],
  919. left: memo,
  920. right: rhs[1]
  921. };
  922. }, a);
  923. },
  924. peg$c22 = "!",
  925. peg$c23 = peg$literalExpectation("!", false),
  926. peg$c24 = function peg$c24(subject, as) {
  927. var b = as.length === 1 ? as[0] : {
  928. type: 'compound',
  929. selectors: as
  930. };
  931. if (subject) b.subject = true;
  932. return b;
  933. },
  934. peg$c25 = "*",
  935. peg$c26 = peg$literalExpectation("*", false),
  936. peg$c27 = function peg$c27(a) {
  937. return {
  938. type: 'wildcard',
  939. value: a
  940. };
  941. },
  942. peg$c28 = "#",
  943. peg$c29 = peg$literalExpectation("#", false),
  944. peg$c30 = function peg$c30(i) {
  945. return {
  946. type: 'identifier',
  947. value: i
  948. };
  949. },
  950. peg$c31 = "[",
  951. peg$c32 = peg$literalExpectation("[", false),
  952. peg$c33 = "]",
  953. peg$c34 = peg$literalExpectation("]", false),
  954. peg$c35 = function peg$c35(v) {
  955. return v;
  956. },
  957. peg$c36 = /^[><!]/,
  958. peg$c37 = peg$classExpectation([">", "<", "!"], false, false),
  959. peg$c38 = "=",
  960. peg$c39 = peg$literalExpectation("=", false),
  961. peg$c40 = function peg$c40(a) {
  962. return (a || '') + '=';
  963. },
  964. peg$c41 = /^[><]/,
  965. peg$c42 = peg$classExpectation([">", "<"], false, false),
  966. peg$c43 = ".",
  967. peg$c44 = peg$literalExpectation(".", false),
  968. peg$c45 = function peg$c45(a, as) {
  969. return [].concat.apply([a], as).join('');
  970. },
  971. peg$c46 = function peg$c46(name, op, value) {
  972. return {
  973. type: 'attribute',
  974. name: name,
  975. operator: op,
  976. value: value
  977. };
  978. },
  979. peg$c47 = function peg$c47(name) {
  980. return {
  981. type: 'attribute',
  982. name: name
  983. };
  984. },
  985. peg$c48 = "\"",
  986. peg$c49 = peg$literalExpectation("\"", false),
  987. peg$c50 = /^[^\\"]/,
  988. peg$c51 = peg$classExpectation(["\\", "\""], true, false),
  989. peg$c52 = "\\",
  990. peg$c53 = peg$literalExpectation("\\", false),
  991. peg$c54 = peg$anyExpectation(),
  992. peg$c55 = function peg$c55(a, b) {
  993. return a + b;
  994. },
  995. peg$c56 = function peg$c56(d) {
  996. return {
  997. type: 'literal',
  998. value: strUnescape(d.join(''))
  999. };
  1000. },
  1001. peg$c57 = "'",
  1002. peg$c58 = peg$literalExpectation("'", false),
  1003. peg$c59 = /^[^\\']/,
  1004. peg$c60 = peg$classExpectation(["\\", "'"], true, false),
  1005. peg$c61 = /^[0-9]/,
  1006. peg$c62 = peg$classExpectation([["0", "9"]], false, false),
  1007. peg$c63 = function peg$c63(a, b) {
  1008. // Can use `a.flat().join('')` once supported
  1009. var leadingDecimals = a ? [].concat.apply([], a).join('') : '';
  1010. return {
  1011. type: 'literal',
  1012. value: parseFloat(leadingDecimals + b.join(''))
  1013. };
  1014. },
  1015. peg$c64 = function peg$c64(i) {
  1016. return {
  1017. type: 'literal',
  1018. value: i
  1019. };
  1020. },
  1021. peg$c65 = "type(",
  1022. peg$c66 = peg$literalExpectation("type(", false),
  1023. peg$c67 = /^[^ )]/,
  1024. peg$c68 = peg$classExpectation([" ", ")"], true, false),
  1025. peg$c69 = ")",
  1026. peg$c70 = peg$literalExpectation(")", false),
  1027. peg$c71 = function peg$c71(t) {
  1028. return {
  1029. type: 'type',
  1030. value: t.join('')
  1031. };
  1032. },
  1033. peg$c72 = /^[imsu]/,
  1034. peg$c73 = peg$classExpectation(["i", "m", "s", "u"], false, false),
  1035. peg$c74 = "/",
  1036. peg$c75 = peg$literalExpectation("/", false),
  1037. peg$c76 = function peg$c76(pattern, flgs) {
  1038. return {
  1039. type: 'regexp',
  1040. value: new RegExp(pattern.join(''), flgs ? flgs.join('') : '')
  1041. };
  1042. },
  1043. peg$c77 = /^[^\]\\]/,
  1044. peg$c78 = peg$classExpectation(["]", "\\"], true, false),
  1045. peg$c79 = function peg$c79(cs) {
  1046. return '[' + cs.join('') + ']';
  1047. },
  1048. peg$c80 = function peg$c80(a) {
  1049. return '\\' + a;
  1050. },
  1051. peg$c81 = /^[^\/\\[]/,
  1052. peg$c82 = peg$classExpectation(["/", "\\", "["], true, false),
  1053. peg$c83 = function peg$c83(cs) {
  1054. return cs.join('');
  1055. },
  1056. peg$c84 = function peg$c84(i, is) {
  1057. return {
  1058. type: 'field',
  1059. name: is.reduce(function (memo, p) {
  1060. return memo + p[0] + p[1];
  1061. }, i)
  1062. };
  1063. },
  1064. peg$c85 = ":not(",
  1065. peg$c86 = peg$literalExpectation(":not(", false),
  1066. peg$c87 = function peg$c87(ss) {
  1067. return {
  1068. type: 'not',
  1069. selectors: ss
  1070. };
  1071. },
  1072. peg$c88 = ":matches(",
  1073. peg$c89 = peg$literalExpectation(":matches(", false),
  1074. peg$c90 = function peg$c90(ss) {
  1075. return {
  1076. type: 'matches',
  1077. selectors: ss
  1078. };
  1079. },
  1080. peg$c91 = ":is(",
  1081. peg$c92 = peg$literalExpectation(":is(", false),
  1082. peg$c93 = ":has(",
  1083. peg$c94 = peg$literalExpectation(":has(", false),
  1084. peg$c95 = function peg$c95(ss) {
  1085. return {
  1086. type: 'has',
  1087. selectors: ss
  1088. };
  1089. },
  1090. peg$c96 = ":first-child",
  1091. peg$c97 = peg$literalExpectation(":first-child", false),
  1092. peg$c98 = function peg$c98() {
  1093. return nth(1);
  1094. },
  1095. peg$c99 = ":last-child",
  1096. peg$c100 = peg$literalExpectation(":last-child", false),
  1097. peg$c101 = function peg$c101() {
  1098. return nthLast(1);
  1099. },
  1100. peg$c102 = ":nth-child(",
  1101. peg$c103 = peg$literalExpectation(":nth-child(", false),
  1102. peg$c104 = function peg$c104(n) {
  1103. return nth(parseInt(n.join(''), 10));
  1104. },
  1105. peg$c105 = ":nth-last-child(",
  1106. peg$c106 = peg$literalExpectation(":nth-last-child(", false),
  1107. peg$c107 = function peg$c107(n) {
  1108. return nthLast(parseInt(n.join(''), 10));
  1109. },
  1110. peg$c108 = ":",
  1111. peg$c109 = peg$literalExpectation(":", false),
  1112. peg$c110 = function peg$c110(c) {
  1113. return {
  1114. type: 'class',
  1115. name: c
  1116. };
  1117. },
  1118. peg$currPos = 0,
  1119. peg$posDetailsCache = [{
  1120. line: 1,
  1121. column: 1
  1122. }],
  1123. peg$maxFailPos = 0,
  1124. peg$maxFailExpected = [],
  1125. peg$resultsCache = {},
  1126. peg$result;
  1127. if ("startRule" in options) {
  1128. if (!(options.startRule in peg$startRuleFunctions)) {
  1129. throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
  1130. }
  1131. peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  1132. }
  1133. function peg$literalExpectation(text, ignoreCase) {
  1134. return {
  1135. type: "literal",
  1136. text: text,
  1137. ignoreCase: ignoreCase
  1138. };
  1139. }
  1140. function peg$classExpectation(parts, inverted, ignoreCase) {
  1141. return {
  1142. type: "class",
  1143. parts: parts,
  1144. inverted: inverted,
  1145. ignoreCase: ignoreCase
  1146. };
  1147. }
  1148. function peg$anyExpectation() {
  1149. return {
  1150. type: "any"
  1151. };
  1152. }
  1153. function peg$endExpectation() {
  1154. return {
  1155. type: "end"
  1156. };
  1157. }
  1158. function peg$computePosDetails(pos) {
  1159. var details = peg$posDetailsCache[pos],
  1160. p;
  1161. if (details) {
  1162. return details;
  1163. } else {
  1164. p = pos - 1;
  1165. while (!peg$posDetailsCache[p]) {
  1166. p--;
  1167. }
  1168. details = peg$posDetailsCache[p];
  1169. details = {
  1170. line: details.line,
  1171. column: details.column
  1172. };
  1173. while (p < pos) {
  1174. if (input.charCodeAt(p) === 10) {
  1175. details.line++;
  1176. details.column = 1;
  1177. } else {
  1178. details.column++;
  1179. }
  1180. p++;
  1181. }
  1182. peg$posDetailsCache[pos] = details;
  1183. return details;
  1184. }
  1185. }
  1186. function peg$computeLocation(startPos, endPos) {
  1187. var startPosDetails = peg$computePosDetails(startPos),
  1188. endPosDetails = peg$computePosDetails(endPos);
  1189. return {
  1190. start: {
  1191. offset: startPos,
  1192. line: startPosDetails.line,
  1193. column: startPosDetails.column
  1194. },
  1195. end: {
  1196. offset: endPos,
  1197. line: endPosDetails.line,
  1198. column: endPosDetails.column
  1199. }
  1200. };
  1201. }
  1202. function peg$fail(expected) {
  1203. if (peg$currPos < peg$maxFailPos) {
  1204. return;
  1205. }
  1206. if (peg$currPos > peg$maxFailPos) {
  1207. peg$maxFailPos = peg$currPos;
  1208. peg$maxFailExpected = [];
  1209. }
  1210. peg$maxFailExpected.push(expected);
  1211. }
  1212. function peg$buildStructuredError(expected, found, location) {
  1213. return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
  1214. }
  1215. function peg$parsestart() {
  1216. var s0, s1, s2, s3;
  1217. var key = peg$currPos * 36 + 0,
  1218. cached = peg$resultsCache[key];
  1219. if (cached) {
  1220. peg$currPos = cached.nextPos;
  1221. return cached.result;
  1222. }
  1223. s0 = peg$currPos;
  1224. s1 = peg$parse_();
  1225. if (s1 !== peg$FAILED) {
  1226. s2 = peg$parseselectors();
  1227. if (s2 !== peg$FAILED) {
  1228. s3 = peg$parse_();
  1229. if (s3 !== peg$FAILED) {
  1230. s1 = peg$c0(s2);
  1231. s0 = s1;
  1232. } else {
  1233. peg$currPos = s0;
  1234. s0 = peg$FAILED;
  1235. }
  1236. } else {
  1237. peg$currPos = s0;
  1238. s0 = peg$FAILED;
  1239. }
  1240. } else {
  1241. peg$currPos = s0;
  1242. s0 = peg$FAILED;
  1243. }
  1244. if (s0 === peg$FAILED) {
  1245. s0 = peg$currPos;
  1246. s1 = peg$parse_();
  1247. if (s1 !== peg$FAILED) {
  1248. s1 = peg$c1();
  1249. }
  1250. s0 = s1;
  1251. }
  1252. peg$resultsCache[key] = {
  1253. nextPos: peg$currPos,
  1254. result: s0
  1255. };
  1256. return s0;
  1257. }
  1258. function peg$parse_() {
  1259. var s0, s1;
  1260. var key = peg$currPos * 36 + 1,
  1261. cached = peg$resultsCache[key];
  1262. if (cached) {
  1263. peg$currPos = cached.nextPos;
  1264. return cached.result;
  1265. }
  1266. s0 = [];
  1267. if (input.charCodeAt(peg$currPos) === 32) {
  1268. s1 = peg$c2;
  1269. peg$currPos++;
  1270. } else {
  1271. s1 = peg$FAILED;
  1272. {
  1273. peg$fail(peg$c3);
  1274. }
  1275. }
  1276. while (s1 !== peg$FAILED) {
  1277. s0.push(s1);
  1278. if (input.charCodeAt(peg$currPos) === 32) {
  1279. s1 = peg$c2;
  1280. peg$currPos++;
  1281. } else {
  1282. s1 = peg$FAILED;
  1283. {
  1284. peg$fail(peg$c3);
  1285. }
  1286. }
  1287. }
  1288. peg$resultsCache[key] = {
  1289. nextPos: peg$currPos,
  1290. result: s0
  1291. };
  1292. return s0;
  1293. }
  1294. function peg$parseidentifierName() {
  1295. var s0, s1, s2;
  1296. var key = peg$currPos * 36 + 2,
  1297. cached = peg$resultsCache[key];
  1298. if (cached) {
  1299. peg$currPos = cached.nextPos;
  1300. return cached.result;
  1301. }
  1302. s0 = peg$currPos;
  1303. s1 = [];
  1304. if (peg$c4.test(input.charAt(peg$currPos))) {
  1305. s2 = input.charAt(peg$currPos);
  1306. peg$currPos++;
  1307. } else {
  1308. s2 = peg$FAILED;
  1309. {
  1310. peg$fail(peg$c5);
  1311. }
  1312. }
  1313. if (s2 !== peg$FAILED) {
  1314. while (s2 !== peg$FAILED) {
  1315. s1.push(s2);
  1316. if (peg$c4.test(input.charAt(peg$currPos))) {
  1317. s2 = input.charAt(peg$currPos);
  1318. peg$currPos++;
  1319. } else {
  1320. s2 = peg$FAILED;
  1321. {
  1322. peg$fail(peg$c5);
  1323. }
  1324. }
  1325. }
  1326. } else {
  1327. s1 = peg$FAILED;
  1328. }
  1329. if (s1 !== peg$FAILED) {
  1330. s1 = peg$c6(s1);
  1331. }
  1332. s0 = s1;
  1333. peg$resultsCache[key] = {
  1334. nextPos: peg$currPos,
  1335. result: s0
  1336. };
  1337. return s0;
  1338. }
  1339. function peg$parsebinaryOp() {
  1340. var s0, s1, s2, s3;
  1341. var key = peg$currPos * 36 + 3,
  1342. cached = peg$resultsCache[key];
  1343. if (cached) {
  1344. peg$currPos = cached.nextPos;
  1345. return cached.result;
  1346. }
  1347. s0 = peg$currPos;
  1348. s1 = peg$parse_();
  1349. if (s1 !== peg$FAILED) {
  1350. if (input.charCodeAt(peg$currPos) === 62) {
  1351. s2 = peg$c7;
  1352. peg$currPos++;
  1353. } else {
  1354. s2 = peg$FAILED;
  1355. {
  1356. peg$fail(peg$c8);
  1357. }
  1358. }
  1359. if (s2 !== peg$FAILED) {
  1360. s3 = peg$parse_();
  1361. if (s3 !== peg$FAILED) {
  1362. s1 = peg$c9();
  1363. s0 = s1;
  1364. } else {
  1365. peg$currPos = s0;
  1366. s0 = peg$FAILED;
  1367. }
  1368. } else {
  1369. peg$currPos = s0;
  1370. s0 = peg$FAILED;
  1371. }
  1372. } else {
  1373. peg$currPos = s0;
  1374. s0 = peg$FAILED;
  1375. }
  1376. if (s0 === peg$FAILED) {
  1377. s0 = peg$currPos;
  1378. s1 = peg$parse_();
  1379. if (s1 !== peg$FAILED) {
  1380. if (input.charCodeAt(peg$currPos) === 126) {
  1381. s2 = peg$c10;
  1382. peg$currPos++;
  1383. } else {
  1384. s2 = peg$FAILED;
  1385. {
  1386. peg$fail(peg$c11);
  1387. }
  1388. }
  1389. if (s2 !== peg$FAILED) {
  1390. s3 = peg$parse_();
  1391. if (s3 !== peg$FAILED) {
  1392. s1 = peg$c12();
  1393. s0 = s1;
  1394. } else {
  1395. peg$currPos = s0;
  1396. s0 = peg$FAILED;
  1397. }
  1398. } else {
  1399. peg$currPos = s0;
  1400. s0 = peg$FAILED;
  1401. }
  1402. } else {
  1403. peg$currPos = s0;
  1404. s0 = peg$FAILED;
  1405. }
  1406. if (s0 === peg$FAILED) {
  1407. s0 = peg$currPos;
  1408. s1 = peg$parse_();
  1409. if (s1 !== peg$FAILED) {
  1410. if (input.charCodeAt(peg$currPos) === 43) {
  1411. s2 = peg$c13;
  1412. peg$currPos++;
  1413. } else {
  1414. s2 = peg$FAILED;
  1415. {
  1416. peg$fail(peg$c14);
  1417. }
  1418. }
  1419. if (s2 !== peg$FAILED) {
  1420. s3 = peg$parse_();
  1421. if (s3 !== peg$FAILED) {
  1422. s1 = peg$c15();
  1423. s0 = s1;
  1424. } else {
  1425. peg$currPos = s0;
  1426. s0 = peg$FAILED;
  1427. }
  1428. } else {
  1429. peg$currPos = s0;
  1430. s0 = peg$FAILED;
  1431. }
  1432. } else {
  1433. peg$currPos = s0;
  1434. s0 = peg$FAILED;
  1435. }
  1436. if (s0 === peg$FAILED) {
  1437. s0 = peg$currPos;
  1438. if (input.charCodeAt(peg$currPos) === 32) {
  1439. s1 = peg$c2;
  1440. peg$currPos++;
  1441. } else {
  1442. s1 = peg$FAILED;
  1443. {
  1444. peg$fail(peg$c3);
  1445. }
  1446. }
  1447. if (s1 !== peg$FAILED) {
  1448. s2 = peg$parse_();
  1449. if (s2 !== peg$FAILED) {
  1450. s1 = peg$c16();
  1451. s0 = s1;
  1452. } else {
  1453. peg$currPos = s0;
  1454. s0 = peg$FAILED;
  1455. }
  1456. } else {
  1457. peg$currPos = s0;
  1458. s0 = peg$FAILED;
  1459. }
  1460. }
  1461. }
  1462. }
  1463. peg$resultsCache[key] = {
  1464. nextPos: peg$currPos,
  1465. result: s0
  1466. };
  1467. return s0;
  1468. }
  1469. function peg$parsehasSelectors() {
  1470. var s0, s1, s2, s3, s4, s5, s6, s7;
  1471. var key = peg$currPos * 36 + 4,
  1472. cached = peg$resultsCache[key];
  1473. if (cached) {
  1474. peg$currPos = cached.nextPos;
  1475. return cached.result;
  1476. }
  1477. s0 = peg$currPos;
  1478. s1 = peg$parsehasSelector();
  1479. if (s1 !== peg$FAILED) {
  1480. s2 = [];
  1481. s3 = peg$currPos;
  1482. s4 = peg$parse_();
  1483. if (s4 !== peg$FAILED) {
  1484. if (input.charCodeAt(peg$currPos) === 44) {
  1485. s5 = peg$c17;
  1486. peg$currPos++;
  1487. } else {
  1488. s5 = peg$FAILED;
  1489. {
  1490. peg$fail(peg$c18);
  1491. }
  1492. }
  1493. if (s5 !== peg$FAILED) {
  1494. s6 = peg$parse_();
  1495. if (s6 !== peg$FAILED) {
  1496. s7 = peg$parsehasSelector();
  1497. if (s7 !== peg$FAILED) {
  1498. s4 = [s4, s5, s6, s7];
  1499. s3 = s4;
  1500. } else {
  1501. peg$currPos = s3;
  1502. s3 = peg$FAILED;
  1503. }
  1504. } else {
  1505. peg$currPos = s3;
  1506. s3 = peg$FAILED;
  1507. }
  1508. } else {
  1509. peg$currPos = s3;
  1510. s3 = peg$FAILED;
  1511. }
  1512. } else {
  1513. peg$currPos = s3;
  1514. s3 = peg$FAILED;
  1515. }
  1516. while (s3 !== peg$FAILED) {
  1517. s2.push(s3);
  1518. s3 = peg$currPos;
  1519. s4 = peg$parse_();
  1520. if (s4 !== peg$FAILED) {
  1521. if (input.charCodeAt(peg$currPos) === 44) {
  1522. s5 = peg$c17;
  1523. peg$currPos++;
  1524. } else {
  1525. s5 = peg$FAILED;
  1526. {
  1527. peg$fail(peg$c18);
  1528. }
  1529. }
  1530. if (s5 !== peg$FAILED) {
  1531. s6 = peg$parse_();
  1532. if (s6 !== peg$FAILED) {
  1533. s7 = peg$parsehasSelector();
  1534. if (s7 !== peg$FAILED) {
  1535. s4 = [s4, s5, s6, s7];
  1536. s3 = s4;
  1537. } else {
  1538. peg$currPos = s3;
  1539. s3 = peg$FAILED;
  1540. }
  1541. } else {
  1542. peg$currPos = s3;
  1543. s3 = peg$FAILED;
  1544. }
  1545. } else {
  1546. peg$currPos = s3;
  1547. s3 = peg$FAILED;
  1548. }
  1549. } else {
  1550. peg$currPos = s3;
  1551. s3 = peg$FAILED;
  1552. }
  1553. }
  1554. if (s2 !== peg$FAILED) {
  1555. s1 = peg$c19(s1, s2);
  1556. s0 = s1;
  1557. } else {
  1558. peg$currPos = s0;
  1559. s0 = peg$FAILED;
  1560. }
  1561. } else {
  1562. peg$currPos = s0;
  1563. s0 = peg$FAILED;
  1564. }
  1565. peg$resultsCache[key] = {
  1566. nextPos: peg$currPos,
  1567. result: s0
  1568. };
  1569. return s0;
  1570. }
  1571. function peg$parseselectors() {
  1572. var s0, s1, s2, s3, s4, s5, s6, s7;
  1573. var key = peg$currPos * 36 + 5,
  1574. cached = peg$resultsCache[key];
  1575. if (cached) {
  1576. peg$currPos = cached.nextPos;
  1577. return cached.result;
  1578. }
  1579. s0 = peg$currPos;
  1580. s1 = peg$parseselector();
  1581. if (s1 !== peg$FAILED) {
  1582. s2 = [];
  1583. s3 = peg$currPos;
  1584. s4 = peg$parse_();
  1585. if (s4 !== peg$FAILED) {
  1586. if (input.charCodeAt(peg$currPos) === 44) {
  1587. s5 = peg$c17;
  1588. peg$currPos++;
  1589. } else {
  1590. s5 = peg$FAILED;
  1591. {
  1592. peg$fail(peg$c18);
  1593. }
  1594. }
  1595. if (s5 !== peg$FAILED) {
  1596. s6 = peg$parse_();
  1597. if (s6 !== peg$FAILED) {
  1598. s7 = peg$parseselector();
  1599. if (s7 !== peg$FAILED) {
  1600. s4 = [s4, s5, s6, s7];
  1601. s3 = s4;
  1602. } else {
  1603. peg$currPos = s3;
  1604. s3 = peg$FAILED;
  1605. }
  1606. } else {
  1607. peg$currPos = s3;
  1608. s3 = peg$FAILED;
  1609. }
  1610. } else {
  1611. peg$currPos = s3;
  1612. s3 = peg$FAILED;
  1613. }
  1614. } else {
  1615. peg$currPos = s3;
  1616. s3 = peg$FAILED;
  1617. }
  1618. while (s3 !== peg$FAILED) {
  1619. s2.push(s3);
  1620. s3 = peg$currPos;
  1621. s4 = peg$parse_();
  1622. if (s4 !== peg$FAILED) {
  1623. if (input.charCodeAt(peg$currPos) === 44) {
  1624. s5 = peg$c17;
  1625. peg$currPos++;
  1626. } else {
  1627. s5 = peg$FAILED;
  1628. {
  1629. peg$fail(peg$c18);
  1630. }
  1631. }
  1632. if (s5 !== peg$FAILED) {
  1633. s6 = peg$parse_();
  1634. if (s6 !== peg$FAILED) {
  1635. s7 = peg$parseselector();
  1636. if (s7 !== peg$FAILED) {
  1637. s4 = [s4, s5, s6, s7];
  1638. s3 = s4;
  1639. } else {
  1640. peg$currPos = s3;
  1641. s3 = peg$FAILED;
  1642. }
  1643. } else {
  1644. peg$currPos = s3;
  1645. s3 = peg$FAILED;
  1646. }
  1647. } else {
  1648. peg$currPos = s3;
  1649. s3 = peg$FAILED;
  1650. }
  1651. } else {
  1652. peg$currPos = s3;
  1653. s3 = peg$FAILED;
  1654. }
  1655. }
  1656. if (s2 !== peg$FAILED) {
  1657. s1 = peg$c19(s1, s2);
  1658. s0 = s1;
  1659. } else {
  1660. peg$currPos = s0;
  1661. s0 = peg$FAILED;
  1662. }
  1663. } else {
  1664. peg$currPos = s0;
  1665. s0 = peg$FAILED;
  1666. }
  1667. peg$resultsCache[key] = {
  1668. nextPos: peg$currPos,
  1669. result: s0
  1670. };
  1671. return s0;
  1672. }
  1673. function peg$parsehasSelector() {
  1674. var s0, s1, s2;
  1675. var key = peg$currPos * 36 + 6,
  1676. cached = peg$resultsCache[key];
  1677. if (cached) {
  1678. peg$currPos = cached.nextPos;
  1679. return cached.result;
  1680. }
  1681. s0 = peg$currPos;
  1682. s1 = peg$parsebinaryOp();
  1683. if (s1 === peg$FAILED) {
  1684. s1 = null;
  1685. }
  1686. if (s1 !== peg$FAILED) {
  1687. s2 = peg$parseselector();
  1688. if (s2 !== peg$FAILED) {
  1689. s1 = peg$c20(s1, s2);
  1690. s0 = s1;
  1691. } else {
  1692. peg$currPos = s0;
  1693. s0 = peg$FAILED;
  1694. }
  1695. } else {
  1696. peg$currPos = s0;
  1697. s0 = peg$FAILED;
  1698. }
  1699. peg$resultsCache[key] = {
  1700. nextPos: peg$currPos,
  1701. result: s0
  1702. };
  1703. return s0;
  1704. }
  1705. function peg$parseselector() {
  1706. var s0, s1, s2, s3, s4, s5;
  1707. var key = peg$currPos * 36 + 7,
  1708. cached = peg$resultsCache[key];
  1709. if (cached) {
  1710. peg$currPos = cached.nextPos;
  1711. return cached.result;
  1712. }
  1713. s0 = peg$currPos;
  1714. s1 = peg$parsesequence();
  1715. if (s1 !== peg$FAILED) {
  1716. s2 = [];
  1717. s3 = peg$currPos;
  1718. s4 = peg$parsebinaryOp();
  1719. if (s4 !== peg$FAILED) {
  1720. s5 = peg$parsesequence();
  1721. if (s5 !== peg$FAILED) {
  1722. s4 = [s4, s5];
  1723. s3 = s4;
  1724. } else {
  1725. peg$currPos = s3;
  1726. s3 = peg$FAILED;
  1727. }
  1728. } else {
  1729. peg$currPos = s3;
  1730. s3 = peg$FAILED;
  1731. }
  1732. while (s3 !== peg$FAILED) {
  1733. s2.push(s3);
  1734. s3 = peg$currPos;
  1735. s4 = peg$parsebinaryOp();
  1736. if (s4 !== peg$FAILED) {
  1737. s5 = peg$parsesequence();
  1738. if (s5 !== peg$FAILED) {
  1739. s4 = [s4, s5];
  1740. s3 = s4;
  1741. } else {
  1742. peg$currPos = s3;
  1743. s3 = peg$FAILED;
  1744. }
  1745. } else {
  1746. peg$currPos = s3;
  1747. s3 = peg$FAILED;
  1748. }
  1749. }
  1750. if (s2 !== peg$FAILED) {
  1751. s1 = peg$c21(s1, s2);
  1752. s0 = s1;
  1753. } else {
  1754. peg$currPos = s0;
  1755. s0 = peg$FAILED;
  1756. }
  1757. } else {
  1758. peg$currPos = s0;
  1759. s0 = peg$FAILED;
  1760. }
  1761. peg$resultsCache[key] = {
  1762. nextPos: peg$currPos,
  1763. result: s0
  1764. };
  1765. return s0;
  1766. }
  1767. function peg$parsesequence() {
  1768. var s0, s1, s2, s3;
  1769. var key = peg$currPos * 36 + 8,
  1770. cached = peg$resultsCache[key];
  1771. if (cached) {
  1772. peg$currPos = cached.nextPos;
  1773. return cached.result;
  1774. }
  1775. s0 = peg$currPos;
  1776. if (input.charCodeAt(peg$currPos) === 33) {
  1777. s1 = peg$c22;
  1778. peg$currPos++;
  1779. } else {
  1780. s1 = peg$FAILED;
  1781. {
  1782. peg$fail(peg$c23);
  1783. }
  1784. }
  1785. if (s1 === peg$FAILED) {
  1786. s1 = null;
  1787. }
  1788. if (s1 !== peg$FAILED) {
  1789. s2 = [];
  1790. s3 = peg$parseatom();
  1791. if (s3 !== peg$FAILED) {
  1792. while (s3 !== peg$FAILED) {
  1793. s2.push(s3);
  1794. s3 = peg$parseatom();
  1795. }
  1796. } else {
  1797. s2 = peg$FAILED;
  1798. }
  1799. if (s2 !== peg$FAILED) {
  1800. s1 = peg$c24(s1, s2);
  1801. s0 = s1;
  1802. } else {
  1803. peg$currPos = s0;
  1804. s0 = peg$FAILED;
  1805. }
  1806. } else {
  1807. peg$currPos = s0;
  1808. s0 = peg$FAILED;
  1809. }
  1810. peg$resultsCache[key] = {
  1811. nextPos: peg$currPos,
  1812. result: s0
  1813. };
  1814. return s0;
  1815. }
  1816. function peg$parseatom() {
  1817. var s0;
  1818. var key = peg$currPos * 36 + 9,
  1819. cached = peg$resultsCache[key];
  1820. if (cached) {
  1821. peg$currPos = cached.nextPos;
  1822. return cached.result;
  1823. }
  1824. s0 = peg$parsewildcard();
  1825. if (s0 === peg$FAILED) {
  1826. s0 = peg$parseidentifier();
  1827. if (s0 === peg$FAILED) {
  1828. s0 = peg$parseattr();
  1829. if (s0 === peg$FAILED) {
  1830. s0 = peg$parsefield();
  1831. if (s0 === peg$FAILED) {
  1832. s0 = peg$parsenegation();
  1833. if (s0 === peg$FAILED) {
  1834. s0 = peg$parsematches();
  1835. if (s0 === peg$FAILED) {
  1836. s0 = peg$parseis();
  1837. if (s0 === peg$FAILED) {
  1838. s0 = peg$parsehas();
  1839. if (s0 === peg$FAILED) {
  1840. s0 = peg$parsefirstChild();
  1841. if (s0 === peg$FAILED) {
  1842. s0 = peg$parselastChild();
  1843. if (s0 === peg$FAILED) {
  1844. s0 = peg$parsenthChild();
  1845. if (s0 === peg$FAILED) {
  1846. s0 = peg$parsenthLastChild();
  1847. if (s0 === peg$FAILED) {
  1848. s0 = peg$parseclass();
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. peg$resultsCache[key] = {
  1862. nextPos: peg$currPos,
  1863. result: s0
  1864. };
  1865. return s0;
  1866. }
  1867. function peg$parsewildcard() {
  1868. var s0, s1;
  1869. var key = peg$currPos * 36 + 10,
  1870. cached = peg$resultsCache[key];
  1871. if (cached) {
  1872. peg$currPos = cached.nextPos;
  1873. return cached.result;
  1874. }
  1875. s0 = peg$currPos;
  1876. if (input.charCodeAt(peg$currPos) === 42) {
  1877. s1 = peg$c25;
  1878. peg$currPos++;
  1879. } else {
  1880. s1 = peg$FAILED;
  1881. {
  1882. peg$fail(peg$c26);
  1883. }
  1884. }
  1885. if (s1 !== peg$FAILED) {
  1886. s1 = peg$c27(s1);
  1887. }
  1888. s0 = s1;
  1889. peg$resultsCache[key] = {
  1890. nextPos: peg$currPos,
  1891. result: s0
  1892. };
  1893. return s0;
  1894. }
  1895. function peg$parseidentifier() {
  1896. var s0, s1, s2;
  1897. var key = peg$currPos * 36 + 11,
  1898. cached = peg$resultsCache[key];
  1899. if (cached) {
  1900. peg$currPos = cached.nextPos;
  1901. return cached.result;
  1902. }
  1903. s0 = peg$currPos;
  1904. if (input.charCodeAt(peg$currPos) === 35) {
  1905. s1 = peg$c28;
  1906. peg$currPos++;
  1907. } else {
  1908. s1 = peg$FAILED;
  1909. {
  1910. peg$fail(peg$c29);
  1911. }
  1912. }
  1913. if (s1 === peg$FAILED) {
  1914. s1 = null;
  1915. }
  1916. if (s1 !== peg$FAILED) {
  1917. s2 = peg$parseidentifierName();
  1918. if (s2 !== peg$FAILED) {
  1919. s1 = peg$c30(s2);
  1920. s0 = s1;
  1921. } else {
  1922. peg$currPos = s0;
  1923. s0 = peg$FAILED;
  1924. }
  1925. } else {
  1926. peg$currPos = s0;
  1927. s0 = peg$FAILED;
  1928. }
  1929. peg$resultsCache[key] = {
  1930. nextPos: peg$currPos,
  1931. result: s0
  1932. };
  1933. return s0;
  1934. }
  1935. function peg$parseattr() {
  1936. var s0, s1, s2, s3, s4, s5;
  1937. var key = peg$currPos * 36 + 12,
  1938. cached = peg$resultsCache[key];
  1939. if (cached) {
  1940. peg$currPos = cached.nextPos;
  1941. return cached.result;
  1942. }
  1943. s0 = peg$currPos;
  1944. if (input.charCodeAt(peg$currPos) === 91) {
  1945. s1 = peg$c31;
  1946. peg$currPos++;
  1947. } else {
  1948. s1 = peg$FAILED;
  1949. {
  1950. peg$fail(peg$c32);
  1951. }
  1952. }
  1953. if (s1 !== peg$FAILED) {
  1954. s2 = peg$parse_();
  1955. if (s2 !== peg$FAILED) {
  1956. s3 = peg$parseattrValue();
  1957. if (s3 !== peg$FAILED) {
  1958. s4 = peg$parse_();
  1959. if (s4 !== peg$FAILED) {
  1960. if (input.charCodeAt(peg$currPos) === 93) {
  1961. s5 = peg$c33;
  1962. peg$currPos++;
  1963. } else {
  1964. s5 = peg$FAILED;
  1965. {
  1966. peg$fail(peg$c34);
  1967. }
  1968. }
  1969. if (s5 !== peg$FAILED) {
  1970. s1 = peg$c35(s3);
  1971. s0 = s1;
  1972. } else {
  1973. peg$currPos = s0;
  1974. s0 = peg$FAILED;
  1975. }
  1976. } else {
  1977. peg$currPos = s0;
  1978. s0 = peg$FAILED;
  1979. }
  1980. } else {
  1981. peg$currPos = s0;
  1982. s0 = peg$FAILED;
  1983. }
  1984. } else {
  1985. peg$currPos = s0;
  1986. s0 = peg$FAILED;
  1987. }
  1988. } else {
  1989. peg$currPos = s0;
  1990. s0 = peg$FAILED;
  1991. }
  1992. peg$resultsCache[key] = {
  1993. nextPos: peg$currPos,
  1994. result: s0
  1995. };
  1996. return s0;
  1997. }
  1998. function peg$parseattrOps() {
  1999. var s0, s1, s2;
  2000. var key = peg$currPos * 36 + 13,
  2001. cached = peg$resultsCache[key];
  2002. if (cached) {
  2003. peg$currPos = cached.nextPos;
  2004. return cached.result;
  2005. }
  2006. s0 = peg$currPos;
  2007. if (peg$c36.test(input.charAt(peg$currPos))) {
  2008. s1 = input.charAt(peg$currPos);
  2009. peg$currPos++;
  2010. } else {
  2011. s1 = peg$FAILED;
  2012. {
  2013. peg$fail(peg$c37);
  2014. }
  2015. }
  2016. if (s1 === peg$FAILED) {
  2017. s1 = null;
  2018. }
  2019. if (s1 !== peg$FAILED) {
  2020. if (input.charCodeAt(peg$currPos) === 61) {
  2021. s2 = peg$c38;
  2022. peg$currPos++;
  2023. } else {
  2024. s2 = peg$FAILED;
  2025. {
  2026. peg$fail(peg$c39);
  2027. }
  2028. }
  2029. if (s2 !== peg$FAILED) {
  2030. s1 = peg$c40(s1);
  2031. s0 = s1;
  2032. } else {
  2033. peg$currPos = s0;
  2034. s0 = peg$FAILED;
  2035. }
  2036. } else {
  2037. peg$currPos = s0;
  2038. s0 = peg$FAILED;
  2039. }
  2040. if (s0 === peg$FAILED) {
  2041. if (peg$c41.test(input.charAt(peg$currPos))) {
  2042. s0 = input.charAt(peg$currPos);
  2043. peg$currPos++;
  2044. } else {
  2045. s0 = peg$FAILED;
  2046. {
  2047. peg$fail(peg$c42);
  2048. }
  2049. }
  2050. }
  2051. peg$resultsCache[key] = {
  2052. nextPos: peg$currPos,
  2053. result: s0
  2054. };
  2055. return s0;
  2056. }
  2057. function peg$parseattrEqOps() {
  2058. var s0, s1, s2;
  2059. var key = peg$currPos * 36 + 14,
  2060. cached = peg$resultsCache[key];
  2061. if (cached) {
  2062. peg$currPos = cached.nextPos;
  2063. return cached.result;
  2064. }
  2065. s0 = peg$currPos;
  2066. if (input.charCodeAt(peg$currPos) === 33) {
  2067. s1 = peg$c22;
  2068. peg$currPos++;
  2069. } else {
  2070. s1 = peg$FAILED;
  2071. {
  2072. peg$fail(peg$c23);
  2073. }
  2074. }
  2075. if (s1 === peg$FAILED) {
  2076. s1 = null;
  2077. }
  2078. if (s1 !== peg$FAILED) {
  2079. if (input.charCodeAt(peg$currPos) === 61) {
  2080. s2 = peg$c38;
  2081. peg$currPos++;
  2082. } else {
  2083. s2 = peg$FAILED;
  2084. {
  2085. peg$fail(peg$c39);
  2086. }
  2087. }
  2088. if (s2 !== peg$FAILED) {
  2089. s1 = peg$c40(s1);
  2090. s0 = s1;
  2091. } else {
  2092. peg$currPos = s0;
  2093. s0 = peg$FAILED;
  2094. }
  2095. } else {
  2096. peg$currPos = s0;
  2097. s0 = peg$FAILED;
  2098. }
  2099. peg$resultsCache[key] = {
  2100. nextPos: peg$currPos,
  2101. result: s0
  2102. };
  2103. return s0;
  2104. }
  2105. function peg$parseattrName() {
  2106. var s0, s1, s2, s3, s4, s5;
  2107. var key = peg$currPos * 36 + 15,
  2108. cached = peg$resultsCache[key];
  2109. if (cached) {
  2110. peg$currPos = cached.nextPos;
  2111. return cached.result;
  2112. }
  2113. s0 = peg$currPos;
  2114. s1 = peg$parseidentifierName();
  2115. if (s1 !== peg$FAILED) {
  2116. s2 = [];
  2117. s3 = peg$currPos;
  2118. if (input.charCodeAt(peg$currPos) === 46) {
  2119. s4 = peg$c43;
  2120. peg$currPos++;
  2121. } else {
  2122. s4 = peg$FAILED;
  2123. {
  2124. peg$fail(peg$c44);
  2125. }
  2126. }
  2127. if (s4 !== peg$FAILED) {
  2128. s5 = peg$parseidentifierName();
  2129. if (s5 !== peg$FAILED) {
  2130. s4 = [s4, s5];
  2131. s3 = s4;
  2132. } else {
  2133. peg$currPos = s3;
  2134. s3 = peg$FAILED;
  2135. }
  2136. } else {
  2137. peg$currPos = s3;
  2138. s3 = peg$FAILED;
  2139. }
  2140. while (s3 !== peg$FAILED) {
  2141. s2.push(s3);
  2142. s3 = peg$currPos;
  2143. if (input.charCodeAt(peg$currPos) === 46) {
  2144. s4 = peg$c43;
  2145. peg$currPos++;
  2146. } else {
  2147. s4 = peg$FAILED;
  2148. {
  2149. peg$fail(peg$c44);
  2150. }
  2151. }
  2152. if (s4 !== peg$FAILED) {
  2153. s5 = peg$parseidentifierName();
  2154. if (s5 !== peg$FAILED) {
  2155. s4 = [s4, s5];
  2156. s3 = s4;
  2157. } else {
  2158. peg$currPos = s3;
  2159. s3 = peg$FAILED;
  2160. }
  2161. } else {
  2162. peg$currPos = s3;
  2163. s3 = peg$FAILED;
  2164. }
  2165. }
  2166. if (s2 !== peg$FAILED) {
  2167. s1 = peg$c45(s1, s2);
  2168. s0 = s1;
  2169. } else {
  2170. peg$currPos = s0;
  2171. s0 = peg$FAILED;
  2172. }
  2173. } else {
  2174. peg$currPos = s0;
  2175. s0 = peg$FAILED;
  2176. }
  2177. peg$resultsCache[key] = {
  2178. nextPos: peg$currPos,
  2179. result: s0
  2180. };
  2181. return s0;
  2182. }
  2183. function peg$parseattrValue() {
  2184. var s0, s1, s2, s3, s4, s5;
  2185. var key = peg$currPos * 36 + 16,
  2186. cached = peg$resultsCache[key];
  2187. if (cached) {
  2188. peg$currPos = cached.nextPos;
  2189. return cached.result;
  2190. }
  2191. s0 = peg$currPos;
  2192. s1 = peg$parseattrName();
  2193. if (s1 !== peg$FAILED) {
  2194. s2 = peg$parse_();
  2195. if (s2 !== peg$FAILED) {
  2196. s3 = peg$parseattrEqOps();
  2197. if (s3 !== peg$FAILED) {
  2198. s4 = peg$parse_();
  2199. if (s4 !== peg$FAILED) {
  2200. s5 = peg$parsetype();
  2201. if (s5 === peg$FAILED) {
  2202. s5 = peg$parseregex();
  2203. }
  2204. if (s5 !== peg$FAILED) {
  2205. s1 = peg$c46(s1, s3, s5);
  2206. s0 = s1;
  2207. } else {
  2208. peg$currPos = s0;
  2209. s0 = peg$FAILED;
  2210. }
  2211. } else {
  2212. peg$currPos = s0;
  2213. s0 = peg$FAILED;
  2214. }
  2215. } else {
  2216. peg$currPos = s0;
  2217. s0 = peg$FAILED;
  2218. }
  2219. } else {
  2220. peg$currPos = s0;
  2221. s0 = peg$FAILED;
  2222. }
  2223. } else {
  2224. peg$currPos = s0;
  2225. s0 = peg$FAILED;
  2226. }
  2227. if (s0 === peg$FAILED) {
  2228. s0 = peg$currPos;
  2229. s1 = peg$parseattrName();
  2230. if (s1 !== peg$FAILED) {
  2231. s2 = peg$parse_();
  2232. if (s2 !== peg$FAILED) {
  2233. s3 = peg$parseattrOps();
  2234. if (s3 !== peg$FAILED) {
  2235. s4 = peg$parse_();
  2236. if (s4 !== peg$FAILED) {
  2237. s5 = peg$parsestring();
  2238. if (s5 === peg$FAILED) {
  2239. s5 = peg$parsenumber();
  2240. if (s5 === peg$FAILED) {
  2241. s5 = peg$parsepath();
  2242. }
  2243. }
  2244. if (s5 !== peg$FAILED) {
  2245. s1 = peg$c46(s1, s3, s5);
  2246. s0 = s1;
  2247. } else {
  2248. peg$currPos = s0;
  2249. s0 = peg$FAILED;
  2250. }
  2251. } else {
  2252. peg$currPos = s0;
  2253. s0 = peg$FAILED;
  2254. }
  2255. } else {
  2256. peg$currPos = s0;
  2257. s0 = peg$FAILED;
  2258. }
  2259. } else {
  2260. peg$currPos = s0;
  2261. s0 = peg$FAILED;
  2262. }
  2263. } else {
  2264. peg$currPos = s0;
  2265. s0 = peg$FAILED;
  2266. }
  2267. if (s0 === peg$FAILED) {
  2268. s0 = peg$currPos;
  2269. s1 = peg$parseattrName();
  2270. if (s1 !== peg$FAILED) {
  2271. s1 = peg$c47(s1);
  2272. }
  2273. s0 = s1;
  2274. }
  2275. }
  2276. peg$resultsCache[key] = {
  2277. nextPos: peg$currPos,
  2278. result: s0
  2279. };
  2280. return s0;
  2281. }
  2282. function peg$parsestring() {
  2283. var s0, s1, s2, s3, s4, s5;
  2284. var key = peg$currPos * 36 + 17,
  2285. cached = peg$resultsCache[key];
  2286. if (cached) {
  2287. peg$currPos = cached.nextPos;
  2288. return cached.result;
  2289. }
  2290. s0 = peg$currPos;
  2291. if (input.charCodeAt(peg$currPos) === 34) {
  2292. s1 = peg$c48;
  2293. peg$currPos++;
  2294. } else {
  2295. s1 = peg$FAILED;
  2296. {
  2297. peg$fail(peg$c49);
  2298. }
  2299. }
  2300. if (s1 !== peg$FAILED) {
  2301. s2 = [];
  2302. if (peg$c50.test(input.charAt(peg$currPos))) {
  2303. s3 = input.charAt(peg$currPos);
  2304. peg$currPos++;
  2305. } else {
  2306. s3 = peg$FAILED;
  2307. {
  2308. peg$fail(peg$c51);
  2309. }
  2310. }
  2311. if (s3 === peg$FAILED) {
  2312. s3 = peg$currPos;
  2313. if (input.charCodeAt(peg$currPos) === 92) {
  2314. s4 = peg$c52;
  2315. peg$currPos++;
  2316. } else {
  2317. s4 = peg$FAILED;
  2318. {
  2319. peg$fail(peg$c53);
  2320. }
  2321. }
  2322. if (s4 !== peg$FAILED) {
  2323. if (input.length > peg$currPos) {
  2324. s5 = input.charAt(peg$currPos);
  2325. peg$currPos++;
  2326. } else {
  2327. s5 = peg$FAILED;
  2328. {
  2329. peg$fail(peg$c54);
  2330. }
  2331. }
  2332. if (s5 !== peg$FAILED) {
  2333. s4 = peg$c55(s4, s5);
  2334. s3 = s4;
  2335. } else {
  2336. peg$currPos = s3;
  2337. s3 = peg$FAILED;
  2338. }
  2339. } else {
  2340. peg$currPos = s3;
  2341. s3 = peg$FAILED;
  2342. }
  2343. }
  2344. while (s3 !== peg$FAILED) {
  2345. s2.push(s3);
  2346. if (peg$c50.test(input.charAt(peg$currPos))) {
  2347. s3 = input.charAt(peg$currPos);
  2348. peg$currPos++;
  2349. } else {
  2350. s3 = peg$FAILED;
  2351. {
  2352. peg$fail(peg$c51);
  2353. }
  2354. }
  2355. if (s3 === peg$FAILED) {
  2356. s3 = peg$currPos;
  2357. if (input.charCodeAt(peg$currPos) === 92) {
  2358. s4 = peg$c52;
  2359. peg$currPos++;
  2360. } else {
  2361. s4 = peg$FAILED;
  2362. {
  2363. peg$fail(peg$c53);
  2364. }
  2365. }
  2366. if (s4 !== peg$FAILED) {
  2367. if (input.length > peg$currPos) {
  2368. s5 = input.charAt(peg$currPos);
  2369. peg$currPos++;
  2370. } else {
  2371. s5 = peg$FAILED;
  2372. {
  2373. peg$fail(peg$c54);
  2374. }
  2375. }
  2376. if (s5 !== peg$FAILED) {
  2377. s4 = peg$c55(s4, s5);
  2378. s3 = s4;
  2379. } else {
  2380. peg$currPos = s3;
  2381. s3 = peg$FAILED;
  2382. }
  2383. } else {
  2384. peg$currPos = s3;
  2385. s3 = peg$FAILED;
  2386. }
  2387. }
  2388. }
  2389. if (s2 !== peg$FAILED) {
  2390. if (input.charCodeAt(peg$currPos) === 34) {
  2391. s3 = peg$c48;
  2392. peg$currPos++;
  2393. } else {
  2394. s3 = peg$FAILED;
  2395. {
  2396. peg$fail(peg$c49);
  2397. }
  2398. }
  2399. if (s3 !== peg$FAILED) {
  2400. s1 = peg$c56(s2);
  2401. s0 = s1;
  2402. } else {
  2403. peg$currPos = s0;
  2404. s0 = peg$FAILED;
  2405. }
  2406. } else {
  2407. peg$currPos = s0;
  2408. s0 = peg$FAILED;
  2409. }
  2410. } else {
  2411. peg$currPos = s0;
  2412. s0 = peg$FAILED;
  2413. }
  2414. if (s0 === peg$FAILED) {
  2415. s0 = peg$currPos;
  2416. if (input.charCodeAt(peg$currPos) === 39) {
  2417. s1 = peg$c57;
  2418. peg$currPos++;
  2419. } else {
  2420. s1 = peg$FAILED;
  2421. {
  2422. peg$fail(peg$c58);
  2423. }
  2424. }
  2425. if (s1 !== peg$FAILED) {
  2426. s2 = [];
  2427. if (peg$c59.test(input.charAt(peg$currPos))) {
  2428. s3 = input.charAt(peg$currPos);
  2429. peg$currPos++;
  2430. } else {
  2431. s3 = peg$FAILED;
  2432. {
  2433. peg$fail(peg$c60);
  2434. }
  2435. }
  2436. if (s3 === peg$FAILED) {
  2437. s3 = peg$currPos;
  2438. if (input.charCodeAt(peg$currPos) === 92) {
  2439. s4 = peg$c52;
  2440. peg$currPos++;
  2441. } else {
  2442. s4 = peg$FAILED;
  2443. {
  2444. peg$fail(peg$c53);
  2445. }
  2446. }
  2447. if (s4 !== peg$FAILED) {
  2448. if (input.length > peg$currPos) {
  2449. s5 = input.charAt(peg$currPos);
  2450. peg$currPos++;
  2451. } else {
  2452. s5 = peg$FAILED;
  2453. {
  2454. peg$fail(peg$c54);
  2455. }
  2456. }
  2457. if (s5 !== peg$FAILED) {
  2458. s4 = peg$c55(s4, s5);
  2459. s3 = s4;
  2460. } else {
  2461. peg$currPos = s3;
  2462. s3 = peg$FAILED;
  2463. }
  2464. } else {
  2465. peg$currPos = s3;
  2466. s3 = peg$FAILED;
  2467. }
  2468. }
  2469. while (s3 !== peg$FAILED) {
  2470. s2.push(s3);
  2471. if (peg$c59.test(input.charAt(peg$currPos))) {
  2472. s3 = input.charAt(peg$currPos);
  2473. peg$currPos++;
  2474. } else {
  2475. s3 = peg$FAILED;
  2476. {
  2477. peg$fail(peg$c60);
  2478. }
  2479. }
  2480. if (s3 === peg$FAILED) {
  2481. s3 = peg$currPos;
  2482. if (input.charCodeAt(peg$currPos) === 92) {
  2483. s4 = peg$c52;
  2484. peg$currPos++;
  2485. } else {
  2486. s4 = peg$FAILED;
  2487. {
  2488. peg$fail(peg$c53);
  2489. }
  2490. }
  2491. if (s4 !== peg$FAILED) {
  2492. if (input.length > peg$currPos) {
  2493. s5 = input.charAt(peg$currPos);
  2494. peg$currPos++;
  2495. } else {
  2496. s5 = peg$FAILED;
  2497. {
  2498. peg$fail(peg$c54);
  2499. }
  2500. }
  2501. if (s5 !== peg$FAILED) {
  2502. s4 = peg$c55(s4, s5);
  2503. s3 = s4;
  2504. } else {
  2505. peg$currPos = s3;
  2506. s3 = peg$FAILED;
  2507. }
  2508. } else {
  2509. peg$currPos = s3;
  2510. s3 = peg$FAILED;
  2511. }
  2512. }
  2513. }
  2514. if (s2 !== peg$FAILED) {
  2515. if (input.charCodeAt(peg$currPos) === 39) {
  2516. s3 = peg$c57;
  2517. peg$currPos++;
  2518. } else {
  2519. s3 = peg$FAILED;
  2520. {
  2521. peg$fail(peg$c58);
  2522. }
  2523. }
  2524. if (s3 !== peg$FAILED) {
  2525. s1 = peg$c56(s2);
  2526. s0 = s1;
  2527. } else {
  2528. peg$currPos = s0;
  2529. s0 = peg$FAILED;
  2530. }
  2531. } else {
  2532. peg$currPos = s0;
  2533. s0 = peg$FAILED;
  2534. }
  2535. } else {
  2536. peg$currPos = s0;
  2537. s0 = peg$FAILED;
  2538. }
  2539. }
  2540. peg$resultsCache[key] = {
  2541. nextPos: peg$currPos,
  2542. result: s0
  2543. };
  2544. return s0;
  2545. }
  2546. function peg$parsenumber() {
  2547. var s0, s1, s2, s3;
  2548. var key = peg$currPos * 36 + 18,
  2549. cached = peg$resultsCache[key];
  2550. if (cached) {
  2551. peg$currPos = cached.nextPos;
  2552. return cached.result;
  2553. }
  2554. s0 = peg$currPos;
  2555. s1 = peg$currPos;
  2556. s2 = [];
  2557. if (peg$c61.test(input.charAt(peg$currPos))) {
  2558. s3 = input.charAt(peg$currPos);
  2559. peg$currPos++;
  2560. } else {
  2561. s3 = peg$FAILED;
  2562. {
  2563. peg$fail(peg$c62);
  2564. }
  2565. }
  2566. while (s3 !== peg$FAILED) {
  2567. s2.push(s3);
  2568. if (peg$c61.test(input.charAt(peg$currPos))) {
  2569. s3 = input.charAt(peg$currPos);
  2570. peg$currPos++;
  2571. } else {
  2572. s3 = peg$FAILED;
  2573. {
  2574. peg$fail(peg$c62);
  2575. }
  2576. }
  2577. }
  2578. if (s2 !== peg$FAILED) {
  2579. if (input.charCodeAt(peg$currPos) === 46) {
  2580. s3 = peg$c43;
  2581. peg$currPos++;
  2582. } else {
  2583. s3 = peg$FAILED;
  2584. {
  2585. peg$fail(peg$c44);
  2586. }
  2587. }
  2588. if (s3 !== peg$FAILED) {
  2589. s2 = [s2, s3];
  2590. s1 = s2;
  2591. } else {
  2592. peg$currPos = s1;
  2593. s1 = peg$FAILED;
  2594. }
  2595. } else {
  2596. peg$currPos = s1;
  2597. s1 = peg$FAILED;
  2598. }
  2599. if (s1 === peg$FAILED) {
  2600. s1 = null;
  2601. }
  2602. if (s1 !== peg$FAILED) {
  2603. s2 = [];
  2604. if (peg$c61.test(input.charAt(peg$currPos))) {
  2605. s3 = input.charAt(peg$currPos);
  2606. peg$currPos++;
  2607. } else {
  2608. s3 = peg$FAILED;
  2609. {
  2610. peg$fail(peg$c62);
  2611. }
  2612. }
  2613. if (s3 !== peg$FAILED) {
  2614. while (s3 !== peg$FAILED) {
  2615. s2.push(s3);
  2616. if (peg$c61.test(input.charAt(peg$currPos))) {
  2617. s3 = input.charAt(peg$currPos);
  2618. peg$currPos++;
  2619. } else {
  2620. s3 = peg$FAILED;
  2621. {
  2622. peg$fail(peg$c62);
  2623. }
  2624. }
  2625. }
  2626. } else {
  2627. s2 = peg$FAILED;
  2628. }
  2629. if (s2 !== peg$FAILED) {
  2630. s1 = peg$c63(s1, s2);
  2631. s0 = s1;
  2632. } else {
  2633. peg$currPos = s0;
  2634. s0 = peg$FAILED;
  2635. }
  2636. } else {
  2637. peg$currPos = s0;
  2638. s0 = peg$FAILED;
  2639. }
  2640. peg$resultsCache[key] = {
  2641. nextPos: peg$currPos,
  2642. result: s0
  2643. };
  2644. return s0;
  2645. }
  2646. function peg$parsepath() {
  2647. var s0, s1;
  2648. var key = peg$currPos * 36 + 19,
  2649. cached = peg$resultsCache[key];
  2650. if (cached) {
  2651. peg$currPos = cached.nextPos;
  2652. return cached.result;
  2653. }
  2654. s0 = peg$currPos;
  2655. s1 = peg$parseidentifierName();
  2656. if (s1 !== peg$FAILED) {
  2657. s1 = peg$c64(s1);
  2658. }
  2659. s0 = s1;
  2660. peg$resultsCache[key] = {
  2661. nextPos: peg$currPos,
  2662. result: s0
  2663. };
  2664. return s0;
  2665. }
  2666. function peg$parsetype() {
  2667. var s0, s1, s2, s3, s4, s5;
  2668. var key = peg$currPos * 36 + 20,
  2669. cached = peg$resultsCache[key];
  2670. if (cached) {
  2671. peg$currPos = cached.nextPos;
  2672. return cached.result;
  2673. }
  2674. s0 = peg$currPos;
  2675. if (input.substr(peg$currPos, 5) === peg$c65) {
  2676. s1 = peg$c65;
  2677. peg$currPos += 5;
  2678. } else {
  2679. s1 = peg$FAILED;
  2680. {
  2681. peg$fail(peg$c66);
  2682. }
  2683. }
  2684. if (s1 !== peg$FAILED) {
  2685. s2 = peg$parse_();
  2686. if (s2 !== peg$FAILED) {
  2687. s3 = [];
  2688. if (peg$c67.test(input.charAt(peg$currPos))) {
  2689. s4 = input.charAt(peg$currPos);
  2690. peg$currPos++;
  2691. } else {
  2692. s4 = peg$FAILED;
  2693. {
  2694. peg$fail(peg$c68);
  2695. }
  2696. }
  2697. if (s4 !== peg$FAILED) {
  2698. while (s4 !== peg$FAILED) {
  2699. s3.push(s4);
  2700. if (peg$c67.test(input.charAt(peg$currPos))) {
  2701. s4 = input.charAt(peg$currPos);
  2702. peg$currPos++;
  2703. } else {
  2704. s4 = peg$FAILED;
  2705. {
  2706. peg$fail(peg$c68);
  2707. }
  2708. }
  2709. }
  2710. } else {
  2711. s3 = peg$FAILED;
  2712. }
  2713. if (s3 !== peg$FAILED) {
  2714. s4 = peg$parse_();
  2715. if (s4 !== peg$FAILED) {
  2716. if (input.charCodeAt(peg$currPos) === 41) {
  2717. s5 = peg$c69;
  2718. peg$currPos++;
  2719. } else {
  2720. s5 = peg$FAILED;
  2721. {
  2722. peg$fail(peg$c70);
  2723. }
  2724. }
  2725. if (s5 !== peg$FAILED) {
  2726. s1 = peg$c71(s3);
  2727. s0 = s1;
  2728. } else {
  2729. peg$currPos = s0;
  2730. s0 = peg$FAILED;
  2731. }
  2732. } else {
  2733. peg$currPos = s0;
  2734. s0 = peg$FAILED;
  2735. }
  2736. } else {
  2737. peg$currPos = s0;
  2738. s0 = peg$FAILED;
  2739. }
  2740. } else {
  2741. peg$currPos = s0;
  2742. s0 = peg$FAILED;
  2743. }
  2744. } else {
  2745. peg$currPos = s0;
  2746. s0 = peg$FAILED;
  2747. }
  2748. peg$resultsCache[key] = {
  2749. nextPos: peg$currPos,
  2750. result: s0
  2751. };
  2752. return s0;
  2753. }
  2754. function peg$parseflags() {
  2755. var s0, s1;
  2756. var key = peg$currPos * 36 + 21,
  2757. cached = peg$resultsCache[key];
  2758. if (cached) {
  2759. peg$currPos = cached.nextPos;
  2760. return cached.result;
  2761. }
  2762. s0 = [];
  2763. if (peg$c72.test(input.charAt(peg$currPos))) {
  2764. s1 = input.charAt(peg$currPos);
  2765. peg$currPos++;
  2766. } else {
  2767. s1 = peg$FAILED;
  2768. {
  2769. peg$fail(peg$c73);
  2770. }
  2771. }
  2772. if (s1 !== peg$FAILED) {
  2773. while (s1 !== peg$FAILED) {
  2774. s0.push(s1);
  2775. if (peg$c72.test(input.charAt(peg$currPos))) {
  2776. s1 = input.charAt(peg$currPos);
  2777. peg$currPos++;
  2778. } else {
  2779. s1 = peg$FAILED;
  2780. {
  2781. peg$fail(peg$c73);
  2782. }
  2783. }
  2784. }
  2785. } else {
  2786. s0 = peg$FAILED;
  2787. }
  2788. peg$resultsCache[key] = {
  2789. nextPos: peg$currPos,
  2790. result: s0
  2791. };
  2792. return s0;
  2793. }
  2794. function peg$parseregex() {
  2795. var s0, s1, s2, s3, s4;
  2796. var key = peg$currPos * 36 + 22,
  2797. cached = peg$resultsCache[key];
  2798. if (cached) {
  2799. peg$currPos = cached.nextPos;
  2800. return cached.result;
  2801. }
  2802. s0 = peg$currPos;
  2803. if (input.charCodeAt(peg$currPos) === 47) {
  2804. s1 = peg$c74;
  2805. peg$currPos++;
  2806. } else {
  2807. s1 = peg$FAILED;
  2808. {
  2809. peg$fail(peg$c75);
  2810. }
  2811. }
  2812. if (s1 !== peg$FAILED) {
  2813. s2 = [];
  2814. s3 = peg$parsere_character_class();
  2815. if (s3 === peg$FAILED) {
  2816. s3 = peg$parsere_escape();
  2817. if (s3 === peg$FAILED) {
  2818. s3 = peg$parsere_chars();
  2819. }
  2820. }
  2821. if (s3 !== peg$FAILED) {
  2822. while (s3 !== peg$FAILED) {
  2823. s2.push(s3);
  2824. s3 = peg$parsere_character_class();
  2825. if (s3 === peg$FAILED) {
  2826. s3 = peg$parsere_escape();
  2827. if (s3 === peg$FAILED) {
  2828. s3 = peg$parsere_chars();
  2829. }
  2830. }
  2831. }
  2832. } else {
  2833. s2 = peg$FAILED;
  2834. }
  2835. if (s2 !== peg$FAILED) {
  2836. if (input.charCodeAt(peg$currPos) === 47) {
  2837. s3 = peg$c74;
  2838. peg$currPos++;
  2839. } else {
  2840. s3 = peg$FAILED;
  2841. {
  2842. peg$fail(peg$c75);
  2843. }
  2844. }
  2845. if (s3 !== peg$FAILED) {
  2846. s4 = peg$parseflags();
  2847. if (s4 === peg$FAILED) {
  2848. s4 = null;
  2849. }
  2850. if (s4 !== peg$FAILED) {
  2851. s1 = peg$c76(s2, s4);
  2852. s0 = s1;
  2853. } else {
  2854. peg$currPos = s0;
  2855. s0 = peg$FAILED;
  2856. }
  2857. } else {
  2858. peg$currPos = s0;
  2859. s0 = peg$FAILED;
  2860. }
  2861. } else {
  2862. peg$currPos = s0;
  2863. s0 = peg$FAILED;
  2864. }
  2865. } else {
  2866. peg$currPos = s0;
  2867. s0 = peg$FAILED;
  2868. }
  2869. peg$resultsCache[key] = {
  2870. nextPos: peg$currPos,
  2871. result: s0
  2872. };
  2873. return s0;
  2874. }
  2875. function peg$parsere_character_class() {
  2876. var s0, s1, s2, s3;
  2877. var key = peg$currPos * 36 + 23,
  2878. cached = peg$resultsCache[key];
  2879. if (cached) {
  2880. peg$currPos = cached.nextPos;
  2881. return cached.result;
  2882. }
  2883. s0 = peg$currPos;
  2884. if (input.charCodeAt(peg$currPos) === 91) {
  2885. s1 = peg$c31;
  2886. peg$currPos++;
  2887. } else {
  2888. s1 = peg$FAILED;
  2889. {
  2890. peg$fail(peg$c32);
  2891. }
  2892. }
  2893. if (s1 !== peg$FAILED) {
  2894. s2 = [];
  2895. if (peg$c77.test(input.charAt(peg$currPos))) {
  2896. s3 = input.charAt(peg$currPos);
  2897. peg$currPos++;
  2898. } else {
  2899. s3 = peg$FAILED;
  2900. {
  2901. peg$fail(peg$c78);
  2902. }
  2903. }
  2904. if (s3 === peg$FAILED) {
  2905. s3 = peg$parsere_escape();
  2906. }
  2907. if (s3 !== peg$FAILED) {
  2908. while (s3 !== peg$FAILED) {
  2909. s2.push(s3);
  2910. if (peg$c77.test(input.charAt(peg$currPos))) {
  2911. s3 = input.charAt(peg$currPos);
  2912. peg$currPos++;
  2913. } else {
  2914. s3 = peg$FAILED;
  2915. {
  2916. peg$fail(peg$c78);
  2917. }
  2918. }
  2919. if (s3 === peg$FAILED) {
  2920. s3 = peg$parsere_escape();
  2921. }
  2922. }
  2923. } else {
  2924. s2 = peg$FAILED;
  2925. }
  2926. if (s2 !== peg$FAILED) {
  2927. if (input.charCodeAt(peg$currPos) === 93) {
  2928. s3 = peg$c33;
  2929. peg$currPos++;
  2930. } else {
  2931. s3 = peg$FAILED;
  2932. {
  2933. peg$fail(peg$c34);
  2934. }
  2935. }
  2936. if (s3 !== peg$FAILED) {
  2937. s1 = peg$c79(s2);
  2938. s0 = s1;
  2939. } else {
  2940. peg$currPos = s0;
  2941. s0 = peg$FAILED;
  2942. }
  2943. } else {
  2944. peg$currPos = s0;
  2945. s0 = peg$FAILED;
  2946. }
  2947. } else {
  2948. peg$currPos = s0;
  2949. s0 = peg$FAILED;
  2950. }
  2951. peg$resultsCache[key] = {
  2952. nextPos: peg$currPos,
  2953. result: s0
  2954. };
  2955. return s0;
  2956. }
  2957. function peg$parsere_escape() {
  2958. var s0, s1, s2;
  2959. var key = peg$currPos * 36 + 24,
  2960. cached = peg$resultsCache[key];
  2961. if (cached) {
  2962. peg$currPos = cached.nextPos;
  2963. return cached.result;
  2964. }
  2965. s0 = peg$currPos;
  2966. if (input.charCodeAt(peg$currPos) === 92) {
  2967. s1 = peg$c52;
  2968. peg$currPos++;
  2969. } else {
  2970. s1 = peg$FAILED;
  2971. {
  2972. peg$fail(peg$c53);
  2973. }
  2974. }
  2975. if (s1 !== peg$FAILED) {
  2976. if (input.length > peg$currPos) {
  2977. s2 = input.charAt(peg$currPos);
  2978. peg$currPos++;
  2979. } else {
  2980. s2 = peg$FAILED;
  2981. {
  2982. peg$fail(peg$c54);
  2983. }
  2984. }
  2985. if (s2 !== peg$FAILED) {
  2986. s1 = peg$c80(s2);
  2987. s0 = s1;
  2988. } else {
  2989. peg$currPos = s0;
  2990. s0 = peg$FAILED;
  2991. }
  2992. } else {
  2993. peg$currPos = s0;
  2994. s0 = peg$FAILED;
  2995. }
  2996. peg$resultsCache[key] = {
  2997. nextPos: peg$currPos,
  2998. result: s0
  2999. };
  3000. return s0;
  3001. }
  3002. function peg$parsere_chars() {
  3003. var s0, s1, s2;
  3004. var key = peg$currPos * 36 + 25,
  3005. cached = peg$resultsCache[key];
  3006. if (cached) {
  3007. peg$currPos = cached.nextPos;
  3008. return cached.result;
  3009. }
  3010. s0 = peg$currPos;
  3011. s1 = [];
  3012. if (peg$c81.test(input.charAt(peg$currPos))) {
  3013. s2 = input.charAt(peg$currPos);
  3014. peg$currPos++;
  3015. } else {
  3016. s2 = peg$FAILED;
  3017. {
  3018. peg$fail(peg$c82);
  3019. }
  3020. }
  3021. if (s2 !== peg$FAILED) {
  3022. while (s2 !== peg$FAILED) {
  3023. s1.push(s2);
  3024. if (peg$c81.test(input.charAt(peg$currPos))) {
  3025. s2 = input.charAt(peg$currPos);
  3026. peg$currPos++;
  3027. } else {
  3028. s2 = peg$FAILED;
  3029. {
  3030. peg$fail(peg$c82);
  3031. }
  3032. }
  3033. }
  3034. } else {
  3035. s1 = peg$FAILED;
  3036. }
  3037. if (s1 !== peg$FAILED) {
  3038. s1 = peg$c83(s1);
  3039. }
  3040. s0 = s1;
  3041. peg$resultsCache[key] = {
  3042. nextPos: peg$currPos,
  3043. result: s0
  3044. };
  3045. return s0;
  3046. }
  3047. function peg$parsefield() {
  3048. var s0, s1, s2, s3, s4, s5, s6;
  3049. var key = peg$currPos * 36 + 26,
  3050. cached = peg$resultsCache[key];
  3051. if (cached) {
  3052. peg$currPos = cached.nextPos;
  3053. return cached.result;
  3054. }
  3055. s0 = peg$currPos;
  3056. if (input.charCodeAt(peg$currPos) === 46) {
  3057. s1 = peg$c43;
  3058. peg$currPos++;
  3059. } else {
  3060. s1 = peg$FAILED;
  3061. {
  3062. peg$fail(peg$c44);
  3063. }
  3064. }
  3065. if (s1 !== peg$FAILED) {
  3066. s2 = peg$parseidentifierName();
  3067. if (s2 !== peg$FAILED) {
  3068. s3 = [];
  3069. s4 = peg$currPos;
  3070. if (input.charCodeAt(peg$currPos) === 46) {
  3071. s5 = peg$c43;
  3072. peg$currPos++;
  3073. } else {
  3074. s5 = peg$FAILED;
  3075. {
  3076. peg$fail(peg$c44);
  3077. }
  3078. }
  3079. if (s5 !== peg$FAILED) {
  3080. s6 = peg$parseidentifierName();
  3081. if (s6 !== peg$FAILED) {
  3082. s5 = [s5, s6];
  3083. s4 = s5;
  3084. } else {
  3085. peg$currPos = s4;
  3086. s4 = peg$FAILED;
  3087. }
  3088. } else {
  3089. peg$currPos = s4;
  3090. s4 = peg$FAILED;
  3091. }
  3092. while (s4 !== peg$FAILED) {
  3093. s3.push(s4);
  3094. s4 = peg$currPos;
  3095. if (input.charCodeAt(peg$currPos) === 46) {
  3096. s5 = peg$c43;
  3097. peg$currPos++;
  3098. } else {
  3099. s5 = peg$FAILED;
  3100. {
  3101. peg$fail(peg$c44);
  3102. }
  3103. }
  3104. if (s5 !== peg$FAILED) {
  3105. s6 = peg$parseidentifierName();
  3106. if (s6 !== peg$FAILED) {
  3107. s5 = [s5, s6];
  3108. s4 = s5;
  3109. } else {
  3110. peg$currPos = s4;
  3111. s4 = peg$FAILED;
  3112. }
  3113. } else {
  3114. peg$currPos = s4;
  3115. s4 = peg$FAILED;
  3116. }
  3117. }
  3118. if (s3 !== peg$FAILED) {
  3119. s1 = peg$c84(s2, s3);
  3120. s0 = s1;
  3121. } else {
  3122. peg$currPos = s0;
  3123. s0 = peg$FAILED;
  3124. }
  3125. } else {
  3126. peg$currPos = s0;
  3127. s0 = peg$FAILED;
  3128. }
  3129. } else {
  3130. peg$currPos = s0;
  3131. s0 = peg$FAILED;
  3132. }
  3133. peg$resultsCache[key] = {
  3134. nextPos: peg$currPos,
  3135. result: s0
  3136. };
  3137. return s0;
  3138. }
  3139. function peg$parsenegation() {
  3140. var s0, s1, s2, s3, s4, s5;
  3141. var key = peg$currPos * 36 + 27,
  3142. cached = peg$resultsCache[key];
  3143. if (cached) {
  3144. peg$currPos = cached.nextPos;
  3145. return cached.result;
  3146. }
  3147. s0 = peg$currPos;
  3148. if (input.substr(peg$currPos, 5) === peg$c85) {
  3149. s1 = peg$c85;
  3150. peg$currPos += 5;
  3151. } else {
  3152. s1 = peg$FAILED;
  3153. {
  3154. peg$fail(peg$c86);
  3155. }
  3156. }
  3157. if (s1 !== peg$FAILED) {
  3158. s2 = peg$parse_();
  3159. if (s2 !== peg$FAILED) {
  3160. s3 = peg$parseselectors();
  3161. if (s3 !== peg$FAILED) {
  3162. s4 = peg$parse_();
  3163. if (s4 !== peg$FAILED) {
  3164. if (input.charCodeAt(peg$currPos) === 41) {
  3165. s5 = peg$c69;
  3166. peg$currPos++;
  3167. } else {
  3168. s5 = peg$FAILED;
  3169. {
  3170. peg$fail(peg$c70);
  3171. }
  3172. }
  3173. if (s5 !== peg$FAILED) {
  3174. s1 = peg$c87(s3);
  3175. s0 = s1;
  3176. } else {
  3177. peg$currPos = s0;
  3178. s0 = peg$FAILED;
  3179. }
  3180. } else {
  3181. peg$currPos = s0;
  3182. s0 = peg$FAILED;
  3183. }
  3184. } else {
  3185. peg$currPos = s0;
  3186. s0 = peg$FAILED;
  3187. }
  3188. } else {
  3189. peg$currPos = s0;
  3190. s0 = peg$FAILED;
  3191. }
  3192. } else {
  3193. peg$currPos = s0;
  3194. s0 = peg$FAILED;
  3195. }
  3196. peg$resultsCache[key] = {
  3197. nextPos: peg$currPos,
  3198. result: s0
  3199. };
  3200. return s0;
  3201. }
  3202. function peg$parsematches() {
  3203. var s0, s1, s2, s3, s4, s5;
  3204. var key = peg$currPos * 36 + 28,
  3205. cached = peg$resultsCache[key];
  3206. if (cached) {
  3207. peg$currPos = cached.nextPos;
  3208. return cached.result;
  3209. }
  3210. s0 = peg$currPos;
  3211. if (input.substr(peg$currPos, 9) === peg$c88) {
  3212. s1 = peg$c88;
  3213. peg$currPos += 9;
  3214. } else {
  3215. s1 = peg$FAILED;
  3216. {
  3217. peg$fail(peg$c89);
  3218. }
  3219. }
  3220. if (s1 !== peg$FAILED) {
  3221. s2 = peg$parse_();
  3222. if (s2 !== peg$FAILED) {
  3223. s3 = peg$parseselectors();
  3224. if (s3 !== peg$FAILED) {
  3225. s4 = peg$parse_();
  3226. if (s4 !== peg$FAILED) {
  3227. if (input.charCodeAt(peg$currPos) === 41) {
  3228. s5 = peg$c69;
  3229. peg$currPos++;
  3230. } else {
  3231. s5 = peg$FAILED;
  3232. {
  3233. peg$fail(peg$c70);
  3234. }
  3235. }
  3236. if (s5 !== peg$FAILED) {
  3237. s1 = peg$c90(s3);
  3238. s0 = s1;
  3239. } else {
  3240. peg$currPos = s0;
  3241. s0 = peg$FAILED;
  3242. }
  3243. } else {
  3244. peg$currPos = s0;
  3245. s0 = peg$FAILED;
  3246. }
  3247. } else {
  3248. peg$currPos = s0;
  3249. s0 = peg$FAILED;
  3250. }
  3251. } else {
  3252. peg$currPos = s0;
  3253. s0 = peg$FAILED;
  3254. }
  3255. } else {
  3256. peg$currPos = s0;
  3257. s0 = peg$FAILED;
  3258. }
  3259. peg$resultsCache[key] = {
  3260. nextPos: peg$currPos,
  3261. result: s0
  3262. };
  3263. return s0;
  3264. }
  3265. function peg$parseis() {
  3266. var s0, s1, s2, s3, s4, s5;
  3267. var key = peg$currPos * 36 + 29,
  3268. cached = peg$resultsCache[key];
  3269. if (cached) {
  3270. peg$currPos = cached.nextPos;
  3271. return cached.result;
  3272. }
  3273. s0 = peg$currPos;
  3274. if (input.substr(peg$currPos, 4) === peg$c91) {
  3275. s1 = peg$c91;
  3276. peg$currPos += 4;
  3277. } else {
  3278. s1 = peg$FAILED;
  3279. {
  3280. peg$fail(peg$c92);
  3281. }
  3282. }
  3283. if (s1 !== peg$FAILED) {
  3284. s2 = peg$parse_();
  3285. if (s2 !== peg$FAILED) {
  3286. s3 = peg$parseselectors();
  3287. if (s3 !== peg$FAILED) {
  3288. s4 = peg$parse_();
  3289. if (s4 !== peg$FAILED) {
  3290. if (input.charCodeAt(peg$currPos) === 41) {
  3291. s5 = peg$c69;
  3292. peg$currPos++;
  3293. } else {
  3294. s5 = peg$FAILED;
  3295. {
  3296. peg$fail(peg$c70);
  3297. }
  3298. }
  3299. if (s5 !== peg$FAILED) {
  3300. s1 = peg$c90(s3);
  3301. s0 = s1;
  3302. } else {
  3303. peg$currPos = s0;
  3304. s0 = peg$FAILED;
  3305. }
  3306. } else {
  3307. peg$currPos = s0;
  3308. s0 = peg$FAILED;
  3309. }
  3310. } else {
  3311. peg$currPos = s0;
  3312. s0 = peg$FAILED;
  3313. }
  3314. } else {
  3315. peg$currPos = s0;
  3316. s0 = peg$FAILED;
  3317. }
  3318. } else {
  3319. peg$currPos = s0;
  3320. s0 = peg$FAILED;
  3321. }
  3322. peg$resultsCache[key] = {
  3323. nextPos: peg$currPos,
  3324. result: s0
  3325. };
  3326. return s0;
  3327. }
  3328. function peg$parsehas() {
  3329. var s0, s1, s2, s3, s4, s5;
  3330. var key = peg$currPos * 36 + 30,
  3331. cached = peg$resultsCache[key];
  3332. if (cached) {
  3333. peg$currPos = cached.nextPos;
  3334. return cached.result;
  3335. }
  3336. s0 = peg$currPos;
  3337. if (input.substr(peg$currPos, 5) === peg$c93) {
  3338. s1 = peg$c93;
  3339. peg$currPos += 5;
  3340. } else {
  3341. s1 = peg$FAILED;
  3342. {
  3343. peg$fail(peg$c94);
  3344. }
  3345. }
  3346. if (s1 !== peg$FAILED) {
  3347. s2 = peg$parse_();
  3348. if (s2 !== peg$FAILED) {
  3349. s3 = peg$parsehasSelectors();
  3350. if (s3 !== peg$FAILED) {
  3351. s4 = peg$parse_();
  3352. if (s4 !== peg$FAILED) {
  3353. if (input.charCodeAt(peg$currPos) === 41) {
  3354. s5 = peg$c69;
  3355. peg$currPos++;
  3356. } else {
  3357. s5 = peg$FAILED;
  3358. {
  3359. peg$fail(peg$c70);
  3360. }
  3361. }
  3362. if (s5 !== peg$FAILED) {
  3363. s1 = peg$c95(s3);
  3364. s0 = s1;
  3365. } else {
  3366. peg$currPos = s0;
  3367. s0 = peg$FAILED;
  3368. }
  3369. } else {
  3370. peg$currPos = s0;
  3371. s0 = peg$FAILED;
  3372. }
  3373. } else {
  3374. peg$currPos = s0;
  3375. s0 = peg$FAILED;
  3376. }
  3377. } else {
  3378. peg$currPos = s0;
  3379. s0 = peg$FAILED;
  3380. }
  3381. } else {
  3382. peg$currPos = s0;
  3383. s0 = peg$FAILED;
  3384. }
  3385. peg$resultsCache[key] = {
  3386. nextPos: peg$currPos,
  3387. result: s0
  3388. };
  3389. return s0;
  3390. }
  3391. function peg$parsefirstChild() {
  3392. var s0, s1;
  3393. var key = peg$currPos * 36 + 31,
  3394. cached = peg$resultsCache[key];
  3395. if (cached) {
  3396. peg$currPos = cached.nextPos;
  3397. return cached.result;
  3398. }
  3399. s0 = peg$currPos;
  3400. if (input.substr(peg$currPos, 12) === peg$c96) {
  3401. s1 = peg$c96;
  3402. peg$currPos += 12;
  3403. } else {
  3404. s1 = peg$FAILED;
  3405. {
  3406. peg$fail(peg$c97);
  3407. }
  3408. }
  3409. if (s1 !== peg$FAILED) {
  3410. s1 = peg$c98();
  3411. }
  3412. s0 = s1;
  3413. peg$resultsCache[key] = {
  3414. nextPos: peg$currPos,
  3415. result: s0
  3416. };
  3417. return s0;
  3418. }
  3419. function peg$parselastChild() {
  3420. var s0, s1;
  3421. var key = peg$currPos * 36 + 32,
  3422. cached = peg$resultsCache[key];
  3423. if (cached) {
  3424. peg$currPos = cached.nextPos;
  3425. return cached.result;
  3426. }
  3427. s0 = peg$currPos;
  3428. if (input.substr(peg$currPos, 11) === peg$c99) {
  3429. s1 = peg$c99;
  3430. peg$currPos += 11;
  3431. } else {
  3432. s1 = peg$FAILED;
  3433. {
  3434. peg$fail(peg$c100);
  3435. }
  3436. }
  3437. if (s1 !== peg$FAILED) {
  3438. s1 = peg$c101();
  3439. }
  3440. s0 = s1;
  3441. peg$resultsCache[key] = {
  3442. nextPos: peg$currPos,
  3443. result: s0
  3444. };
  3445. return s0;
  3446. }
  3447. function peg$parsenthChild() {
  3448. var s0, s1, s2, s3, s4, s5;
  3449. var key = peg$currPos * 36 + 33,
  3450. cached = peg$resultsCache[key];
  3451. if (cached) {
  3452. peg$currPos = cached.nextPos;
  3453. return cached.result;
  3454. }
  3455. s0 = peg$currPos;
  3456. if (input.substr(peg$currPos, 11) === peg$c102) {
  3457. s1 = peg$c102;
  3458. peg$currPos += 11;
  3459. } else {
  3460. s1 = peg$FAILED;
  3461. {
  3462. peg$fail(peg$c103);
  3463. }
  3464. }
  3465. if (s1 !== peg$FAILED) {
  3466. s2 = peg$parse_();
  3467. if (s2 !== peg$FAILED) {
  3468. s3 = [];
  3469. if (peg$c61.test(input.charAt(peg$currPos))) {
  3470. s4 = input.charAt(peg$currPos);
  3471. peg$currPos++;
  3472. } else {
  3473. s4 = peg$FAILED;
  3474. {
  3475. peg$fail(peg$c62);
  3476. }
  3477. }
  3478. if (s4 !== peg$FAILED) {
  3479. while (s4 !== peg$FAILED) {
  3480. s3.push(s4);
  3481. if (peg$c61.test(input.charAt(peg$currPos))) {
  3482. s4 = input.charAt(peg$currPos);
  3483. peg$currPos++;
  3484. } else {
  3485. s4 = peg$FAILED;
  3486. {
  3487. peg$fail(peg$c62);
  3488. }
  3489. }
  3490. }
  3491. } else {
  3492. s3 = peg$FAILED;
  3493. }
  3494. if (s3 !== peg$FAILED) {
  3495. s4 = peg$parse_();
  3496. if (s4 !== peg$FAILED) {
  3497. if (input.charCodeAt(peg$currPos) === 41) {
  3498. s5 = peg$c69;
  3499. peg$currPos++;
  3500. } else {
  3501. s5 = peg$FAILED;
  3502. {
  3503. peg$fail(peg$c70);
  3504. }
  3505. }
  3506. if (s5 !== peg$FAILED) {
  3507. s1 = peg$c104(s3);
  3508. s0 = s1;
  3509. } else {
  3510. peg$currPos = s0;
  3511. s0 = peg$FAILED;
  3512. }
  3513. } else {
  3514. peg$currPos = s0;
  3515. s0 = peg$FAILED;
  3516. }
  3517. } else {
  3518. peg$currPos = s0;
  3519. s0 = peg$FAILED;
  3520. }
  3521. } else {
  3522. peg$currPos = s0;
  3523. s0 = peg$FAILED;
  3524. }
  3525. } else {
  3526. peg$currPos = s0;
  3527. s0 = peg$FAILED;
  3528. }
  3529. peg$resultsCache[key] = {
  3530. nextPos: peg$currPos,
  3531. result: s0
  3532. };
  3533. return s0;
  3534. }
  3535. function peg$parsenthLastChild() {
  3536. var s0, s1, s2, s3, s4, s5;
  3537. var key = peg$currPos * 36 + 34,
  3538. cached = peg$resultsCache[key];
  3539. if (cached) {
  3540. peg$currPos = cached.nextPos;
  3541. return cached.result;
  3542. }
  3543. s0 = peg$currPos;
  3544. if (input.substr(peg$currPos, 16) === peg$c105) {
  3545. s1 = peg$c105;
  3546. peg$currPos += 16;
  3547. } else {
  3548. s1 = peg$FAILED;
  3549. {
  3550. peg$fail(peg$c106);
  3551. }
  3552. }
  3553. if (s1 !== peg$FAILED) {
  3554. s2 = peg$parse_();
  3555. if (s2 !== peg$FAILED) {
  3556. s3 = [];
  3557. if (peg$c61.test(input.charAt(peg$currPos))) {
  3558. s4 = input.charAt(peg$currPos);
  3559. peg$currPos++;
  3560. } else {
  3561. s4 = peg$FAILED;
  3562. {
  3563. peg$fail(peg$c62);
  3564. }
  3565. }
  3566. if (s4 !== peg$FAILED) {
  3567. while (s4 !== peg$FAILED) {
  3568. s3.push(s4);
  3569. if (peg$c61.test(input.charAt(peg$currPos))) {
  3570. s4 = input.charAt(peg$currPos);
  3571. peg$currPos++;
  3572. } else {
  3573. s4 = peg$FAILED;
  3574. {
  3575. peg$fail(peg$c62);
  3576. }
  3577. }
  3578. }
  3579. } else {
  3580. s3 = peg$FAILED;
  3581. }
  3582. if (s3 !== peg$FAILED) {
  3583. s4 = peg$parse_();
  3584. if (s4 !== peg$FAILED) {
  3585. if (input.charCodeAt(peg$currPos) === 41) {
  3586. s5 = peg$c69;
  3587. peg$currPos++;
  3588. } else {
  3589. s5 = peg$FAILED;
  3590. {
  3591. peg$fail(peg$c70);
  3592. }
  3593. }
  3594. if (s5 !== peg$FAILED) {
  3595. s1 = peg$c107(s3);
  3596. s0 = s1;
  3597. } else {
  3598. peg$currPos = s0;
  3599. s0 = peg$FAILED;
  3600. }
  3601. } else {
  3602. peg$currPos = s0;
  3603. s0 = peg$FAILED;
  3604. }
  3605. } else {
  3606. peg$currPos = s0;
  3607. s0 = peg$FAILED;
  3608. }
  3609. } else {
  3610. peg$currPos = s0;
  3611. s0 = peg$FAILED;
  3612. }
  3613. } else {
  3614. peg$currPos = s0;
  3615. s0 = peg$FAILED;
  3616. }
  3617. peg$resultsCache[key] = {
  3618. nextPos: peg$currPos,
  3619. result: s0
  3620. };
  3621. return s0;
  3622. }
  3623. function peg$parseclass() {
  3624. var s0, s1, s2;
  3625. var key = peg$currPos * 36 + 35,
  3626. cached = peg$resultsCache[key];
  3627. if (cached) {
  3628. peg$currPos = cached.nextPos;
  3629. return cached.result;
  3630. }
  3631. s0 = peg$currPos;
  3632. if (input.charCodeAt(peg$currPos) === 58) {
  3633. s1 = peg$c108;
  3634. peg$currPos++;
  3635. } else {
  3636. s1 = peg$FAILED;
  3637. {
  3638. peg$fail(peg$c109);
  3639. }
  3640. }
  3641. if (s1 !== peg$FAILED) {
  3642. s2 = peg$parseidentifierName();
  3643. if (s2 !== peg$FAILED) {
  3644. s1 = peg$c110(s2);
  3645. s0 = s1;
  3646. } else {
  3647. peg$currPos = s0;
  3648. s0 = peg$FAILED;
  3649. }
  3650. } else {
  3651. peg$currPos = s0;
  3652. s0 = peg$FAILED;
  3653. }
  3654. peg$resultsCache[key] = {
  3655. nextPos: peg$currPos,
  3656. result: s0
  3657. };
  3658. return s0;
  3659. }
  3660. function nth(n) {
  3661. return {
  3662. type: 'nth-child',
  3663. index: {
  3664. type: 'literal',
  3665. value: n
  3666. }
  3667. };
  3668. }
  3669. function nthLast(n) {
  3670. return {
  3671. type: 'nth-last-child',
  3672. index: {
  3673. type: 'literal',
  3674. value: n
  3675. }
  3676. };
  3677. }
  3678. function strUnescape(s) {
  3679. return s.replace(/\\(.)/g, function (match, ch) {
  3680. switch (ch) {
  3681. case 'b':
  3682. return '\b';
  3683. case 'f':
  3684. return '\f';
  3685. case 'n':
  3686. return '\n';
  3687. case 'r':
  3688. return '\r';
  3689. case 't':
  3690. return '\t';
  3691. case 'v':
  3692. return '\v';
  3693. default:
  3694. return ch;
  3695. }
  3696. });
  3697. }
  3698. peg$result = peg$startRuleFunction();
  3699. if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  3700. return peg$result;
  3701. } else {
  3702. if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  3703. peg$fail(peg$endExpectation());
  3704. }
  3705. throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
  3706. }
  3707. }
  3708. return {
  3709. SyntaxError: peg$SyntaxError,
  3710. parse: peg$parse
  3711. };
  3712. });
  3713. });
  3714. /**
  3715. * @typedef {"LEFT_SIDE"|"RIGHT_SIDE"} Side
  3716. */
  3717. var LEFT_SIDE = 'LEFT_SIDE';
  3718. var RIGHT_SIDE = 'RIGHT_SIDE';
  3719. /**
  3720. * @external AST
  3721. * @see https://esprima.readthedocs.io/en/latest/syntax-tree-format.html
  3722. */
  3723. /**
  3724. * One of the rules of `grammar.pegjs`
  3725. * @typedef {PlainObject} SelectorAST
  3726. * @see grammar.pegjs
  3727. */
  3728. /**
  3729. * The `sequence` production of `grammar.pegjs`
  3730. * @typedef {PlainObject} SelectorSequenceAST
  3731. */
  3732. /**
  3733. * Get the value of a property which may be multiple levels down
  3734. * in the object.
  3735. * @param {?PlainObject} obj
  3736. * @param {string[]} keys
  3737. * @returns {undefined|boolean|string|number|external:AST}
  3738. */
  3739. function getPath(obj, keys) {
  3740. for (var i = 0; i < keys.length; ++i) {
  3741. if (obj == null) {
  3742. return obj;
  3743. }
  3744. obj = obj[keys[i]];
  3745. }
  3746. return obj;
  3747. }
  3748. /**
  3749. * Determine whether `node` can be reached by following `path`,
  3750. * starting at `ancestor`.
  3751. * @param {?external:AST} node
  3752. * @param {?external:AST} ancestor
  3753. * @param {string[]} path
  3754. * @param {Integer} fromPathIndex
  3755. * @returns {boolean}
  3756. */
  3757. function inPath(node, ancestor, path, fromPathIndex) {
  3758. var current = ancestor;
  3759. for (var i = fromPathIndex; i < path.length; ++i) {
  3760. if (current == null) {
  3761. return false;
  3762. }
  3763. var field = current[path[i]];
  3764. if (Array.isArray(field)) {
  3765. for (var k = 0; k < field.length; ++k) {
  3766. if (inPath(node, field[k], path, i + 1)) {
  3767. return true;
  3768. }
  3769. }
  3770. return false;
  3771. }
  3772. current = field;
  3773. }
  3774. return node === current;
  3775. }
  3776. /**
  3777. * A generated matcher function for a selector.
  3778. * @callback SelectorMatcher
  3779. * @param {?SelectorAST} selector
  3780. * @param {external:AST[]} [ancestry=[]]
  3781. * @param {ESQueryOptions} [options]
  3782. * @returns {void}
  3783. */
  3784. /**
  3785. * A WeakMap for holding cached matcher functions for selectors.
  3786. * @type {WeakMap<SelectorAST, SelectorMatcher>}
  3787. */
  3788. var MATCHER_CACHE = typeof WeakMap === 'function' ? new WeakMap() : null;
  3789. /**
  3790. * Look up a matcher function for `selector` in the cache.
  3791. * If it does not exist, generate it with `generateMatcher` and add it to the cache.
  3792. * In engines without WeakMap, the caching is skipped and matchers are generated with every call.
  3793. * @param {?SelectorAST} selector
  3794. * @returns {SelectorMatcher}
  3795. */
  3796. function getMatcher(selector) {
  3797. if (selector == null) {
  3798. return function () {
  3799. return true;
  3800. };
  3801. }
  3802. if (MATCHER_CACHE != null) {
  3803. var matcher = MATCHER_CACHE.get(selector);
  3804. if (matcher != null) {
  3805. return matcher;
  3806. }
  3807. matcher = generateMatcher(selector);
  3808. MATCHER_CACHE.set(selector, matcher);
  3809. return matcher;
  3810. }
  3811. return generateMatcher(selector);
  3812. }
  3813. /**
  3814. * Create a matcher function for `selector`,
  3815. * @param {?SelectorAST} selector
  3816. * @returns {SelectorMatcher}
  3817. */
  3818. function generateMatcher(selector) {
  3819. switch (selector.type) {
  3820. case 'wildcard':
  3821. return function () {
  3822. return true;
  3823. };
  3824. case 'identifier':
  3825. {
  3826. var value = selector.value.toLowerCase();
  3827. return function (node, ancestry, options) {
  3828. var nodeTypeKey = options && options.nodeTypeKey || 'type';
  3829. return value === node[nodeTypeKey].toLowerCase();
  3830. };
  3831. }
  3832. case 'exactNode':
  3833. return function (node, ancestry) {
  3834. return ancestry.length === 0;
  3835. };
  3836. case 'field':
  3837. {
  3838. var path = selector.name.split('.');
  3839. return function (node, ancestry) {
  3840. var ancestor = ancestry[path.length - 1];
  3841. return inPath(node, ancestor, path, 0);
  3842. };
  3843. }
  3844. case 'matches':
  3845. {
  3846. var matchers = selector.selectors.map(getMatcher);
  3847. return function (node, ancestry, options) {
  3848. for (var i = 0; i < matchers.length; ++i) {
  3849. if (matchers[i](node, ancestry, options)) {
  3850. return true;
  3851. }
  3852. }
  3853. return false;
  3854. };
  3855. }
  3856. case 'compound':
  3857. {
  3858. var _matchers = selector.selectors.map(getMatcher);
  3859. return function (node, ancestry, options) {
  3860. for (var i = 0; i < _matchers.length; ++i) {
  3861. if (!_matchers[i](node, ancestry, options)) {
  3862. return false;
  3863. }
  3864. }
  3865. return true;
  3866. };
  3867. }
  3868. case 'not':
  3869. {
  3870. var _matchers2 = selector.selectors.map(getMatcher);
  3871. return function (node, ancestry, options) {
  3872. for (var i = 0; i < _matchers2.length; ++i) {
  3873. if (_matchers2[i](node, ancestry, options)) {
  3874. return false;
  3875. }
  3876. }
  3877. return true;
  3878. };
  3879. }
  3880. case 'has':
  3881. {
  3882. var _matchers3 = selector.selectors.map(getMatcher);
  3883. return function (node, ancestry, options) {
  3884. var result = false;
  3885. var a = [];
  3886. estraverse.traverse(node, {
  3887. enter: function enter(node, parent) {
  3888. if (parent != null) {
  3889. a.unshift(parent);
  3890. }
  3891. for (var i = 0; i < _matchers3.length; ++i) {
  3892. if (_matchers3[i](node, a, options)) {
  3893. result = true;
  3894. this["break"]();
  3895. return;
  3896. }
  3897. }
  3898. },
  3899. leave: function leave() {
  3900. a.shift();
  3901. },
  3902. keys: options && options.visitorKeys,
  3903. fallback: options && options.fallback || 'iteration'
  3904. });
  3905. return result;
  3906. };
  3907. }
  3908. case 'child':
  3909. {
  3910. var left = getMatcher(selector.left);
  3911. var right = getMatcher(selector.right);
  3912. return function (node, ancestry, options) {
  3913. if (ancestry.length > 0 && right(node, ancestry, options)) {
  3914. return left(ancestry[0], ancestry.slice(1), options);
  3915. }
  3916. return false;
  3917. };
  3918. }
  3919. case 'descendant':
  3920. {
  3921. var _left = getMatcher(selector.left);
  3922. var _right = getMatcher(selector.right);
  3923. return function (node, ancestry, options) {
  3924. if (_right(node, ancestry, options)) {
  3925. for (var i = 0, l = ancestry.length; i < l; ++i) {
  3926. if (_left(ancestry[i], ancestry.slice(i + 1), options)) {
  3927. return true;
  3928. }
  3929. }
  3930. }
  3931. return false;
  3932. };
  3933. }
  3934. case 'attribute':
  3935. {
  3936. var _path = selector.name.split('.');
  3937. switch (selector.operator) {
  3938. case void 0:
  3939. return function (node) {
  3940. return getPath(node, _path) != null;
  3941. };
  3942. case '=':
  3943. switch (selector.value.type) {
  3944. case 'regexp':
  3945. return function (node) {
  3946. var p = getPath(node, _path);
  3947. return typeof p === 'string' && selector.value.value.test(p);
  3948. };
  3949. case 'literal':
  3950. {
  3951. var literal = "".concat(selector.value.value);
  3952. return function (node) {
  3953. return literal === "".concat(getPath(node, _path));
  3954. };
  3955. }
  3956. case 'type':
  3957. return function (node) {
  3958. return selector.value.value === _typeof(getPath(node, _path));
  3959. };
  3960. }
  3961. throw new Error("Unknown selector value type: ".concat(selector.value.type));
  3962. case '!=':
  3963. switch (selector.value.type) {
  3964. case 'regexp':
  3965. return function (node) {
  3966. return !selector.value.value.test(getPath(node, _path));
  3967. };
  3968. case 'literal':
  3969. {
  3970. var _literal = "".concat(selector.value.value);
  3971. return function (node) {
  3972. return _literal !== "".concat(getPath(node, _path));
  3973. };
  3974. }
  3975. case 'type':
  3976. return function (node) {
  3977. return selector.value.value !== _typeof(getPath(node, _path));
  3978. };
  3979. }
  3980. throw new Error("Unknown selector value type: ".concat(selector.value.type));
  3981. case '<=':
  3982. return function (node) {
  3983. return getPath(node, _path) <= selector.value.value;
  3984. };
  3985. case '<':
  3986. return function (node) {
  3987. return getPath(node, _path) < selector.value.value;
  3988. };
  3989. case '>':
  3990. return function (node) {
  3991. return getPath(node, _path) > selector.value.value;
  3992. };
  3993. case '>=':
  3994. return function (node) {
  3995. return getPath(node, _path) >= selector.value.value;
  3996. };
  3997. }
  3998. throw new Error("Unknown operator: ".concat(selector.operator));
  3999. }
  4000. case 'sibling':
  4001. {
  4002. var _left2 = getMatcher(selector.left);
  4003. var _right2 = getMatcher(selector.right);
  4004. return function (node, ancestry, options) {
  4005. return _right2(node, ancestry, options) && sibling(node, _left2, ancestry, LEFT_SIDE, options) || selector.left.subject && _left2(node, ancestry, options) && sibling(node, _right2, ancestry, RIGHT_SIDE, options);
  4006. };
  4007. }
  4008. case 'adjacent':
  4009. {
  4010. var _left3 = getMatcher(selector.left);
  4011. var _right3 = getMatcher(selector.right);
  4012. return function (node, ancestry, options) {
  4013. return _right3(node, ancestry, options) && adjacent(node, _left3, ancestry, LEFT_SIDE, options) || selector.right.subject && _left3(node, ancestry, options) && adjacent(node, _right3, ancestry, RIGHT_SIDE, options);
  4014. };
  4015. }
  4016. case 'nth-child':
  4017. {
  4018. var nth = selector.index.value;
  4019. var _right4 = getMatcher(selector.right);
  4020. return function (node, ancestry, options) {
  4021. return _right4(node, ancestry, options) && nthChild(node, ancestry, nth, options);
  4022. };
  4023. }
  4024. case 'nth-last-child':
  4025. {
  4026. var _nth = -selector.index.value;
  4027. var _right5 = getMatcher(selector.right);
  4028. return function (node, ancestry, options) {
  4029. return _right5(node, ancestry, options) && nthChild(node, ancestry, _nth, options);
  4030. };
  4031. }
  4032. case 'class':
  4033. {
  4034. var name = selector.name.toLowerCase();
  4035. return function (node, ancestry, options) {
  4036. if (options && options.matchClass) {
  4037. return options.matchClass(selector.name, node, ancestry);
  4038. }
  4039. if (options && options.nodeTypeKey) return false;
  4040. switch (name) {
  4041. case 'statement':
  4042. if (node.type.slice(-9) === 'Statement') return true;
  4043. // fallthrough: interface Declaration <: Statement { }
  4044. case 'declaration':
  4045. return node.type.slice(-11) === 'Declaration';
  4046. case 'pattern':
  4047. if (node.type.slice(-7) === 'Pattern') return true;
  4048. // fallthrough: interface Expression <: Node, Pattern { }
  4049. case 'expression':
  4050. return node.type.slice(-10) === 'Expression' || node.type.slice(-7) === 'Literal' || node.type === 'Identifier' && (ancestry.length === 0 || ancestry[0].type !== 'MetaProperty') || node.type === 'MetaProperty';
  4051. case 'function':
  4052. return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
  4053. }
  4054. throw new Error("Unknown class name: ".concat(selector.name));
  4055. };
  4056. }
  4057. }
  4058. throw new Error("Unknown selector type: ".concat(selector.type));
  4059. }
  4060. /**
  4061. * @callback TraverseOptionFallback
  4062. * @param {external:AST} node The given node.
  4063. * @returns {string[]} An array of visitor keys for the given node.
  4064. */
  4065. /**
  4066. * @callback ClassMatcher
  4067. * @param {string} className The name of the class to match.
  4068. * @param {external:AST} node The node to match against.
  4069. * @param {Array<external:AST>} ancestry The ancestry of the node.
  4070. * @returns {boolean} True if the node matches the class, false if not.
  4071. */
  4072. /**
  4073. * @typedef {object} ESQueryOptions
  4074. * @property {string} [nodeTypeKey="type"] By passing `nodeTypeKey`, we can allow other ASTs to use ESQuery.
  4075. * @property { { [nodeType: string]: string[] } } [visitorKeys] By passing `visitorKeys` mapping, we can extend the properties of the nodes that traverse the node.
  4076. * @property {TraverseOptionFallback} [fallback] By passing `fallback` option, we can control the properties of traversing nodes when encountering unknown nodes.
  4077. * @property {ClassMatcher} [matchClass] By passing `matchClass` option, we can customize the interpretation of classes.
  4078. */
  4079. /**
  4080. * Given a `node` and its ancestors, determine if `node` is matched
  4081. * by `selector`.
  4082. * @param {?external:AST} node
  4083. * @param {?SelectorAST} selector
  4084. * @param {external:AST[]} [ancestry=[]]
  4085. * @param {ESQueryOptions} [options]
  4086. * @throws {Error} Unknowns (operator, class name, selector type, or
  4087. * selector value type)
  4088. * @returns {boolean}
  4089. */
  4090. function matches(node, selector, ancestry, options) {
  4091. if (!selector) {
  4092. return true;
  4093. }
  4094. if (!node) {
  4095. return false;
  4096. }
  4097. if (!ancestry) {
  4098. ancestry = [];
  4099. }
  4100. return getMatcher(selector)(node, ancestry, options);
  4101. }
  4102. /**
  4103. * Get visitor keys of a given node.
  4104. * @param {external:AST} node The AST node to get keys.
  4105. * @param {ESQueryOptions|undefined} options
  4106. * @returns {string[]} Visitor keys of the node.
  4107. */
  4108. function getVisitorKeys(node, options) {
  4109. var nodeTypeKey = options && options.nodeTypeKey || 'type';
  4110. var nodeType = node[nodeTypeKey];
  4111. if (options && options.visitorKeys && options.visitorKeys[nodeType]) {
  4112. return options.visitorKeys[nodeType];
  4113. }
  4114. if (estraverse.VisitorKeys[nodeType]) {
  4115. return estraverse.VisitorKeys[nodeType];
  4116. }
  4117. if (options && typeof options.fallback === 'function') {
  4118. return options.fallback(node);
  4119. }
  4120. // 'iteration' fallback
  4121. return Object.keys(node).filter(function (key) {
  4122. return key !== nodeTypeKey;
  4123. });
  4124. }
  4125. /**
  4126. * Check whether the given value is an ASTNode or not.
  4127. * @param {any} node The value to check.
  4128. * @param {ESQueryOptions|undefined} options The options to use.
  4129. * @returns {boolean} `true` if the value is an ASTNode.
  4130. */
  4131. function isNode(node, options) {
  4132. var nodeTypeKey = options && options.nodeTypeKey || 'type';
  4133. return node !== null && _typeof(node) === 'object' && typeof node[nodeTypeKey] === 'string';
  4134. }
  4135. /**
  4136. * Determines if the given node has a sibling that matches the
  4137. * given selector matcher.
  4138. * @param {external:AST} node
  4139. * @param {SelectorMatcher} matcher
  4140. * @param {external:AST[]} ancestry
  4141. * @param {Side} side
  4142. * @param {ESQueryOptions|undefined} options
  4143. * @returns {boolean}
  4144. */
  4145. function sibling(node, matcher, ancestry, side, options) {
  4146. var _ancestry = _slicedToArray(ancestry, 1),
  4147. parent = _ancestry[0];
  4148. if (!parent) {
  4149. return false;
  4150. }
  4151. var keys = getVisitorKeys(parent, options);
  4152. for (var i = 0; i < keys.length; ++i) {
  4153. var listProp = parent[keys[i]];
  4154. if (Array.isArray(listProp)) {
  4155. var startIndex = listProp.indexOf(node);
  4156. if (startIndex < 0) {
  4157. continue;
  4158. }
  4159. var lowerBound = void 0,
  4160. upperBound = void 0;
  4161. if (side === LEFT_SIDE) {
  4162. lowerBound = 0;
  4163. upperBound = startIndex;
  4164. } else {
  4165. lowerBound = startIndex + 1;
  4166. upperBound = listProp.length;
  4167. }
  4168. for (var k = lowerBound; k < upperBound; ++k) {
  4169. if (isNode(listProp[k], options) && matcher(listProp[k], ancestry, options)) {
  4170. return true;
  4171. }
  4172. }
  4173. }
  4174. }
  4175. return false;
  4176. }
  4177. /**
  4178. * Determines if the given node has an adjacent sibling that matches
  4179. * the given selector matcher.
  4180. * @param {external:AST} node
  4181. * @param {SelectorMatcher} matcher
  4182. * @param {external:AST[]} ancestry
  4183. * @param {Side} side
  4184. * @param {ESQueryOptions|undefined} options
  4185. * @returns {boolean}
  4186. */
  4187. function adjacent(node, matcher, ancestry, side, options) {
  4188. var _ancestry2 = _slicedToArray(ancestry, 1),
  4189. parent = _ancestry2[0];
  4190. if (!parent) {
  4191. return false;
  4192. }
  4193. var keys = getVisitorKeys(parent, options);
  4194. for (var i = 0; i < keys.length; ++i) {
  4195. var listProp = parent[keys[i]];
  4196. if (Array.isArray(listProp)) {
  4197. var idx = listProp.indexOf(node);
  4198. if (idx < 0) {
  4199. continue;
  4200. }
  4201. if (side === LEFT_SIDE && idx > 0 && isNode(listProp[idx - 1], options) && matcher(listProp[idx - 1], ancestry, options)) {
  4202. return true;
  4203. }
  4204. if (side === RIGHT_SIDE && idx < listProp.length - 1 && isNode(listProp[idx + 1], options) && matcher(listProp[idx + 1], ancestry, options)) {
  4205. return true;
  4206. }
  4207. }
  4208. }
  4209. return false;
  4210. }
  4211. /**
  4212. * Determines if the given node is the `nth` child.
  4213. * If `nth` is negative then the position is counted
  4214. * from the end of the list of children.
  4215. * @param {external:AST} node
  4216. * @param {external:AST[]} ancestry
  4217. * @param {Integer} nth
  4218. * @param {ESQueryOptions|undefined} options
  4219. * @returns {boolean}
  4220. */
  4221. function nthChild(node, ancestry, nth, options) {
  4222. if (nth === 0) {
  4223. return false;
  4224. }
  4225. var _ancestry3 = _slicedToArray(ancestry, 1),
  4226. parent = _ancestry3[0];
  4227. if (!parent) {
  4228. return false;
  4229. }
  4230. var keys = getVisitorKeys(parent, options);
  4231. for (var i = 0; i < keys.length; ++i) {
  4232. var listProp = parent[keys[i]];
  4233. if (Array.isArray(listProp)) {
  4234. var idx = nth < 0 ? listProp.length + nth : nth - 1;
  4235. if (idx >= 0 && idx < listProp.length && listProp[idx] === node) {
  4236. return true;
  4237. }
  4238. }
  4239. }
  4240. return false;
  4241. }
  4242. /**
  4243. * For each selector node marked as a subject, find the portion of the
  4244. * selector that the subject must match.
  4245. * @param {SelectorAST} selector
  4246. * @param {SelectorAST} [ancestor] Defaults to `selector`
  4247. * @returns {SelectorAST[]}
  4248. */
  4249. function subjects(selector, ancestor) {
  4250. if (selector == null || _typeof(selector) != 'object') {
  4251. return [];
  4252. }
  4253. if (ancestor == null) {
  4254. ancestor = selector;
  4255. }
  4256. var results = selector.subject ? [ancestor] : [];
  4257. var keys = Object.keys(selector);
  4258. for (var i = 0; i < keys.length; ++i) {
  4259. var p = keys[i];
  4260. var sel = selector[p];
  4261. results.push.apply(results, _toConsumableArray(subjects(sel, p === 'left' ? sel : ancestor)));
  4262. }
  4263. return results;
  4264. }
  4265. /**
  4266. * @callback TraverseVisitor
  4267. * @param {?external:AST} node
  4268. * @param {?external:AST} parent
  4269. * @param {external:AST[]} ancestry
  4270. */
  4271. /**
  4272. * From a JS AST and a selector AST, collect all JS AST nodes that
  4273. * match the selector.
  4274. * @param {external:AST} ast
  4275. * @param {?SelectorAST} selector
  4276. * @param {TraverseVisitor} visitor
  4277. * @param {ESQueryOptions} [options]
  4278. * @returns {external:AST[]}
  4279. */
  4280. function traverse(ast, selector, visitor, options) {
  4281. if (!selector) {
  4282. return;
  4283. }
  4284. var ancestry = [];
  4285. var matcher = getMatcher(selector);
  4286. var altSubjects = subjects(selector).map(getMatcher);
  4287. estraverse.traverse(ast, {
  4288. enter: function enter(node, parent) {
  4289. if (parent != null) {
  4290. ancestry.unshift(parent);
  4291. }
  4292. if (matcher(node, ancestry, options)) {
  4293. if (altSubjects.length) {
  4294. for (var i = 0, l = altSubjects.length; i < l; ++i) {
  4295. if (altSubjects[i](node, ancestry, options)) {
  4296. visitor(node, parent, ancestry);
  4297. }
  4298. for (var k = 0, m = ancestry.length; k < m; ++k) {
  4299. var succeedingAncestry = ancestry.slice(k + 1);
  4300. if (altSubjects[i](ancestry[k], succeedingAncestry, options)) {
  4301. visitor(ancestry[k], parent, succeedingAncestry);
  4302. }
  4303. }
  4304. }
  4305. } else {
  4306. visitor(node, parent, ancestry);
  4307. }
  4308. }
  4309. },
  4310. leave: function leave() {
  4311. ancestry.shift();
  4312. },
  4313. keys: options && options.visitorKeys,
  4314. fallback: options && options.fallback || 'iteration'
  4315. });
  4316. }
  4317. /**
  4318. * From a JS AST and a selector AST, collect all JS AST nodes that
  4319. * match the selector.
  4320. * @param {external:AST} ast
  4321. * @param {?SelectorAST} selector
  4322. * @param {ESQueryOptions} [options]
  4323. * @returns {external:AST[]}
  4324. */
  4325. function match(ast, selector, options) {
  4326. var results = [];
  4327. traverse(ast, selector, function (node) {
  4328. results.push(node);
  4329. }, options);
  4330. return results;
  4331. }
  4332. /**
  4333. * Parse a selector string and return its AST.
  4334. * @param {string} selector
  4335. * @returns {SelectorAST}
  4336. */
  4337. function parse(selector) {
  4338. return parser.parse(selector);
  4339. }
  4340. /**
  4341. * Query the code AST using the selector string.
  4342. * @param {external:AST} ast
  4343. * @param {string} selector
  4344. * @param {ESQueryOptions} [options]
  4345. * @returns {external:AST[]}
  4346. */
  4347. function query(ast, selector, options) {
  4348. return match(ast, parse(selector), options);
  4349. }
  4350. query.parse = parse;
  4351. query.match = match;
  4352. query.traverse = traverse;
  4353. query.matches = matches;
  4354. query.query = query;
  4355. export default query;