esquery.lite.js 112 KB

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