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