Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

esquery.esm.js 119KB

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