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