1 (function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3 typeof define === 'function' && define.amd ? define(factory) :
4 (global = global || self, global.esquery = factory());
5 }(this, (function () { 'use strict';
7 function _typeof(obj) {
8 "@babel/helpers - typeof";
10 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
11 _typeof = function (obj) {
15 _typeof = function (obj) {
16 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
23 function _slicedToArray(arr, i) {
24 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
27 function _toConsumableArray(arr) {
28 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
31 function _arrayWithoutHoles(arr) {
32 if (Array.isArray(arr)) return _arrayLikeToArray(arr);
35 function _arrayWithHoles(arr) {
36 if (Array.isArray(arr)) return arr;
39 function _iterableToArray(iter) {
40 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
43 function _iterableToArrayLimit(arr, i) {
44 if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
51 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
54 if (i && _arr.length === i) break;
61 if (!_n && _i["return"] != null) _i["return"]();
70 function _unsupportedIterableToArray(o, minLen) {
72 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
73 var n = Object.prototype.toString.call(o).slice(8, -1);
74 if (n === "Object" && o.constructor) n = o.constructor.name;
75 if (n === "Map" || n === "Set") return Array.from(n);
76 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
79 function _arrayLikeToArray(arr, len) {
80 if (len == null || len > arr.length) len = arr.length;
82 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
87 function _nonIterableSpread() {
88 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
91 function _nonIterableRest() {
92 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
95 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
97 function createCommonjsModule(fn, module) {
98 return module = { exports: {} }, fn(module, module.exports), module.exports;
101 var estraverse = createCommonjsModule(function (module, exports) {
103 Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
104 Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
106 Redistribution and use in source and binary forms, with or without
107 modification, are permitted provided that the following conditions are met:
109 * Redistributions of source code must retain the above copyright
110 notice, this list of conditions and the following disclaimer.
111 * Redistributions in binary form must reproduce the above copyright
112 notice, this list of conditions and the following disclaimer in the
113 documentation and/or other materials provided with the distribution.
115 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
116 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
117 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
118 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
119 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
120 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
121 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
122 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
124 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
127 /*jslint vars:false, bitwise:true*/
131 /*global exports:true*/
132 (function clone(exports) {
134 var Syntax, VisitorOption, VisitorKeys, BREAK, SKIP, REMOVE;
136 function deepCopy(obj) {
142 if (obj.hasOwnProperty(key)) {
145 if (typeof val === 'object' && val !== null) {
146 ret[key] = deepCopy(val);
154 } // based on LLVM libc++ upper_bound / lower_bound
158 function upperBound(array, func) {
159 var diff, len, i, current;
167 if (func(array[current])) {
179 AssignmentExpression: 'AssignmentExpression',
180 AssignmentPattern: 'AssignmentPattern',
181 ArrayExpression: 'ArrayExpression',
182 ArrayPattern: 'ArrayPattern',
183 ArrowFunctionExpression: 'ArrowFunctionExpression',
184 AwaitExpression: 'AwaitExpression',
185 // CAUTION: It's deferred to ES7.
186 BlockStatement: 'BlockStatement',
187 BinaryExpression: 'BinaryExpression',
188 BreakStatement: 'BreakStatement',
189 CallExpression: 'CallExpression',
190 CatchClause: 'CatchClause',
191 ClassBody: 'ClassBody',
192 ClassDeclaration: 'ClassDeclaration',
193 ClassExpression: 'ClassExpression',
194 ComprehensionBlock: 'ComprehensionBlock',
195 // CAUTION: It's deferred to ES7.
196 ComprehensionExpression: 'ComprehensionExpression',
197 // CAUTION: It's deferred to ES7.
198 ConditionalExpression: 'ConditionalExpression',
199 ContinueStatement: 'ContinueStatement',
200 DebuggerStatement: 'DebuggerStatement',
201 DirectiveStatement: 'DirectiveStatement',
202 DoWhileStatement: 'DoWhileStatement',
203 EmptyStatement: 'EmptyStatement',
204 ExportAllDeclaration: 'ExportAllDeclaration',
205 ExportDefaultDeclaration: 'ExportDefaultDeclaration',
206 ExportNamedDeclaration: 'ExportNamedDeclaration',
207 ExportSpecifier: 'ExportSpecifier',
208 ExpressionStatement: 'ExpressionStatement',
209 ForStatement: 'ForStatement',
210 ForInStatement: 'ForInStatement',
211 ForOfStatement: 'ForOfStatement',
212 FunctionDeclaration: 'FunctionDeclaration',
213 FunctionExpression: 'FunctionExpression',
214 GeneratorExpression: 'GeneratorExpression',
215 // CAUTION: It's deferred to ES7.
216 Identifier: 'Identifier',
217 IfStatement: 'IfStatement',
218 ImportExpression: 'ImportExpression',
219 ImportDeclaration: 'ImportDeclaration',
220 ImportDefaultSpecifier: 'ImportDefaultSpecifier',
221 ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
222 ImportSpecifier: 'ImportSpecifier',
224 LabeledStatement: 'LabeledStatement',
225 LogicalExpression: 'LogicalExpression',
226 MemberExpression: 'MemberExpression',
227 MetaProperty: 'MetaProperty',
228 MethodDefinition: 'MethodDefinition',
229 ModuleSpecifier: 'ModuleSpecifier',
230 NewExpression: 'NewExpression',
231 ObjectExpression: 'ObjectExpression',
232 ObjectPattern: 'ObjectPattern',
234 Property: 'Property',
235 RestElement: 'RestElement',
236 ReturnStatement: 'ReturnStatement',
237 SequenceExpression: 'SequenceExpression',
238 SpreadElement: 'SpreadElement',
240 SwitchStatement: 'SwitchStatement',
241 SwitchCase: 'SwitchCase',
242 TaggedTemplateExpression: 'TaggedTemplateExpression',
243 TemplateElement: 'TemplateElement',
244 TemplateLiteral: 'TemplateLiteral',
245 ThisExpression: 'ThisExpression',
246 ThrowStatement: 'ThrowStatement',
247 TryStatement: 'TryStatement',
248 UnaryExpression: 'UnaryExpression',
249 UpdateExpression: 'UpdateExpression',
250 VariableDeclaration: 'VariableDeclaration',
251 VariableDeclarator: 'VariableDeclarator',
252 WhileStatement: 'WhileStatement',
253 WithStatement: 'WithStatement',
254 YieldExpression: 'YieldExpression'
257 AssignmentExpression: ['left', 'right'],
258 AssignmentPattern: ['left', 'right'],
259 ArrayExpression: ['elements'],
260 ArrayPattern: ['elements'],
261 ArrowFunctionExpression: ['params', 'body'],
262 AwaitExpression: ['argument'],
263 // CAUTION: It's deferred to ES7.
264 BlockStatement: ['body'],
265 BinaryExpression: ['left', 'right'],
266 BreakStatement: ['label'],
267 CallExpression: ['callee', 'arguments'],
268 CatchClause: ['param', 'body'],
270 ClassDeclaration: ['id', 'superClass', 'body'],
271 ClassExpression: ['id', 'superClass', 'body'],
272 ComprehensionBlock: ['left', 'right'],
273 // CAUTION: It's deferred to ES7.
274 ComprehensionExpression: ['blocks', 'filter', 'body'],
275 // CAUTION: It's deferred to ES7.
276 ConditionalExpression: ['test', 'consequent', 'alternate'],
277 ContinueStatement: ['label'],
278 DebuggerStatement: [],
279 DirectiveStatement: [],
280 DoWhileStatement: ['body', 'test'],
282 ExportAllDeclaration: ['source'],
283 ExportDefaultDeclaration: ['declaration'],
284 ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
285 ExportSpecifier: ['exported', 'local'],
286 ExpressionStatement: ['expression'],
287 ForStatement: ['init', 'test', 'update', 'body'],
288 ForInStatement: ['left', 'right', 'body'],
289 ForOfStatement: ['left', 'right', 'body'],
290 FunctionDeclaration: ['id', 'params', 'body'],
291 FunctionExpression: ['id', 'params', 'body'],
292 GeneratorExpression: ['blocks', 'filter', 'body'],
293 // CAUTION: It's deferred to ES7.
295 IfStatement: ['test', 'consequent', 'alternate'],
296 ImportExpression: ['source'],
297 ImportDeclaration: ['specifiers', 'source'],
298 ImportDefaultSpecifier: ['local'],
299 ImportNamespaceSpecifier: ['local'],
300 ImportSpecifier: ['imported', 'local'],
302 LabeledStatement: ['label', 'body'],
303 LogicalExpression: ['left', 'right'],
304 MemberExpression: ['object', 'property'],
305 MetaProperty: ['meta', 'property'],
306 MethodDefinition: ['key', 'value'],
308 NewExpression: ['callee', 'arguments'],
309 ObjectExpression: ['properties'],
310 ObjectPattern: ['properties'],
312 Property: ['key', 'value'],
313 RestElement: ['argument'],
314 ReturnStatement: ['argument'],
315 SequenceExpression: ['expressions'],
316 SpreadElement: ['argument'],
318 SwitchStatement: ['discriminant', 'cases'],
319 SwitchCase: ['test', 'consequent'],
320 TaggedTemplateExpression: ['tag', 'quasi'],
322 TemplateLiteral: ['quasis', 'expressions'],
324 ThrowStatement: ['argument'],
325 TryStatement: ['block', 'handler', 'finalizer'],
326 UnaryExpression: ['argument'],
327 UpdateExpression: ['argument'],
328 VariableDeclaration: ['declarations'],
329 VariableDeclarator: ['id', 'init'],
330 WhileStatement: ['test', 'body'],
331 WithStatement: ['object', 'body'],
332 YieldExpression: ['argument']
344 function Reference(parent, key) {
345 this.parent = parent;
349 Reference.prototype.replace = function replace(node) {
350 this.parent[this.key] = node;
353 Reference.prototype.remove = function remove() {
354 if (Array.isArray(this.parent)) {
355 this.parent.splice(this.key, 1);
363 function Element(node, path, wrap, ref) {
370 function Controller() {} // API:
371 // return property path array from root to current node
374 Controller.prototype.path = function path() {
375 var i, iz, j, jz, result, element;
377 function addToPath(result, path) {
378 if (Array.isArray(path)) {
379 for (j = 0, jz = path.length; j < jz; ++j) {
380 result.push(path[j]);
388 if (!this.__current.path) {
390 } // first node is sentinel, second node is root element
395 for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
396 element = this.__leavelist[i];
397 addToPath(result, element.path);
400 addToPath(result, this.__current.path);
403 // return type of current node
406 Controller.prototype.type = function () {
407 var node = this.current();
408 return node.type || this.__current.wrap;
410 // return array of parent elements
413 Controller.prototype.parents = function parents() {
414 var i, iz, result; // first node is sentinel
418 for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
419 result.push(this.__leavelist[i].node);
424 // return current node
427 Controller.prototype.current = function current() {
428 return this.__current.node;
431 Controller.prototype.__execute = function __execute(callback, element) {
432 var previous, result;
434 previous = this.__current;
435 this.__current = element;
439 result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
442 this.__current = previous;
445 // notify control skip / break
448 Controller.prototype.notify = function notify(flag) {
451 // skip child nodes of current node
454 Controller.prototype.skip = function () {
460 Controller.prototype['break'] = function () {
466 Controller.prototype.remove = function () {
470 Controller.prototype.__initialize = function (root, visitor) {
471 this.visitor = visitor;
473 this.__worklist = [];
474 this.__leavelist = [];
475 this.__current = null;
477 this.__fallback = null;
479 if (visitor.fallback === 'iteration') {
480 this.__fallback = Object.keys;
481 } else if (typeof visitor.fallback === 'function') {
482 this.__fallback = visitor.fallback;
485 this.__keys = VisitorKeys;
488 this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
492 function isNode(node) {
497 return typeof node === 'object' && typeof node.type === 'string';
500 function isProperty(nodeType, key) {
501 return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
504 function candidateExistsInLeaveList(leavelist, candidate) {
505 for (var i = leavelist.length - 1; i >= 0; --i) {
506 if (leavelist[i].node === candidate) {
514 Controller.prototype.traverse = function traverse(root, visitor) {
515 var worklist, leavelist, element, node, nodeType, ret, key, current, current2, candidates, candidate, sentinel;
517 this.__initialize(root, visitor);
519 sentinel = {}; // reference
521 worklist = this.__worklist;
522 leavelist = this.__leavelist; // initialize
524 worklist.push(new Element(root, null, null, null));
525 leavelist.push(new Element(null, null, null, null));
527 while (worklist.length) {
528 element = worklist.pop();
530 if (element === sentinel) {
531 element = leavelist.pop();
532 ret = this.__execute(visitor.leave, element);
534 if (this.__state === BREAK || ret === BREAK) {
542 ret = this.__execute(visitor.enter, element);
544 if (this.__state === BREAK || ret === BREAK) {
548 worklist.push(sentinel);
549 leavelist.push(element);
551 if (this.__state === SKIP || ret === SKIP) {
556 nodeType = node.type || element.wrap;
557 candidates = this.__keys[nodeType];
560 if (this.__fallback) {
561 candidates = this.__fallback(node);
563 throw new Error('Unknown node type ' + nodeType + '.');
567 current = candidates.length;
569 while ((current -= 1) >= 0) {
570 key = candidates[current];
571 candidate = node[key];
577 if (Array.isArray(candidate)) {
578 current2 = candidate.length;
580 while ((current2 -= 1) >= 0) {
581 if (!candidate[current2]) {
585 if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
589 if (isProperty(nodeType, candidates[current])) {
590 element = new Element(candidate[current2], [key, current2], 'Property', null);
591 } else if (isNode(candidate[current2])) {
592 element = new Element(candidate[current2], [key, current2], null, null);
597 worklist.push(element);
599 } else if (isNode(candidate)) {
600 if (candidateExistsInLeaveList(leavelist, candidate)) {
604 worklist.push(new Element(candidate, key, null, null));
611 Controller.prototype.replace = function replace(root, visitor) {
612 var worklist, leavelist, node, nodeType, target, element, current, current2, candidates, candidate, sentinel, outer, key;
614 function removeElem(element) {
615 var i, key, nextElem, parent;
617 if (element.ref.remove()) {
618 // When the reference is an element of an array.
619 key = element.ref.key;
620 parent = element.ref.parent; // If removed from array, then decrease following items' keys.
625 nextElem = worklist[i];
627 if (nextElem.ref && nextElem.ref.parent === parent) {
628 if (nextElem.ref.key < key) {
638 this.__initialize(root, visitor);
640 sentinel = {}; // reference
642 worklist = this.__worklist;
643 leavelist = this.__leavelist; // initialize
648 element = new Element(root, null, null, new Reference(outer, 'root'));
649 worklist.push(element);
650 leavelist.push(element);
652 while (worklist.length) {
653 element = worklist.pop();
655 if (element === sentinel) {
656 element = leavelist.pop();
657 target = this.__execute(visitor.leave, element); // node may be replaced with null,
658 // so distinguish between undefined and null in this place
660 if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
662 element.ref.replace(target);
665 if (this.__state === REMOVE || target === REMOVE) {
669 if (this.__state === BREAK || target === BREAK) {
676 target = this.__execute(visitor.enter, element); // node may be replaced with null,
677 // so distinguish between undefined and null in this place
679 if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
681 element.ref.replace(target);
682 element.node = target;
685 if (this.__state === REMOVE || target === REMOVE) {
690 if (this.__state === BREAK || target === BREAK) {
692 } // node may be null
701 worklist.push(sentinel);
702 leavelist.push(element);
704 if (this.__state === SKIP || target === SKIP) {
708 nodeType = node.type || element.wrap;
709 candidates = this.__keys[nodeType];
712 if (this.__fallback) {
713 candidates = this.__fallback(node);
715 throw new Error('Unknown node type ' + nodeType + '.');
719 current = candidates.length;
721 while ((current -= 1) >= 0) {
722 key = candidates[current];
723 candidate = node[key];
729 if (Array.isArray(candidate)) {
730 current2 = candidate.length;
732 while ((current2 -= 1) >= 0) {
733 if (!candidate[current2]) {
737 if (isProperty(nodeType, candidates[current])) {
738 element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
739 } else if (isNode(candidate[current2])) {
740 element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
745 worklist.push(element);
747 } else if (isNode(candidate)) {
748 worklist.push(new Element(candidate, key, null, new Reference(node, key)));
756 function traverse(root, visitor) {
757 var controller = new Controller();
758 return controller.traverse(root, visitor);
761 function replace(root, visitor) {
762 var controller = new Controller();
763 return controller.replace(root, visitor);
766 function extendCommentRange(comment, tokens) {
768 target = upperBound(tokens, function search(token) {
769 return token.range[0] > comment.range[0];
771 comment.extendedRange = [comment.range[0], comment.range[1]];
773 if (target !== tokens.length) {
774 comment.extendedRange[1] = tokens[target].range[0];
780 comment.extendedRange[0] = tokens[target].range[1];
786 function attachComments(tree, providedComments, tokens) {
787 // At first, we should calculate extended comment ranges.
795 throw new Error('attachComments needs range information');
796 } // tokens array is empty, we attach comments to tree as 'leadingComments'
799 if (!tokens.length) {
800 if (providedComments.length) {
801 for (i = 0, len = providedComments.length; i < len; i += 1) {
802 comment = deepCopy(providedComments[i]);
803 comment.extendedRange = [0, tree.range[0]];
804 comments.push(comment);
807 tree.leadingComments = comments;
813 for (i = 0, len = providedComments.length; i < len; i += 1) {
814 comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
815 } // This is based on John Freeman's implementation.
820 enter: function (node) {
823 while (cursor < comments.length) {
824 comment = comments[cursor];
826 if (comment.extendedRange[1] > node.range[0]) {
830 if (comment.extendedRange[1] === node.range[0]) {
831 if (!node.leadingComments) {
832 node.leadingComments = [];
835 node.leadingComments.push(comment);
836 comments.splice(cursor, 1);
840 } // already out of owned node
843 if (cursor === comments.length) {
844 return VisitorOption.Break;
847 if (comments[cursor].extendedRange[0] > node.range[1]) {
848 return VisitorOption.Skip;
854 leave: function (node) {
857 while (cursor < comments.length) {
858 comment = comments[cursor];
860 if (node.range[1] < comment.extendedRange[0]) {
864 if (node.range[1] === comment.extendedRange[0]) {
865 if (!node.trailingComments) {
866 node.trailingComments = [];
869 node.trailingComments.push(comment);
870 comments.splice(cursor, 1);
874 } // already out of owned node
877 if (cursor === comments.length) {
878 return VisitorOption.Break;
881 if (comments[cursor].extendedRange[0] > node.range[1]) {
882 return VisitorOption.Skip;
889 exports.Syntax = Syntax;
890 exports.traverse = traverse;
891 exports.replace = replace;
892 exports.attachComments = attachComments;
893 exports.VisitorKeys = VisitorKeys;
894 exports.VisitorOption = VisitorOption;
895 exports.Controller = Controller;
897 exports.cloneEnvironment = function () {
903 /* vim: set sw=4 ts=4 et tw=80 : */
907 var parser = createCommonjsModule(function (module) {
909 * Generated by PEG.js 0.10.0.
913 (function (root, factory) {
914 if ( module.exports) {
915 module.exports = factory();
917 })(commonjsGlobal, function () {
919 function peg$subclass(child, parent) {
921 this.constructor = child;
924 ctor.prototype = parent.prototype;
925 child.prototype = new ctor();
928 function peg$SyntaxError(message, expected, found, location) {
929 this.message = message;
930 this.expected = expected;
932 this.location = location;
933 this.name = "SyntaxError";
935 if (typeof Error.captureStackTrace === "function") {
936 Error.captureStackTrace(this, peg$SyntaxError);
940 peg$subclass(peg$SyntaxError, Error);
942 peg$SyntaxError.buildMessage = function (expected, found) {
943 var DESCRIBE_EXPECTATION_FNS = {
944 literal: function literal(expectation) {
945 return "\"" + literalEscape(expectation.text) + "\"";
947 "class": function _class(expectation) {
948 var escapedParts = "",
951 for (i = 0; i < expectation.parts.length; i++) {
952 escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
955 return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
957 any: function any(expectation) {
958 return "any character";
960 end: function end(expectation) {
961 return "end of input";
963 other: function other(expectation) {
964 return expectation.description;
969 return ch.charCodeAt(0).toString(16).toUpperCase();
972 function literalEscape(s) {
973 return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
974 return '\\x0' + hex(ch);
975 }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
976 return '\\x' + hex(ch);
980 function classEscape(s) {
981 return s.replace(/\\/g, '\\\\').replace(/\]/g, '\\]').replace(/\^/g, '\\^').replace(/-/g, '\\-').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
982 return '\\x0' + hex(ch);
983 }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
984 return '\\x' + hex(ch);
988 function describeExpectation(expectation) {
989 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
992 function describeExpected(expected) {
993 var descriptions = new Array(expected.length),
997 for (i = 0; i < expected.length; i++) {
998 descriptions[i] = describeExpectation(expected[i]);
1001 descriptions.sort();
1003 if (descriptions.length > 0) {
1004 for (i = 1, j = 1; i < descriptions.length; i++) {
1005 if (descriptions[i - 1] !== descriptions[i]) {
1006 descriptions[j] = descriptions[i];
1011 descriptions.length = j;
1014 switch (descriptions.length) {
1016 return descriptions[0];
1019 return descriptions[0] + " or " + descriptions[1];
1022 return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
1026 function describeFound(found) {
1027 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
1030 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
1033 function peg$parse(input, options) {
1034 options = options !== void 0 ? options : {};
1036 var peg$FAILED = {},
1037 peg$startRuleFunctions = {
1038 start: peg$parsestart
1040 peg$startRuleFunction = peg$parsestart,
1041 peg$c0 = function peg$c0(ss) {
1042 return ss.length === 1 ? ss[0] : {
1047 peg$c1 = function peg$c1() {
1051 peg$c3 = peg$literalExpectation(" ", false),
1052 peg$c4 = /^[^ [\],():#!=><~+.]/,
1053 peg$c5 = peg$classExpectation([" ", "[", "]", ",", "(", ")", ":", "#", "!", "=", ">", "<", "~", "+", "."], true, false),
1054 peg$c6 = function peg$c6(i) {
1058 peg$c8 = peg$literalExpectation(">", false),
1059 peg$c9 = function peg$c9() {
1063 peg$c11 = peg$literalExpectation("~", false),
1064 peg$c12 = function peg$c12() {
1068 peg$c14 = peg$literalExpectation("+", false),
1069 peg$c15 = function peg$c15() {
1072 peg$c16 = function peg$c16() {
1073 return 'descendant';
1076 peg$c18 = peg$literalExpectation(",", false),
1077 peg$c19 = function peg$c19(s, ss) {
1078 return [s].concat(ss.map(function (s) {
1082 peg$c20 = function peg$c20(a, ops) {
1083 return ops.reduce(function (memo, rhs) {
1092 peg$c22 = peg$literalExpectation("!", false),
1093 peg$c23 = function peg$c23(subject, as) {
1094 var b = as.length === 1 ? as[0] : {
1098 if (subject) b.subject = true;
1102 peg$c25 = peg$literalExpectation("*", false),
1103 peg$c26 = function peg$c26(a) {
1110 peg$c28 = peg$literalExpectation("#", false),
1111 peg$c29 = function peg$c29(i) {
1118 peg$c31 = peg$literalExpectation("[", false),
1120 peg$c33 = peg$literalExpectation("]", false),
1121 peg$c34 = function peg$c34(v) {
1125 peg$c36 = peg$classExpectation([">", "<", "!"], false, false),
1127 peg$c38 = peg$literalExpectation("=", false),
1128 peg$c39 = function peg$c39(a) {
1129 return (a || '') + '=';
1132 peg$c41 = peg$classExpectation([">", "<"], false, false),
1134 peg$c43 = peg$literalExpectation(".", false),
1135 peg$c44 = function peg$c44(name, op, value) {
1143 peg$c45 = function peg$c45(name) {
1150 peg$c47 = peg$literalExpectation("\"", false),
1151 peg$c48 = /^[^\\"]/,
1152 peg$c49 = peg$classExpectation(["\\", "\""], true, false),
1154 peg$c51 = peg$literalExpectation("\\", false),
1155 peg$c52 = peg$anyExpectation(),
1156 peg$c53 = function peg$c53(a, b) {
1159 peg$c54 = function peg$c54(d) {
1162 value: strUnescape(d.join(''))
1166 peg$c56 = peg$literalExpectation("'", false),
1167 peg$c57 = /^[^\\']/,
1168 peg$c58 = peg$classExpectation(["\\", "'"], true, false),
1170 peg$c60 = peg$classExpectation([["0", "9"]], false, false),
1171 peg$c61 = function peg$c61(a, b) {
1172 // Can use `a.flat().join('')` once supported
1173 var leadingDecimals = a ? [].concat.apply([], a).join('') : '';
1176 value: parseFloat(leadingDecimals + b.join(''))
1179 peg$c62 = function peg$c62(i) {
1186 peg$c64 = peg$literalExpectation("type(", false),
1188 peg$c66 = peg$classExpectation([" ", ")"], true, false),
1190 peg$c68 = peg$literalExpectation(")", false),
1191 peg$c69 = function peg$c69(t) {
1197 peg$c70 = /^[imsu]/,
1198 peg$c71 = peg$classExpectation(["i", "m", "s", "u"], false, false),
1200 peg$c73 = peg$literalExpectation("/", false),
1202 peg$c75 = peg$classExpectation(["/"], true, false),
1203 peg$c76 = function peg$c76(d, flgs) {
1206 value: new RegExp(d.join(''), flgs ? flgs.join('') : '')
1209 peg$c77 = function peg$c77(i, is) {
1212 name: is.reduce(function (memo, p) {
1213 return memo + p[0] + p[1];
1218 peg$c79 = peg$literalExpectation(":not(", false),
1219 peg$c80 = function peg$c80(ss) {
1225 peg$c81 = ":matches(",
1226 peg$c82 = peg$literalExpectation(":matches(", false),
1227 peg$c83 = function peg$c83(ss) {
1234 peg$c85 = peg$literalExpectation(":has(", false),
1235 peg$c86 = function peg$c86(ss) {
1241 peg$c87 = ":first-child",
1242 peg$c88 = peg$literalExpectation(":first-child", false),
1243 peg$c89 = function peg$c89() {
1246 peg$c90 = ":last-child",
1247 peg$c91 = peg$literalExpectation(":last-child", false),
1248 peg$c92 = function peg$c92() {
1251 peg$c93 = ":nth-child(",
1252 peg$c94 = peg$literalExpectation(":nth-child(", false),
1253 peg$c95 = function peg$c95(n) {
1254 return nth(parseInt(n.join(''), 10));
1256 peg$c96 = ":nth-last-child(",
1257 peg$c97 = peg$literalExpectation(":nth-last-child(", false),
1258 peg$c98 = function peg$c98(n) {
1259 return nthLast(parseInt(n.join(''), 10));
1262 peg$c100 = peg$literalExpectation(":", false),
1263 peg$c101 = "statement",
1264 peg$c102 = peg$literalExpectation("statement", true),
1265 peg$c103 = "expression",
1266 peg$c104 = peg$literalExpectation("expression", true),
1267 peg$c105 = "declaration",
1268 peg$c106 = peg$literalExpectation("declaration", true),
1269 peg$c107 = "function",
1270 peg$c108 = peg$literalExpectation("function", true),
1271 peg$c109 = "pattern",
1272 peg$c110 = peg$literalExpectation("pattern", true),
1273 peg$c111 = function peg$c111(c) {
1280 peg$posDetailsCache = [{
1285 peg$maxFailExpected = [],
1286 peg$resultsCache = {},
1289 if ("startRule" in options) {
1290 if (!(options.startRule in peg$startRuleFunctions)) {
1291 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
1294 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
1297 function peg$literalExpectation(text, ignoreCase) {
1301 ignoreCase: ignoreCase
1305 function peg$classExpectation(parts, inverted, ignoreCase) {
1310 ignoreCase: ignoreCase
1314 function peg$anyExpectation() {
1320 function peg$endExpectation() {
1326 function peg$computePosDetails(pos) {
1327 var details = peg$posDetailsCache[pos],
1335 while (!peg$posDetailsCache[p]) {
1339 details = peg$posDetailsCache[p];
1342 column: details.column
1346 if (input.charCodeAt(p) === 10) {
1356 peg$posDetailsCache[pos] = details;
1361 function peg$computeLocation(startPos, endPos) {
1362 var startPosDetails = peg$computePosDetails(startPos),
1363 endPosDetails = peg$computePosDetails(endPos);
1367 line: startPosDetails.line,
1368 column: startPosDetails.column
1372 line: endPosDetails.line,
1373 column: endPosDetails.column
1378 function peg$fail(expected) {
1379 if (peg$currPos < peg$maxFailPos) {
1383 if (peg$currPos > peg$maxFailPos) {
1384 peg$maxFailPos = peg$currPos;
1385 peg$maxFailExpected = [];
1388 peg$maxFailExpected.push(expected);
1391 function peg$buildStructuredError(expected, found, location) {
1392 return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1395 function peg$parsestart() {
1397 var key = peg$currPos * 30 + 0,
1398 cached = peg$resultsCache[key];
1401 peg$currPos = cached.nextPos;
1402 return cached.result;
1408 if (s1 !== peg$FAILED) {
1409 s2 = peg$parseselectors();
1411 if (s2 !== peg$FAILED) {
1414 if (s3 !== peg$FAILED) {
1430 if (s0 === peg$FAILED) {
1434 if (s1 !== peg$FAILED) {
1441 peg$resultsCache[key] = {
1442 nextPos: peg$currPos,
1448 function peg$parse_() {
1450 var key = peg$currPos * 30 + 1,
1451 cached = peg$resultsCache[key];
1454 peg$currPos = cached.nextPos;
1455 return cached.result;
1460 if (input.charCodeAt(peg$currPos) === 32) {
1471 while (s1 !== peg$FAILED) {
1474 if (input.charCodeAt(peg$currPos) === 32) {
1486 peg$resultsCache[key] = {
1487 nextPos: peg$currPos,
1493 function peg$parseidentifierName() {
1495 var key = peg$currPos * 30 + 2,
1496 cached = peg$resultsCache[key];
1499 peg$currPos = cached.nextPos;
1500 return cached.result;
1506 if (peg$c4.test(input.charAt(peg$currPos))) {
1507 s2 = input.charAt(peg$currPos);
1517 if (s2 !== peg$FAILED) {
1518 while (s2 !== peg$FAILED) {
1521 if (peg$c4.test(input.charAt(peg$currPos))) {
1522 s2 = input.charAt(peg$currPos);
1536 if (s1 !== peg$FAILED) {
1541 peg$resultsCache[key] = {
1542 nextPos: peg$currPos,
1548 function peg$parsebinaryOp() {
1550 var key = peg$currPos * 30 + 3,
1551 cached = peg$resultsCache[key];
1554 peg$currPos = cached.nextPos;
1555 return cached.result;
1561 if (s1 !== peg$FAILED) {
1562 if (input.charCodeAt(peg$currPos) === 62) {
1573 if (s2 !== peg$FAILED) {
1576 if (s3 !== peg$FAILED) {
1592 if (s0 === peg$FAILED) {
1596 if (s1 !== peg$FAILED) {
1597 if (input.charCodeAt(peg$currPos) === 126) {
1608 if (s2 !== peg$FAILED) {
1611 if (s3 !== peg$FAILED) {
1627 if (s0 === peg$FAILED) {
1631 if (s1 !== peg$FAILED) {
1632 if (input.charCodeAt(peg$currPos) === 43) {
1643 if (s2 !== peg$FAILED) {
1646 if (s3 !== peg$FAILED) {
1662 if (s0 === peg$FAILED) {
1665 if (input.charCodeAt(peg$currPos) === 32) {
1676 if (s1 !== peg$FAILED) {
1679 if (s2 !== peg$FAILED) {
1694 peg$resultsCache[key] = {
1695 nextPos: peg$currPos,
1701 function peg$parseselectors() {
1702 var s0, s1, s2, s3, s4, s5, s6, s7;
1703 var key = peg$currPos * 30 + 4,
1704 cached = peg$resultsCache[key];
1707 peg$currPos = cached.nextPos;
1708 return cached.result;
1712 s1 = peg$parseselector();
1714 if (s1 !== peg$FAILED) {
1719 if (s4 !== peg$FAILED) {
1720 if (input.charCodeAt(peg$currPos) === 44) {
1731 if (s5 !== peg$FAILED) {
1734 if (s6 !== peg$FAILED) {
1735 s7 = peg$parseselector();
1737 if (s7 !== peg$FAILED) {
1738 s4 = [s4, s5, s6, s7];
1757 while (s3 !== peg$FAILED) {
1762 if (s4 !== peg$FAILED) {
1763 if (input.charCodeAt(peg$currPos) === 44) {
1774 if (s5 !== peg$FAILED) {
1777 if (s6 !== peg$FAILED) {
1778 s7 = peg$parseselector();
1780 if (s7 !== peg$FAILED) {
1781 s4 = [s4, s5, s6, s7];
1801 if (s2 !== peg$FAILED) {
1802 s1 = peg$c19(s1, s2);
1813 peg$resultsCache[key] = {
1814 nextPos: peg$currPos,
1820 function peg$parseselector() {
1821 var s0, s1, s2, s3, s4, s5;
1822 var key = peg$currPos * 30 + 5,
1823 cached = peg$resultsCache[key];
1826 peg$currPos = cached.nextPos;
1827 return cached.result;
1831 s1 = peg$parsesequence();
1833 if (s1 !== peg$FAILED) {
1836 s4 = peg$parsebinaryOp();
1838 if (s4 !== peg$FAILED) {
1839 s5 = peg$parsesequence();
1841 if (s5 !== peg$FAILED) {
1853 while (s3 !== peg$FAILED) {
1856 s4 = peg$parsebinaryOp();
1858 if (s4 !== peg$FAILED) {
1859 s5 = peg$parsesequence();
1861 if (s5 !== peg$FAILED) {
1874 if (s2 !== peg$FAILED) {
1875 s1 = peg$c20(s1, s2);
1886 peg$resultsCache[key] = {
1887 nextPos: peg$currPos,
1893 function peg$parsesequence() {
1895 var key = peg$currPos * 30 + 6,
1896 cached = peg$resultsCache[key];
1899 peg$currPos = cached.nextPos;
1900 return cached.result;
1905 if (input.charCodeAt(peg$currPos) === 33) {
1916 if (s1 === peg$FAILED) {
1920 if (s1 !== peg$FAILED) {
1922 s3 = peg$parseatom();
1924 if (s3 !== peg$FAILED) {
1925 while (s3 !== peg$FAILED) {
1927 s3 = peg$parseatom();
1933 if (s2 !== peg$FAILED) {
1934 s1 = peg$c23(s1, s2);
1945 peg$resultsCache[key] = {
1946 nextPos: peg$currPos,
1952 function peg$parseatom() {
1954 var key = peg$currPos * 30 + 7,
1955 cached = peg$resultsCache[key];
1958 peg$currPos = cached.nextPos;
1959 return cached.result;
1962 s0 = peg$parsewildcard();
1964 if (s0 === peg$FAILED) {
1965 s0 = peg$parseidentifier();
1967 if (s0 === peg$FAILED) {
1968 s0 = peg$parseattr();
1970 if (s0 === peg$FAILED) {
1971 s0 = peg$parsefield();
1973 if (s0 === peg$FAILED) {
1974 s0 = peg$parsenegation();
1976 if (s0 === peg$FAILED) {
1977 s0 = peg$parsematches();
1979 if (s0 === peg$FAILED) {
1980 s0 = peg$parsehas();
1982 if (s0 === peg$FAILED) {
1983 s0 = peg$parsefirstChild();
1985 if (s0 === peg$FAILED) {
1986 s0 = peg$parselastChild();
1988 if (s0 === peg$FAILED) {
1989 s0 = peg$parsenthChild();
1991 if (s0 === peg$FAILED) {
1992 s0 = peg$parsenthLastChild();
1994 if (s0 === peg$FAILED) {
1995 s0 = peg$parseclass();
2008 peg$resultsCache[key] = {
2009 nextPos: peg$currPos,
2015 function peg$parsewildcard() {
2017 var key = peg$currPos * 30 + 8,
2018 cached = peg$resultsCache[key];
2021 peg$currPos = cached.nextPos;
2022 return cached.result;
2027 if (input.charCodeAt(peg$currPos) === 42) {
2038 if (s1 !== peg$FAILED) {
2043 peg$resultsCache[key] = {
2044 nextPos: peg$currPos,
2050 function peg$parseidentifier() {
2052 var key = peg$currPos * 30 + 9,
2053 cached = peg$resultsCache[key];
2056 peg$currPos = cached.nextPos;
2057 return cached.result;
2062 if (input.charCodeAt(peg$currPos) === 35) {
2073 if (s1 === peg$FAILED) {
2077 if (s1 !== peg$FAILED) {
2078 s2 = peg$parseidentifierName();
2080 if (s2 !== peg$FAILED) {
2092 peg$resultsCache[key] = {
2093 nextPos: peg$currPos,
2099 function peg$parseattr() {
2100 var s0, s1, s2, s3, s4, s5;
2101 var key = peg$currPos * 30 + 10,
2102 cached = peg$resultsCache[key];
2105 peg$currPos = cached.nextPos;
2106 return cached.result;
2111 if (input.charCodeAt(peg$currPos) === 91) {
2122 if (s1 !== peg$FAILED) {
2125 if (s2 !== peg$FAILED) {
2126 s3 = peg$parseattrValue();
2128 if (s3 !== peg$FAILED) {
2131 if (s4 !== peg$FAILED) {
2132 if (input.charCodeAt(peg$currPos) === 93) {
2143 if (s5 !== peg$FAILED) {
2167 peg$resultsCache[key] = {
2168 nextPos: peg$currPos,
2174 function peg$parseattrOps() {
2176 var key = peg$currPos * 30 + 11,
2177 cached = peg$resultsCache[key];
2180 peg$currPos = cached.nextPos;
2181 return cached.result;
2186 if (peg$c35.test(input.charAt(peg$currPos))) {
2187 s1 = input.charAt(peg$currPos);
2197 if (s1 === peg$FAILED) {
2201 if (s1 !== peg$FAILED) {
2202 if (input.charCodeAt(peg$currPos) === 61) {
2213 if (s2 !== peg$FAILED) {
2225 if (s0 === peg$FAILED) {
2226 if (peg$c40.test(input.charAt(peg$currPos))) {
2227 s0 = input.charAt(peg$currPos);
2238 peg$resultsCache[key] = {
2239 nextPos: peg$currPos,
2245 function peg$parseattrEqOps() {
2247 var key = peg$currPos * 30 + 12,
2248 cached = peg$resultsCache[key];
2251 peg$currPos = cached.nextPos;
2252 return cached.result;
2257 if (input.charCodeAt(peg$currPos) === 33) {
2268 if (s1 === peg$FAILED) {
2272 if (s1 !== peg$FAILED) {
2273 if (input.charCodeAt(peg$currPos) === 61) {
2284 if (s2 !== peg$FAILED) {
2296 peg$resultsCache[key] = {
2297 nextPos: peg$currPos,
2303 function peg$parseattrName() {
2305 var key = peg$currPos * 30 + 13,
2306 cached = peg$resultsCache[key];
2309 peg$currPos = cached.nextPos;
2310 return cached.result;
2315 s2 = peg$parseidentifierName();
2317 if (s2 === peg$FAILED) {
2318 if (input.charCodeAt(peg$currPos) === 46) {
2330 if (s2 !== peg$FAILED) {
2331 while (s2 !== peg$FAILED) {
2333 s2 = peg$parseidentifierName();
2335 if (s2 === peg$FAILED) {
2336 if (input.charCodeAt(peg$currPos) === 46) {
2352 if (s1 !== peg$FAILED) {
2357 peg$resultsCache[key] = {
2358 nextPos: peg$currPos,
2364 function peg$parseattrValue() {
2365 var s0, s1, s2, s3, s4, s5;
2366 var key = peg$currPos * 30 + 14,
2367 cached = peg$resultsCache[key];
2370 peg$currPos = cached.nextPos;
2371 return cached.result;
2375 s1 = peg$parseattrName();
2377 if (s1 !== peg$FAILED) {
2380 if (s2 !== peg$FAILED) {
2381 s3 = peg$parseattrEqOps();
2383 if (s3 !== peg$FAILED) {
2386 if (s4 !== peg$FAILED) {
2387 s5 = peg$parsetype();
2389 if (s5 === peg$FAILED) {
2390 s5 = peg$parseregex();
2393 if (s5 !== peg$FAILED) {
2394 s1 = peg$c44(s1, s3, s5);
2417 if (s0 === peg$FAILED) {
2419 s1 = peg$parseattrName();
2421 if (s1 !== peg$FAILED) {
2424 if (s2 !== peg$FAILED) {
2425 s3 = peg$parseattrOps();
2427 if (s3 !== peg$FAILED) {
2430 if (s4 !== peg$FAILED) {
2431 s5 = peg$parsestring();
2433 if (s5 === peg$FAILED) {
2434 s5 = peg$parsenumber();
2436 if (s5 === peg$FAILED) {
2437 s5 = peg$parsepath();
2441 if (s5 !== peg$FAILED) {
2442 s1 = peg$c44(s1, s3, s5);
2465 if (s0 === peg$FAILED) {
2467 s1 = peg$parseattrName();
2469 if (s1 !== peg$FAILED) {
2477 peg$resultsCache[key] = {
2478 nextPos: peg$currPos,
2484 function peg$parsestring() {
2485 var s0, s1, s2, s3, s4, s5;
2486 var key = peg$currPos * 30 + 15,
2487 cached = peg$resultsCache[key];
2490 peg$currPos = cached.nextPos;
2491 return cached.result;
2496 if (input.charCodeAt(peg$currPos) === 34) {
2507 if (s1 !== peg$FAILED) {
2510 if (peg$c48.test(input.charAt(peg$currPos))) {
2511 s3 = input.charAt(peg$currPos);
2521 if (s3 === peg$FAILED) {
2524 if (input.charCodeAt(peg$currPos) === 92) {
2535 if (s4 !== peg$FAILED) {
2536 if (input.length > peg$currPos) {
2537 s5 = input.charAt(peg$currPos);
2547 if (s5 !== peg$FAILED) {
2548 s4 = peg$c53(s4, s5);
2560 while (s3 !== peg$FAILED) {
2563 if (peg$c48.test(input.charAt(peg$currPos))) {
2564 s3 = input.charAt(peg$currPos);
2574 if (s3 === peg$FAILED) {
2577 if (input.charCodeAt(peg$currPos) === 92) {
2588 if (s4 !== peg$FAILED) {
2589 if (input.length > peg$currPos) {
2590 s5 = input.charAt(peg$currPos);
2600 if (s5 !== peg$FAILED) {
2601 s4 = peg$c53(s4, s5);
2614 if (s2 !== peg$FAILED) {
2615 if (input.charCodeAt(peg$currPos) === 34) {
2626 if (s3 !== peg$FAILED) {
2642 if (s0 === peg$FAILED) {
2645 if (input.charCodeAt(peg$currPos) === 39) {
2656 if (s1 !== peg$FAILED) {
2659 if (peg$c57.test(input.charAt(peg$currPos))) {
2660 s3 = input.charAt(peg$currPos);
2670 if (s3 === peg$FAILED) {
2673 if (input.charCodeAt(peg$currPos) === 92) {
2684 if (s4 !== peg$FAILED) {
2685 if (input.length > peg$currPos) {
2686 s5 = input.charAt(peg$currPos);
2696 if (s5 !== peg$FAILED) {
2697 s4 = peg$c53(s4, s5);
2709 while (s3 !== peg$FAILED) {
2712 if (peg$c57.test(input.charAt(peg$currPos))) {
2713 s3 = input.charAt(peg$currPos);
2723 if (s3 === peg$FAILED) {
2726 if (input.charCodeAt(peg$currPos) === 92) {
2737 if (s4 !== peg$FAILED) {
2738 if (input.length > peg$currPos) {
2739 s5 = input.charAt(peg$currPos);
2749 if (s5 !== peg$FAILED) {
2750 s4 = peg$c53(s4, s5);
2763 if (s2 !== peg$FAILED) {
2764 if (input.charCodeAt(peg$currPos) === 39) {
2775 if (s3 !== peg$FAILED) {
2792 peg$resultsCache[key] = {
2793 nextPos: peg$currPos,
2799 function peg$parsenumber() {
2801 var key = peg$currPos * 30 + 16,
2802 cached = peg$resultsCache[key];
2805 peg$currPos = cached.nextPos;
2806 return cached.result;
2813 if (peg$c59.test(input.charAt(peg$currPos))) {
2814 s3 = input.charAt(peg$currPos);
2824 while (s3 !== peg$FAILED) {
2827 if (peg$c59.test(input.charAt(peg$currPos))) {
2828 s3 = input.charAt(peg$currPos);
2839 if (s2 !== peg$FAILED) {
2840 if (input.charCodeAt(peg$currPos) === 46) {
2851 if (s3 !== peg$FAILED) {
2863 if (s1 === peg$FAILED) {
2867 if (s1 !== peg$FAILED) {
2870 if (peg$c59.test(input.charAt(peg$currPos))) {
2871 s3 = input.charAt(peg$currPos);
2881 if (s3 !== peg$FAILED) {
2882 while (s3 !== peg$FAILED) {
2885 if (peg$c59.test(input.charAt(peg$currPos))) {
2886 s3 = input.charAt(peg$currPos);
2900 if (s2 !== peg$FAILED) {
2901 s1 = peg$c61(s1, s2);
2912 peg$resultsCache[key] = {
2913 nextPos: peg$currPos,
2919 function peg$parsepath() {
2921 var key = peg$currPos * 30 + 17,
2922 cached = peg$resultsCache[key];
2925 peg$currPos = cached.nextPos;
2926 return cached.result;
2930 s1 = peg$parseidentifierName();
2932 if (s1 !== peg$FAILED) {
2937 peg$resultsCache[key] = {
2938 nextPos: peg$currPos,
2944 function peg$parsetype() {
2945 var s0, s1, s2, s3, s4, s5;
2946 var key = peg$currPos * 30 + 18,
2947 cached = peg$resultsCache[key];
2950 peg$currPos = cached.nextPos;
2951 return cached.result;
2956 if (input.substr(peg$currPos, 5) === peg$c63) {
2967 if (s1 !== peg$FAILED) {
2970 if (s2 !== peg$FAILED) {
2973 if (peg$c65.test(input.charAt(peg$currPos))) {
2974 s4 = input.charAt(peg$currPos);
2984 if (s4 !== peg$FAILED) {
2985 while (s4 !== peg$FAILED) {
2988 if (peg$c65.test(input.charAt(peg$currPos))) {
2989 s4 = input.charAt(peg$currPos);
3003 if (s3 !== peg$FAILED) {
3006 if (s4 !== peg$FAILED) {
3007 if (input.charCodeAt(peg$currPos) === 41) {
3018 if (s5 !== peg$FAILED) {
3042 peg$resultsCache[key] = {
3043 nextPos: peg$currPos,
3049 function peg$parseflags() {
3051 var key = peg$currPos * 30 + 19,
3052 cached = peg$resultsCache[key];
3055 peg$currPos = cached.nextPos;
3056 return cached.result;
3061 if (peg$c70.test(input.charAt(peg$currPos))) {
3062 s1 = input.charAt(peg$currPos);
3072 if (s1 !== peg$FAILED) {
3073 while (s1 !== peg$FAILED) {
3076 if (peg$c70.test(input.charAt(peg$currPos))) {
3077 s1 = input.charAt(peg$currPos);
3091 peg$resultsCache[key] = {
3092 nextPos: peg$currPos,
3098 function peg$parseregex() {
3099 var s0, s1, s2, s3, s4;
3100 var key = peg$currPos * 30 + 20,
3101 cached = peg$resultsCache[key];
3104 peg$currPos = cached.nextPos;
3105 return cached.result;
3110 if (input.charCodeAt(peg$currPos) === 47) {
3121 if (s1 !== peg$FAILED) {
3124 if (peg$c74.test(input.charAt(peg$currPos))) {
3125 s3 = input.charAt(peg$currPos);
3135 if (s3 !== peg$FAILED) {
3136 while (s3 !== peg$FAILED) {
3139 if (peg$c74.test(input.charAt(peg$currPos))) {
3140 s3 = input.charAt(peg$currPos);
3154 if (s2 !== peg$FAILED) {
3155 if (input.charCodeAt(peg$currPos) === 47) {
3166 if (s3 !== peg$FAILED) {
3167 s4 = peg$parseflags();
3169 if (s4 === peg$FAILED) {
3173 if (s4 !== peg$FAILED) {
3174 s1 = peg$c76(s2, s4);
3193 peg$resultsCache[key] = {
3194 nextPos: peg$currPos,
3200 function peg$parsefield() {
3201 var s0, s1, s2, s3, s4, s5, s6;
3202 var key = peg$currPos * 30 + 21,
3203 cached = peg$resultsCache[key];
3206 peg$currPos = cached.nextPos;
3207 return cached.result;
3212 if (input.charCodeAt(peg$currPos) === 46) {
3223 if (s1 !== peg$FAILED) {
3224 s2 = peg$parseidentifierName();
3226 if (s2 !== peg$FAILED) {
3230 if (input.charCodeAt(peg$currPos) === 46) {
3241 if (s5 !== peg$FAILED) {
3242 s6 = peg$parseidentifierName();
3244 if (s6 !== peg$FAILED) {
3256 while (s4 !== peg$FAILED) {
3260 if (input.charCodeAt(peg$currPos) === 46) {
3271 if (s5 !== peg$FAILED) {
3272 s6 = peg$parseidentifierName();
3274 if (s6 !== peg$FAILED) {
3287 if (s3 !== peg$FAILED) {
3288 s1 = peg$c77(s2, s3);
3303 peg$resultsCache[key] = {
3304 nextPos: peg$currPos,
3310 function peg$parsenegation() {
3311 var s0, s1, s2, s3, s4, s5;
3312 var key = peg$currPos * 30 + 22,
3313 cached = peg$resultsCache[key];
3316 peg$currPos = cached.nextPos;
3317 return cached.result;
3322 if (input.substr(peg$currPos, 5) === peg$c78) {
3333 if (s1 !== peg$FAILED) {
3336 if (s2 !== peg$FAILED) {
3337 s3 = peg$parseselectors();
3339 if (s3 !== peg$FAILED) {
3342 if (s4 !== peg$FAILED) {
3343 if (input.charCodeAt(peg$currPos) === 41) {
3354 if (s5 !== peg$FAILED) {
3378 peg$resultsCache[key] = {
3379 nextPos: peg$currPos,
3385 function peg$parsematches() {
3386 var s0, s1, s2, s3, s4, s5;
3387 var key = peg$currPos * 30 + 23,
3388 cached = peg$resultsCache[key];
3391 peg$currPos = cached.nextPos;
3392 return cached.result;
3397 if (input.substr(peg$currPos, 9) === peg$c81) {
3408 if (s1 !== peg$FAILED) {
3411 if (s2 !== peg$FAILED) {
3412 s3 = peg$parseselectors();
3414 if (s3 !== peg$FAILED) {
3417 if (s4 !== peg$FAILED) {
3418 if (input.charCodeAt(peg$currPos) === 41) {
3429 if (s5 !== peg$FAILED) {
3453 peg$resultsCache[key] = {
3454 nextPos: peg$currPos,
3460 function peg$parsehas() {
3461 var s0, s1, s2, s3, s4, s5;
3462 var key = peg$currPos * 30 + 24,
3463 cached = peg$resultsCache[key];
3466 peg$currPos = cached.nextPos;
3467 return cached.result;
3472 if (input.substr(peg$currPos, 5) === peg$c84) {
3483 if (s1 !== peg$FAILED) {
3486 if (s2 !== peg$FAILED) {
3487 s3 = peg$parseselectors();
3489 if (s3 !== peg$FAILED) {
3492 if (s4 !== peg$FAILED) {
3493 if (input.charCodeAt(peg$currPos) === 41) {
3504 if (s5 !== peg$FAILED) {
3528 peg$resultsCache[key] = {
3529 nextPos: peg$currPos,
3535 function peg$parsefirstChild() {
3537 var key = peg$currPos * 30 + 25,
3538 cached = peg$resultsCache[key];
3541 peg$currPos = cached.nextPos;
3542 return cached.result;
3547 if (input.substr(peg$currPos, 12) === peg$c87) {
3558 if (s1 !== peg$FAILED) {
3563 peg$resultsCache[key] = {
3564 nextPos: peg$currPos,
3570 function peg$parselastChild() {
3572 var key = peg$currPos * 30 + 26,
3573 cached = peg$resultsCache[key];
3576 peg$currPos = cached.nextPos;
3577 return cached.result;
3582 if (input.substr(peg$currPos, 11) === peg$c90) {
3593 if (s1 !== peg$FAILED) {
3598 peg$resultsCache[key] = {
3599 nextPos: peg$currPos,
3605 function peg$parsenthChild() {
3606 var s0, s1, s2, s3, s4, s5;
3607 var key = peg$currPos * 30 + 27,
3608 cached = peg$resultsCache[key];
3611 peg$currPos = cached.nextPos;
3612 return cached.result;
3617 if (input.substr(peg$currPos, 11) === peg$c93) {
3628 if (s1 !== peg$FAILED) {
3631 if (s2 !== peg$FAILED) {
3634 if (peg$c59.test(input.charAt(peg$currPos))) {
3635 s4 = input.charAt(peg$currPos);
3645 if (s4 !== peg$FAILED) {
3646 while (s4 !== peg$FAILED) {
3649 if (peg$c59.test(input.charAt(peg$currPos))) {
3650 s4 = input.charAt(peg$currPos);
3664 if (s3 !== peg$FAILED) {
3667 if (s4 !== peg$FAILED) {
3668 if (input.charCodeAt(peg$currPos) === 41) {
3679 if (s5 !== peg$FAILED) {
3703 peg$resultsCache[key] = {
3704 nextPos: peg$currPos,
3710 function peg$parsenthLastChild() {
3711 var s0, s1, s2, s3, s4, s5;
3712 var key = peg$currPos * 30 + 28,
3713 cached = peg$resultsCache[key];
3716 peg$currPos = cached.nextPos;
3717 return cached.result;
3722 if (input.substr(peg$currPos, 16) === peg$c96) {
3733 if (s1 !== peg$FAILED) {
3736 if (s2 !== peg$FAILED) {
3739 if (peg$c59.test(input.charAt(peg$currPos))) {
3740 s4 = input.charAt(peg$currPos);
3750 if (s4 !== peg$FAILED) {
3751 while (s4 !== peg$FAILED) {
3754 if (peg$c59.test(input.charAt(peg$currPos))) {
3755 s4 = input.charAt(peg$currPos);
3769 if (s3 !== peg$FAILED) {
3772 if (s4 !== peg$FAILED) {
3773 if (input.charCodeAt(peg$currPos) === 41) {
3784 if (s5 !== peg$FAILED) {
3808 peg$resultsCache[key] = {
3809 nextPos: peg$currPos,
3815 function peg$parseclass() {
3817 var key = peg$currPos * 30 + 29,
3818 cached = peg$resultsCache[key];
3821 peg$currPos = cached.nextPos;
3822 return cached.result;
3827 if (input.charCodeAt(peg$currPos) === 58) {
3838 if (s1 !== peg$FAILED) {
3839 if (input.substr(peg$currPos, 9).toLowerCase() === peg$c101) {
3840 s2 = input.substr(peg$currPos, 9);
3850 if (s2 === peg$FAILED) {
3851 if (input.substr(peg$currPos, 10).toLowerCase() === peg$c103) {
3852 s2 = input.substr(peg$currPos, 10);
3862 if (s2 === peg$FAILED) {
3863 if (input.substr(peg$currPos, 11).toLowerCase() === peg$c105) {
3864 s2 = input.substr(peg$currPos, 11);
3874 if (s2 === peg$FAILED) {
3875 if (input.substr(peg$currPos, 8).toLowerCase() === peg$c107) {
3876 s2 = input.substr(peg$currPos, 8);
3886 if (s2 === peg$FAILED) {
3887 if (input.substr(peg$currPos, 7).toLowerCase() === peg$c109) {
3888 s2 = input.substr(peg$currPos, 7);
3902 if (s2 !== peg$FAILED) {
3914 peg$resultsCache[key] = {
3915 nextPos: peg$currPos,
3931 function nthLast(n) {
3933 type: 'nth-last-child',
3941 function strUnescape(s) {
3942 return s.replace(/\\(.)/g, function (match, ch) {
3968 peg$result = peg$startRuleFunction();
3970 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
3973 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
3974 peg$fail(peg$endExpectation());
3977 throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
3982 SyntaxError: peg$SyntaxError,
3988 function _objectEntries(obj) {
3990 var keys = Object.keys(obj);
3992 for (var k = 0; k < keys.length; k++) entries.push([keys[k], obj[keys[k]]]);
3997 * @typedef {"LEFT_SIDE"|"RIGHT_SIDE"} Side
4000 var LEFT_SIDE = 'LEFT_SIDE';
4001 var RIGHT_SIDE = 'RIGHT_SIDE';
4004 * @see https://esprima.readthedocs.io/en/latest/syntax-tree-format.html
4008 * One of the rules of `grammar.pegjs`
4009 * @typedef {PlainObject} SelectorAST
4010 * @see grammar.pegjs
4014 * The `sequence` production of `grammar.pegjs`
4015 * @typedef {PlainObject} SelectorSequenceAST
4019 * Get the value of a property which may be multiple levels down
4021 * @param {?PlainObject} obj
4022 * @param {string} key
4023 * @returns {undefined|boolean|string|number|external:AST}
4026 function getPath(obj, key) {
4027 var keys = key.split('.');
4029 for (var i = 0; i < keys.length; i++) {
4040 * Determine whether `node` can be reached by following `path`,
4041 * starting at `ancestor`.
4042 * @param {?external:AST} node
4043 * @param {?external:AST} ancestor
4044 * @param {string[]} path
4045 * @returns {boolean}
4049 function inPath(node, ancestor, path) {
4050 if (path.length === 0) {
4051 return node === ancestor;
4054 if (ancestor == null) {
4058 var field = ancestor[path[0]];
4059 var remainingPath = path.slice(1);
4061 if (Array.isArray(field)) {
4062 for (var i = 0, l = field.length; i < l; ++i) {
4063 if (inPath(node, field[i], remainingPath)) {
4070 return inPath(node, field, remainingPath);
4074 * Given a `node` and its ancestors, determine if `node` is matched
4076 * @param {?external:AST} node
4077 * @param {?SelectorAST} selector
4078 * @param {external:AST[]} [ancestry=[]]
4079 * @throws {Error} Unknowns (operator, class name, selector type, or
4080 * selector value type)
4081 * @returns {boolean}
4085 function matches(node, selector, ancestry) {
4098 switch (selector.type) {
4103 return selector.value.toLowerCase() === node.type.toLowerCase();
4107 var path = selector.name.split('.');
4108 var ancestor = ancestry[path.length - 1];
4109 return inPath(node, ancestor, path);
4113 for (var i = 0, l = selector.selectors.length; i < l; ++i) {
4114 if (matches(node, selector.selectors[i], ancestry)) {
4122 for (var _i = 0, _l = selector.selectors.length; _i < _l; ++_i) {
4123 if (!matches(node, selector.selectors[_i], ancestry)) {
4131 for (var _i2 = 0, _l2 = selector.selectors.length; _i2 < _l2; ++_i2) {
4132 if (matches(node, selector.selectors[_i2], ancestry)) {
4141 var _ret = function () {
4144 var _loop = function _loop(_i3, _l3) {
4146 estraverse.traverse(node, {
4147 enter: function enter(node, parent) {
4148 if (parent != null) {
4152 if (matches(node, selector.selectors[_i3], a)) {
4153 collector.push(node);
4156 leave: function leave() {
4159 fallback: 'iteration'
4163 for (var _i3 = 0, _l3 = selector.selectors.length; _i3 < _l3; ++_i3) {
4168 v: collector.length !== 0
4172 if (_typeof(_ret) === "object") return _ret.v;
4176 if (matches(node, selector.right, ancestry)) {
4177 return matches(ancestry[0], selector.left, ancestry.slice(1));
4183 if (matches(node, selector.right, ancestry)) {
4184 for (var _i4 = 0, _l4 = ancestry.length; _i4 < _l4; ++_i4) {
4185 if (matches(ancestry[_i4], selector.left, ancestry.slice(_i4 + 1))) {
4195 var p = getPath(node, selector.name);
4197 switch (selector.operator) {
4202 switch (selector.value.type) {
4204 return typeof p === 'string' && selector.value.value.test(p);
4207 return "".concat(selector.value.value) === "".concat(p);
4210 return selector.value.value === _typeof(p);
4213 throw new Error("Unknown selector value type: ".concat(selector.value.type));
4216 switch (selector.value.type) {
4218 return !selector.value.value.test(p);
4221 return "".concat(selector.value.value) !== "".concat(p);
4224 return selector.value.value !== _typeof(p);
4227 throw new Error("Unknown selector value type: ".concat(selector.value.type));
4230 return p <= selector.value.value;
4233 return p < selector.value.value;
4236 return p > selector.value.value;
4239 return p >= selector.value.value;
4242 throw new Error("Unknown operator: ".concat(selector.operator));
4246 return matches(node, selector.right, ancestry) && sibling(node, selector.left, ancestry, LEFT_SIDE) || selector.left.subject && matches(node, selector.left, ancestry) && sibling(node, selector.right, ancestry, RIGHT_SIDE);
4249 return matches(node, selector.right, ancestry) && adjacent(node, selector.left, ancestry, LEFT_SIDE) || selector.right.subject && matches(node, selector.left, ancestry) && adjacent(node, selector.right, ancestry, RIGHT_SIDE);
4252 return matches(node, selector.right, ancestry) && nthChild(node, ancestry, function () {
4253 return selector.index.value - 1;
4256 case 'nth-last-child':
4257 return matches(node, selector.right, ancestry) && nthChild(node, ancestry, function (length) {
4258 return length - selector.index.value;
4262 switch (selector.name.toLowerCase()) {
4264 if (node.type.slice(-9) === 'Statement') return true;
4265 // fallthrough: interface Declaration <: Statement { }
4268 return node.type.slice(-11) === 'Declaration';
4271 if (node.type.slice(-7) === 'Pattern') return true;
4272 // fallthrough: interface Expression <: Node, Pattern { }
4275 return node.type.slice(-10) === 'Expression' || node.type.slice(-7) === 'Literal' || node.type === 'Identifier' && (ancestry.length === 0 || ancestry[0].type !== 'MetaProperty') || node.type === 'MetaProperty';
4278 return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
4281 throw new Error("Unknown class name: ".concat(selector.name));
4284 throw new Error("Unknown selector type: ".concat(selector.type));
4287 * Determines if the given node has a sibling that matches the
4289 * @param {external:AST} node
4290 * @param {SelectorSequenceAST} selector
4291 * @param {external:AST[]} ancestry
4292 * @param {Side} side
4293 * @returns {boolean}
4297 function sibling(node, selector, ancestry, side) {
4298 var _ancestry = _slicedToArray(ancestry, 1),
4299 parent = _ancestry[0];
4305 var keys = estraverse.VisitorKeys[parent.type];
4307 for (var i = 0, l = keys.length; i < l; ++i) {
4308 var listProp = parent[keys[i]];
4310 if (Array.isArray(listProp)) {
4311 var startIndex = listProp.indexOf(node);
4313 if (startIndex < 0) {
4317 var lowerBound = void 0,
4318 upperBound = void 0;
4320 if (side === LEFT_SIDE) {
4322 upperBound = startIndex;
4324 lowerBound = startIndex + 1;
4325 upperBound = listProp.length;
4328 for (var k = lowerBound; k < upperBound; ++k) {
4329 if (matches(listProp[k], selector, ancestry)) {
4339 * Determines if the given node has an adjacent sibling that matches
4340 * the given selector.
4341 * @param {external:AST} node
4342 * @param {SelectorSequenceAST} selector
4343 * @param {external:AST[]} ancestry
4344 * @param {Side} side
4345 * @returns {boolean}
4349 function adjacent(node, selector, ancestry, side) {
4350 var _ancestry2 = _slicedToArray(ancestry, 1),
4351 parent = _ancestry2[0];
4357 var keys = estraverse.VisitorKeys[parent.type];
4359 for (var i = 0, l = keys.length; i < l; ++i) {
4360 var listProp = parent[keys[i]];
4362 if (Array.isArray(listProp)) {
4363 var idx = listProp.indexOf(node);
4369 if (side === LEFT_SIDE && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
4373 if (side === RIGHT_SIDE && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
4382 * @callback IndexFunction
4383 * @param {Integer} len Containing list's length
4384 * @returns {Integer}
4388 * Determines if the given node is the nth child, determined by
4389 * `idxFn`, which is given the containing list's length.
4390 * @param {external:AST} node
4391 * @param {external:AST[]} ancestry
4392 * @param {IndexFunction} idxFn
4393 * @returns {boolean}
4397 function nthChild(node, ancestry, idxFn) {
4398 var _ancestry3 = _slicedToArray(ancestry, 1),
4399 parent = _ancestry3[0];
4405 var keys = estraverse.VisitorKeys[parent.type];
4407 for (var i = 0, l = keys.length; i < l; ++i) {
4408 var listProp = parent[keys[i]];
4410 if (Array.isArray(listProp)) {
4411 var idx = listProp.indexOf(node);
4413 if (idx >= 0 && idx === idxFn(listProp.length)) {
4422 * For each selector node marked as a subject, find the portion of the
4423 * selector that the subject must match.
4424 * @param {SelectorAST} selector
4425 * @param {SelectorAST} [ancestor] Defaults to `selector`
4426 * @returns {SelectorAST[]}
4430 function subjects(selector, ancestor) {
4431 if (selector == null || _typeof(selector) != 'object') {
4435 if (ancestor == null) {
4436 ancestor = selector;
4439 var results = selector.subject ? [ancestor] : [];
4441 for (var _i5 = 0, _Object$entries = _objectEntries(selector); _i5 < _Object$entries.length; _i5++) {
4442 var _Object$entries$_i = _slicedToArray(_Object$entries[_i5], 2),
4443 p = _Object$entries$_i[0],
4444 sel = _Object$entries$_i[1];
4446 results.push.apply(results, _toConsumableArray(subjects(sel, p === 'left' ? sel : ancestor)));
4452 * @callback TraverseVisitor
4453 * @param {?external:AST} node
4454 * @param {?external:AST} parent
4455 * @param {external:AST[]} ancestry
4459 * From a JS AST and a selector AST, collect all JS AST nodes that
4460 * match the selector.
4461 * @param {external:AST} ast
4462 * @param {?SelectorAST} selector
4463 * @param {TraverseVisitor} visitor
4464 * @returns {external:AST[]}
4468 function traverse(ast, selector, visitor) {
4474 var altSubjects = subjects(selector);
4475 estraverse.traverse(ast, {
4476 enter: function enter(node, parent) {
4477 if (parent != null) {
4478 ancestry.unshift(parent);
4481 if (matches(node, selector, ancestry)) {
4482 if (altSubjects.length) {
4483 for (var i = 0, l = altSubjects.length; i < l; ++i) {
4484 if (matches(node, altSubjects[i], ancestry)) {
4485 visitor(node, parent, ancestry);
4488 for (var k = 0, m = ancestry.length; k < m; ++k) {
4489 var succeedingAncestry = ancestry.slice(k + 1);
4491 if (matches(ancestry[k], altSubjects[i], succeedingAncestry)) {
4492 visitor(ancestry[k], parent, succeedingAncestry);
4497 visitor(node, parent, ancestry);
4501 leave: function leave() {
4504 fallback: 'iteration'
4508 * From a JS AST and a selector AST, collect all JS AST nodes that
4509 * match the selector.
4510 * @param {external:AST} ast
4511 * @param {?SelectorAST} selector
4512 * @returns {external:AST[]}
4516 function match(ast, selector) {
4518 traverse(ast, selector, function (node) {
4524 * Parse a selector string and return its AST.
4525 * @param {string} selector
4526 * @returns {SelectorAST}
4530 function parse(selector) {
4531 return parser.parse(selector);
4534 * Query the code AST using the selector string.
4535 * @param {external:AST} ast
4536 * @param {string} selector
4537 * @returns {external:AST[]}
4541 function query(ast, selector) {
4542 return match(ast, parse(selector));
4545 query.parse = parse;
4546 query.match = match;
4547 query.traverse = traverse;
4548 query.matches = matches;
4549 query.query = query;