1 function _typeof(obj) {
2 "@babel/helpers - typeof";
4 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
5 _typeof = function (obj) {
9 _typeof = function (obj) {
10 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
17 function _slicedToArray(arr, i) {
18 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
21 function _toConsumableArray(arr) {
22 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
25 function _arrayWithoutHoles(arr) {
26 if (Array.isArray(arr)) return _arrayLikeToArray(arr);
29 function _arrayWithHoles(arr) {
30 if (Array.isArray(arr)) return arr;
33 function _iterableToArray(iter) {
34 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
37 function _iterableToArrayLimit(arr, i) {
38 if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
45 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
48 if (i && _arr.length === i) break;
55 if (!_n && _i["return"] != null) _i["return"]();
64 function _unsupportedIterableToArray(o, minLen) {
66 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
67 var n = Object.prototype.toString.call(o).slice(8, -1);
68 if (n === "Object" && o.constructor) n = o.constructor.name;
69 if (n === "Map" || n === "Set") return Array.from(n);
70 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
73 function _arrayLikeToArray(arr, len) {
74 if (len == null || len > arr.length) len = arr.length;
76 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
81 function _nonIterableSpread() {
82 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
85 function _nonIterableRest() {
86 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
89 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
91 function createCommonjsModule(fn, module) {
92 return module = { exports: {} }, fn(module, module.exports), module.exports;
95 var estraverse = createCommonjsModule(function (module, exports) {
97 Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
98 Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
100 Redistribution and use in source and binary forms, with or without
101 modification, are permitted provided that the following conditions are met:
103 * Redistributions of source code must retain the above copyright
104 notice, this list of conditions and the following disclaimer.
105 * Redistributions in binary form must reproduce the above copyright
106 notice, this list of conditions and the following disclaimer in the
107 documentation and/or other materials provided with the distribution.
109 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
110 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
111 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
112 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
113 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
114 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
115 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
116 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
117 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
118 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
121 /*jslint vars:false, bitwise:true*/
125 /*global exports:true*/
126 (function clone(exports) {
128 var Syntax, VisitorOption, VisitorKeys, BREAK, SKIP, REMOVE;
130 function deepCopy(obj) {
136 if (obj.hasOwnProperty(key)) {
139 if (typeof val === 'object' && val !== null) {
140 ret[key] = deepCopy(val);
148 } // based on LLVM libc++ upper_bound / lower_bound
152 function upperBound(array, func) {
153 var diff, len, i, current;
161 if (func(array[current])) {
173 AssignmentExpression: 'AssignmentExpression',
174 AssignmentPattern: 'AssignmentPattern',
175 ArrayExpression: 'ArrayExpression',
176 ArrayPattern: 'ArrayPattern',
177 ArrowFunctionExpression: 'ArrowFunctionExpression',
178 AwaitExpression: 'AwaitExpression',
179 // CAUTION: It's deferred to ES7.
180 BlockStatement: 'BlockStatement',
181 BinaryExpression: 'BinaryExpression',
182 BreakStatement: 'BreakStatement',
183 CallExpression: 'CallExpression',
184 CatchClause: 'CatchClause',
185 ClassBody: 'ClassBody',
186 ClassDeclaration: 'ClassDeclaration',
187 ClassExpression: 'ClassExpression',
188 ComprehensionBlock: 'ComprehensionBlock',
189 // CAUTION: It's deferred to ES7.
190 ComprehensionExpression: 'ComprehensionExpression',
191 // CAUTION: It's deferred to ES7.
192 ConditionalExpression: 'ConditionalExpression',
193 ContinueStatement: 'ContinueStatement',
194 DebuggerStatement: 'DebuggerStatement',
195 DirectiveStatement: 'DirectiveStatement',
196 DoWhileStatement: 'DoWhileStatement',
197 EmptyStatement: 'EmptyStatement',
198 ExportAllDeclaration: 'ExportAllDeclaration',
199 ExportDefaultDeclaration: 'ExportDefaultDeclaration',
200 ExportNamedDeclaration: 'ExportNamedDeclaration',
201 ExportSpecifier: 'ExportSpecifier',
202 ExpressionStatement: 'ExpressionStatement',
203 ForStatement: 'ForStatement',
204 ForInStatement: 'ForInStatement',
205 ForOfStatement: 'ForOfStatement',
206 FunctionDeclaration: 'FunctionDeclaration',
207 FunctionExpression: 'FunctionExpression',
208 GeneratorExpression: 'GeneratorExpression',
209 // CAUTION: It's deferred to ES7.
210 Identifier: 'Identifier',
211 IfStatement: 'IfStatement',
212 ImportExpression: 'ImportExpression',
213 ImportDeclaration: 'ImportDeclaration',
214 ImportDefaultSpecifier: 'ImportDefaultSpecifier',
215 ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
216 ImportSpecifier: 'ImportSpecifier',
218 LabeledStatement: 'LabeledStatement',
219 LogicalExpression: 'LogicalExpression',
220 MemberExpression: 'MemberExpression',
221 MetaProperty: 'MetaProperty',
222 MethodDefinition: 'MethodDefinition',
223 ModuleSpecifier: 'ModuleSpecifier',
224 NewExpression: 'NewExpression',
225 ObjectExpression: 'ObjectExpression',
226 ObjectPattern: 'ObjectPattern',
228 Property: 'Property',
229 RestElement: 'RestElement',
230 ReturnStatement: 'ReturnStatement',
231 SequenceExpression: 'SequenceExpression',
232 SpreadElement: 'SpreadElement',
234 SwitchStatement: 'SwitchStatement',
235 SwitchCase: 'SwitchCase',
236 TaggedTemplateExpression: 'TaggedTemplateExpression',
237 TemplateElement: 'TemplateElement',
238 TemplateLiteral: 'TemplateLiteral',
239 ThisExpression: 'ThisExpression',
240 ThrowStatement: 'ThrowStatement',
241 TryStatement: 'TryStatement',
242 UnaryExpression: 'UnaryExpression',
243 UpdateExpression: 'UpdateExpression',
244 VariableDeclaration: 'VariableDeclaration',
245 VariableDeclarator: 'VariableDeclarator',
246 WhileStatement: 'WhileStatement',
247 WithStatement: 'WithStatement',
248 YieldExpression: 'YieldExpression'
251 AssignmentExpression: ['left', 'right'],
252 AssignmentPattern: ['left', 'right'],
253 ArrayExpression: ['elements'],
254 ArrayPattern: ['elements'],
255 ArrowFunctionExpression: ['params', 'body'],
256 AwaitExpression: ['argument'],
257 // CAUTION: It's deferred to ES7.
258 BlockStatement: ['body'],
259 BinaryExpression: ['left', 'right'],
260 BreakStatement: ['label'],
261 CallExpression: ['callee', 'arguments'],
262 CatchClause: ['param', 'body'],
264 ClassDeclaration: ['id', 'superClass', 'body'],
265 ClassExpression: ['id', 'superClass', 'body'],
266 ComprehensionBlock: ['left', 'right'],
267 // CAUTION: It's deferred to ES7.
268 ComprehensionExpression: ['blocks', 'filter', 'body'],
269 // CAUTION: It's deferred to ES7.
270 ConditionalExpression: ['test', 'consequent', 'alternate'],
271 ContinueStatement: ['label'],
272 DebuggerStatement: [],
273 DirectiveStatement: [],
274 DoWhileStatement: ['body', 'test'],
276 ExportAllDeclaration: ['source'],
277 ExportDefaultDeclaration: ['declaration'],
278 ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
279 ExportSpecifier: ['exported', 'local'],
280 ExpressionStatement: ['expression'],
281 ForStatement: ['init', 'test', 'update', 'body'],
282 ForInStatement: ['left', 'right', 'body'],
283 ForOfStatement: ['left', 'right', 'body'],
284 FunctionDeclaration: ['id', 'params', 'body'],
285 FunctionExpression: ['id', 'params', 'body'],
286 GeneratorExpression: ['blocks', 'filter', 'body'],
287 // CAUTION: It's deferred to ES7.
289 IfStatement: ['test', 'consequent', 'alternate'],
290 ImportExpression: ['source'],
291 ImportDeclaration: ['specifiers', 'source'],
292 ImportDefaultSpecifier: ['local'],
293 ImportNamespaceSpecifier: ['local'],
294 ImportSpecifier: ['imported', 'local'],
296 LabeledStatement: ['label', 'body'],
297 LogicalExpression: ['left', 'right'],
298 MemberExpression: ['object', 'property'],
299 MetaProperty: ['meta', 'property'],
300 MethodDefinition: ['key', 'value'],
302 NewExpression: ['callee', 'arguments'],
303 ObjectExpression: ['properties'],
304 ObjectPattern: ['properties'],
306 Property: ['key', 'value'],
307 RestElement: ['argument'],
308 ReturnStatement: ['argument'],
309 SequenceExpression: ['expressions'],
310 SpreadElement: ['argument'],
312 SwitchStatement: ['discriminant', 'cases'],
313 SwitchCase: ['test', 'consequent'],
314 TaggedTemplateExpression: ['tag', 'quasi'],
316 TemplateLiteral: ['quasis', 'expressions'],
318 ThrowStatement: ['argument'],
319 TryStatement: ['block', 'handler', 'finalizer'],
320 UnaryExpression: ['argument'],
321 UpdateExpression: ['argument'],
322 VariableDeclaration: ['declarations'],
323 VariableDeclarator: ['id', 'init'],
324 WhileStatement: ['test', 'body'],
325 WithStatement: ['object', 'body'],
326 YieldExpression: ['argument']
338 function Reference(parent, key) {
339 this.parent = parent;
343 Reference.prototype.replace = function replace(node) {
344 this.parent[this.key] = node;
347 Reference.prototype.remove = function remove() {
348 if (Array.isArray(this.parent)) {
349 this.parent.splice(this.key, 1);
357 function Element(node, path, wrap, ref) {
364 function Controller() {} // API:
365 // return property path array from root to current node
368 Controller.prototype.path = function path() {
369 var i, iz, j, jz, result, element;
371 function addToPath(result, path) {
372 if (Array.isArray(path)) {
373 for (j = 0, jz = path.length; j < jz; ++j) {
374 result.push(path[j]);
382 if (!this.__current.path) {
384 } // first node is sentinel, second node is root element
389 for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
390 element = this.__leavelist[i];
391 addToPath(result, element.path);
394 addToPath(result, this.__current.path);
397 // return type of current node
400 Controller.prototype.type = function () {
401 var node = this.current();
402 return node.type || this.__current.wrap;
404 // return array of parent elements
407 Controller.prototype.parents = function parents() {
408 var i, iz, result; // first node is sentinel
412 for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
413 result.push(this.__leavelist[i].node);
418 // return current node
421 Controller.prototype.current = function current() {
422 return this.__current.node;
425 Controller.prototype.__execute = function __execute(callback, element) {
426 var previous, result;
428 previous = this.__current;
429 this.__current = element;
433 result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
436 this.__current = previous;
439 // notify control skip / break
442 Controller.prototype.notify = function notify(flag) {
445 // skip child nodes of current node
448 Controller.prototype.skip = function () {
454 Controller.prototype['break'] = function () {
460 Controller.prototype.remove = function () {
464 Controller.prototype.__initialize = function (root, visitor) {
465 this.visitor = visitor;
467 this.__worklist = [];
468 this.__leavelist = [];
469 this.__current = null;
471 this.__fallback = null;
473 if (visitor.fallback === 'iteration') {
474 this.__fallback = Object.keys;
475 } else if (typeof visitor.fallback === 'function') {
476 this.__fallback = visitor.fallback;
479 this.__keys = VisitorKeys;
482 this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
486 function isNode(node) {
491 return typeof node === 'object' && typeof node.type === 'string';
494 function isProperty(nodeType, key) {
495 return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
498 function candidateExistsInLeaveList(leavelist, candidate) {
499 for (var i = leavelist.length - 1; i >= 0; --i) {
500 if (leavelist[i].node === candidate) {
508 Controller.prototype.traverse = function traverse(root, visitor) {
509 var worklist, leavelist, element, node, nodeType, ret, key, current, current2, candidates, candidate, sentinel;
511 this.__initialize(root, visitor);
513 sentinel = {}; // reference
515 worklist = this.__worklist;
516 leavelist = this.__leavelist; // initialize
518 worklist.push(new Element(root, null, null, null));
519 leavelist.push(new Element(null, null, null, null));
521 while (worklist.length) {
522 element = worklist.pop();
524 if (element === sentinel) {
525 element = leavelist.pop();
526 ret = this.__execute(visitor.leave, element);
528 if (this.__state === BREAK || ret === BREAK) {
536 ret = this.__execute(visitor.enter, element);
538 if (this.__state === BREAK || ret === BREAK) {
542 worklist.push(sentinel);
543 leavelist.push(element);
545 if (this.__state === SKIP || ret === SKIP) {
550 nodeType = node.type || element.wrap;
551 candidates = this.__keys[nodeType];
554 if (this.__fallback) {
555 candidates = this.__fallback(node);
557 throw new Error('Unknown node type ' + nodeType + '.');
561 current = candidates.length;
563 while ((current -= 1) >= 0) {
564 key = candidates[current];
565 candidate = node[key];
571 if (Array.isArray(candidate)) {
572 current2 = candidate.length;
574 while ((current2 -= 1) >= 0) {
575 if (!candidate[current2]) {
579 if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
583 if (isProperty(nodeType, candidates[current])) {
584 element = new Element(candidate[current2], [key, current2], 'Property', null);
585 } else if (isNode(candidate[current2])) {
586 element = new Element(candidate[current2], [key, current2], null, null);
591 worklist.push(element);
593 } else if (isNode(candidate)) {
594 if (candidateExistsInLeaveList(leavelist, candidate)) {
598 worklist.push(new Element(candidate, key, null, null));
605 Controller.prototype.replace = function replace(root, visitor) {
606 var worklist, leavelist, node, nodeType, target, element, current, current2, candidates, candidate, sentinel, outer, key;
608 function removeElem(element) {
609 var i, key, nextElem, parent;
611 if (element.ref.remove()) {
612 // When the reference is an element of an array.
613 key = element.ref.key;
614 parent = element.ref.parent; // If removed from array, then decrease following items' keys.
619 nextElem = worklist[i];
621 if (nextElem.ref && nextElem.ref.parent === parent) {
622 if (nextElem.ref.key < key) {
632 this.__initialize(root, visitor);
634 sentinel = {}; // reference
636 worklist = this.__worklist;
637 leavelist = this.__leavelist; // initialize
642 element = new Element(root, null, null, new Reference(outer, 'root'));
643 worklist.push(element);
644 leavelist.push(element);
646 while (worklist.length) {
647 element = worklist.pop();
649 if (element === sentinel) {
650 element = leavelist.pop();
651 target = this.__execute(visitor.leave, element); // node may be replaced with null,
652 // so distinguish between undefined and null in this place
654 if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
656 element.ref.replace(target);
659 if (this.__state === REMOVE || target === REMOVE) {
663 if (this.__state === BREAK || target === BREAK) {
670 target = this.__execute(visitor.enter, element); // node may be replaced with null,
671 // so distinguish between undefined and null in this place
673 if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
675 element.ref.replace(target);
676 element.node = target;
679 if (this.__state === REMOVE || target === REMOVE) {
684 if (this.__state === BREAK || target === BREAK) {
686 } // node may be null
695 worklist.push(sentinel);
696 leavelist.push(element);
698 if (this.__state === SKIP || target === SKIP) {
702 nodeType = node.type || element.wrap;
703 candidates = this.__keys[nodeType];
706 if (this.__fallback) {
707 candidates = this.__fallback(node);
709 throw new Error('Unknown node type ' + nodeType + '.');
713 current = candidates.length;
715 while ((current -= 1) >= 0) {
716 key = candidates[current];
717 candidate = node[key];
723 if (Array.isArray(candidate)) {
724 current2 = candidate.length;
726 while ((current2 -= 1) >= 0) {
727 if (!candidate[current2]) {
731 if (isProperty(nodeType, candidates[current])) {
732 element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
733 } else if (isNode(candidate[current2])) {
734 element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
739 worklist.push(element);
741 } else if (isNode(candidate)) {
742 worklist.push(new Element(candidate, key, null, new Reference(node, key)));
750 function traverse(root, visitor) {
751 var controller = new Controller();
752 return controller.traverse(root, visitor);
755 function replace(root, visitor) {
756 var controller = new Controller();
757 return controller.replace(root, visitor);
760 function extendCommentRange(comment, tokens) {
762 target = upperBound(tokens, function search(token) {
763 return token.range[0] > comment.range[0];
765 comment.extendedRange = [comment.range[0], comment.range[1]];
767 if (target !== tokens.length) {
768 comment.extendedRange[1] = tokens[target].range[0];
774 comment.extendedRange[0] = tokens[target].range[1];
780 function attachComments(tree, providedComments, tokens) {
781 // At first, we should calculate extended comment ranges.
789 throw new Error('attachComments needs range information');
790 } // tokens array is empty, we attach comments to tree as 'leadingComments'
793 if (!tokens.length) {
794 if (providedComments.length) {
795 for (i = 0, len = providedComments.length; i < len; i += 1) {
796 comment = deepCopy(providedComments[i]);
797 comment.extendedRange = [0, tree.range[0]];
798 comments.push(comment);
801 tree.leadingComments = comments;
807 for (i = 0, len = providedComments.length; i < len; i += 1) {
808 comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
809 } // This is based on John Freeman's implementation.
814 enter: function (node) {
817 while (cursor < comments.length) {
818 comment = comments[cursor];
820 if (comment.extendedRange[1] > node.range[0]) {
824 if (comment.extendedRange[1] === node.range[0]) {
825 if (!node.leadingComments) {
826 node.leadingComments = [];
829 node.leadingComments.push(comment);
830 comments.splice(cursor, 1);
834 } // already out of owned node
837 if (cursor === comments.length) {
838 return VisitorOption.Break;
841 if (comments[cursor].extendedRange[0] > node.range[1]) {
842 return VisitorOption.Skip;
848 leave: function (node) {
851 while (cursor < comments.length) {
852 comment = comments[cursor];
854 if (node.range[1] < comment.extendedRange[0]) {
858 if (node.range[1] === comment.extendedRange[0]) {
859 if (!node.trailingComments) {
860 node.trailingComments = [];
863 node.trailingComments.push(comment);
864 comments.splice(cursor, 1);
868 } // already out of owned node
871 if (cursor === comments.length) {
872 return VisitorOption.Break;
875 if (comments[cursor].extendedRange[0] > node.range[1]) {
876 return VisitorOption.Skip;
883 exports.Syntax = Syntax;
884 exports.traverse = traverse;
885 exports.replace = replace;
886 exports.attachComments = attachComments;
887 exports.VisitorKeys = VisitorKeys;
888 exports.VisitorOption = VisitorOption;
889 exports.Controller = Controller;
891 exports.cloneEnvironment = function () {
897 /* vim: set sw=4 ts=4 et tw=80 : */
901 var parser = createCommonjsModule(function (module) {
903 * Generated by PEG.js 0.10.0.
907 (function (root, factory) {
908 if ( module.exports) {
909 module.exports = factory();
911 })(commonjsGlobal, function () {
913 function peg$subclass(child, parent) {
915 this.constructor = child;
918 ctor.prototype = parent.prototype;
919 child.prototype = new ctor();
922 function peg$SyntaxError(message, expected, found, location) {
923 this.message = message;
924 this.expected = expected;
926 this.location = location;
927 this.name = "SyntaxError";
929 if (typeof Error.captureStackTrace === "function") {
930 Error.captureStackTrace(this, peg$SyntaxError);
934 peg$subclass(peg$SyntaxError, Error);
936 peg$SyntaxError.buildMessage = function (expected, found) {
937 var DESCRIBE_EXPECTATION_FNS = {
938 literal: function literal(expectation) {
939 return "\"" + literalEscape(expectation.text) + "\"";
941 "class": function _class(expectation) {
942 var escapedParts = "",
945 for (i = 0; i < expectation.parts.length; i++) {
946 escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
949 return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
951 any: function any(expectation) {
952 return "any character";
954 end: function end(expectation) {
955 return "end of input";
957 other: function other(expectation) {
958 return expectation.description;
963 return ch.charCodeAt(0).toString(16).toUpperCase();
966 function literalEscape(s) {
967 return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
968 return '\\x0' + hex(ch);
969 }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
970 return '\\x' + hex(ch);
974 function classEscape(s) {
975 return s.replace(/\\/g, '\\\\').replace(/\]/g, '\\]').replace(/\^/g, '\\^').replace(/-/g, '\\-').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
976 return '\\x0' + hex(ch);
977 }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
978 return '\\x' + hex(ch);
982 function describeExpectation(expectation) {
983 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
986 function describeExpected(expected) {
987 var descriptions = new Array(expected.length),
991 for (i = 0; i < expected.length; i++) {
992 descriptions[i] = describeExpectation(expected[i]);
997 if (descriptions.length > 0) {
998 for (i = 1, j = 1; i < descriptions.length; i++) {
999 if (descriptions[i - 1] !== descriptions[i]) {
1000 descriptions[j] = descriptions[i];
1005 descriptions.length = j;
1008 switch (descriptions.length) {
1010 return descriptions[0];
1013 return descriptions[0] + " or " + descriptions[1];
1016 return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
1020 function describeFound(found) {
1021 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
1024 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
1027 function peg$parse(input, options) {
1028 options = options !== void 0 ? options : {};
1030 var peg$FAILED = {},
1031 peg$startRuleFunctions = {
1032 start: peg$parsestart
1034 peg$startRuleFunction = peg$parsestart,
1035 peg$c0 = function peg$c0(ss) {
1036 return ss.length === 1 ? ss[0] : {
1041 peg$c1 = function peg$c1() {
1045 peg$c3 = peg$literalExpectation(" ", false),
1046 peg$c4 = /^[^ [\],():#!=><~+.]/,
1047 peg$c5 = peg$classExpectation([" ", "[", "]", ",", "(", ")", ":", "#", "!", "=", ">", "<", "~", "+", "."], true, false),
1048 peg$c6 = function peg$c6(i) {
1052 peg$c8 = peg$literalExpectation(">", false),
1053 peg$c9 = function peg$c9() {
1057 peg$c11 = peg$literalExpectation("~", false),
1058 peg$c12 = function peg$c12() {
1062 peg$c14 = peg$literalExpectation("+", false),
1063 peg$c15 = function peg$c15() {
1066 peg$c16 = function peg$c16() {
1067 return 'descendant';
1070 peg$c18 = peg$literalExpectation(",", false),
1071 peg$c19 = function peg$c19(s, ss) {
1072 return [s].concat(ss.map(function (s) {
1076 peg$c20 = function peg$c20(a, ops) {
1077 return ops.reduce(function (memo, rhs) {
1086 peg$c22 = peg$literalExpectation("!", false),
1087 peg$c23 = function peg$c23(subject, as) {
1088 var b = as.length === 1 ? as[0] : {
1092 if (subject) b.subject = true;
1096 peg$c25 = peg$literalExpectation("*", false),
1097 peg$c26 = function peg$c26(a) {
1104 peg$c28 = peg$literalExpectation("#", false),
1105 peg$c29 = function peg$c29(i) {
1112 peg$c31 = peg$literalExpectation("[", false),
1114 peg$c33 = peg$literalExpectation("]", false),
1115 peg$c34 = function peg$c34(v) {
1119 peg$c36 = peg$classExpectation([">", "<", "!"], false, false),
1121 peg$c38 = peg$literalExpectation("=", false),
1122 peg$c39 = function peg$c39(a) {
1123 return (a || '') + '=';
1126 peg$c41 = peg$classExpectation([">", "<"], false, false),
1128 peg$c43 = peg$literalExpectation(".", false),
1129 peg$c44 = function peg$c44(name, op, value) {
1137 peg$c45 = function peg$c45(name) {
1144 peg$c47 = peg$literalExpectation("\"", false),
1145 peg$c48 = /^[^\\"]/,
1146 peg$c49 = peg$classExpectation(["\\", "\""], true, false),
1148 peg$c51 = peg$literalExpectation("\\", false),
1149 peg$c52 = peg$anyExpectation(),
1150 peg$c53 = function peg$c53(a, b) {
1153 peg$c54 = function peg$c54(d) {
1156 value: strUnescape(d.join(''))
1160 peg$c56 = peg$literalExpectation("'", false),
1161 peg$c57 = /^[^\\']/,
1162 peg$c58 = peg$classExpectation(["\\", "'"], true, false),
1164 peg$c60 = peg$classExpectation([["0", "9"]], false, false),
1165 peg$c61 = function peg$c61(a, b) {
1166 // Can use `a.flat().join('')` once supported
1167 var leadingDecimals = a ? [].concat.apply([], a).join('') : '';
1170 value: parseFloat(leadingDecimals + b.join(''))
1173 peg$c62 = function peg$c62(i) {
1180 peg$c64 = peg$literalExpectation("type(", false),
1182 peg$c66 = peg$classExpectation([" ", ")"], true, false),
1184 peg$c68 = peg$literalExpectation(")", false),
1185 peg$c69 = function peg$c69(t) {
1191 peg$c70 = /^[imsu]/,
1192 peg$c71 = peg$classExpectation(["i", "m", "s", "u"], false, false),
1194 peg$c73 = peg$literalExpectation("/", false),
1196 peg$c75 = peg$classExpectation(["/"], true, false),
1197 peg$c76 = function peg$c76(d, flgs) {
1200 value: new RegExp(d.join(''), flgs ? flgs.join('') : '')
1203 peg$c77 = function peg$c77(i, is) {
1206 name: is.reduce(function (memo, p) {
1207 return memo + p[0] + p[1];
1212 peg$c79 = peg$literalExpectation(":not(", false),
1213 peg$c80 = function peg$c80(ss) {
1219 peg$c81 = ":matches(",
1220 peg$c82 = peg$literalExpectation(":matches(", false),
1221 peg$c83 = function peg$c83(ss) {
1228 peg$c85 = peg$literalExpectation(":has(", false),
1229 peg$c86 = function peg$c86(ss) {
1235 peg$c87 = ":first-child",
1236 peg$c88 = peg$literalExpectation(":first-child", false),
1237 peg$c89 = function peg$c89() {
1240 peg$c90 = ":last-child",
1241 peg$c91 = peg$literalExpectation(":last-child", false),
1242 peg$c92 = function peg$c92() {
1245 peg$c93 = ":nth-child(",
1246 peg$c94 = peg$literalExpectation(":nth-child(", false),
1247 peg$c95 = function peg$c95(n) {
1248 return nth(parseInt(n.join(''), 10));
1250 peg$c96 = ":nth-last-child(",
1251 peg$c97 = peg$literalExpectation(":nth-last-child(", false),
1252 peg$c98 = function peg$c98(n) {
1253 return nthLast(parseInt(n.join(''), 10));
1256 peg$c100 = peg$literalExpectation(":", false),
1257 peg$c101 = "statement",
1258 peg$c102 = peg$literalExpectation("statement", true),
1259 peg$c103 = "expression",
1260 peg$c104 = peg$literalExpectation("expression", true),
1261 peg$c105 = "declaration",
1262 peg$c106 = peg$literalExpectation("declaration", true),
1263 peg$c107 = "function",
1264 peg$c108 = peg$literalExpectation("function", true),
1265 peg$c109 = "pattern",
1266 peg$c110 = peg$literalExpectation("pattern", true),
1267 peg$c111 = function peg$c111(c) {
1274 peg$posDetailsCache = [{
1279 peg$maxFailExpected = [],
1280 peg$resultsCache = {},
1283 if ("startRule" in options) {
1284 if (!(options.startRule in peg$startRuleFunctions)) {
1285 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
1288 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
1291 function peg$literalExpectation(text, ignoreCase) {
1295 ignoreCase: ignoreCase
1299 function peg$classExpectation(parts, inverted, ignoreCase) {
1304 ignoreCase: ignoreCase
1308 function peg$anyExpectation() {
1314 function peg$endExpectation() {
1320 function peg$computePosDetails(pos) {
1321 var details = peg$posDetailsCache[pos],
1329 while (!peg$posDetailsCache[p]) {
1333 details = peg$posDetailsCache[p];
1336 column: details.column
1340 if (input.charCodeAt(p) === 10) {
1350 peg$posDetailsCache[pos] = details;
1355 function peg$computeLocation(startPos, endPos) {
1356 var startPosDetails = peg$computePosDetails(startPos),
1357 endPosDetails = peg$computePosDetails(endPos);
1361 line: startPosDetails.line,
1362 column: startPosDetails.column
1366 line: endPosDetails.line,
1367 column: endPosDetails.column
1372 function peg$fail(expected) {
1373 if (peg$currPos < peg$maxFailPos) {
1377 if (peg$currPos > peg$maxFailPos) {
1378 peg$maxFailPos = peg$currPos;
1379 peg$maxFailExpected = [];
1382 peg$maxFailExpected.push(expected);
1385 function peg$buildStructuredError(expected, found, location) {
1386 return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1389 function peg$parsestart() {
1391 var key = peg$currPos * 30 + 0,
1392 cached = peg$resultsCache[key];
1395 peg$currPos = cached.nextPos;
1396 return cached.result;
1402 if (s1 !== peg$FAILED) {
1403 s2 = peg$parseselectors();
1405 if (s2 !== peg$FAILED) {
1408 if (s3 !== peg$FAILED) {
1424 if (s0 === peg$FAILED) {
1428 if (s1 !== peg$FAILED) {
1435 peg$resultsCache[key] = {
1436 nextPos: peg$currPos,
1442 function peg$parse_() {
1444 var key = peg$currPos * 30 + 1,
1445 cached = peg$resultsCache[key];
1448 peg$currPos = cached.nextPos;
1449 return cached.result;
1454 if (input.charCodeAt(peg$currPos) === 32) {
1465 while (s1 !== peg$FAILED) {
1468 if (input.charCodeAt(peg$currPos) === 32) {
1480 peg$resultsCache[key] = {
1481 nextPos: peg$currPos,
1487 function peg$parseidentifierName() {
1489 var key = peg$currPos * 30 + 2,
1490 cached = peg$resultsCache[key];
1493 peg$currPos = cached.nextPos;
1494 return cached.result;
1500 if (peg$c4.test(input.charAt(peg$currPos))) {
1501 s2 = input.charAt(peg$currPos);
1511 if (s2 !== peg$FAILED) {
1512 while (s2 !== peg$FAILED) {
1515 if (peg$c4.test(input.charAt(peg$currPos))) {
1516 s2 = input.charAt(peg$currPos);
1530 if (s1 !== peg$FAILED) {
1535 peg$resultsCache[key] = {
1536 nextPos: peg$currPos,
1542 function peg$parsebinaryOp() {
1544 var key = peg$currPos * 30 + 3,
1545 cached = peg$resultsCache[key];
1548 peg$currPos = cached.nextPos;
1549 return cached.result;
1555 if (s1 !== peg$FAILED) {
1556 if (input.charCodeAt(peg$currPos) === 62) {
1567 if (s2 !== peg$FAILED) {
1570 if (s3 !== peg$FAILED) {
1586 if (s0 === peg$FAILED) {
1590 if (s1 !== peg$FAILED) {
1591 if (input.charCodeAt(peg$currPos) === 126) {
1602 if (s2 !== peg$FAILED) {
1605 if (s3 !== peg$FAILED) {
1621 if (s0 === peg$FAILED) {
1625 if (s1 !== peg$FAILED) {
1626 if (input.charCodeAt(peg$currPos) === 43) {
1637 if (s2 !== peg$FAILED) {
1640 if (s3 !== peg$FAILED) {
1656 if (s0 === peg$FAILED) {
1659 if (input.charCodeAt(peg$currPos) === 32) {
1670 if (s1 !== peg$FAILED) {
1673 if (s2 !== peg$FAILED) {
1688 peg$resultsCache[key] = {
1689 nextPos: peg$currPos,
1695 function peg$parseselectors() {
1696 var s0, s1, s2, s3, s4, s5, s6, s7;
1697 var key = peg$currPos * 30 + 4,
1698 cached = peg$resultsCache[key];
1701 peg$currPos = cached.nextPos;
1702 return cached.result;
1706 s1 = peg$parseselector();
1708 if (s1 !== peg$FAILED) {
1713 if (s4 !== peg$FAILED) {
1714 if (input.charCodeAt(peg$currPos) === 44) {
1725 if (s5 !== peg$FAILED) {
1728 if (s6 !== peg$FAILED) {
1729 s7 = peg$parseselector();
1731 if (s7 !== peg$FAILED) {
1732 s4 = [s4, s5, s6, s7];
1751 while (s3 !== peg$FAILED) {
1756 if (s4 !== peg$FAILED) {
1757 if (input.charCodeAt(peg$currPos) === 44) {
1768 if (s5 !== peg$FAILED) {
1771 if (s6 !== peg$FAILED) {
1772 s7 = peg$parseselector();
1774 if (s7 !== peg$FAILED) {
1775 s4 = [s4, s5, s6, s7];
1795 if (s2 !== peg$FAILED) {
1796 s1 = peg$c19(s1, s2);
1807 peg$resultsCache[key] = {
1808 nextPos: peg$currPos,
1814 function peg$parseselector() {
1815 var s0, s1, s2, s3, s4, s5;
1816 var key = peg$currPos * 30 + 5,
1817 cached = peg$resultsCache[key];
1820 peg$currPos = cached.nextPos;
1821 return cached.result;
1825 s1 = peg$parsesequence();
1827 if (s1 !== peg$FAILED) {
1830 s4 = peg$parsebinaryOp();
1832 if (s4 !== peg$FAILED) {
1833 s5 = peg$parsesequence();
1835 if (s5 !== peg$FAILED) {
1847 while (s3 !== peg$FAILED) {
1850 s4 = peg$parsebinaryOp();
1852 if (s4 !== peg$FAILED) {
1853 s5 = peg$parsesequence();
1855 if (s5 !== peg$FAILED) {
1868 if (s2 !== peg$FAILED) {
1869 s1 = peg$c20(s1, s2);
1880 peg$resultsCache[key] = {
1881 nextPos: peg$currPos,
1887 function peg$parsesequence() {
1889 var key = peg$currPos * 30 + 6,
1890 cached = peg$resultsCache[key];
1893 peg$currPos = cached.nextPos;
1894 return cached.result;
1899 if (input.charCodeAt(peg$currPos) === 33) {
1910 if (s1 === peg$FAILED) {
1914 if (s1 !== peg$FAILED) {
1916 s3 = peg$parseatom();
1918 if (s3 !== peg$FAILED) {
1919 while (s3 !== peg$FAILED) {
1921 s3 = peg$parseatom();
1927 if (s2 !== peg$FAILED) {
1928 s1 = peg$c23(s1, s2);
1939 peg$resultsCache[key] = {
1940 nextPos: peg$currPos,
1946 function peg$parseatom() {
1948 var key = peg$currPos * 30 + 7,
1949 cached = peg$resultsCache[key];
1952 peg$currPos = cached.nextPos;
1953 return cached.result;
1956 s0 = peg$parsewildcard();
1958 if (s0 === peg$FAILED) {
1959 s0 = peg$parseidentifier();
1961 if (s0 === peg$FAILED) {
1962 s0 = peg$parseattr();
1964 if (s0 === peg$FAILED) {
1965 s0 = peg$parsefield();
1967 if (s0 === peg$FAILED) {
1968 s0 = peg$parsenegation();
1970 if (s0 === peg$FAILED) {
1971 s0 = peg$parsematches();
1973 if (s0 === peg$FAILED) {
1974 s0 = peg$parsehas();
1976 if (s0 === peg$FAILED) {
1977 s0 = peg$parsefirstChild();
1979 if (s0 === peg$FAILED) {
1980 s0 = peg$parselastChild();
1982 if (s0 === peg$FAILED) {
1983 s0 = peg$parsenthChild();
1985 if (s0 === peg$FAILED) {
1986 s0 = peg$parsenthLastChild();
1988 if (s0 === peg$FAILED) {
1989 s0 = peg$parseclass();
2002 peg$resultsCache[key] = {
2003 nextPos: peg$currPos,
2009 function peg$parsewildcard() {
2011 var key = peg$currPos * 30 + 8,
2012 cached = peg$resultsCache[key];
2015 peg$currPos = cached.nextPos;
2016 return cached.result;
2021 if (input.charCodeAt(peg$currPos) === 42) {
2032 if (s1 !== peg$FAILED) {
2037 peg$resultsCache[key] = {
2038 nextPos: peg$currPos,
2044 function peg$parseidentifier() {
2046 var key = peg$currPos * 30 + 9,
2047 cached = peg$resultsCache[key];
2050 peg$currPos = cached.nextPos;
2051 return cached.result;
2056 if (input.charCodeAt(peg$currPos) === 35) {
2067 if (s1 === peg$FAILED) {
2071 if (s1 !== peg$FAILED) {
2072 s2 = peg$parseidentifierName();
2074 if (s2 !== peg$FAILED) {
2086 peg$resultsCache[key] = {
2087 nextPos: peg$currPos,
2093 function peg$parseattr() {
2094 var s0, s1, s2, s3, s4, s5;
2095 var key = peg$currPos * 30 + 10,
2096 cached = peg$resultsCache[key];
2099 peg$currPos = cached.nextPos;
2100 return cached.result;
2105 if (input.charCodeAt(peg$currPos) === 91) {
2116 if (s1 !== peg$FAILED) {
2119 if (s2 !== peg$FAILED) {
2120 s3 = peg$parseattrValue();
2122 if (s3 !== peg$FAILED) {
2125 if (s4 !== peg$FAILED) {
2126 if (input.charCodeAt(peg$currPos) === 93) {
2137 if (s5 !== peg$FAILED) {
2161 peg$resultsCache[key] = {
2162 nextPos: peg$currPos,
2168 function peg$parseattrOps() {
2170 var key = peg$currPos * 30 + 11,
2171 cached = peg$resultsCache[key];
2174 peg$currPos = cached.nextPos;
2175 return cached.result;
2180 if (peg$c35.test(input.charAt(peg$currPos))) {
2181 s1 = input.charAt(peg$currPos);
2191 if (s1 === peg$FAILED) {
2195 if (s1 !== peg$FAILED) {
2196 if (input.charCodeAt(peg$currPos) === 61) {
2207 if (s2 !== peg$FAILED) {
2219 if (s0 === peg$FAILED) {
2220 if (peg$c40.test(input.charAt(peg$currPos))) {
2221 s0 = input.charAt(peg$currPos);
2232 peg$resultsCache[key] = {
2233 nextPos: peg$currPos,
2239 function peg$parseattrEqOps() {
2241 var key = peg$currPos * 30 + 12,
2242 cached = peg$resultsCache[key];
2245 peg$currPos = cached.nextPos;
2246 return cached.result;
2251 if (input.charCodeAt(peg$currPos) === 33) {
2262 if (s1 === peg$FAILED) {
2266 if (s1 !== peg$FAILED) {
2267 if (input.charCodeAt(peg$currPos) === 61) {
2278 if (s2 !== peg$FAILED) {
2290 peg$resultsCache[key] = {
2291 nextPos: peg$currPos,
2297 function peg$parseattrName() {
2299 var key = peg$currPos * 30 + 13,
2300 cached = peg$resultsCache[key];
2303 peg$currPos = cached.nextPos;
2304 return cached.result;
2309 s2 = peg$parseidentifierName();
2311 if (s2 === peg$FAILED) {
2312 if (input.charCodeAt(peg$currPos) === 46) {
2324 if (s2 !== peg$FAILED) {
2325 while (s2 !== peg$FAILED) {
2327 s2 = peg$parseidentifierName();
2329 if (s2 === peg$FAILED) {
2330 if (input.charCodeAt(peg$currPos) === 46) {
2346 if (s1 !== peg$FAILED) {
2351 peg$resultsCache[key] = {
2352 nextPos: peg$currPos,
2358 function peg$parseattrValue() {
2359 var s0, s1, s2, s3, s4, s5;
2360 var key = peg$currPos * 30 + 14,
2361 cached = peg$resultsCache[key];
2364 peg$currPos = cached.nextPos;
2365 return cached.result;
2369 s1 = peg$parseattrName();
2371 if (s1 !== peg$FAILED) {
2374 if (s2 !== peg$FAILED) {
2375 s3 = peg$parseattrEqOps();
2377 if (s3 !== peg$FAILED) {
2380 if (s4 !== peg$FAILED) {
2381 s5 = peg$parsetype();
2383 if (s5 === peg$FAILED) {
2384 s5 = peg$parseregex();
2387 if (s5 !== peg$FAILED) {
2388 s1 = peg$c44(s1, s3, s5);
2411 if (s0 === peg$FAILED) {
2413 s1 = peg$parseattrName();
2415 if (s1 !== peg$FAILED) {
2418 if (s2 !== peg$FAILED) {
2419 s3 = peg$parseattrOps();
2421 if (s3 !== peg$FAILED) {
2424 if (s4 !== peg$FAILED) {
2425 s5 = peg$parsestring();
2427 if (s5 === peg$FAILED) {
2428 s5 = peg$parsenumber();
2430 if (s5 === peg$FAILED) {
2431 s5 = peg$parsepath();
2435 if (s5 !== peg$FAILED) {
2436 s1 = peg$c44(s1, s3, s5);
2459 if (s0 === peg$FAILED) {
2461 s1 = peg$parseattrName();
2463 if (s1 !== peg$FAILED) {
2471 peg$resultsCache[key] = {
2472 nextPos: peg$currPos,
2478 function peg$parsestring() {
2479 var s0, s1, s2, s3, s4, s5;
2480 var key = peg$currPos * 30 + 15,
2481 cached = peg$resultsCache[key];
2484 peg$currPos = cached.nextPos;
2485 return cached.result;
2490 if (input.charCodeAt(peg$currPos) === 34) {
2501 if (s1 !== peg$FAILED) {
2504 if (peg$c48.test(input.charAt(peg$currPos))) {
2505 s3 = input.charAt(peg$currPos);
2515 if (s3 === peg$FAILED) {
2518 if (input.charCodeAt(peg$currPos) === 92) {
2529 if (s4 !== peg$FAILED) {
2530 if (input.length > peg$currPos) {
2531 s5 = input.charAt(peg$currPos);
2541 if (s5 !== peg$FAILED) {
2542 s4 = peg$c53(s4, s5);
2554 while (s3 !== peg$FAILED) {
2557 if (peg$c48.test(input.charAt(peg$currPos))) {
2558 s3 = input.charAt(peg$currPos);
2568 if (s3 === peg$FAILED) {
2571 if (input.charCodeAt(peg$currPos) === 92) {
2582 if (s4 !== peg$FAILED) {
2583 if (input.length > peg$currPos) {
2584 s5 = input.charAt(peg$currPos);
2594 if (s5 !== peg$FAILED) {
2595 s4 = peg$c53(s4, s5);
2608 if (s2 !== peg$FAILED) {
2609 if (input.charCodeAt(peg$currPos) === 34) {
2620 if (s3 !== peg$FAILED) {
2636 if (s0 === peg$FAILED) {
2639 if (input.charCodeAt(peg$currPos) === 39) {
2650 if (s1 !== peg$FAILED) {
2653 if (peg$c57.test(input.charAt(peg$currPos))) {
2654 s3 = input.charAt(peg$currPos);
2664 if (s3 === peg$FAILED) {
2667 if (input.charCodeAt(peg$currPos) === 92) {
2678 if (s4 !== peg$FAILED) {
2679 if (input.length > peg$currPos) {
2680 s5 = input.charAt(peg$currPos);
2690 if (s5 !== peg$FAILED) {
2691 s4 = peg$c53(s4, s5);
2703 while (s3 !== peg$FAILED) {
2706 if (peg$c57.test(input.charAt(peg$currPos))) {
2707 s3 = input.charAt(peg$currPos);
2717 if (s3 === peg$FAILED) {
2720 if (input.charCodeAt(peg$currPos) === 92) {
2731 if (s4 !== peg$FAILED) {
2732 if (input.length > peg$currPos) {
2733 s5 = input.charAt(peg$currPos);
2743 if (s5 !== peg$FAILED) {
2744 s4 = peg$c53(s4, s5);
2757 if (s2 !== peg$FAILED) {
2758 if (input.charCodeAt(peg$currPos) === 39) {
2769 if (s3 !== peg$FAILED) {
2786 peg$resultsCache[key] = {
2787 nextPos: peg$currPos,
2793 function peg$parsenumber() {
2795 var key = peg$currPos * 30 + 16,
2796 cached = peg$resultsCache[key];
2799 peg$currPos = cached.nextPos;
2800 return cached.result;
2807 if (peg$c59.test(input.charAt(peg$currPos))) {
2808 s3 = input.charAt(peg$currPos);
2818 while (s3 !== peg$FAILED) {
2821 if (peg$c59.test(input.charAt(peg$currPos))) {
2822 s3 = input.charAt(peg$currPos);
2833 if (s2 !== peg$FAILED) {
2834 if (input.charCodeAt(peg$currPos) === 46) {
2845 if (s3 !== peg$FAILED) {
2857 if (s1 === peg$FAILED) {
2861 if (s1 !== peg$FAILED) {
2864 if (peg$c59.test(input.charAt(peg$currPos))) {
2865 s3 = input.charAt(peg$currPos);
2875 if (s3 !== peg$FAILED) {
2876 while (s3 !== peg$FAILED) {
2879 if (peg$c59.test(input.charAt(peg$currPos))) {
2880 s3 = input.charAt(peg$currPos);
2894 if (s2 !== peg$FAILED) {
2895 s1 = peg$c61(s1, s2);
2906 peg$resultsCache[key] = {
2907 nextPos: peg$currPos,
2913 function peg$parsepath() {
2915 var key = peg$currPos * 30 + 17,
2916 cached = peg$resultsCache[key];
2919 peg$currPos = cached.nextPos;
2920 return cached.result;
2924 s1 = peg$parseidentifierName();
2926 if (s1 !== peg$FAILED) {
2931 peg$resultsCache[key] = {
2932 nextPos: peg$currPos,
2938 function peg$parsetype() {
2939 var s0, s1, s2, s3, s4, s5;
2940 var key = peg$currPos * 30 + 18,
2941 cached = peg$resultsCache[key];
2944 peg$currPos = cached.nextPos;
2945 return cached.result;
2950 if (input.substr(peg$currPos, 5) === peg$c63) {
2961 if (s1 !== peg$FAILED) {
2964 if (s2 !== peg$FAILED) {
2967 if (peg$c65.test(input.charAt(peg$currPos))) {
2968 s4 = input.charAt(peg$currPos);
2978 if (s4 !== peg$FAILED) {
2979 while (s4 !== peg$FAILED) {
2982 if (peg$c65.test(input.charAt(peg$currPos))) {
2983 s4 = input.charAt(peg$currPos);
2997 if (s3 !== peg$FAILED) {
3000 if (s4 !== peg$FAILED) {
3001 if (input.charCodeAt(peg$currPos) === 41) {
3012 if (s5 !== peg$FAILED) {
3036 peg$resultsCache[key] = {
3037 nextPos: peg$currPos,
3043 function peg$parseflags() {
3045 var key = peg$currPos * 30 + 19,
3046 cached = peg$resultsCache[key];
3049 peg$currPos = cached.nextPos;
3050 return cached.result;
3055 if (peg$c70.test(input.charAt(peg$currPos))) {
3056 s1 = input.charAt(peg$currPos);
3066 if (s1 !== peg$FAILED) {
3067 while (s1 !== peg$FAILED) {
3070 if (peg$c70.test(input.charAt(peg$currPos))) {
3071 s1 = input.charAt(peg$currPos);
3085 peg$resultsCache[key] = {
3086 nextPos: peg$currPos,
3092 function peg$parseregex() {
3093 var s0, s1, s2, s3, s4;
3094 var key = peg$currPos * 30 + 20,
3095 cached = peg$resultsCache[key];
3098 peg$currPos = cached.nextPos;
3099 return cached.result;
3104 if (input.charCodeAt(peg$currPos) === 47) {
3115 if (s1 !== peg$FAILED) {
3118 if (peg$c74.test(input.charAt(peg$currPos))) {
3119 s3 = input.charAt(peg$currPos);
3129 if (s3 !== peg$FAILED) {
3130 while (s3 !== peg$FAILED) {
3133 if (peg$c74.test(input.charAt(peg$currPos))) {
3134 s3 = input.charAt(peg$currPos);
3148 if (s2 !== peg$FAILED) {
3149 if (input.charCodeAt(peg$currPos) === 47) {
3160 if (s3 !== peg$FAILED) {
3161 s4 = peg$parseflags();
3163 if (s4 === peg$FAILED) {
3167 if (s4 !== peg$FAILED) {
3168 s1 = peg$c76(s2, s4);
3187 peg$resultsCache[key] = {
3188 nextPos: peg$currPos,
3194 function peg$parsefield() {
3195 var s0, s1, s2, s3, s4, s5, s6;
3196 var key = peg$currPos * 30 + 21,
3197 cached = peg$resultsCache[key];
3200 peg$currPos = cached.nextPos;
3201 return cached.result;
3206 if (input.charCodeAt(peg$currPos) === 46) {
3217 if (s1 !== peg$FAILED) {
3218 s2 = peg$parseidentifierName();
3220 if (s2 !== peg$FAILED) {
3224 if (input.charCodeAt(peg$currPos) === 46) {
3235 if (s5 !== peg$FAILED) {
3236 s6 = peg$parseidentifierName();
3238 if (s6 !== peg$FAILED) {
3250 while (s4 !== peg$FAILED) {
3254 if (input.charCodeAt(peg$currPos) === 46) {
3265 if (s5 !== peg$FAILED) {
3266 s6 = peg$parseidentifierName();
3268 if (s6 !== peg$FAILED) {
3281 if (s3 !== peg$FAILED) {
3282 s1 = peg$c77(s2, s3);
3297 peg$resultsCache[key] = {
3298 nextPos: peg$currPos,
3304 function peg$parsenegation() {
3305 var s0, s1, s2, s3, s4, s5;
3306 var key = peg$currPos * 30 + 22,
3307 cached = peg$resultsCache[key];
3310 peg$currPos = cached.nextPos;
3311 return cached.result;
3316 if (input.substr(peg$currPos, 5) === peg$c78) {
3327 if (s1 !== peg$FAILED) {
3330 if (s2 !== peg$FAILED) {
3331 s3 = peg$parseselectors();
3333 if (s3 !== peg$FAILED) {
3336 if (s4 !== peg$FAILED) {
3337 if (input.charCodeAt(peg$currPos) === 41) {
3348 if (s5 !== peg$FAILED) {
3372 peg$resultsCache[key] = {
3373 nextPos: peg$currPos,
3379 function peg$parsematches() {
3380 var s0, s1, s2, s3, s4, s5;
3381 var key = peg$currPos * 30 + 23,
3382 cached = peg$resultsCache[key];
3385 peg$currPos = cached.nextPos;
3386 return cached.result;
3391 if (input.substr(peg$currPos, 9) === peg$c81) {
3402 if (s1 !== peg$FAILED) {
3405 if (s2 !== peg$FAILED) {
3406 s3 = peg$parseselectors();
3408 if (s3 !== peg$FAILED) {
3411 if (s4 !== peg$FAILED) {
3412 if (input.charCodeAt(peg$currPos) === 41) {
3423 if (s5 !== peg$FAILED) {
3447 peg$resultsCache[key] = {
3448 nextPos: peg$currPos,
3454 function peg$parsehas() {
3455 var s0, s1, s2, s3, s4, s5;
3456 var key = peg$currPos * 30 + 24,
3457 cached = peg$resultsCache[key];
3460 peg$currPos = cached.nextPos;
3461 return cached.result;
3466 if (input.substr(peg$currPos, 5) === peg$c84) {
3477 if (s1 !== peg$FAILED) {
3480 if (s2 !== peg$FAILED) {
3481 s3 = peg$parseselectors();
3483 if (s3 !== peg$FAILED) {
3486 if (s4 !== peg$FAILED) {
3487 if (input.charCodeAt(peg$currPos) === 41) {
3498 if (s5 !== peg$FAILED) {
3522 peg$resultsCache[key] = {
3523 nextPos: peg$currPos,
3529 function peg$parsefirstChild() {
3531 var key = peg$currPos * 30 + 25,
3532 cached = peg$resultsCache[key];
3535 peg$currPos = cached.nextPos;
3536 return cached.result;
3541 if (input.substr(peg$currPos, 12) === peg$c87) {
3552 if (s1 !== peg$FAILED) {
3557 peg$resultsCache[key] = {
3558 nextPos: peg$currPos,
3564 function peg$parselastChild() {
3566 var key = peg$currPos * 30 + 26,
3567 cached = peg$resultsCache[key];
3570 peg$currPos = cached.nextPos;
3571 return cached.result;
3576 if (input.substr(peg$currPos, 11) === peg$c90) {
3587 if (s1 !== peg$FAILED) {
3592 peg$resultsCache[key] = {
3593 nextPos: peg$currPos,
3599 function peg$parsenthChild() {
3600 var s0, s1, s2, s3, s4, s5;
3601 var key = peg$currPos * 30 + 27,
3602 cached = peg$resultsCache[key];
3605 peg$currPos = cached.nextPos;
3606 return cached.result;
3611 if (input.substr(peg$currPos, 11) === peg$c93) {
3622 if (s1 !== peg$FAILED) {
3625 if (s2 !== peg$FAILED) {
3628 if (peg$c59.test(input.charAt(peg$currPos))) {
3629 s4 = input.charAt(peg$currPos);
3639 if (s4 !== peg$FAILED) {
3640 while (s4 !== peg$FAILED) {
3643 if (peg$c59.test(input.charAt(peg$currPos))) {
3644 s4 = input.charAt(peg$currPos);
3658 if (s3 !== peg$FAILED) {
3661 if (s4 !== peg$FAILED) {
3662 if (input.charCodeAt(peg$currPos) === 41) {
3673 if (s5 !== peg$FAILED) {
3697 peg$resultsCache[key] = {
3698 nextPos: peg$currPos,
3704 function peg$parsenthLastChild() {
3705 var s0, s1, s2, s3, s4, s5;
3706 var key = peg$currPos * 30 + 28,
3707 cached = peg$resultsCache[key];
3710 peg$currPos = cached.nextPos;
3711 return cached.result;
3716 if (input.substr(peg$currPos, 16) === peg$c96) {
3727 if (s1 !== peg$FAILED) {
3730 if (s2 !== peg$FAILED) {
3733 if (peg$c59.test(input.charAt(peg$currPos))) {
3734 s4 = input.charAt(peg$currPos);
3744 if (s4 !== peg$FAILED) {
3745 while (s4 !== peg$FAILED) {
3748 if (peg$c59.test(input.charAt(peg$currPos))) {
3749 s4 = input.charAt(peg$currPos);
3763 if (s3 !== peg$FAILED) {
3766 if (s4 !== peg$FAILED) {
3767 if (input.charCodeAt(peg$currPos) === 41) {
3778 if (s5 !== peg$FAILED) {
3802 peg$resultsCache[key] = {
3803 nextPos: peg$currPos,
3809 function peg$parseclass() {
3811 var key = peg$currPos * 30 + 29,
3812 cached = peg$resultsCache[key];
3815 peg$currPos = cached.nextPos;
3816 return cached.result;
3821 if (input.charCodeAt(peg$currPos) === 58) {
3832 if (s1 !== peg$FAILED) {
3833 if (input.substr(peg$currPos, 9).toLowerCase() === peg$c101) {
3834 s2 = input.substr(peg$currPos, 9);
3844 if (s2 === peg$FAILED) {
3845 if (input.substr(peg$currPos, 10).toLowerCase() === peg$c103) {
3846 s2 = input.substr(peg$currPos, 10);
3856 if (s2 === peg$FAILED) {
3857 if (input.substr(peg$currPos, 11).toLowerCase() === peg$c105) {
3858 s2 = input.substr(peg$currPos, 11);
3868 if (s2 === peg$FAILED) {
3869 if (input.substr(peg$currPos, 8).toLowerCase() === peg$c107) {
3870 s2 = input.substr(peg$currPos, 8);
3880 if (s2 === peg$FAILED) {
3881 if (input.substr(peg$currPos, 7).toLowerCase() === peg$c109) {
3882 s2 = input.substr(peg$currPos, 7);
3896 if (s2 !== peg$FAILED) {
3908 peg$resultsCache[key] = {
3909 nextPos: peg$currPos,
3925 function nthLast(n) {
3927 type: 'nth-last-child',
3935 function strUnescape(s) {
3936 return s.replace(/\\(.)/g, function (match, ch) {
3962 peg$result = peg$startRuleFunction();
3964 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
3967 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
3968 peg$fail(peg$endExpectation());
3971 throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
3976 SyntaxError: peg$SyntaxError,
3982 function _objectEntries(obj) {
3984 var keys = Object.keys(obj);
3986 for (var k = 0; k < keys.length; k++) entries.push([keys[k], obj[keys[k]]]);
3991 * @typedef {"LEFT_SIDE"|"RIGHT_SIDE"} Side
3994 var LEFT_SIDE = 'LEFT_SIDE';
3995 var RIGHT_SIDE = 'RIGHT_SIDE';
3998 * @see https://esprima.readthedocs.io/en/latest/syntax-tree-format.html
4002 * One of the rules of `grammar.pegjs`
4003 * @typedef {PlainObject} SelectorAST
4004 * @see grammar.pegjs
4008 * The `sequence` production of `grammar.pegjs`
4009 * @typedef {PlainObject} SelectorSequenceAST
4013 * Get the value of a property which may be multiple levels down
4015 * @param {?PlainObject} obj
4016 * @param {string} key
4017 * @returns {undefined|boolean|string|number|external:AST}
4020 function getPath(obj, key) {
4021 var keys = key.split('.');
4023 for (var i = 0; i < keys.length; i++) {
4034 * Determine whether `node` can be reached by following `path`,
4035 * starting at `ancestor`.
4036 * @param {?external:AST} node
4037 * @param {?external:AST} ancestor
4038 * @param {string[]} path
4039 * @returns {boolean}
4043 function inPath(node, ancestor, path) {
4044 if (path.length === 0) {
4045 return node === ancestor;
4048 if (ancestor == null) {
4052 var field = ancestor[path[0]];
4053 var remainingPath = path.slice(1);
4055 if (Array.isArray(field)) {
4056 for (var i = 0, l = field.length; i < l; ++i) {
4057 if (inPath(node, field[i], remainingPath)) {
4064 return inPath(node, field, remainingPath);
4068 * Given a `node` and its ancestors, determine if `node` is matched
4070 * @param {?external:AST} node
4071 * @param {?SelectorAST} selector
4072 * @param {external:AST[]} [ancestry=[]]
4073 * @throws {Error} Unknowns (operator, class name, selector type, or
4074 * selector value type)
4075 * @returns {boolean}
4079 function matches(node, selector, ancestry) {
4092 switch (selector.type) {
4097 return selector.value.toLowerCase() === node.type.toLowerCase();
4101 var path = selector.name.split('.');
4102 var ancestor = ancestry[path.length - 1];
4103 return inPath(node, ancestor, path);
4107 for (var i = 0, l = selector.selectors.length; i < l; ++i) {
4108 if (matches(node, selector.selectors[i], ancestry)) {
4116 for (var _i = 0, _l = selector.selectors.length; _i < _l; ++_i) {
4117 if (!matches(node, selector.selectors[_i], ancestry)) {
4125 for (var _i2 = 0, _l2 = selector.selectors.length; _i2 < _l2; ++_i2) {
4126 if (matches(node, selector.selectors[_i2], ancestry)) {
4135 var _ret = function () {
4138 var _loop = function _loop(_i3, _l3) {
4140 estraverse.traverse(node, {
4141 enter: function enter(node, parent) {
4142 if (parent != null) {
4146 if (matches(node, selector.selectors[_i3], a)) {
4147 collector.push(node);
4150 leave: function leave() {
4153 fallback: 'iteration'
4157 for (var _i3 = 0, _l3 = selector.selectors.length; _i3 < _l3; ++_i3) {
4162 v: collector.length !== 0
4166 if (_typeof(_ret) === "object") return _ret.v;
4170 if (matches(node, selector.right, ancestry)) {
4171 return matches(ancestry[0], selector.left, ancestry.slice(1));
4177 if (matches(node, selector.right, ancestry)) {
4178 for (var _i4 = 0, _l4 = ancestry.length; _i4 < _l4; ++_i4) {
4179 if (matches(ancestry[_i4], selector.left, ancestry.slice(_i4 + 1))) {
4189 var p = getPath(node, selector.name);
4191 switch (selector.operator) {
4196 switch (selector.value.type) {
4198 return typeof p === 'string' && selector.value.value.test(p);
4201 return "".concat(selector.value.value) === "".concat(p);
4204 return selector.value.value === _typeof(p);
4207 throw new Error("Unknown selector value type: ".concat(selector.value.type));
4210 switch (selector.value.type) {
4212 return !selector.value.value.test(p);
4215 return "".concat(selector.value.value) !== "".concat(p);
4218 return selector.value.value !== _typeof(p);
4221 throw new Error("Unknown selector value type: ".concat(selector.value.type));
4224 return p <= selector.value.value;
4227 return p < selector.value.value;
4230 return p > selector.value.value;
4233 return p >= selector.value.value;
4236 throw new Error("Unknown operator: ".concat(selector.operator));
4240 return matches(node, selector.right, ancestry) && sibling(node, selector.left, ancestry, LEFT_SIDE) || selector.left.subject && matches(node, selector.left, ancestry) && sibling(node, selector.right, ancestry, RIGHT_SIDE);
4243 return matches(node, selector.right, ancestry) && adjacent(node, selector.left, ancestry, LEFT_SIDE) || selector.right.subject && matches(node, selector.left, ancestry) && adjacent(node, selector.right, ancestry, RIGHT_SIDE);
4246 return matches(node, selector.right, ancestry) && nthChild(node, ancestry, function () {
4247 return selector.index.value - 1;
4250 case 'nth-last-child':
4251 return matches(node, selector.right, ancestry) && nthChild(node, ancestry, function (length) {
4252 return length - selector.index.value;
4256 switch (selector.name.toLowerCase()) {
4258 if (node.type.slice(-9) === 'Statement') return true;
4259 // fallthrough: interface Declaration <: Statement { }
4262 return node.type.slice(-11) === 'Declaration';
4265 if (node.type.slice(-7) === 'Pattern') return true;
4266 // fallthrough: interface Expression <: Node, Pattern { }
4269 return node.type.slice(-10) === 'Expression' || node.type.slice(-7) === 'Literal' || node.type === 'Identifier' && (ancestry.length === 0 || ancestry[0].type !== 'MetaProperty') || node.type === 'MetaProperty';
4272 return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
4275 throw new Error("Unknown class name: ".concat(selector.name));
4278 throw new Error("Unknown selector type: ".concat(selector.type));
4281 * Determines if the given node has a sibling that matches the
4283 * @param {external:AST} node
4284 * @param {SelectorSequenceAST} selector
4285 * @param {external:AST[]} ancestry
4286 * @param {Side} side
4287 * @returns {boolean}
4291 function sibling(node, selector, ancestry, side) {
4292 var _ancestry = _slicedToArray(ancestry, 1),
4293 parent = _ancestry[0];
4299 var keys = estraverse.VisitorKeys[parent.type];
4301 for (var i = 0, l = keys.length; i < l; ++i) {
4302 var listProp = parent[keys[i]];
4304 if (Array.isArray(listProp)) {
4305 var startIndex = listProp.indexOf(node);
4307 if (startIndex < 0) {
4311 var lowerBound = void 0,
4312 upperBound = void 0;
4314 if (side === LEFT_SIDE) {
4316 upperBound = startIndex;
4318 lowerBound = startIndex + 1;
4319 upperBound = listProp.length;
4322 for (var k = lowerBound; k < upperBound; ++k) {
4323 if (matches(listProp[k], selector, ancestry)) {
4333 * Determines if the given node has an adjacent sibling that matches
4334 * the given selector.
4335 * @param {external:AST} node
4336 * @param {SelectorSequenceAST} selector
4337 * @param {external:AST[]} ancestry
4338 * @param {Side} side
4339 * @returns {boolean}
4343 function adjacent(node, selector, ancestry, side) {
4344 var _ancestry2 = _slicedToArray(ancestry, 1),
4345 parent = _ancestry2[0];
4351 var keys = estraverse.VisitorKeys[parent.type];
4353 for (var i = 0, l = keys.length; i < l; ++i) {
4354 var listProp = parent[keys[i]];
4356 if (Array.isArray(listProp)) {
4357 var idx = listProp.indexOf(node);
4363 if (side === LEFT_SIDE && idx > 0 && matches(listProp[idx - 1], selector, ancestry)) {
4367 if (side === RIGHT_SIDE && idx < listProp.length - 1 && matches(listProp[idx + 1], selector, ancestry)) {
4376 * @callback IndexFunction
4377 * @param {Integer} len Containing list's length
4378 * @returns {Integer}
4382 * Determines if the given node is the nth child, determined by
4383 * `idxFn`, which is given the containing list's length.
4384 * @param {external:AST} node
4385 * @param {external:AST[]} ancestry
4386 * @param {IndexFunction} idxFn
4387 * @returns {boolean}
4391 function nthChild(node, ancestry, idxFn) {
4392 var _ancestry3 = _slicedToArray(ancestry, 1),
4393 parent = _ancestry3[0];
4399 var keys = estraverse.VisitorKeys[parent.type];
4401 for (var i = 0, l = keys.length; i < l; ++i) {
4402 var listProp = parent[keys[i]];
4404 if (Array.isArray(listProp)) {
4405 var idx = listProp.indexOf(node);
4407 if (idx >= 0 && idx === idxFn(listProp.length)) {
4416 * For each selector node marked as a subject, find the portion of the
4417 * selector that the subject must match.
4418 * @param {SelectorAST} selector
4419 * @param {SelectorAST} [ancestor] Defaults to `selector`
4420 * @returns {SelectorAST[]}
4424 function subjects(selector, ancestor) {
4425 if (selector == null || _typeof(selector) != 'object') {
4429 if (ancestor == null) {
4430 ancestor = selector;
4433 var results = selector.subject ? [ancestor] : [];
4435 for (var _i5 = 0, _Object$entries = _objectEntries(selector); _i5 < _Object$entries.length; _i5++) {
4436 var _Object$entries$_i = _slicedToArray(_Object$entries[_i5], 2),
4437 p = _Object$entries$_i[0],
4438 sel = _Object$entries$_i[1];
4440 results.push.apply(results, _toConsumableArray(subjects(sel, p === 'left' ? sel : ancestor)));
4446 * @callback TraverseVisitor
4447 * @param {?external:AST} node
4448 * @param {?external:AST} parent
4449 * @param {external:AST[]} ancestry
4453 * From a JS AST and a selector AST, collect all JS AST nodes that
4454 * match the selector.
4455 * @param {external:AST} ast
4456 * @param {?SelectorAST} selector
4457 * @param {TraverseVisitor} visitor
4458 * @returns {external:AST[]}
4462 function traverse(ast, selector, visitor) {
4468 var altSubjects = subjects(selector);
4469 estraverse.traverse(ast, {
4470 enter: function enter(node, parent) {
4471 if (parent != null) {
4472 ancestry.unshift(parent);
4475 if (matches(node, selector, ancestry)) {
4476 if (altSubjects.length) {
4477 for (var i = 0, l = altSubjects.length; i < l; ++i) {
4478 if (matches(node, altSubjects[i], ancestry)) {
4479 visitor(node, parent, ancestry);
4482 for (var k = 0, m = ancestry.length; k < m; ++k) {
4483 var succeedingAncestry = ancestry.slice(k + 1);
4485 if (matches(ancestry[k], altSubjects[i], succeedingAncestry)) {
4486 visitor(ancestry[k], parent, succeedingAncestry);
4491 visitor(node, parent, ancestry);
4495 leave: function leave() {
4498 fallback: 'iteration'
4502 * From a JS AST and a selector AST, collect all JS AST nodes that
4503 * match the selector.
4504 * @param {external:AST} ast
4505 * @param {?SelectorAST} selector
4506 * @returns {external:AST[]}
4510 function match(ast, selector) {
4512 traverse(ast, selector, function (node) {
4518 * Parse a selector string and return its AST.
4519 * @param {string} selector
4520 * @returns {SelectorAST}
4524 function parse(selector) {
4525 return parser.parse(selector);
4528 * Query the code AST using the selector string.
4529 * @param {external:AST} ast
4530 * @param {string} selector
4531 * @returns {external:AST[]}
4535 function query(ast, selector) {
4536 return match(ast, parse(selector));
4539 query.parse = parse;
4540 query.match = match;
4541 query.traverse = traverse;
4542 query.matches = matches;
4543 query.query = query;
4545 export default query;