source: frontend/node_modules/esquery/dist/esquery.esm.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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