source: imaps-frontend/node_modules/esquery/dist/esquery.lite.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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