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