esquery.lite.js 105 KB

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