esquery.js 121 KB

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