blob: 7a62b8b39ada4e3702f1b11e800def6268b32368 [file] [log] [blame]
Tim van der Lippe16aca392020-11-13 11:37:131function _typeof(obj) {
2 "@babel/helpers - typeof";
3
4 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
5 _typeof = function (obj) {
6 return typeof obj;
7 };
8 } else {
9 _typeof = function (obj) {
10 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
11 };
12 }
13
14 return _typeof(obj);
15}
16
17function _slicedToArray(arr, i) {
18 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
19}
20
21function _toConsumableArray(arr) {
22 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
23}
24
25function _arrayWithoutHoles(arr) {
26 if (Array.isArray(arr)) return _arrayLikeToArray(arr);
27}
28
29function _arrayWithHoles(arr) {
30 if (Array.isArray(arr)) return arr;
31}
32
33function _iterableToArray(iter) {
34 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
35}
36
37function _iterableToArrayLimit(arr, i) {
38 if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
39 var _arr = [];
40 var _n = true;
41 var _d = false;
42 var _e = undefined;
43
44 try {
45 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
46 _arr.push(_s.value);
47
48 if (i && _arr.length === i) break;
49 }
50 } catch (err) {
51 _d = true;
52 _e = err;
53 } finally {
54 try {
55 if (!_n && _i["return"] != null) _i["return"]();
56 } finally {
57 if (_d) throw _e;
58 }
59 }
60
61 return _arr;
62}
63
64function _unsupportedIterableToArray(o, minLen) {
65 if (!o) return;
66 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
67 var n = Object.prototype.toString.call(o).slice(8, -1);
68 if (n === "Object" && o.constructor) n = o.constructor.name;
Tim van der Lippeb97da6b2021-02-12 14:32:5369 if (n === "Map" || n === "Set") return Array.from(o);
Tim van der Lippe16aca392020-11-13 11:37:1370 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
71}
72
73function _arrayLikeToArray(arr, len) {
74 if (len == null || len > arr.length) len = arr.length;
75
76 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
77
78 return arr2;
79}
80
81function _nonIterableSpread() {
82 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
83}
84
85function _nonIterableRest() {
86 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
87}
88
Tim van der Lippeb97da6b2021-02-12 14:32:5389function _createForOfIteratorHelper(o, allowArrayLike) {
90 var it;
91
92 if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
93 if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
94 if (it) o = it;
95 var i = 0;
96
97 var F = function () {};
98
99 return {
100 s: F,
101 n: function () {
102 if (i >= o.length) return {
103 done: true
104 };
105 return {
106 done: false,
107 value: o[i++]
108 };
109 },
110 e: function (e) {
111 throw e;
112 },
113 f: F
114 };
115 }
116
117 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
118 }
119
120 var normalCompletion = true,
121 didErr = false,
122 err;
123 return {
124 s: function () {
125 it = o[Symbol.iterator]();
126 },
127 n: function () {
128 var step = it.next();
129 normalCompletion = step.done;
130 return step;
131 },
132 e: function (e) {
133 didErr = true;
134 err = e;
135 },
136 f: function () {
137 try {
138 if (!normalCompletion && it.return != null) it.return();
139 } finally {
140 if (didErr) throw err;
141 }
142 }
143 };
144}
145
Tim van der Lippec8f6ffd2020-04-06 12:42:00146var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
147
148function createCommonjsModule(fn, module) {
149 return module = { exports: {} }, fn(module, module.exports), module.exports;
150}
151
152var estraverse = createCommonjsModule(function (module, exports) {
Tim van der Lippe16aca392020-11-13 11:37:13153 /*
154 Copyright (C) 2012-2013 Yusuke Suzuki <[email protected]>
155 Copyright (C) 2012 Ariya Hidayat <[email protected]>
156
157 Redistribution and use in source and binary forms, with or without
158 modification, are permitted provided that the following conditions are met:
159
160 * Redistributions of source code must retain the above copyright
161 notice, this list of conditions and the following disclaimer.
162 * Redistributions in binary form must reproduce the above copyright
163 notice, this list of conditions and the following disclaimer in the
164 documentation and/or other materials provided with the distribution.
165
166 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
167 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
168 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
169 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
170 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
171 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
172 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
173 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
174 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
175 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
176 */
Tim van der Lippec8f6ffd2020-04-06 12:42:00177
Tim van der Lippe16aca392020-11-13 11:37:13178 /*jslint vars:false, bitwise:true*/
Tim van der Lippec8f6ffd2020-04-06 12:42:00179
Tim van der Lippe16aca392020-11-13 11:37:13180 /*jshint indent:4*/
Tim van der Lippec8f6ffd2020-04-06 12:42:00181
Tim van der Lippe16aca392020-11-13 11:37:13182 /*global exports:true*/
183 (function clone(exports) {
Tim van der Lippec8f6ffd2020-04-06 12:42:00184
Tim van der Lippe16aca392020-11-13 11:37:13185 var Syntax, VisitorOption, VisitorKeys, BREAK, SKIP, REMOVE;
Tim van der Lippec8f6ffd2020-04-06 12:42:00186
187 function deepCopy(obj) {
Tim van der Lippe16aca392020-11-13 11:37:13188 var ret = {},
189 key,
190 val;
Tim van der Lippec8f6ffd2020-04-06 12:42:00191
Tim van der Lippe16aca392020-11-13 11:37:13192 for (key in obj) {
193 if (obj.hasOwnProperty(key)) {
194 val = obj[key];
195
196 if (typeof val === 'object' && val !== null) {
197 ret[key] = deepCopy(val);
198 } else {
199 ret[key] = val;
200 }
201 }
202 }
203
204 return ret;
205 } // based on LLVM libc++ upper_bound / lower_bound
Tim van der Lippec8f6ffd2020-04-06 12:42:00206 // MIT License
207
Tim van der Lippe16aca392020-11-13 11:37:13208
Tim van der Lippec8f6ffd2020-04-06 12:42:00209 function upperBound(array, func) {
Tim van der Lippe16aca392020-11-13 11:37:13210 var diff, len, i, current;
211 len = array.length;
212 i = 0;
Tim van der Lippec8f6ffd2020-04-06 12:42:00213
Tim van der Lippe16aca392020-11-13 11:37:13214 while (len) {
215 diff = len >>> 1;
216 current = i + diff;
Tim van der Lippec8f6ffd2020-04-06 12:42:00217
Tim van der Lippe16aca392020-11-13 11:37:13218 if (func(array[current])) {
219 len = diff;
220 } else {
221 i = current + 1;
222 len -= diff + 1;
Tim van der Lippec8f6ffd2020-04-06 12:42:00223 }
Tim van der Lippe16aca392020-11-13 11:37:13224 }
225
226 return i;
Tim van der Lippec8f6ffd2020-04-06 12:42:00227 }
228
229 Syntax = {
Tim van der Lippe16aca392020-11-13 11:37:13230 AssignmentExpression: 'AssignmentExpression',
231 AssignmentPattern: 'AssignmentPattern',
232 ArrayExpression: 'ArrayExpression',
233 ArrayPattern: 'ArrayPattern',
234 ArrowFunctionExpression: 'ArrowFunctionExpression',
235 AwaitExpression: 'AwaitExpression',
236 // CAUTION: It's deferred to ES7.
237 BlockStatement: 'BlockStatement',
238 BinaryExpression: 'BinaryExpression',
239 BreakStatement: 'BreakStatement',
240 CallExpression: 'CallExpression',
241 CatchClause: 'CatchClause',
Tim van der Lippeb97da6b2021-02-12 14:32:53242 ChainExpression: 'ChainExpression',
Tim van der Lippe16aca392020-11-13 11:37:13243 ClassBody: 'ClassBody',
244 ClassDeclaration: 'ClassDeclaration',
245 ClassExpression: 'ClassExpression',
246 ComprehensionBlock: 'ComprehensionBlock',
247 // CAUTION: It's deferred to ES7.
248 ComprehensionExpression: 'ComprehensionExpression',
249 // CAUTION: It's deferred to ES7.
250 ConditionalExpression: 'ConditionalExpression',
251 ContinueStatement: 'ContinueStatement',
252 DebuggerStatement: 'DebuggerStatement',
253 DirectiveStatement: 'DirectiveStatement',
254 DoWhileStatement: 'DoWhileStatement',
255 EmptyStatement: 'EmptyStatement',
256 ExportAllDeclaration: 'ExportAllDeclaration',
257 ExportDefaultDeclaration: 'ExportDefaultDeclaration',
258 ExportNamedDeclaration: 'ExportNamedDeclaration',
259 ExportSpecifier: 'ExportSpecifier',
260 ExpressionStatement: 'ExpressionStatement',
261 ForStatement: 'ForStatement',
262 ForInStatement: 'ForInStatement',
263 ForOfStatement: 'ForOfStatement',
264 FunctionDeclaration: 'FunctionDeclaration',
265 FunctionExpression: 'FunctionExpression',
266 GeneratorExpression: 'GeneratorExpression',
267 // CAUTION: It's deferred to ES7.
268 Identifier: 'Identifier',
269 IfStatement: 'IfStatement',
270 ImportExpression: 'ImportExpression',
271 ImportDeclaration: 'ImportDeclaration',
272 ImportDefaultSpecifier: 'ImportDefaultSpecifier',
273 ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
274 ImportSpecifier: 'ImportSpecifier',
275 Literal: 'Literal',
276 LabeledStatement: 'LabeledStatement',
277 LogicalExpression: 'LogicalExpression',
278 MemberExpression: 'MemberExpression',
279 MetaProperty: 'MetaProperty',
280 MethodDefinition: 'MethodDefinition',
281 ModuleSpecifier: 'ModuleSpecifier',
282 NewExpression: 'NewExpression',
283 ObjectExpression: 'ObjectExpression',
284 ObjectPattern: 'ObjectPattern',
285 Program: 'Program',
286 Property: 'Property',
287 RestElement: 'RestElement',
288 ReturnStatement: 'ReturnStatement',
289 SequenceExpression: 'SequenceExpression',
290 SpreadElement: 'SpreadElement',
291 Super: 'Super',
292 SwitchStatement: 'SwitchStatement',
293 SwitchCase: 'SwitchCase',
294 TaggedTemplateExpression: 'TaggedTemplateExpression',
295 TemplateElement: 'TemplateElement',
296 TemplateLiteral: 'TemplateLiteral',
297 ThisExpression: 'ThisExpression',
298 ThrowStatement: 'ThrowStatement',
299 TryStatement: 'TryStatement',
300 UnaryExpression: 'UnaryExpression',
301 UpdateExpression: 'UpdateExpression',
302 VariableDeclaration: 'VariableDeclaration',
303 VariableDeclarator: 'VariableDeclarator',
304 WhileStatement: 'WhileStatement',
305 WithStatement: 'WithStatement',
306 YieldExpression: 'YieldExpression'
Tim van der Lippec8f6ffd2020-04-06 12:42:00307 };
Tim van der Lippec8f6ffd2020-04-06 12:42:00308 VisitorKeys = {
Tim van der Lippe16aca392020-11-13 11:37:13309 AssignmentExpression: ['left', 'right'],
310 AssignmentPattern: ['left', 'right'],
311 ArrayExpression: ['elements'],
312 ArrayPattern: ['elements'],
313 ArrowFunctionExpression: ['params', 'body'],
314 AwaitExpression: ['argument'],
315 // CAUTION: It's deferred to ES7.
316 BlockStatement: ['body'],
317 BinaryExpression: ['left', 'right'],
318 BreakStatement: ['label'],
319 CallExpression: ['callee', 'arguments'],
320 CatchClause: ['param', 'body'],
Tim van der Lippeb97da6b2021-02-12 14:32:53321 ChainExpression: ['expression'],
Tim van der Lippe16aca392020-11-13 11:37:13322 ClassBody: ['body'],
323 ClassDeclaration: ['id', 'superClass', 'body'],
324 ClassExpression: ['id', 'superClass', 'body'],
325 ComprehensionBlock: ['left', 'right'],
326 // CAUTION: It's deferred to ES7.
327 ComprehensionExpression: ['blocks', 'filter', 'body'],
328 // CAUTION: It's deferred to ES7.
329 ConditionalExpression: ['test', 'consequent', 'alternate'],
330 ContinueStatement: ['label'],
331 DebuggerStatement: [],
332 DirectiveStatement: [],
333 DoWhileStatement: ['body', 'test'],
334 EmptyStatement: [],
335 ExportAllDeclaration: ['source'],
336 ExportDefaultDeclaration: ['declaration'],
337 ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
338 ExportSpecifier: ['exported', 'local'],
339 ExpressionStatement: ['expression'],
340 ForStatement: ['init', 'test', 'update', 'body'],
341 ForInStatement: ['left', 'right', 'body'],
342 ForOfStatement: ['left', 'right', 'body'],
343 FunctionDeclaration: ['id', 'params', 'body'],
344 FunctionExpression: ['id', 'params', 'body'],
345 GeneratorExpression: ['blocks', 'filter', 'body'],
346 // CAUTION: It's deferred to ES7.
347 Identifier: [],
348 IfStatement: ['test', 'consequent', 'alternate'],
349 ImportExpression: ['source'],
350 ImportDeclaration: ['specifiers', 'source'],
351 ImportDefaultSpecifier: ['local'],
352 ImportNamespaceSpecifier: ['local'],
353 ImportSpecifier: ['imported', 'local'],
354 Literal: [],
355 LabeledStatement: ['label', 'body'],
356 LogicalExpression: ['left', 'right'],
357 MemberExpression: ['object', 'property'],
358 MetaProperty: ['meta', 'property'],
359 MethodDefinition: ['key', 'value'],
360 ModuleSpecifier: [],
361 NewExpression: ['callee', 'arguments'],
362 ObjectExpression: ['properties'],
363 ObjectPattern: ['properties'],
364 Program: ['body'],
365 Property: ['key', 'value'],
366 RestElement: ['argument'],
367 ReturnStatement: ['argument'],
368 SequenceExpression: ['expressions'],
369 SpreadElement: ['argument'],
370 Super: [],
371 SwitchStatement: ['discriminant', 'cases'],
372 SwitchCase: ['test', 'consequent'],
373 TaggedTemplateExpression: ['tag', 'quasi'],
374 TemplateElement: [],
375 TemplateLiteral: ['quasis', 'expressions'],
376 ThisExpression: [],
377 ThrowStatement: ['argument'],
378 TryStatement: ['block', 'handler', 'finalizer'],
379 UnaryExpression: ['argument'],
380 UpdateExpression: ['argument'],
381 VariableDeclaration: ['declarations'],
382 VariableDeclarator: ['id', 'init'],
383 WhileStatement: ['test', 'body'],
384 WithStatement: ['object', 'body'],
385 YieldExpression: ['argument']
386 }; // unique id
Tim van der Lippec8f6ffd2020-04-06 12:42:00387
Tim van der Lippec8f6ffd2020-04-06 12:42:00388 BREAK = {};
389 SKIP = {};
390 REMOVE = {};
Tim van der Lippec8f6ffd2020-04-06 12:42:00391 VisitorOption = {
Tim van der Lippe16aca392020-11-13 11:37:13392 Break: BREAK,
393 Skip: SKIP,
394 Remove: REMOVE
Tim van der Lippec8f6ffd2020-04-06 12:42:00395 };
396
397 function Reference(parent, key) {
Tim van der Lippe16aca392020-11-13 11:37:13398 this.parent = parent;
399 this.key = key;
Tim van der Lippec8f6ffd2020-04-06 12:42:00400 }
401
402 Reference.prototype.replace = function replace(node) {
Tim van der Lippe16aca392020-11-13 11:37:13403 this.parent[this.key] = node;
Tim van der Lippec8f6ffd2020-04-06 12:42:00404 };
405
406 Reference.prototype.remove = function remove() {
Tim van der Lippe16aca392020-11-13 11:37:13407 if (Array.isArray(this.parent)) {
408 this.parent.splice(this.key, 1);
409 return true;
410 } else {
411 this.replace(null);
412 return false;
413 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00414 };
415
416 function Element(node, path, wrap, ref) {
Tim van der Lippe16aca392020-11-13 11:37:13417 this.node = node;
418 this.path = path;
419 this.wrap = wrap;
420 this.ref = ref;
Tim van der Lippec8f6ffd2020-04-06 12:42:00421 }
422
Tim van der Lippe16aca392020-11-13 11:37:13423 function Controller() {} // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00424 // return property path array from root to current node
Tim van der Lippe16aca392020-11-13 11:37:13425
426
Tim van der Lippec8f6ffd2020-04-06 12:42:00427 Controller.prototype.path = function path() {
Tim van der Lippe16aca392020-11-13 11:37:13428 var i, iz, j, jz, result, element;
Tim van der Lippec8f6ffd2020-04-06 12:42:00429
Tim van der Lippe16aca392020-11-13 11:37:13430 function addToPath(result, path) {
431 if (Array.isArray(path)) {
432 for (j = 0, jz = path.length; j < jz; ++j) {
433 result.push(path[j]);
434 }
435 } else {
436 result.push(path);
Tim van der Lippec8f6ffd2020-04-06 12:42:00437 }
Tim van der Lippe16aca392020-11-13 11:37:13438 } // root node
Tim van der Lippec8f6ffd2020-04-06 12:42:00439
Tim van der Lippec8f6ffd2020-04-06 12:42:00440
Tim van der Lippe16aca392020-11-13 11:37:13441 if (!this.__current.path) {
442 return null;
443 } // first node is sentinel, second node is root element
Tim van der Lippec8f6ffd2020-04-06 12:42:00444
Tim van der Lippe16aca392020-11-13 11:37:13445
446 result = [];
447
448 for (i = 2, iz = this.__leavelist.length; i < iz; ++i) {
449 element = this.__leavelist[i];
450 addToPath(result, element.path);
451 }
452
453 addToPath(result, this.__current.path);
454 return result;
455 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00456 // return type of current node
Tim van der Lippe16aca392020-11-13 11:37:13457
458
Tim van der Lippec8f6ffd2020-04-06 12:42:00459 Controller.prototype.type = function () {
Tim van der Lippe16aca392020-11-13 11:37:13460 var node = this.current();
461 return node.type || this.__current.wrap;
462 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00463 // return array of parent elements
Tim van der Lippe16aca392020-11-13 11:37:13464
465
Tim van der Lippec8f6ffd2020-04-06 12:42:00466 Controller.prototype.parents = function parents() {
Tim van der Lippe16aca392020-11-13 11:37:13467 var i, iz, result; // first node is sentinel
Tim van der Lippec8f6ffd2020-04-06 12:42:00468
Tim van der Lippe16aca392020-11-13 11:37:13469 result = [];
Tim van der Lippec8f6ffd2020-04-06 12:42:00470
Tim van der Lippe16aca392020-11-13 11:37:13471 for (i = 1, iz = this.__leavelist.length; i < iz; ++i) {
472 result.push(this.__leavelist[i].node);
473 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00474
Tim van der Lippe16aca392020-11-13 11:37:13475 return result;
476 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00477 // return current node
Tim van der Lippe16aca392020-11-13 11:37:13478
479
Tim van der Lippec8f6ffd2020-04-06 12:42:00480 Controller.prototype.current = function current() {
Tim van der Lippe16aca392020-11-13 11:37:13481 return this.__current.node;
Tim van der Lippec8f6ffd2020-04-06 12:42:00482 };
483
484 Controller.prototype.__execute = function __execute(callback, element) {
Tim van der Lippe16aca392020-11-13 11:37:13485 var previous, result;
486 result = undefined;
487 previous = this.__current;
488 this.__current = element;
489 this.__state = null;
Tim van der Lippec8f6ffd2020-04-06 12:42:00490
Tim van der Lippe16aca392020-11-13 11:37:13491 if (callback) {
492 result = callback.call(this, element.node, this.__leavelist[this.__leavelist.length - 1].node);
493 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00494
Tim van der Lippe16aca392020-11-13 11:37:13495 this.__current = previous;
496 return result;
497 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00498 // notify control skip / break
Tim van der Lippe16aca392020-11-13 11:37:13499
500
Tim van der Lippec8f6ffd2020-04-06 12:42:00501 Controller.prototype.notify = function notify(flag) {
Tim van der Lippe16aca392020-11-13 11:37:13502 this.__state = flag;
503 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00504 // skip child nodes of current node
Tim van der Lippe16aca392020-11-13 11:37:13505
506
Tim van der Lippec8f6ffd2020-04-06 12:42:00507 Controller.prototype.skip = function () {
Tim van der Lippe16aca392020-11-13 11:37:13508 this.notify(SKIP);
509 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00510 // break traversals
Tim van der Lippe16aca392020-11-13 11:37:13511
512
Tim van der Lippec8f6ffd2020-04-06 12:42:00513 Controller.prototype['break'] = function () {
Tim van der Lippe16aca392020-11-13 11:37:13514 this.notify(BREAK);
515 }; // API:
Tim van der Lippec8f6ffd2020-04-06 12:42:00516 // remove node
Tim van der Lippe16aca392020-11-13 11:37:13517
518
Tim van der Lippec8f6ffd2020-04-06 12:42:00519 Controller.prototype.remove = function () {
Tim van der Lippe16aca392020-11-13 11:37:13520 this.notify(REMOVE);
Tim van der Lippec8f6ffd2020-04-06 12:42:00521 };
522
Tim van der Lippe16aca392020-11-13 11:37:13523 Controller.prototype.__initialize = function (root, visitor) {
524 this.visitor = visitor;
525 this.root = root;
526 this.__worklist = [];
527 this.__leavelist = [];
528 this.__current = null;
529 this.__state = null;
530 this.__fallback = null;
Tim van der Lippec8f6ffd2020-04-06 12:42:00531
Tim van der Lippe16aca392020-11-13 11:37:13532 if (visitor.fallback === 'iteration') {
533 this.__fallback = Object.keys;
534 } else if (typeof visitor.fallback === 'function') {
535 this.__fallback = visitor.fallback;
536 }
537
538 this.__keys = VisitorKeys;
539
540 if (visitor.keys) {
541 this.__keys = Object.assign(Object.create(this.__keys), visitor.keys);
542 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00543 };
544
545 function isNode(node) {
Tim van der Lippe16aca392020-11-13 11:37:13546 if (node == null) {
547 return false;
548 }
549
550 return typeof node === 'object' && typeof node.type === 'string';
Tim van der Lippec8f6ffd2020-04-06 12:42:00551 }
552
553 function isProperty(nodeType, key) {
Tim van der Lippe16aca392020-11-13 11:37:13554 return (nodeType === Syntax.ObjectExpression || nodeType === Syntax.ObjectPattern) && 'properties' === key;
555 }
556
557 function candidateExistsInLeaveList(leavelist, candidate) {
558 for (var i = leavelist.length - 1; i >= 0; --i) {
559 if (leavelist[i].node === candidate) {
560 return true;
561 }
562 }
563
564 return false;
Tim van der Lippec8f6ffd2020-04-06 12:42:00565 }
566
567 Controller.prototype.traverse = function traverse(root, visitor) {
Tim van der Lippe16aca392020-11-13 11:37:13568 var worklist, leavelist, element, node, nodeType, ret, key, current, current2, candidates, candidate, sentinel;
Tim van der Lippec8f6ffd2020-04-06 12:42:00569
Tim van der Lippe16aca392020-11-13 11:37:13570 this.__initialize(root, visitor);
Tim van der Lippec8f6ffd2020-04-06 12:42:00571
Tim van der Lippe16aca392020-11-13 11:37:13572 sentinel = {}; // reference
Tim van der Lippec8f6ffd2020-04-06 12:42:00573
Tim van der Lippe16aca392020-11-13 11:37:13574 worklist = this.__worklist;
575 leavelist = this.__leavelist; // initialize
Tim van der Lippec8f6ffd2020-04-06 12:42:00576
Tim van der Lippe16aca392020-11-13 11:37:13577 worklist.push(new Element(root, null, null, null));
578 leavelist.push(new Element(null, null, null, null));
Tim van der Lippec8f6ffd2020-04-06 12:42:00579
Tim van der Lippe16aca392020-11-13 11:37:13580 while (worklist.length) {
581 element = worklist.pop();
Tim van der Lippec8f6ffd2020-04-06 12:42:00582
Tim van der Lippe16aca392020-11-13 11:37:13583 if (element === sentinel) {
584 element = leavelist.pop();
585 ret = this.__execute(visitor.leave, element);
Tim van der Lippec8f6ffd2020-04-06 12:42:00586
Tim van der Lippe16aca392020-11-13 11:37:13587 if (this.__state === BREAK || ret === BREAK) {
588 return;
589 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00590
Tim van der Lippe16aca392020-11-13 11:37:13591 continue;
Tim van der Lippec8f6ffd2020-04-06 12:42:00592 }
Tim van der Lippe16aca392020-11-13 11:37:13593
594 if (element.node) {
595 ret = this.__execute(visitor.enter, element);
596
597 if (this.__state === BREAK || ret === BREAK) {
598 return;
599 }
600
601 worklist.push(sentinel);
602 leavelist.push(element);
603
604 if (this.__state === SKIP || ret === SKIP) {
605 continue;
606 }
607
608 node = element.node;
609 nodeType = node.type || element.wrap;
610 candidates = this.__keys[nodeType];
611
612 if (!candidates) {
613 if (this.__fallback) {
614 candidates = this.__fallback(node);
615 } else {
616 throw new Error('Unknown node type ' + nodeType + '.');
617 }
618 }
619
620 current = candidates.length;
621
622 while ((current -= 1) >= 0) {
623 key = candidates[current];
624 candidate = node[key];
625
626 if (!candidate) {
627 continue;
628 }
629
630 if (Array.isArray(candidate)) {
631 current2 = candidate.length;
632
633 while ((current2 -= 1) >= 0) {
634 if (!candidate[current2]) {
635 continue;
636 }
637
638 if (candidateExistsInLeaveList(leavelist, candidate[current2])) {
639 continue;
640 }
641
642 if (isProperty(nodeType, candidates[current])) {
643 element = new Element(candidate[current2], [key, current2], 'Property', null);
644 } else if (isNode(candidate[current2])) {
645 element = new Element(candidate[current2], [key, current2], null, null);
646 } else {
647 continue;
648 }
649
650 worklist.push(element);
651 }
652 } else if (isNode(candidate)) {
653 if (candidateExistsInLeaveList(leavelist, candidate)) {
654 continue;
655 }
656
657 worklist.push(new Element(candidate, key, null, null));
658 }
659 }
660 }
661 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00662 };
663
664 Controller.prototype.replace = function replace(root, visitor) {
Tim van der Lippe16aca392020-11-13 11:37:13665 var worklist, leavelist, node, nodeType, target, element, current, current2, candidates, candidate, sentinel, outer, key;
Tim van der Lippec8f6ffd2020-04-06 12:42:00666
Tim van der Lippe16aca392020-11-13 11:37:13667 function removeElem(element) {
668 var i, key, nextElem, parent;
Tim van der Lippec8f6ffd2020-04-06 12:42:00669
Tim van der Lippe16aca392020-11-13 11:37:13670 if (element.ref.remove()) {
671 // When the reference is an element of an array.
672 key = element.ref.key;
673 parent = element.ref.parent; // If removed from array, then decrease following items' keys.
Tim van der Lippec8f6ffd2020-04-06 12:42:00674
Tim van der Lippe16aca392020-11-13 11:37:13675 i = worklist.length;
676
677 while (i--) {
678 nextElem = worklist[i];
679
680 if (nextElem.ref && nextElem.ref.parent === parent) {
681 if (nextElem.ref.key < key) {
682 break;
683 }
684
685 --nextElem.ref.key;
Tim van der Lippec8f6ffd2020-04-06 12:42:00686 }
Tim van der Lippe16aca392020-11-13 11:37:13687 }
688 }
689 }
690
691 this.__initialize(root, visitor);
692
693 sentinel = {}; // reference
694
695 worklist = this.__worklist;
696 leavelist = this.__leavelist; // initialize
697
698 outer = {
699 root: root
700 };
701 element = new Element(root, null, null, new Reference(outer, 'root'));
702 worklist.push(element);
703 leavelist.push(element);
704
705 while (worklist.length) {
706 element = worklist.pop();
707
708 if (element === sentinel) {
709 element = leavelist.pop();
710 target = this.__execute(visitor.leave, element); // node may be replaced with null,
711 // so distinguish between undefined and null in this place
712
713 if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
714 // replace
715 element.ref.replace(target);
716 }
717
718 if (this.__state === REMOVE || target === REMOVE) {
719 removeElem(element);
720 }
721
722 if (this.__state === BREAK || target === BREAK) {
723 return outer.root;
724 }
725
726 continue;
Tim van der Lippec8f6ffd2020-04-06 12:42:00727 }
728
Tim van der Lippe16aca392020-11-13 11:37:13729 target = this.__execute(visitor.enter, element); // node may be replaced with null,
730 // so distinguish between undefined and null in this place
Tim van der Lippec8f6ffd2020-04-06 12:42:00731
Tim van der Lippe16aca392020-11-13 11:37:13732 if (target !== undefined && target !== BREAK && target !== SKIP && target !== REMOVE) {
733 // replace
734 element.ref.replace(target);
735 element.node = target;
736 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00737
Tim van der Lippe16aca392020-11-13 11:37:13738 if (this.__state === REMOVE || target === REMOVE) {
739 removeElem(element);
740 element.node = null;
741 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00742
Tim van der Lippe16aca392020-11-13 11:37:13743 if (this.__state === BREAK || target === BREAK) {
744 return outer.root;
745 } // node may be null
746
747
748 node = element.node;
749
750 if (!node) {
751 continue;
752 }
753
754 worklist.push(sentinel);
Tim van der Lippec8f6ffd2020-04-06 12:42:00755 leavelist.push(element);
756
Tim van der Lippe16aca392020-11-13 11:37:13757 if (this.__state === SKIP || target === SKIP) {
758 continue;
Tim van der Lippec8f6ffd2020-04-06 12:42:00759 }
760
Tim van der Lippe16aca392020-11-13 11:37:13761 nodeType = node.type || element.wrap;
762 candidates = this.__keys[nodeType];
763
764 if (!candidates) {
765 if (this.__fallback) {
766 candidates = this.__fallback(node);
767 } else {
768 throw new Error('Unknown node type ' + nodeType + '.');
769 }
770 }
771
772 current = candidates.length;
773
774 while ((current -= 1) >= 0) {
775 key = candidates[current];
776 candidate = node[key];
777
778 if (!candidate) {
779 continue;
780 }
781
782 if (Array.isArray(candidate)) {
783 current2 = candidate.length;
784
785 while ((current2 -= 1) >= 0) {
786 if (!candidate[current2]) {
787 continue;
788 }
789
790 if (isProperty(nodeType, candidates[current])) {
791 element = new Element(candidate[current2], [key, current2], 'Property', new Reference(candidate, current2));
792 } else if (isNode(candidate[current2])) {
793 element = new Element(candidate[current2], [key, current2], null, new Reference(candidate, current2));
794 } else {
795 continue;
796 }
797
798 worklist.push(element);
799 }
800 } else if (isNode(candidate)) {
801 worklist.push(new Element(candidate, key, null, new Reference(node, key)));
802 }
803 }
804 }
805
806 return outer.root;
Tim van der Lippec8f6ffd2020-04-06 12:42:00807 };
808
809 function traverse(root, visitor) {
Tim van der Lippe16aca392020-11-13 11:37:13810 var controller = new Controller();
811 return controller.traverse(root, visitor);
Tim van der Lippec8f6ffd2020-04-06 12:42:00812 }
813
814 function replace(root, visitor) {
Tim van der Lippe16aca392020-11-13 11:37:13815 var controller = new Controller();
816 return controller.replace(root, visitor);
Tim van der Lippec8f6ffd2020-04-06 12:42:00817 }
818
819 function extendCommentRange(comment, tokens) {
Tim van der Lippe16aca392020-11-13 11:37:13820 var target;
821 target = upperBound(tokens, function search(token) {
822 return token.range[0] > comment.range[0];
823 });
824 comment.extendedRange = [comment.range[0], comment.range[1]];
Tim van der Lippec8f6ffd2020-04-06 12:42:00825
Tim van der Lippe16aca392020-11-13 11:37:13826 if (target !== tokens.length) {
827 comment.extendedRange[1] = tokens[target].range[0];
828 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00829
Tim van der Lippe16aca392020-11-13 11:37:13830 target -= 1;
Tim van der Lippec8f6ffd2020-04-06 12:42:00831
Tim van der Lippe16aca392020-11-13 11:37:13832 if (target >= 0) {
833 comment.extendedRange[0] = tokens[target].range[1];
834 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00835
Tim van der Lippe16aca392020-11-13 11:37:13836 return comment;
Tim van der Lippec8f6ffd2020-04-06 12:42:00837 }
838
839 function attachComments(tree, providedComments, tokens) {
Tim van der Lippe16aca392020-11-13 11:37:13840 // At first, we should calculate extended comment ranges.
841 var comments = [],
842 comment,
843 len,
844 i,
845 cursor;
Tim van der Lippec8f6ffd2020-04-06 12:42:00846
Tim van der Lippe16aca392020-11-13 11:37:13847 if (!tree.range) {
848 throw new Error('attachComments needs range information');
849 } // tokens array is empty, we attach comments to tree as 'leadingComments'
850
851
852 if (!tokens.length) {
853 if (providedComments.length) {
854 for (i = 0, len = providedComments.length; i < len; i += 1) {
855 comment = deepCopy(providedComments[i]);
856 comment.extendedRange = [0, tree.range[0]];
857 comments.push(comment);
858 }
859
860 tree.leadingComments = comments;
Tim van der Lippec8f6ffd2020-04-06 12:42:00861 }
862
Tim van der Lippec8f6ffd2020-04-06 12:42:00863 return tree;
Tim van der Lippe16aca392020-11-13 11:37:13864 }
865
866 for (i = 0, len = providedComments.length; i < len; i += 1) {
867 comments.push(extendCommentRange(deepCopy(providedComments[i]), tokens));
868 } // This is based on John Freeman's implementation.
869
870
871 cursor = 0;
872 traverse(tree, {
873 enter: function (node) {
874 var comment;
875
876 while (cursor < comments.length) {
877 comment = comments[cursor];
878
879 if (comment.extendedRange[1] > node.range[0]) {
880 break;
881 }
882
883 if (comment.extendedRange[1] === node.range[0]) {
884 if (!node.leadingComments) {
885 node.leadingComments = [];
886 }
887
888 node.leadingComments.push(comment);
889 comments.splice(cursor, 1);
890 } else {
891 cursor += 1;
892 }
893 } // already out of owned node
894
895
896 if (cursor === comments.length) {
897 return VisitorOption.Break;
898 }
899
900 if (comments[cursor].extendedRange[0] > node.range[1]) {
901 return VisitorOption.Skip;
902 }
903 }
904 });
905 cursor = 0;
906 traverse(tree, {
907 leave: function (node) {
908 var comment;
909
910 while (cursor < comments.length) {
911 comment = comments[cursor];
912
913 if (node.range[1] < comment.extendedRange[0]) {
914 break;
915 }
916
917 if (node.range[1] === comment.extendedRange[0]) {
918 if (!node.trailingComments) {
919 node.trailingComments = [];
920 }
921
922 node.trailingComments.push(comment);
923 comments.splice(cursor, 1);
924 } else {
925 cursor += 1;
926 }
927 } // already out of owned node
928
929
930 if (cursor === comments.length) {
931 return VisitorOption.Break;
932 }
933
934 if (comments[cursor].extendedRange[0] > node.range[1]) {
935 return VisitorOption.Skip;
936 }
937 }
938 });
939 return tree;
Tim van der Lippec8f6ffd2020-04-06 12:42:00940 }
941
942 exports.Syntax = Syntax;
943 exports.traverse = traverse;
944 exports.replace = replace;
945 exports.attachComments = attachComments;
946 exports.VisitorKeys = VisitorKeys;
947 exports.VisitorOption = VisitorOption;
948 exports.Controller = Controller;
Tim van der Lippe16aca392020-11-13 11:37:13949
950 exports.cloneEnvironment = function () {
951 return clone({});
952 };
Tim van der Lippec8f6ffd2020-04-06 12:42:00953
954 return exports;
Tim van der Lippe16aca392020-11-13 11:37:13955 })(exports);
956 /* vim: set sw=4 ts=4 et tw=80 : */
957
Tim van der Lippec8f6ffd2020-04-06 12:42:00958});
959
960var parser = createCommonjsModule(function (module) {
Tim van der Lippe16aca392020-11-13 11:37:13961 /*
962 * Generated by PEG.js 0.10.0.
963 *
964 * http://pegjs.org/
965 */
966 (function (root, factory) {
967 if ( module.exports) {
968 module.exports = factory();
Tim van der Lippec8f6ffd2020-04-06 12:42:00969 }
Tim van der Lippe16aca392020-11-13 11:37:13970 })(commonjsGlobal, function () {
Tim van der Lippec8f6ffd2020-04-06 12:42:00971
Tim van der Lippe16aca392020-11-13 11:37:13972 function peg$subclass(child, parent) {
973 function ctor() {
974 this.constructor = child;
Tim van der Lippec8f6ffd2020-04-06 12:42:00975 }
976
Tim van der Lippe16aca392020-11-13 11:37:13977 ctor.prototype = parent.prototype;
978 child.prototype = new ctor();
979 }
Tim van der Lippec8f6ffd2020-04-06 12:42:00980
Tim van der Lippe16aca392020-11-13 11:37:13981 function peg$SyntaxError(message, expected, found, location) {
982 this.message = message;
983 this.expected = expected;
984 this.found = found;
985 this.location = location;
986 this.name = "SyntaxError";
Tim van der Lippec8f6ffd2020-04-06 12:42:00987
Tim van der Lippe16aca392020-11-13 11:37:13988 if (typeof Error.captureStackTrace === "function") {
989 Error.captureStackTrace(this, peg$SyntaxError);
Tim van der Lippec8f6ffd2020-04-06 12:42:00990 }
991 }
992
Tim van der Lippe16aca392020-11-13 11:37:13993 peg$subclass(peg$SyntaxError, Error);
Tim van der Lippec8f6ffd2020-04-06 12:42:00994
Tim van der Lippe16aca392020-11-13 11:37:13995 peg$SyntaxError.buildMessage = function (expected, found) {
996 var DESCRIBE_EXPECTATION_FNS = {
997 literal: function literal(expectation) {
998 return "\"" + literalEscape(expectation.text) + "\"";
Tim van der Lippec8f6ffd2020-04-06 12:42:00999 },
Tim van der Lippe16aca392020-11-13 11:37:131000 "class": function _class(expectation) {
1001 var escapedParts = "",
1002 i;
Tim van der Lippec8f6ffd2020-04-06 12:42:001003
Tim van der Lippe16aca392020-11-13 11:37:131004 for (i = 0; i < expectation.parts.length; i++) {
1005 escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
Tim van der Lippec8f6ffd2020-04-06 12:42:001006 }
1007
Tim van der Lippe16aca392020-11-13 11:37:131008 return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
Tim van der Lippec8f6ffd2020-04-06 12:42:001009 },
Tim van der Lippe16aca392020-11-13 11:37:131010 any: function any(expectation) {
1011 return "any character";
1012 },
1013 end: function end(expectation) {
1014 return "end of input";
1015 },
1016 other: function other(expectation) {
1017 return expectation.description;
Tim van der Lippec8f6ffd2020-04-06 12:42:001018 }
1019 };
Tim van der Lippec8f6ffd2020-04-06 12:42:001020
Tim van der Lippe16aca392020-11-13 11:37:131021 function hex(ch) {
1022 return ch.charCodeAt(0).toString(16).toUpperCase();
Tim van der Lippec8f6ffd2020-04-06 12:42:001023 }
1024
Tim van der Lippe16aca392020-11-13 11:37:131025 function literalEscape(s) {
1026 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) {
1027 return '\\x0' + hex(ch);
1028 }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
1029 return '\\x' + hex(ch);
1030 });
Tim van der Lippec8f6ffd2020-04-06 12:42:001031 }
1032
Tim van der Lippe16aca392020-11-13 11:37:131033 function classEscape(s) {
1034 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) {
1035 return '\\x0' + hex(ch);
1036 }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
1037 return '\\x' + hex(ch);
1038 });
1039 }
1040
1041 function describeExpectation(expectation) {
1042 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
1043 }
1044
1045 function describeExpected(expected) {
1046 var descriptions = new Array(expected.length),
1047 i,
1048 j;
1049
1050 for (i = 0; i < expected.length; i++) {
1051 descriptions[i] = describeExpectation(expected[i]);
Tim van der Lippec8f6ffd2020-04-06 12:42:001052 }
Tim van der Lippe16aca392020-11-13 11:37:131053
1054 descriptions.sort();
1055
1056 if (descriptions.length > 0) {
1057 for (i = 1, j = 1; i < descriptions.length; i++) {
1058 if (descriptions[i - 1] !== descriptions[i]) {
1059 descriptions[j] = descriptions[i];
1060 j++;
1061 }
1062 }
1063
1064 descriptions.length = j;
1065 }
1066
1067 switch (descriptions.length) {
1068 case 1:
1069 return descriptions[0];
1070
1071 case 2:
1072 return descriptions[0] + " or " + descriptions[1];
1073
1074 default:
1075 return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
1076 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001077 }
Tim van der Lippe16aca392020-11-13 11:37:131078
1079 function describeFound(found) {
1080 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
1081 }
1082
1083 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
1084 };
1085
1086 function peg$parse(input, options) {
1087 options = options !== void 0 ? options : {};
1088
1089 var peg$FAILED = {},
1090 peg$startRuleFunctions = {
1091 start: peg$parsestart
1092 },
1093 peg$startRuleFunction = peg$parsestart,
1094 peg$c0 = function peg$c0(ss) {
1095 return ss.length === 1 ? ss[0] : {
1096 type: 'matches',
1097 selectors: ss
1098 };
1099 },
1100 peg$c1 = function peg$c1() {
1101 return void 0;
1102 },
1103 peg$c2 = " ",
1104 peg$c3 = peg$literalExpectation(" ", false),
1105 peg$c4 = /^[^ [\],():#!=><~+.]/,
1106 peg$c5 = peg$classExpectation([" ", "[", "]", ",", "(", ")", ":", "#", "!", "=", ">", "<", "~", "+", "."], true, false),
1107 peg$c6 = function peg$c6(i) {
1108 return i.join('');
1109 },
1110 peg$c7 = ">",
1111 peg$c8 = peg$literalExpectation(">", false),
1112 peg$c9 = function peg$c9() {
1113 return 'child';
1114 },
1115 peg$c10 = "~",
1116 peg$c11 = peg$literalExpectation("~", false),
1117 peg$c12 = function peg$c12() {
1118 return 'sibling';
1119 },
1120 peg$c13 = "+",
1121 peg$c14 = peg$literalExpectation("+", false),
1122 peg$c15 = function peg$c15() {
1123 return 'adjacent';
1124 },
1125 peg$c16 = function peg$c16() {
1126 return 'descendant';
1127 },
1128 peg$c17 = ",",
1129 peg$c18 = peg$literalExpectation(",", false),
1130 peg$c19 = function peg$c19(s, ss) {
1131 return [s].concat(ss.map(function (s) {
1132 return s[3];
1133 }));
1134 },
1135 peg$c20 = function peg$c20(a, ops) {
1136 return ops.reduce(function (memo, rhs) {
1137 return {
1138 type: rhs[0],
1139 left: memo,
1140 right: rhs[1]
1141 };
1142 }, a);
1143 },
1144 peg$c21 = "!",
1145 peg$c22 = peg$literalExpectation("!", false),
1146 peg$c23 = function peg$c23(subject, as) {
1147 var b = as.length === 1 ? as[0] : {
1148 type: 'compound',
1149 selectors: as
1150 };
1151 if (subject) b.subject = true;
1152 return b;
1153 },
1154 peg$c24 = "*",
1155 peg$c25 = peg$literalExpectation("*", false),
1156 peg$c26 = function peg$c26(a) {
1157 return {
1158 type: 'wildcard',
1159 value: a
1160 };
1161 },
1162 peg$c27 = "#",
1163 peg$c28 = peg$literalExpectation("#", false),
1164 peg$c29 = function peg$c29(i) {
1165 return {
1166 type: 'identifier',
1167 value: i
1168 };
1169 },
1170 peg$c30 = "[",
1171 peg$c31 = peg$literalExpectation("[", false),
1172 peg$c32 = "]",
1173 peg$c33 = peg$literalExpectation("]", false),
1174 peg$c34 = function peg$c34(v) {
1175 return v;
1176 },
1177 peg$c35 = /^[><!]/,
1178 peg$c36 = peg$classExpectation([">", "<", "!"], false, false),
1179 peg$c37 = "=",
1180 peg$c38 = peg$literalExpectation("=", false),
1181 peg$c39 = function peg$c39(a) {
1182 return (a || '') + '=';
1183 },
1184 peg$c40 = /^[><]/,
1185 peg$c41 = peg$classExpectation([">", "<"], false, false),
1186 peg$c42 = ".",
1187 peg$c43 = peg$literalExpectation(".", false),
Tim van der Lippeb97da6b2021-02-12 14:32:531188 peg$c44 = function peg$c44(a, as) {
1189 return [].concat.apply([a], as).join('');
1190 },
1191 peg$c45 = function peg$c45(name, op, value) {
Tim van der Lippe16aca392020-11-13 11:37:131192 return {
1193 type: 'attribute',
1194 name: name,
1195 operator: op,
1196 value: value
1197 };
1198 },
Tim van der Lippeb97da6b2021-02-12 14:32:531199 peg$c46 = function peg$c46(name) {
Tim van der Lippe16aca392020-11-13 11:37:131200 return {
1201 type: 'attribute',
1202 name: name
1203 };
1204 },
Tim van der Lippeb97da6b2021-02-12 14:32:531205 peg$c47 = "\"",
1206 peg$c48 = peg$literalExpectation("\"", false),
1207 peg$c49 = /^[^\\"]/,
1208 peg$c50 = peg$classExpectation(["\\", "\""], true, false),
1209 peg$c51 = "\\",
1210 peg$c52 = peg$literalExpectation("\\", false),
1211 peg$c53 = peg$anyExpectation(),
1212 peg$c54 = function peg$c54(a, b) {
Tim van der Lippe16aca392020-11-13 11:37:131213 return a + b;
1214 },
Tim van der Lippeb97da6b2021-02-12 14:32:531215 peg$c55 = function peg$c55(d) {
Tim van der Lippe16aca392020-11-13 11:37:131216 return {
1217 type: 'literal',
1218 value: strUnescape(d.join(''))
1219 };
1220 },
Tim van der Lippeb97da6b2021-02-12 14:32:531221 peg$c56 = "'",
1222 peg$c57 = peg$literalExpectation("'", false),
1223 peg$c58 = /^[^\\']/,
1224 peg$c59 = peg$classExpectation(["\\", "'"], true, false),
1225 peg$c60 = /^[0-9]/,
1226 peg$c61 = peg$classExpectation([["0", "9"]], false, false),
1227 peg$c62 = function peg$c62(a, b) {
Tim van der Lippe16aca392020-11-13 11:37:131228 // Can use `a.flat().join('')` once supported
1229 var leadingDecimals = a ? [].concat.apply([], a).join('') : '';
1230 return {
1231 type: 'literal',
1232 value: parseFloat(leadingDecimals + b.join(''))
1233 };
1234 },
Tim van der Lippeb97da6b2021-02-12 14:32:531235 peg$c63 = function peg$c63(i) {
Tim van der Lippe16aca392020-11-13 11:37:131236 return {
1237 type: 'literal',
1238 value: i
1239 };
1240 },
Tim van der Lippeb97da6b2021-02-12 14:32:531241 peg$c64 = "type(",
1242 peg$c65 = peg$literalExpectation("type(", false),
1243 peg$c66 = /^[^ )]/,
1244 peg$c67 = peg$classExpectation([" ", ")"], true, false),
1245 peg$c68 = ")",
1246 peg$c69 = peg$literalExpectation(")", false),
1247 peg$c70 = function peg$c70(t) {
Tim van der Lippe16aca392020-11-13 11:37:131248 return {
1249 type: 'type',
1250 value: t.join('')
1251 };
1252 },
Tim van der Lippeb97da6b2021-02-12 14:32:531253 peg$c71 = /^[imsu]/,
1254 peg$c72 = peg$classExpectation(["i", "m", "s", "u"], false, false),
1255 peg$c73 = "/",
1256 peg$c74 = peg$literalExpectation("/", false),
1257 peg$c75 = /^[^\/]/,
1258 peg$c76 = peg$classExpectation(["/"], true, false),
1259 peg$c77 = function peg$c77(d, flgs) {
Tim van der Lippe16aca392020-11-13 11:37:131260 return {
1261 type: 'regexp',
1262 value: new RegExp(d.join(''), flgs ? flgs.join('') : '')
1263 };
1264 },
Tim van der Lippeb97da6b2021-02-12 14:32:531265 peg$c78 = function peg$c78(i, is) {
Tim van der Lippe16aca392020-11-13 11:37:131266 return {
1267 type: 'field',
1268 name: is.reduce(function (memo, p) {
1269 return memo + p[0] + p[1];
1270 }, i)
1271 };
1272 },
Tim van der Lippeb97da6b2021-02-12 14:32:531273 peg$c79 = ":not(",
1274 peg$c80 = peg$literalExpectation(":not(", false),
1275 peg$c81 = function peg$c81(ss) {
Tim van der Lippe16aca392020-11-13 11:37:131276 return {
1277 type: 'not',
1278 selectors: ss
1279 };
1280 },
Tim van der Lippeb97da6b2021-02-12 14:32:531281 peg$c82 = ":matches(",
1282 peg$c83 = peg$literalExpectation(":matches(", false),
1283 peg$c84 = function peg$c84(ss) {
Tim van der Lippe16aca392020-11-13 11:37:131284 return {
1285 type: 'matches',
1286 selectors: ss
1287 };
1288 },
Tim van der Lippeb97da6b2021-02-12 14:32:531289 peg$c85 = ":has(",
1290 peg$c86 = peg$literalExpectation(":has(", false),
1291 peg$c87 = function peg$c87(ss) {
Tim van der Lippe16aca392020-11-13 11:37:131292 return {
1293 type: 'has',
1294 selectors: ss
1295 };
1296 },
Tim van der Lippeb97da6b2021-02-12 14:32:531297 peg$c88 = ":first-child",
1298 peg$c89 = peg$literalExpectation(":first-child", false),
1299 peg$c90 = function peg$c90() {
Tim van der Lippe16aca392020-11-13 11:37:131300 return nth(1);
1301 },
Tim van der Lippeb97da6b2021-02-12 14:32:531302 peg$c91 = ":last-child",
1303 peg$c92 = peg$literalExpectation(":last-child", false),
1304 peg$c93 = function peg$c93() {
Tim van der Lippe16aca392020-11-13 11:37:131305 return nthLast(1);
1306 },
Tim van der Lippeb97da6b2021-02-12 14:32:531307 peg$c94 = ":nth-child(",
1308 peg$c95 = peg$literalExpectation(":nth-child(", false),
1309 peg$c96 = function peg$c96(n) {
Tim van der Lippe16aca392020-11-13 11:37:131310 return nth(parseInt(n.join(''), 10));
1311 },
Tim van der Lippeb97da6b2021-02-12 14:32:531312 peg$c97 = ":nth-last-child(",
1313 peg$c98 = peg$literalExpectation(":nth-last-child(", false),
1314 peg$c99 = function peg$c99(n) {
Tim van der Lippe16aca392020-11-13 11:37:131315 return nthLast(parseInt(n.join(''), 10));
1316 },
Tim van der Lippeb97da6b2021-02-12 14:32:531317 peg$c100 = ":",
1318 peg$c101 = peg$literalExpectation(":", false),
1319 peg$c102 = "statement",
1320 peg$c103 = peg$literalExpectation("statement", true),
1321 peg$c104 = "expression",
1322 peg$c105 = peg$literalExpectation("expression", true),
1323 peg$c106 = "declaration",
1324 peg$c107 = peg$literalExpectation("declaration", true),
1325 peg$c108 = "function",
1326 peg$c109 = peg$literalExpectation("function", true),
1327 peg$c110 = "pattern",
1328 peg$c111 = peg$literalExpectation("pattern", true),
1329 peg$c112 = function peg$c112(c) {
Tim van der Lippe16aca392020-11-13 11:37:131330 return {
1331 type: 'class',
1332 name: c
1333 };
1334 },
1335 peg$currPos = 0,
1336 peg$posDetailsCache = [{
1337 line: 1,
1338 column: 1
1339 }],
1340 peg$maxFailPos = 0,
1341 peg$maxFailExpected = [],
1342 peg$resultsCache = {},
1343 peg$result;
1344
1345 if ("startRule" in options) {
1346 if (!(options.startRule in peg$startRuleFunctions)) {
1347 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
1348 }
1349
1350 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
1351 }
1352
1353 function peg$literalExpectation(text, ignoreCase) {
1354 return {
1355 type: "literal",
1356 text: text,
1357 ignoreCase: ignoreCase
1358 };
1359 }
1360
1361 function peg$classExpectation(parts, inverted, ignoreCase) {
1362 return {
1363 type: "class",
1364 parts: parts,
1365 inverted: inverted,
1366 ignoreCase: ignoreCase
1367 };
1368 }
1369
1370 function peg$anyExpectation() {
1371 return {
1372 type: "any"
1373 };
1374 }
1375
1376 function peg$endExpectation() {
1377 return {
1378 type: "end"
1379 };
1380 }
1381
1382 function peg$computePosDetails(pos) {
1383 var details = peg$posDetailsCache[pos],
1384 p;
1385
1386 if (details) {
1387 return details;
1388 } else {
1389 p = pos - 1;
1390
1391 while (!peg$posDetailsCache[p]) {
1392 p--;
1393 }
1394
1395 details = peg$posDetailsCache[p];
1396 details = {
1397 line: details.line,
1398 column: details.column
1399 };
1400
1401 while (p < pos) {
1402 if (input.charCodeAt(p) === 10) {
1403 details.line++;
1404 details.column = 1;
1405 } else {
1406 details.column++;
1407 }
1408
1409 p++;
1410 }
1411
1412 peg$posDetailsCache[pos] = details;
1413 return details;
1414 }
1415 }
1416
1417 function peg$computeLocation(startPos, endPos) {
1418 var startPosDetails = peg$computePosDetails(startPos),
1419 endPosDetails = peg$computePosDetails(endPos);
1420 return {
1421 start: {
1422 offset: startPos,
1423 line: startPosDetails.line,
1424 column: startPosDetails.column
1425 },
1426 end: {
1427 offset: endPos,
1428 line: endPosDetails.line,
1429 column: endPosDetails.column
1430 }
1431 };
1432 }
1433
1434 function peg$fail(expected) {
1435 if (peg$currPos < peg$maxFailPos) {
1436 return;
1437 }
1438
1439 if (peg$currPos > peg$maxFailPos) {
1440 peg$maxFailPos = peg$currPos;
1441 peg$maxFailExpected = [];
1442 }
1443
1444 peg$maxFailExpected.push(expected);
1445 }
1446
1447 function peg$buildStructuredError(expected, found, location) {
1448 return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
1449 }
1450
1451 function peg$parsestart() {
1452 var s0, s1, s2, s3;
1453 var key = peg$currPos * 30 + 0,
1454 cached = peg$resultsCache[key];
1455
1456 if (cached) {
1457 peg$currPos = cached.nextPos;
1458 return cached.result;
1459 }
1460
Tim van der Lippec8f6ffd2020-04-06 12:42:001461 s0 = peg$currPos;
1462 s1 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:131463
Tim van der Lippec8f6ffd2020-04-06 12:42:001464 if (s1 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:131465 s2 = peg$parseselectors();
Tim van der Lippec8f6ffd2020-04-06 12:42:001466
Tim van der Lippec8f6ffd2020-04-06 12:42:001467 if (s2 !== peg$FAILED) {
1468 s3 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:131469
Tim van der Lippec8f6ffd2020-04-06 12:42:001470 if (s3 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:131471 s1 = peg$c0(s2);
Tim van der Lippec8f6ffd2020-04-06 12:42:001472 s0 = s1;
1473 } else {
1474 peg$currPos = s0;
1475 s0 = peg$FAILED;
1476 }
1477 } else {
1478 peg$currPos = s0;
1479 s0 = peg$FAILED;
1480 }
1481 } else {
1482 peg$currPos = s0;
1483 s0 = peg$FAILED;
1484 }
Tim van der Lippe16aca392020-11-13 11:37:131485
Tim van der Lippec8f6ffd2020-04-06 12:42:001486 if (s0 === peg$FAILED) {
1487 s0 = peg$currPos;
1488 s1 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:131489
Tim van der Lippec8f6ffd2020-04-06 12:42:001490 if (s1 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:131491 s1 = peg$c1();
1492 }
1493
1494 s0 = s1;
1495 }
1496
1497 peg$resultsCache[key] = {
1498 nextPos: peg$currPos,
1499 result: s0
1500 };
1501 return s0;
1502 }
1503
1504 function peg$parse_() {
1505 var s0, s1;
1506 var key = peg$currPos * 30 + 1,
1507 cached = peg$resultsCache[key];
1508
1509 if (cached) {
1510 peg$currPos = cached.nextPos;
1511 return cached.result;
1512 }
1513
1514 s0 = [];
1515
1516 if (input.charCodeAt(peg$currPos) === 32) {
1517 s1 = peg$c2;
1518 peg$currPos++;
1519 } else {
1520 s1 = peg$FAILED;
1521
1522 {
1523 peg$fail(peg$c3);
1524 }
1525 }
1526
1527 while (s1 !== peg$FAILED) {
1528 s0.push(s1);
1529
1530 if (input.charCodeAt(peg$currPos) === 32) {
1531 s1 = peg$c2;
1532 peg$currPos++;
1533 } else {
1534 s1 = peg$FAILED;
1535
1536 {
1537 peg$fail(peg$c3);
1538 }
1539 }
1540 }
1541
1542 peg$resultsCache[key] = {
1543 nextPos: peg$currPos,
1544 result: s0
1545 };
1546 return s0;
1547 }
1548
1549 function peg$parseidentifierName() {
1550 var s0, s1, s2;
1551 var key = peg$currPos * 30 + 2,
1552 cached = peg$resultsCache[key];
1553
1554 if (cached) {
1555 peg$currPos = cached.nextPos;
1556 return cached.result;
1557 }
1558
1559 s0 = peg$currPos;
1560 s1 = [];
1561
1562 if (peg$c4.test(input.charAt(peg$currPos))) {
1563 s2 = input.charAt(peg$currPos);
1564 peg$currPos++;
1565 } else {
1566 s2 = peg$FAILED;
1567
1568 {
1569 peg$fail(peg$c5);
1570 }
1571 }
1572
1573 if (s2 !== peg$FAILED) {
1574 while (s2 !== peg$FAILED) {
1575 s1.push(s2);
1576
1577 if (peg$c4.test(input.charAt(peg$currPos))) {
1578 s2 = input.charAt(peg$currPos);
Tim van der Lippec8f6ffd2020-04-06 12:42:001579 peg$currPos++;
1580 } else {
1581 s2 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:131582
1583 {
1584 peg$fail(peg$c5);
1585 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001586 }
Tim van der Lippe16aca392020-11-13 11:37:131587 }
1588 } else {
1589 s1 = peg$FAILED;
1590 }
1591
1592 if (s1 !== peg$FAILED) {
1593 s1 = peg$c6(s1);
1594 }
1595
1596 s0 = s1;
1597 peg$resultsCache[key] = {
1598 nextPos: peg$currPos,
1599 result: s0
1600 };
1601 return s0;
1602 }
1603
1604 function peg$parsebinaryOp() {
1605 var s0, s1, s2, s3;
1606 var key = peg$currPos * 30 + 3,
1607 cached = peg$resultsCache[key];
1608
1609 if (cached) {
1610 peg$currPos = cached.nextPos;
1611 return cached.result;
1612 }
1613
1614 s0 = peg$currPos;
1615 s1 = peg$parse_();
1616
1617 if (s1 !== peg$FAILED) {
1618 if (input.charCodeAt(peg$currPos) === 62) {
1619 s2 = peg$c7;
1620 peg$currPos++;
1621 } else {
1622 s2 = peg$FAILED;
1623
1624 {
1625 peg$fail(peg$c8);
1626 }
1627 }
1628
1629 if (s2 !== peg$FAILED) {
1630 s3 = peg$parse_();
1631
1632 if (s3 !== peg$FAILED) {
1633 s1 = peg$c9();
1634 s0 = s1;
1635 } else {
1636 peg$currPos = s0;
1637 s0 = peg$FAILED;
1638 }
1639 } else {
1640 peg$currPos = s0;
1641 s0 = peg$FAILED;
1642 }
1643 } else {
1644 peg$currPos = s0;
1645 s0 = peg$FAILED;
1646 }
1647
1648 if (s0 === peg$FAILED) {
1649 s0 = peg$currPos;
1650 s1 = peg$parse_();
1651
1652 if (s1 !== peg$FAILED) {
1653 if (input.charCodeAt(peg$currPos) === 126) {
1654 s2 = peg$c10;
1655 peg$currPos++;
1656 } else {
1657 s2 = peg$FAILED;
1658
1659 {
1660 peg$fail(peg$c11);
1661 }
1662 }
1663
Tim van der Lippec8f6ffd2020-04-06 12:42:001664 if (s2 !== peg$FAILED) {
1665 s3 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:131666
Tim van der Lippec8f6ffd2020-04-06 12:42:001667 if (s3 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:131668 s1 = peg$c12();
Tim van der Lippec8f6ffd2020-04-06 12:42:001669 s0 = s1;
1670 } else {
1671 peg$currPos = s0;
1672 s0 = peg$FAILED;
1673 }
1674 } else {
1675 peg$currPos = s0;
1676 s0 = peg$FAILED;
1677 }
1678 } else {
1679 peg$currPos = s0;
1680 s0 = peg$FAILED;
1681 }
Tim van der Lippe16aca392020-11-13 11:37:131682
Tim van der Lippec8f6ffd2020-04-06 12:42:001683 if (s0 === peg$FAILED) {
1684 s0 = peg$currPos;
Tim van der Lippe16aca392020-11-13 11:37:131685 s1 = peg$parse_();
1686
Tim van der Lippec8f6ffd2020-04-06 12:42:001687 if (s1 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:131688 if (input.charCodeAt(peg$currPos) === 43) {
1689 s2 = peg$c13;
1690 peg$currPos++;
1691 } else {
1692 s2 = peg$FAILED;
1693
1694 {
1695 peg$fail(peg$c14);
1696 }
1697 }
1698
Tim van der Lippec8f6ffd2020-04-06 12:42:001699 if (s2 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:131700 s3 = peg$parse_();
1701
1702 if (s3 !== peg$FAILED) {
1703 s1 = peg$c15();
1704 s0 = s1;
1705 } else {
1706 peg$currPos = s0;
1707 s0 = peg$FAILED;
1708 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001709 } else {
1710 peg$currPos = s0;
1711 s0 = peg$FAILED;
1712 }
1713 } else {
1714 peg$currPos = s0;
1715 s0 = peg$FAILED;
1716 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001717
Tim van der Lippe16aca392020-11-13 11:37:131718 if (s0 === peg$FAILED) {
1719 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:001720
Tim van der Lippe16aca392020-11-13 11:37:131721 if (input.charCodeAt(peg$currPos) === 32) {
1722 s1 = peg$c2;
1723 peg$currPos++;
Tim van der Lippec8f6ffd2020-04-06 12:42:001724 } else {
Tim van der Lippe16aca392020-11-13 11:37:131725 s1 = peg$FAILED;
1726
1727 {
1728 peg$fail(peg$c3);
1729 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001730 }
Tim van der Lippe16aca392020-11-13 11:37:131731
1732 if (s1 !== peg$FAILED) {
1733 s2 = peg$parse_();
1734
1735 if (s2 !== peg$FAILED) {
1736 s1 = peg$c16();
1737 s0 = s1;
1738 } else {
1739 peg$currPos = s0;
1740 s0 = peg$FAILED;
1741 }
1742 } else {
1743 peg$currPos = s0;
1744 s0 = peg$FAILED;
1745 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001746 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001747 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001748 }
Tim van der Lippe16aca392020-11-13 11:37:131749
1750 peg$resultsCache[key] = {
1751 nextPos: peg$currPos,
1752 result: s0
1753 };
1754 return s0;
1755 }
1756
1757 function peg$parseselectors() {
1758 var s0, s1, s2, s3, s4, s5, s6, s7;
1759 var key = peg$currPos * 30 + 4,
1760 cached = peg$resultsCache[key];
1761
1762 if (cached) {
1763 peg$currPos = cached.nextPos;
1764 return cached.result;
1765 }
1766
1767 s0 = peg$currPos;
1768 s1 = peg$parseselector();
1769
1770 if (s1 !== peg$FAILED) {
1771 s2 = [];
Tim van der Lippec8f6ffd2020-04-06 12:42:001772 s3 = peg$currPos;
1773 s4 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:131774
Tim van der Lippec8f6ffd2020-04-06 12:42:001775 if (s4 !== peg$FAILED) {
1776 if (input.charCodeAt(peg$currPos) === 44) {
1777 s5 = peg$c17;
1778 peg$currPos++;
1779 } else {
1780 s5 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:131781
1782 {
1783 peg$fail(peg$c18);
1784 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001785 }
Tim van der Lippe16aca392020-11-13 11:37:131786
Tim van der Lippec8f6ffd2020-04-06 12:42:001787 if (s5 !== peg$FAILED) {
1788 s6 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:131789
Tim van der Lippec8f6ffd2020-04-06 12:42:001790 if (s6 !== peg$FAILED) {
1791 s7 = peg$parseselector();
Tim van der Lippe16aca392020-11-13 11:37:131792
Tim van der Lippec8f6ffd2020-04-06 12:42:001793 if (s7 !== peg$FAILED) {
1794 s4 = [s4, s5, s6, s7];
1795 s3 = s4;
1796 } else {
1797 peg$currPos = s3;
1798 s3 = peg$FAILED;
1799 }
1800 } else {
1801 peg$currPos = s3;
1802 s3 = peg$FAILED;
1803 }
1804 } else {
1805 peg$currPos = s3;
1806 s3 = peg$FAILED;
1807 }
1808 } else {
1809 peg$currPos = s3;
1810 s3 = peg$FAILED;
1811 }
Tim van der Lippe16aca392020-11-13 11:37:131812
1813 while (s3 !== peg$FAILED) {
1814 s2.push(s3);
1815 s3 = peg$currPos;
1816 s4 = peg$parse_();
1817
1818 if (s4 !== peg$FAILED) {
1819 if (input.charCodeAt(peg$currPos) === 44) {
1820 s5 = peg$c17;
1821 peg$currPos++;
1822 } else {
1823 s5 = peg$FAILED;
1824
1825 {
1826 peg$fail(peg$c18);
1827 }
1828 }
1829
1830 if (s5 !== peg$FAILED) {
1831 s6 = peg$parse_();
1832
1833 if (s6 !== peg$FAILED) {
1834 s7 = peg$parseselector();
1835
1836 if (s7 !== peg$FAILED) {
1837 s4 = [s4, s5, s6, s7];
1838 s3 = s4;
1839 } else {
1840 peg$currPos = s3;
1841 s3 = peg$FAILED;
1842 }
1843 } else {
1844 peg$currPos = s3;
1845 s3 = peg$FAILED;
1846 }
1847 } else {
1848 peg$currPos = s3;
1849 s3 = peg$FAILED;
1850 }
1851 } else {
1852 peg$currPos = s3;
1853 s3 = peg$FAILED;
1854 }
1855 }
1856
1857 if (s2 !== peg$FAILED) {
1858 s1 = peg$c19(s1, s2);
1859 s0 = s1;
1860 } else {
1861 peg$currPos = s0;
1862 s0 = peg$FAILED;
1863 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001864 } else {
1865 peg$currPos = s0;
1866 s0 = peg$FAILED;
1867 }
Tim van der Lippe16aca392020-11-13 11:37:131868
1869 peg$resultsCache[key] = {
1870 nextPos: peg$currPos,
1871 result: s0
1872 };
1873 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:001874 }
1875
Tim van der Lippe16aca392020-11-13 11:37:131876 function peg$parseselector() {
1877 var s0, s1, s2, s3, s4, s5;
1878 var key = peg$currPos * 30 + 5,
1879 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:001880
Tim van der Lippe16aca392020-11-13 11:37:131881 if (cached) {
1882 peg$currPos = cached.nextPos;
1883 return cached.result;
Tim van der Lippec8f6ffd2020-04-06 12:42:001884 }
Tim van der Lippe16aca392020-11-13 11:37:131885
1886 s0 = peg$currPos;
1887 s1 = peg$parsesequence();
1888
1889 if (s1 !== peg$FAILED) {
1890 s2 = [];
Tim van der Lippec8f6ffd2020-04-06 12:42:001891 s3 = peg$currPos;
1892 s4 = peg$parsebinaryOp();
Tim van der Lippe16aca392020-11-13 11:37:131893
Tim van der Lippec8f6ffd2020-04-06 12:42:001894 if (s4 !== peg$FAILED) {
1895 s5 = peg$parsesequence();
Tim van der Lippe16aca392020-11-13 11:37:131896
Tim van der Lippec8f6ffd2020-04-06 12:42:001897 if (s5 !== peg$FAILED) {
1898 s4 = [s4, s5];
1899 s3 = s4;
1900 } else {
1901 peg$currPos = s3;
1902 s3 = peg$FAILED;
1903 }
1904 } else {
1905 peg$currPos = s3;
1906 s3 = peg$FAILED;
1907 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001908
Tim van der Lippec8f6ffd2020-04-06 12:42:001909 while (s3 !== peg$FAILED) {
1910 s2.push(s3);
Tim van der Lippe16aca392020-11-13 11:37:131911 s3 = peg$currPos;
1912 s4 = peg$parsebinaryOp();
1913
1914 if (s4 !== peg$FAILED) {
1915 s5 = peg$parsesequence();
1916
1917 if (s5 !== peg$FAILED) {
1918 s4 = [s4, s5];
1919 s3 = s4;
1920 } else {
1921 peg$currPos = s3;
1922 s3 = peg$FAILED;
1923 }
1924 } else {
1925 peg$currPos = s3;
1926 s3 = peg$FAILED;
1927 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001928 }
Tim van der Lippe16aca392020-11-13 11:37:131929
1930 if (s2 !== peg$FAILED) {
1931 s1 = peg$c20(s1, s2);
1932 s0 = s1;
1933 } else {
1934 peg$currPos = s0;
1935 s0 = peg$FAILED;
1936 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001937 } else {
1938 peg$currPos = s0;
1939 s0 = peg$FAILED;
1940 }
Tim van der Lippe16aca392020-11-13 11:37:131941
1942 peg$resultsCache[key] = {
1943 nextPos: peg$currPos,
1944 result: s0
1945 };
1946 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:001947 }
1948
Tim van der Lippe16aca392020-11-13 11:37:131949 function peg$parsesequence() {
1950 var s0, s1, s2, s3;
1951 var key = peg$currPos * 30 + 6,
1952 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:001953
Tim van der Lippe16aca392020-11-13 11:37:131954 if (cached) {
1955 peg$currPos = cached.nextPos;
1956 return cached.result;
1957 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001958
Tim van der Lippe16aca392020-11-13 11:37:131959 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:001960
Tim van der Lippe16aca392020-11-13 11:37:131961 if (input.charCodeAt(peg$currPos) === 33) {
1962 s1 = peg$c21;
1963 peg$currPos++;
1964 } else {
1965 s1 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:001966
Tim van der Lippe16aca392020-11-13 11:37:131967 {
1968 peg$fail(peg$c22);
1969 }
1970 }
Tim van der Lippec8f6ffd2020-04-06 12:42:001971
Tim van der Lippe16aca392020-11-13 11:37:131972 if (s1 === peg$FAILED) {
1973 s1 = null;
1974 }
1975
1976 if (s1 !== peg$FAILED) {
1977 s2 = [];
1978 s3 = peg$parseatom();
1979
1980 if (s3 !== peg$FAILED) {
1981 while (s3 !== peg$FAILED) {
1982 s2.push(s3);
1983 s3 = peg$parseatom();
1984 }
1985 } else {
1986 s2 = peg$FAILED;
1987 }
1988
1989 if (s2 !== peg$FAILED) {
1990 s1 = peg$c23(s1, s2);
1991 s0 = s1;
1992 } else {
1993 peg$currPos = s0;
1994 s0 = peg$FAILED;
1995 }
1996 } else {
1997 peg$currPos = s0;
1998 s0 = peg$FAILED;
1999 }
2000
2001 peg$resultsCache[key] = {
2002 nextPos: peg$currPos,
2003 result: s0
2004 };
2005 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:002006 }
2007
Tim van der Lippe16aca392020-11-13 11:37:132008 function peg$parseatom() {
2009 var s0;
2010 var key = peg$currPos * 30 + 7,
2011 cached = peg$resultsCache[key];
2012
2013 if (cached) {
2014 peg$currPos = cached.nextPos;
2015 return cached.result;
2016 }
2017
2018 s0 = peg$parsewildcard();
2019
Tim van der Lippec8f6ffd2020-04-06 12:42:002020 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132021 s0 = peg$parseidentifier();
2022
Tim van der Lippec8f6ffd2020-04-06 12:42:002023 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132024 s0 = peg$parseattr();
2025
Tim van der Lippec8f6ffd2020-04-06 12:42:002026 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132027 s0 = peg$parsefield();
2028
Tim van der Lippec8f6ffd2020-04-06 12:42:002029 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132030 s0 = peg$parsenegation();
2031
Tim van der Lippec8f6ffd2020-04-06 12:42:002032 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132033 s0 = peg$parsematches();
2034
Tim van der Lippec8f6ffd2020-04-06 12:42:002035 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132036 s0 = peg$parsehas();
2037
Tim van der Lippec8f6ffd2020-04-06 12:42:002038 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132039 s0 = peg$parsefirstChild();
2040
Tim van der Lippec8f6ffd2020-04-06 12:42:002041 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132042 s0 = peg$parselastChild();
2043
Tim van der Lippec8f6ffd2020-04-06 12:42:002044 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132045 s0 = peg$parsenthChild();
2046
Tim van der Lippec8f6ffd2020-04-06 12:42:002047 if (s0 === peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132048 s0 = peg$parsenthLastChild();
2049
2050 if (s0 === peg$FAILED) {
2051 s0 = peg$parseclass();
2052 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002053 }
2054 }
2055 }
2056 }
2057 }
2058 }
2059 }
2060 }
2061 }
2062 }
Tim van der Lippe16aca392020-11-13 11:37:132063
2064 peg$resultsCache[key] = {
2065 nextPos: peg$currPos,
2066 result: s0
2067 };
2068 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:002069 }
2070
Tim van der Lippe16aca392020-11-13 11:37:132071 function peg$parsewildcard() {
2072 var s0, s1;
2073 var key = peg$currPos * 30 + 8,
2074 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:002075
Tim van der Lippe16aca392020-11-13 11:37:132076 if (cached) {
2077 peg$currPos = cached.nextPos;
2078 return cached.result;
Tim van der Lippec8f6ffd2020-04-06 12:42:002079 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002080
Tim van der Lippec8f6ffd2020-04-06 12:42:002081 s0 = peg$currPos;
Tim van der Lippe16aca392020-11-13 11:37:132082
2083 if (input.charCodeAt(peg$currPos) === 42) {
2084 s1 = peg$c24;
2085 peg$currPos++;
2086 } else {
2087 s1 = peg$FAILED;
2088
2089 {
2090 peg$fail(peg$c25);
2091 }
2092 }
2093
2094 if (s1 !== peg$FAILED) {
2095 s1 = peg$c26(s1);
2096 }
2097
2098 s0 = s1;
2099 peg$resultsCache[key] = {
2100 nextPos: peg$currPos,
2101 result: s0
2102 };
2103 return s0;
2104 }
2105
2106 function peg$parseidentifier() {
2107 var s0, s1, s2;
2108 var key = peg$currPos * 30 + 9,
2109 cached = peg$resultsCache[key];
2110
2111 if (cached) {
2112 peg$currPos = cached.nextPos;
2113 return cached.result;
2114 }
2115
2116 s0 = peg$currPos;
2117
2118 if (input.charCodeAt(peg$currPos) === 35) {
2119 s1 = peg$c27;
2120 peg$currPos++;
2121 } else {
2122 s1 = peg$FAILED;
2123
2124 {
2125 peg$fail(peg$c28);
2126 }
2127 }
2128
2129 if (s1 === peg$FAILED) {
2130 s1 = null;
2131 }
2132
2133 if (s1 !== peg$FAILED) {
2134 s2 = peg$parseidentifierName();
2135
2136 if (s2 !== peg$FAILED) {
2137 s1 = peg$c29(s2);
2138 s0 = s1;
2139 } else {
2140 peg$currPos = s0;
2141 s0 = peg$FAILED;
2142 }
2143 } else {
2144 peg$currPos = s0;
2145 s0 = peg$FAILED;
2146 }
2147
2148 peg$resultsCache[key] = {
2149 nextPos: peg$currPos,
2150 result: s0
2151 };
2152 return s0;
2153 }
2154
2155 function peg$parseattr() {
2156 var s0, s1, s2, s3, s4, s5;
2157 var key = peg$currPos * 30 + 10,
2158 cached = peg$resultsCache[key];
2159
2160 if (cached) {
2161 peg$currPos = cached.nextPos;
2162 return cached.result;
2163 }
2164
2165 s0 = peg$currPos;
2166
2167 if (input.charCodeAt(peg$currPos) === 91) {
2168 s1 = peg$c30;
2169 peg$currPos++;
2170 } else {
2171 s1 = peg$FAILED;
2172
2173 {
2174 peg$fail(peg$c31);
2175 }
2176 }
2177
Tim van der Lippec8f6ffd2020-04-06 12:42:002178 if (s1 !== peg$FAILED) {
2179 s2 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:132180
Tim van der Lippec8f6ffd2020-04-06 12:42:002181 if (s2 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132182 s3 = peg$parseattrValue();
2183
Tim van der Lippec8f6ffd2020-04-06 12:42:002184 if (s3 !== peg$FAILED) {
2185 s4 = peg$parse_();
Tim van der Lippe16aca392020-11-13 11:37:132186
Tim van der Lippec8f6ffd2020-04-06 12:42:002187 if (s4 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132188 if (input.charCodeAt(peg$currPos) === 93) {
2189 s5 = peg$c32;
2190 peg$currPos++;
2191 } else {
2192 s5 = peg$FAILED;
2193
2194 {
2195 peg$fail(peg$c33);
Tim van der Lippec8f6ffd2020-04-06 12:42:002196 }
2197 }
Tim van der Lippe16aca392020-11-13 11:37:132198
2199 if (s5 !== peg$FAILED) {
2200 s1 = peg$c34(s3);
2201 s0 = s1;
2202 } else {
2203 peg$currPos = s0;
2204 s0 = peg$FAILED;
2205 }
2206 } else {
2207 peg$currPos = s0;
2208 s0 = peg$FAILED;
2209 }
2210 } else {
2211 peg$currPos = s0;
2212 s0 = peg$FAILED;
2213 }
2214 } else {
2215 peg$currPos = s0;
2216 s0 = peg$FAILED;
2217 }
2218 } else {
2219 peg$currPos = s0;
2220 s0 = peg$FAILED;
2221 }
2222
2223 peg$resultsCache[key] = {
2224 nextPos: peg$currPos,
2225 result: s0
2226 };
2227 return s0;
2228 }
2229
2230 function peg$parseattrOps() {
2231 var s0, s1, s2;
2232 var key = peg$currPos * 30 + 11,
2233 cached = peg$resultsCache[key];
2234
2235 if (cached) {
2236 peg$currPos = cached.nextPos;
2237 return cached.result;
2238 }
2239
2240 s0 = peg$currPos;
2241
2242 if (peg$c35.test(input.charAt(peg$currPos))) {
2243 s1 = input.charAt(peg$currPos);
2244 peg$currPos++;
2245 } else {
2246 s1 = peg$FAILED;
2247
2248 {
2249 peg$fail(peg$c36);
2250 }
2251 }
2252
2253 if (s1 === peg$FAILED) {
2254 s1 = null;
2255 }
2256
2257 if (s1 !== peg$FAILED) {
2258 if (input.charCodeAt(peg$currPos) === 61) {
2259 s2 = peg$c37;
2260 peg$currPos++;
2261 } else {
2262 s2 = peg$FAILED;
2263
2264 {
2265 peg$fail(peg$c38);
2266 }
2267 }
2268
2269 if (s2 !== peg$FAILED) {
2270 s1 = peg$c39(s1);
2271 s0 = s1;
2272 } else {
2273 peg$currPos = s0;
2274 s0 = peg$FAILED;
2275 }
2276 } else {
2277 peg$currPos = s0;
2278 s0 = peg$FAILED;
2279 }
2280
2281 if (s0 === peg$FAILED) {
2282 if (peg$c40.test(input.charAt(peg$currPos))) {
2283 s0 = input.charAt(peg$currPos);
2284 peg$currPos++;
2285 } else {
2286 s0 = peg$FAILED;
2287
2288 {
2289 peg$fail(peg$c41);
2290 }
2291 }
2292 }
2293
2294 peg$resultsCache[key] = {
2295 nextPos: peg$currPos,
2296 result: s0
2297 };
2298 return s0;
2299 }
2300
2301 function peg$parseattrEqOps() {
2302 var s0, s1, s2;
2303 var key = peg$currPos * 30 + 12,
2304 cached = peg$resultsCache[key];
2305
2306 if (cached) {
2307 peg$currPos = cached.nextPos;
2308 return cached.result;
2309 }
2310
2311 s0 = peg$currPos;
2312
2313 if (input.charCodeAt(peg$currPos) === 33) {
2314 s1 = peg$c21;
2315 peg$currPos++;
2316 } else {
2317 s1 = peg$FAILED;
2318
2319 {
2320 peg$fail(peg$c22);
2321 }
2322 }
2323
2324 if (s1 === peg$FAILED) {
2325 s1 = null;
2326 }
2327
2328 if (s1 !== peg$FAILED) {
2329 if (input.charCodeAt(peg$currPos) === 61) {
2330 s2 = peg$c37;
2331 peg$currPos++;
2332 } else {
2333 s2 = peg$FAILED;
2334
2335 {
2336 peg$fail(peg$c38);
2337 }
2338 }
2339
2340 if (s2 !== peg$FAILED) {
2341 s1 = peg$c39(s1);
2342 s0 = s1;
2343 } else {
2344 peg$currPos = s0;
2345 s0 = peg$FAILED;
2346 }
2347 } else {
2348 peg$currPos = s0;
2349 s0 = peg$FAILED;
2350 }
2351
2352 peg$resultsCache[key] = {
2353 nextPos: peg$currPos,
2354 result: s0
2355 };
2356 return s0;
2357 }
2358
2359 function peg$parseattrName() {
Tim van der Lippeb97da6b2021-02-12 14:32:532360 var s0, s1, s2, s3, s4, s5;
Tim van der Lippe16aca392020-11-13 11:37:132361 var key = peg$currPos * 30 + 13,
2362 cached = peg$resultsCache[key];
2363
2364 if (cached) {
2365 peg$currPos = cached.nextPos;
2366 return cached.result;
2367 }
2368
2369 s0 = peg$currPos;
Tim van der Lippeb97da6b2021-02-12 14:32:532370 s1 = peg$parseidentifierName();
Tim van der Lippe16aca392020-11-13 11:37:132371
Tim van der Lippeb97da6b2021-02-12 14:32:532372 if (s1 !== peg$FAILED) {
2373 s2 = [];
2374 s3 = peg$currPos;
2375
Tim van der Lippe16aca392020-11-13 11:37:132376 if (input.charCodeAt(peg$currPos) === 46) {
Tim van der Lippeb97da6b2021-02-12 14:32:532377 s4 = peg$c42;
Tim van der Lippe16aca392020-11-13 11:37:132378 peg$currPos++;
2379 } else {
Tim van der Lippeb97da6b2021-02-12 14:32:532380 s4 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132381
2382 {
2383 peg$fail(peg$c43);
2384 }
2385 }
Tim van der Lippe16aca392020-11-13 11:37:132386
Tim van der Lippeb97da6b2021-02-12 14:32:532387 if (s4 !== peg$FAILED) {
2388 s5 = peg$parseidentifierName();
Tim van der Lippe16aca392020-11-13 11:37:132389
Tim van der Lippeb97da6b2021-02-12 14:32:532390 if (s5 !== peg$FAILED) {
2391 s4 = [s4, s5];
2392 s3 = s4;
2393 } else {
2394 peg$currPos = s3;
2395 s3 = peg$FAILED;
2396 }
2397 } else {
2398 peg$currPos = s3;
2399 s3 = peg$FAILED;
2400 }
Tim van der Lippe16aca392020-11-13 11:37:132401
Tim van der Lippeb97da6b2021-02-12 14:32:532402 while (s3 !== peg$FAILED) {
2403 s2.push(s3);
2404 s3 = peg$currPos;
2405
2406 if (input.charCodeAt(peg$currPos) === 46) {
2407 s4 = peg$c42;
2408 peg$currPos++;
2409 } else {
2410 s4 = peg$FAILED;
2411
2412 {
2413 peg$fail(peg$c43);
Tim van der Lippe16aca392020-11-13 11:37:132414 }
2415 }
Tim van der Lippeb97da6b2021-02-12 14:32:532416
2417 if (s4 !== peg$FAILED) {
2418 s5 = peg$parseidentifierName();
2419
2420 if (s5 !== peg$FAILED) {
2421 s4 = [s4, s5];
2422 s3 = s4;
2423 } else {
2424 peg$currPos = s3;
2425 s3 = peg$FAILED;
2426 }
2427 } else {
2428 peg$currPos = s3;
2429 s3 = peg$FAILED;
2430 }
2431 }
2432
2433 if (s2 !== peg$FAILED) {
2434 s1 = peg$c44(s1, s2);
2435 s0 = s1;
2436 } else {
2437 peg$currPos = s0;
2438 s0 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132439 }
2440 } else {
Tim van der Lippeb97da6b2021-02-12 14:32:532441 peg$currPos = s0;
2442 s0 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132443 }
2444
Tim van der Lippe16aca392020-11-13 11:37:132445 peg$resultsCache[key] = {
2446 nextPos: peg$currPos,
2447 result: s0
2448 };
2449 return s0;
2450 }
2451
2452 function peg$parseattrValue() {
2453 var s0, s1, s2, s3, s4, s5;
2454 var key = peg$currPos * 30 + 14,
2455 cached = peg$resultsCache[key];
2456
2457 if (cached) {
2458 peg$currPos = cached.nextPos;
2459 return cached.result;
2460 }
2461
2462 s0 = peg$currPos;
2463 s1 = peg$parseattrName();
2464
2465 if (s1 !== peg$FAILED) {
2466 s2 = peg$parse_();
2467
2468 if (s2 !== peg$FAILED) {
2469 s3 = peg$parseattrEqOps();
2470
2471 if (s3 !== peg$FAILED) {
2472 s4 = peg$parse_();
2473
2474 if (s4 !== peg$FAILED) {
2475 s5 = peg$parsetype();
2476
2477 if (s5 === peg$FAILED) {
2478 s5 = peg$parseregex();
2479 }
2480
Tim van der Lippec8f6ffd2020-04-06 12:42:002481 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532482 s1 = peg$c45(s1, s3, s5);
Tim van der Lippec8f6ffd2020-04-06 12:42:002483 s0 = s1;
2484 } else {
2485 peg$currPos = s0;
2486 s0 = peg$FAILED;
2487 }
2488 } else {
2489 peg$currPos = s0;
2490 s0 = peg$FAILED;
2491 }
2492 } else {
2493 peg$currPos = s0;
2494 s0 = peg$FAILED;
2495 }
2496 } else {
2497 peg$currPos = s0;
2498 s0 = peg$FAILED;
2499 }
2500 } else {
2501 peg$currPos = s0;
2502 s0 = peg$FAILED;
2503 }
Tim van der Lippe16aca392020-11-13 11:37:132504
Tim van der Lippec8f6ffd2020-04-06 12:42:002505 if (s0 === peg$FAILED) {
2506 s0 = peg$currPos;
2507 s1 = peg$parseattrName();
Tim van der Lippe16aca392020-11-13 11:37:132508
Tim van der Lippec8f6ffd2020-04-06 12:42:002509 if (s1 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132510 s2 = peg$parse_();
2511
2512 if (s2 !== peg$FAILED) {
2513 s3 = peg$parseattrOps();
2514
2515 if (s3 !== peg$FAILED) {
2516 s4 = peg$parse_();
2517
2518 if (s4 !== peg$FAILED) {
2519 s5 = peg$parsestring();
2520
2521 if (s5 === peg$FAILED) {
2522 s5 = peg$parsenumber();
2523
2524 if (s5 === peg$FAILED) {
2525 s5 = peg$parsepath();
2526 }
2527 }
2528
2529 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532530 s1 = peg$c45(s1, s3, s5);
Tim van der Lippe16aca392020-11-13 11:37:132531 s0 = s1;
2532 } else {
2533 peg$currPos = s0;
2534 s0 = peg$FAILED;
2535 }
2536 } else {
2537 peg$currPos = s0;
2538 s0 = peg$FAILED;
2539 }
2540 } else {
2541 peg$currPos = s0;
2542 s0 = peg$FAILED;
2543 }
2544 } else {
2545 peg$currPos = s0;
2546 s0 = peg$FAILED;
2547 }
2548 } else {
2549 peg$currPos = s0;
2550 s0 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:002551 }
Tim van der Lippe16aca392020-11-13 11:37:132552
2553 if (s0 === peg$FAILED) {
2554 s0 = peg$currPos;
2555 s1 = peg$parseattrName();
2556
2557 if (s1 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532558 s1 = peg$c46(s1);
Tim van der Lippe16aca392020-11-13 11:37:132559 }
2560
2561 s0 = s1;
2562 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002563 }
Tim van der Lippe16aca392020-11-13 11:37:132564
2565 peg$resultsCache[key] = {
2566 nextPos: peg$currPos,
2567 result: s0
2568 };
2569 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:002570 }
2571
Tim van der Lippe16aca392020-11-13 11:37:132572 function peg$parsestring() {
2573 var s0, s1, s2, s3, s4, s5;
2574 var key = peg$currPos * 30 + 15,
2575 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:002576
Tim van der Lippe16aca392020-11-13 11:37:132577 if (cached) {
2578 peg$currPos = cached.nextPos;
2579 return cached.result;
2580 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002581
Tim van der Lippe16aca392020-11-13 11:37:132582 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:002583
Tim van der Lippe16aca392020-11-13 11:37:132584 if (input.charCodeAt(peg$currPos) === 34) {
Tim van der Lippeb97da6b2021-02-12 14:32:532585 s1 = peg$c47;
Tim van der Lippec8f6ffd2020-04-06 12:42:002586 peg$currPos++;
2587 } else {
Tim van der Lippe16aca392020-11-13 11:37:132588 s1 = peg$FAILED;
2589
2590 {
Tim van der Lippeb97da6b2021-02-12 14:32:532591 peg$fail(peg$c48);
Tim van der Lippec8f6ffd2020-04-06 12:42:002592 }
2593 }
Tim van der Lippe16aca392020-11-13 11:37:132594
2595 if (s1 !== peg$FAILED) {
2596 s2 = [];
2597
Tim van der Lippeb97da6b2021-02-12 14:32:532598 if (peg$c49.test(input.charAt(peg$currPos))) {
Tim van der Lippec8f6ffd2020-04-06 12:42:002599 s3 = input.charAt(peg$currPos);
2600 peg$currPos++;
2601 } else {
2602 s3 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132603
2604 {
Tim van der Lippeb97da6b2021-02-12 14:32:532605 peg$fail(peg$c50);
Tim van der Lippe16aca392020-11-13 11:37:132606 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002607 }
Tim van der Lippe16aca392020-11-13 11:37:132608
Tim van der Lippec8f6ffd2020-04-06 12:42:002609 if (s3 === peg$FAILED) {
2610 s3 = peg$currPos;
Tim van der Lippe16aca392020-11-13 11:37:132611
Tim van der Lippec8f6ffd2020-04-06 12:42:002612 if (input.charCodeAt(peg$currPos) === 92) {
Tim van der Lippeb97da6b2021-02-12 14:32:532613 s4 = peg$c51;
Tim van der Lippec8f6ffd2020-04-06 12:42:002614 peg$currPos++;
2615 } else {
2616 s4 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132617
2618 {
Tim van der Lippeb97da6b2021-02-12 14:32:532619 peg$fail(peg$c52);
Tim van der Lippe16aca392020-11-13 11:37:132620 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002621 }
Tim van der Lippe16aca392020-11-13 11:37:132622
Tim van der Lippec8f6ffd2020-04-06 12:42:002623 if (s4 !== peg$FAILED) {
2624 if (input.length > peg$currPos) {
2625 s5 = input.charAt(peg$currPos);
2626 peg$currPos++;
2627 } else {
2628 s5 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132629
2630 {
Tim van der Lippeb97da6b2021-02-12 14:32:532631 peg$fail(peg$c53);
Tim van der Lippe16aca392020-11-13 11:37:132632 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002633 }
Tim van der Lippe16aca392020-11-13 11:37:132634
Tim van der Lippec8f6ffd2020-04-06 12:42:002635 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532636 s4 = peg$c54(s4, s5);
Tim van der Lippec8f6ffd2020-04-06 12:42:002637 s3 = s4;
2638 } else {
2639 peg$currPos = s3;
2640 s3 = peg$FAILED;
2641 }
2642 } else {
2643 peg$currPos = s3;
2644 s3 = peg$FAILED;
2645 }
2646 }
Tim van der Lippe16aca392020-11-13 11:37:132647
Tim van der Lippec8f6ffd2020-04-06 12:42:002648 while (s3 !== peg$FAILED) {
2649 s2.push(s3);
Tim van der Lippe16aca392020-11-13 11:37:132650
Tim van der Lippeb97da6b2021-02-12 14:32:532651 if (peg$c49.test(input.charAt(peg$currPos))) {
Tim van der Lippec8f6ffd2020-04-06 12:42:002652 s3 = input.charAt(peg$currPos);
2653 peg$currPos++;
2654 } else {
2655 s3 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132656
2657 {
Tim van der Lippeb97da6b2021-02-12 14:32:532658 peg$fail(peg$c50);
Tim van der Lippe16aca392020-11-13 11:37:132659 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002660 }
Tim van der Lippe16aca392020-11-13 11:37:132661
Tim van der Lippec8f6ffd2020-04-06 12:42:002662 if (s3 === peg$FAILED) {
2663 s3 = peg$currPos;
Tim van der Lippe16aca392020-11-13 11:37:132664
Tim van der Lippec8f6ffd2020-04-06 12:42:002665 if (input.charCodeAt(peg$currPos) === 92) {
Tim van der Lippeb97da6b2021-02-12 14:32:532666 s4 = peg$c51;
Tim van der Lippec8f6ffd2020-04-06 12:42:002667 peg$currPos++;
2668 } else {
2669 s4 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132670
2671 {
Tim van der Lippeb97da6b2021-02-12 14:32:532672 peg$fail(peg$c52);
Tim van der Lippe16aca392020-11-13 11:37:132673 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002674 }
Tim van der Lippe16aca392020-11-13 11:37:132675
Tim van der Lippec8f6ffd2020-04-06 12:42:002676 if (s4 !== peg$FAILED) {
2677 if (input.length > peg$currPos) {
2678 s5 = input.charAt(peg$currPos);
2679 peg$currPos++;
2680 } else {
2681 s5 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132682
2683 {
Tim van der Lippeb97da6b2021-02-12 14:32:532684 peg$fail(peg$c53);
Tim van der Lippe16aca392020-11-13 11:37:132685 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002686 }
Tim van der Lippe16aca392020-11-13 11:37:132687
Tim van der Lippec8f6ffd2020-04-06 12:42:002688 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532689 s4 = peg$c54(s4, s5);
Tim van der Lippec8f6ffd2020-04-06 12:42:002690 s3 = s4;
2691 } else {
2692 peg$currPos = s3;
2693 s3 = peg$FAILED;
2694 }
2695 } else {
2696 peg$currPos = s3;
2697 s3 = peg$FAILED;
2698 }
2699 }
2700 }
Tim van der Lippe16aca392020-11-13 11:37:132701
Tim van der Lippec8f6ffd2020-04-06 12:42:002702 if (s2 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132703 if (input.charCodeAt(peg$currPos) === 34) {
Tim van der Lippeb97da6b2021-02-12 14:32:532704 s3 = peg$c47;
Tim van der Lippec8f6ffd2020-04-06 12:42:002705 peg$currPos++;
2706 } else {
2707 s3 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132708
2709 {
Tim van der Lippeb97da6b2021-02-12 14:32:532710 peg$fail(peg$c48);
Tim van der Lippe16aca392020-11-13 11:37:132711 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002712 }
Tim van der Lippe16aca392020-11-13 11:37:132713
Tim van der Lippec8f6ffd2020-04-06 12:42:002714 if (s3 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532715 s1 = peg$c55(s2);
Tim van der Lippec8f6ffd2020-04-06 12:42:002716 s0 = s1;
2717 } else {
2718 peg$currPos = s0;
2719 s0 = peg$FAILED;
2720 }
2721 } else {
2722 peg$currPos = s0;
2723 s0 = peg$FAILED;
2724 }
2725 } else {
2726 peg$currPos = s0;
2727 s0 = peg$FAILED;
2728 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002729
Tim van der Lippe16aca392020-11-13 11:37:132730 if (s0 === peg$FAILED) {
2731 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:002732
Tim van der Lippe16aca392020-11-13 11:37:132733 if (input.charCodeAt(peg$currPos) === 39) {
Tim van der Lippeb97da6b2021-02-12 14:32:532734 s1 = peg$c56;
Tim van der Lippe16aca392020-11-13 11:37:132735 peg$currPos++;
2736 } else {
2737 s1 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:002738
Tim van der Lippe16aca392020-11-13 11:37:132739 {
Tim van der Lippeb97da6b2021-02-12 14:32:532740 peg$fail(peg$c57);
Tim van der Lippe16aca392020-11-13 11:37:132741 }
2742 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002743
Tim van der Lippe16aca392020-11-13 11:37:132744 if (s1 !== peg$FAILED) {
2745 s2 = [];
Tim van der Lippec8f6ffd2020-04-06 12:42:002746
Tim van der Lippeb97da6b2021-02-12 14:32:532747 if (peg$c58.test(input.charAt(peg$currPos))) {
Tim van der Lippec8f6ffd2020-04-06 12:42:002748 s3 = input.charAt(peg$currPos);
2749 peg$currPos++;
2750 } else {
2751 s3 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:132752
2753 {
Tim van der Lippeb97da6b2021-02-12 14:32:532754 peg$fail(peg$c59);
Tim van der Lippe16aca392020-11-13 11:37:132755 }
2756 }
2757
2758 if (s3 === peg$FAILED) {
2759 s3 = peg$currPos;
2760
2761 if (input.charCodeAt(peg$currPos) === 92) {
Tim van der Lippeb97da6b2021-02-12 14:32:532762 s4 = peg$c51;
Tim van der Lippe16aca392020-11-13 11:37:132763 peg$currPos++;
2764 } else {
2765 s4 = peg$FAILED;
2766
2767 {
Tim van der Lippeb97da6b2021-02-12 14:32:532768 peg$fail(peg$c52);
Tim van der Lippe16aca392020-11-13 11:37:132769 }
2770 }
2771
2772 if (s4 !== peg$FAILED) {
2773 if (input.length > peg$currPos) {
2774 s5 = input.charAt(peg$currPos);
2775 peg$currPos++;
2776 } else {
2777 s5 = peg$FAILED;
2778
2779 {
Tim van der Lippeb97da6b2021-02-12 14:32:532780 peg$fail(peg$c53);
Tim van der Lippe16aca392020-11-13 11:37:132781 }
2782 }
2783
2784 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532785 s4 = peg$c54(s4, s5);
Tim van der Lippe16aca392020-11-13 11:37:132786 s3 = s4;
2787 } else {
2788 peg$currPos = s3;
2789 s3 = peg$FAILED;
2790 }
2791 } else {
2792 peg$currPos = s3;
2793 s3 = peg$FAILED;
2794 }
2795 }
2796
2797 while (s3 !== peg$FAILED) {
2798 s2.push(s3);
2799
Tim van der Lippeb97da6b2021-02-12 14:32:532800 if (peg$c58.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:132801 s3 = input.charAt(peg$currPos);
2802 peg$currPos++;
2803 } else {
2804 s3 = peg$FAILED;
2805
2806 {
Tim van der Lippeb97da6b2021-02-12 14:32:532807 peg$fail(peg$c59);
Tim van der Lippe16aca392020-11-13 11:37:132808 }
2809 }
2810
2811 if (s3 === peg$FAILED) {
2812 s3 = peg$currPos;
2813
2814 if (input.charCodeAt(peg$currPos) === 92) {
Tim van der Lippeb97da6b2021-02-12 14:32:532815 s4 = peg$c51;
Tim van der Lippe16aca392020-11-13 11:37:132816 peg$currPos++;
2817 } else {
2818 s4 = peg$FAILED;
2819
2820 {
Tim van der Lippeb97da6b2021-02-12 14:32:532821 peg$fail(peg$c52);
Tim van der Lippe16aca392020-11-13 11:37:132822 }
2823 }
2824
2825 if (s4 !== peg$FAILED) {
2826 if (input.length > peg$currPos) {
2827 s5 = input.charAt(peg$currPos);
2828 peg$currPos++;
2829 } else {
2830 s5 = peg$FAILED;
2831
2832 {
Tim van der Lippeb97da6b2021-02-12 14:32:532833 peg$fail(peg$c53);
Tim van der Lippe16aca392020-11-13 11:37:132834 }
2835 }
2836
2837 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532838 s4 = peg$c54(s4, s5);
Tim van der Lippe16aca392020-11-13 11:37:132839 s3 = s4;
2840 } else {
2841 peg$currPos = s3;
2842 s3 = peg$FAILED;
2843 }
2844 } else {
2845 peg$currPos = s3;
2846 s3 = peg$FAILED;
2847 }
2848 }
2849 }
2850
2851 if (s2 !== peg$FAILED) {
2852 if (input.charCodeAt(peg$currPos) === 39) {
Tim van der Lippeb97da6b2021-02-12 14:32:532853 s3 = peg$c56;
Tim van der Lippe16aca392020-11-13 11:37:132854 peg$currPos++;
2855 } else {
2856 s3 = peg$FAILED;
2857
2858 {
Tim van der Lippeb97da6b2021-02-12 14:32:532859 peg$fail(peg$c57);
Tim van der Lippe16aca392020-11-13 11:37:132860 }
2861 }
2862
2863 if (s3 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532864 s1 = peg$c55(s2);
Tim van der Lippe16aca392020-11-13 11:37:132865 s0 = s1;
2866 } else {
2867 peg$currPos = s0;
2868 s0 = peg$FAILED;
2869 }
2870 } else {
2871 peg$currPos = s0;
2872 s0 = peg$FAILED;
2873 }
2874 } else {
2875 peg$currPos = s0;
2876 s0 = peg$FAILED;
2877 }
2878 }
2879
2880 peg$resultsCache[key] = {
2881 nextPos: peg$currPos,
2882 result: s0
2883 };
2884 return s0;
2885 }
2886
2887 function peg$parsenumber() {
2888 var s0, s1, s2, s3;
2889 var key = peg$currPos * 30 + 16,
2890 cached = peg$resultsCache[key];
2891
2892 if (cached) {
2893 peg$currPos = cached.nextPos;
2894 return cached.result;
2895 }
2896
2897 s0 = peg$currPos;
2898 s1 = peg$currPos;
2899 s2 = [];
2900
Tim van der Lippeb97da6b2021-02-12 14:32:532901 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:132902 s3 = input.charAt(peg$currPos);
2903 peg$currPos++;
2904 } else {
2905 s3 = peg$FAILED;
2906
2907 {
Tim van der Lippeb97da6b2021-02-12 14:32:532908 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:132909 }
2910 }
2911
2912 while (s3 !== peg$FAILED) {
2913 s2.push(s3);
2914
Tim van der Lippeb97da6b2021-02-12 14:32:532915 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:132916 s3 = input.charAt(peg$currPos);
2917 peg$currPos++;
2918 } else {
2919 s3 = peg$FAILED;
2920
2921 {
Tim van der Lippeb97da6b2021-02-12 14:32:532922 peg$fail(peg$c61);
Tim van der Lippec8f6ffd2020-04-06 12:42:002923 }
2924 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002925 }
Tim van der Lippe16aca392020-11-13 11:37:132926
Tim van der Lippec8f6ffd2020-04-06 12:42:002927 if (s2 !== peg$FAILED) {
Tim van der Lippe16aca392020-11-13 11:37:132928 if (input.charCodeAt(peg$currPos) === 46) {
2929 s3 = peg$c42;
2930 peg$currPos++;
2931 } else {
2932 s3 = peg$FAILED;
2933
2934 {
2935 peg$fail(peg$c43);
2936 }
2937 }
2938
2939 if (s3 !== peg$FAILED) {
2940 s2 = [s2, s3];
2941 s1 = s2;
2942 } else {
2943 peg$currPos = s1;
2944 s1 = peg$FAILED;
2945 }
2946 } else {
2947 peg$currPos = s1;
2948 s1 = peg$FAILED;
2949 }
2950
2951 if (s1 === peg$FAILED) {
2952 s1 = null;
2953 }
2954
2955 if (s1 !== peg$FAILED) {
2956 s2 = [];
2957
Tim van der Lippeb97da6b2021-02-12 14:32:532958 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:132959 s3 = input.charAt(peg$currPos);
2960 peg$currPos++;
2961 } else {
2962 s3 = peg$FAILED;
2963
2964 {
Tim van der Lippeb97da6b2021-02-12 14:32:532965 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:132966 }
2967 }
2968
2969 if (s3 !== peg$FAILED) {
2970 while (s3 !== peg$FAILED) {
2971 s2.push(s3);
2972
Tim van der Lippeb97da6b2021-02-12 14:32:532973 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:132974 s3 = input.charAt(peg$currPos);
2975 peg$currPos++;
2976 } else {
2977 s3 = peg$FAILED;
2978
2979 {
Tim van der Lippeb97da6b2021-02-12 14:32:532980 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:132981 }
2982 }
2983 }
2984 } else {
2985 s2 = peg$FAILED;
2986 }
2987
2988 if (s2 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:532989 s1 = peg$c62(s1, s2);
Tim van der Lippe16aca392020-11-13 11:37:132990 s0 = s1;
2991 } else {
2992 peg$currPos = s0;
2993 s0 = peg$FAILED;
2994 }
Tim van der Lippec8f6ffd2020-04-06 12:42:002995 } else {
2996 peg$currPos = s0;
2997 s0 = peg$FAILED;
2998 }
Tim van der Lippe16aca392020-11-13 11:37:132999
3000 peg$resultsCache[key] = {
3001 nextPos: peg$currPos,
3002 result: s0
3003 };
3004 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:003005 }
3006
Tim van der Lippe16aca392020-11-13 11:37:133007 function peg$parsepath() {
3008 var s0, s1;
3009 var key = peg$currPos * 30 + 17,
3010 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:003011
Tim van der Lippe16aca392020-11-13 11:37:133012 if (cached) {
3013 peg$currPos = cached.nextPos;
3014 return cached.result;
3015 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003016
Tim van der Lippe16aca392020-11-13 11:37:133017 s0 = peg$currPos;
3018 s1 = peg$parseidentifierName();
Tim van der Lippec8f6ffd2020-04-06 12:42:003019
Tim van der Lippe16aca392020-11-13 11:37:133020 if (s1 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533021 s1 = peg$c63(s1);
Tim van der Lippe16aca392020-11-13 11:37:133022 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003023
Tim van der Lippe16aca392020-11-13 11:37:133024 s0 = s1;
3025 peg$resultsCache[key] = {
3026 nextPos: peg$currPos,
3027 result: s0
3028 };
3029 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:003030 }
3031
Tim van der Lippe16aca392020-11-13 11:37:133032 function peg$parsetype() {
3033 var s0, s1, s2, s3, s4, s5;
3034 var key = peg$currPos * 30 + 18,
3035 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:003036
Tim van der Lippe16aca392020-11-13 11:37:133037 if (cached) {
3038 peg$currPos = cached.nextPos;
3039 return cached.result;
3040 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003041
Tim van der Lippe16aca392020-11-13 11:37:133042 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:003043
Tim van der Lippeb97da6b2021-02-12 14:32:533044 if (input.substr(peg$currPos, 5) === peg$c64) {
3045 s1 = peg$c64;
Tim van der Lippe16aca392020-11-13 11:37:133046 peg$currPos += 5;
3047 } else {
3048 s1 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:003049
Tim van der Lippe16aca392020-11-13 11:37:133050 {
Tim van der Lippeb97da6b2021-02-12 14:32:533051 peg$fail(peg$c65);
Tim van der Lippe16aca392020-11-13 11:37:133052 }
3053 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003054
Tim van der Lippe16aca392020-11-13 11:37:133055 if (s1 !== peg$FAILED) {
3056 s2 = peg$parse_();
Tim van der Lippec8f6ffd2020-04-06 12:42:003057
Tim van der Lippe16aca392020-11-13 11:37:133058 if (s2 !== peg$FAILED) {
3059 s3 = [];
3060
Tim van der Lippeb97da6b2021-02-12 14:32:533061 if (peg$c66.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133062 s4 = input.charAt(peg$currPos);
3063 peg$currPos++;
3064 } else {
3065 s4 = peg$FAILED;
3066
3067 {
Tim van der Lippeb97da6b2021-02-12 14:32:533068 peg$fail(peg$c67);
Tim van der Lippe16aca392020-11-13 11:37:133069 }
3070 }
3071
3072 if (s4 !== peg$FAILED) {
3073 while (s4 !== peg$FAILED) {
3074 s3.push(s4);
3075
Tim van der Lippeb97da6b2021-02-12 14:32:533076 if (peg$c66.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133077 s4 = input.charAt(peg$currPos);
3078 peg$currPos++;
3079 } else {
3080 s4 = peg$FAILED;
3081
3082 {
Tim van der Lippeb97da6b2021-02-12 14:32:533083 peg$fail(peg$c67);
Tim van der Lippe16aca392020-11-13 11:37:133084 }
3085 }
3086 }
3087 } else {
3088 s3 = peg$FAILED;
3089 }
3090
3091 if (s3 !== peg$FAILED) {
3092 s4 = peg$parse_();
3093
3094 if (s4 !== peg$FAILED) {
3095 if (input.charCodeAt(peg$currPos) === 41) {
Tim van der Lippeb97da6b2021-02-12 14:32:533096 s5 = peg$c68;
Tim van der Lippe16aca392020-11-13 11:37:133097 peg$currPos++;
3098 } else {
3099 s5 = peg$FAILED;
3100
3101 {
Tim van der Lippeb97da6b2021-02-12 14:32:533102 peg$fail(peg$c69);
Tim van der Lippe16aca392020-11-13 11:37:133103 }
3104 }
3105
3106 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533107 s1 = peg$c70(s3);
Tim van der Lippe16aca392020-11-13 11:37:133108 s0 = s1;
3109 } else {
3110 peg$currPos = s0;
3111 s0 = peg$FAILED;
3112 }
3113 } else {
3114 peg$currPos = s0;
3115 s0 = peg$FAILED;
3116 }
3117 } else {
3118 peg$currPos = s0;
3119 s0 = peg$FAILED;
3120 }
3121 } else {
3122 peg$currPos = s0;
3123 s0 = peg$FAILED;
3124 }
3125 } else {
3126 peg$currPos = s0;
3127 s0 = peg$FAILED;
3128 }
3129
3130 peg$resultsCache[key] = {
3131 nextPos: peg$currPos,
3132 result: s0
3133 };
3134 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:003135 }
3136
Tim van der Lippe16aca392020-11-13 11:37:133137 function peg$parseflags() {
3138 var s0, s1;
3139 var key = peg$currPos * 30 + 19,
3140 cached = peg$resultsCache[key];
3141
3142 if (cached) {
3143 peg$currPos = cached.nextPos;
3144 return cached.result;
3145 }
3146
3147 s0 = [];
3148
Tim van der Lippeb97da6b2021-02-12 14:32:533149 if (peg$c71.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133150 s1 = input.charAt(peg$currPos);
3151 peg$currPos++;
3152 } else {
3153 s1 = peg$FAILED;
3154
3155 {
Tim van der Lippeb97da6b2021-02-12 14:32:533156 peg$fail(peg$c72);
Tim van der Lippe16aca392020-11-13 11:37:133157 }
3158 }
3159
3160 if (s1 !== peg$FAILED) {
3161 while (s1 !== peg$FAILED) {
3162 s0.push(s1);
3163
Tim van der Lippeb97da6b2021-02-12 14:32:533164 if (peg$c71.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133165 s1 = input.charAt(peg$currPos);
3166 peg$currPos++;
3167 } else {
3168 s1 = peg$FAILED;
3169
3170 {
Tim van der Lippeb97da6b2021-02-12 14:32:533171 peg$fail(peg$c72);
Tim van der Lippe16aca392020-11-13 11:37:133172 }
3173 }
3174 }
3175 } else {
3176 s0 = peg$FAILED;
3177 }
3178
3179 peg$resultsCache[key] = {
3180 nextPos: peg$currPos,
3181 result: s0
3182 };
3183 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:003184 }
Tim van der Lippe16aca392020-11-13 11:37:133185
3186 function peg$parseregex() {
3187 var s0, s1, s2, s3, s4;
3188 var key = peg$currPos * 30 + 20,
3189 cached = peg$resultsCache[key];
3190
3191 if (cached) {
3192 peg$currPos = cached.nextPos;
3193 return cached.result;
3194 }
3195
3196 s0 = peg$currPos;
3197
3198 if (input.charCodeAt(peg$currPos) === 47) {
Tim van der Lippeb97da6b2021-02-12 14:32:533199 s1 = peg$c73;
Tim van der Lippe16aca392020-11-13 11:37:133200 peg$currPos++;
3201 } else {
3202 s1 = peg$FAILED;
3203
3204 {
Tim van der Lippeb97da6b2021-02-12 14:32:533205 peg$fail(peg$c74);
Tim van der Lippe16aca392020-11-13 11:37:133206 }
3207 }
3208
3209 if (s1 !== peg$FAILED) {
3210 s2 = [];
3211
Tim van der Lippeb97da6b2021-02-12 14:32:533212 if (peg$c75.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133213 s3 = input.charAt(peg$currPos);
Tim van der Lippec8f6ffd2020-04-06 12:42:003214 peg$currPos++;
3215 } else {
Tim van der Lippe16aca392020-11-13 11:37:133216 s3 = peg$FAILED;
3217
3218 {
Tim van der Lippeb97da6b2021-02-12 14:32:533219 peg$fail(peg$c76);
Tim van der Lippe16aca392020-11-13 11:37:133220 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003221 }
Tim van der Lippe16aca392020-11-13 11:37:133222
3223 if (s3 !== peg$FAILED) {
3224 while (s3 !== peg$FAILED) {
3225 s2.push(s3);
3226
Tim van der Lippeb97da6b2021-02-12 14:32:533227 if (peg$c75.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133228 s3 = input.charAt(peg$currPos);
Tim van der Lippec8f6ffd2020-04-06 12:42:003229 peg$currPos++;
3230 } else {
Tim van der Lippe16aca392020-11-13 11:37:133231 s3 = peg$FAILED;
3232
3233 {
Tim van der Lippeb97da6b2021-02-12 14:32:533234 peg$fail(peg$c76);
Tim van der Lippe16aca392020-11-13 11:37:133235 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003236 }
3237 }
3238 } else {
Tim van der Lippe16aca392020-11-13 11:37:133239 s2 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:003240 }
Tim van der Lippe16aca392020-11-13 11:37:133241
3242 if (s2 !== peg$FAILED) {
3243 if (input.charCodeAt(peg$currPos) === 47) {
Tim van der Lippeb97da6b2021-02-12 14:32:533244 s3 = peg$c73;
Tim van der Lippe16aca392020-11-13 11:37:133245 peg$currPos++;
3246 } else {
3247 s3 = peg$FAILED;
3248
3249 {
Tim van der Lippeb97da6b2021-02-12 14:32:533250 peg$fail(peg$c74);
Tim van der Lippec8f6ffd2020-04-06 12:42:003251 }
Tim van der Lippe16aca392020-11-13 11:37:133252 }
3253
3254 if (s3 !== peg$FAILED) {
3255 s4 = peg$parseflags();
3256
3257 if (s4 === peg$FAILED) {
3258 s4 = null;
3259 }
3260
3261 if (s4 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533262 s1 = peg$c77(s2, s4);
Tim van der Lippec8f6ffd2020-04-06 12:42:003263 s0 = s1;
3264 } else {
3265 peg$currPos = s0;
3266 s0 = peg$FAILED;
3267 }
3268 } else {
3269 peg$currPos = s0;
3270 s0 = peg$FAILED;
3271 }
3272 } else {
3273 peg$currPos = s0;
3274 s0 = peg$FAILED;
3275 }
3276 } else {
3277 peg$currPos = s0;
3278 s0 = peg$FAILED;
3279 }
Tim van der Lippe16aca392020-11-13 11:37:133280
3281 peg$resultsCache[key] = {
3282 nextPos: peg$currPos,
3283 result: s0
3284 };
3285 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:003286 }
3287
Tim van der Lippe16aca392020-11-13 11:37:133288 function peg$parsefield() {
3289 var s0, s1, s2, s3, s4, s5, s6;
3290 var key = peg$currPos * 30 + 21,
3291 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:003292
Tim van der Lippe16aca392020-11-13 11:37:133293 if (cached) {
3294 peg$currPos = cached.nextPos;
3295 return cached.result;
Tim van der Lippec8f6ffd2020-04-06 12:42:003296 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003297
Tim van der Lippe16aca392020-11-13 11:37:133298 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:003299
Tim van der Lippe16aca392020-11-13 11:37:133300 if (input.charCodeAt(peg$currPos) === 46) {
3301 s1 = peg$c42;
Tim van der Lippec8f6ffd2020-04-06 12:42:003302 peg$currPos++;
3303 } else {
Tim van der Lippe16aca392020-11-13 11:37:133304 s1 = peg$FAILED;
3305
3306 {
3307 peg$fail(peg$c43);
3308 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003309 }
Tim van der Lippe16aca392020-11-13 11:37:133310
3311 if (s1 !== peg$FAILED) {
3312 s2 = peg$parseidentifierName();
3313
3314 if (s2 !== peg$FAILED) {
3315 s3 = [];
3316 s4 = peg$currPos;
3317
3318 if (input.charCodeAt(peg$currPos) === 46) {
3319 s5 = peg$c42;
Tim van der Lippec8f6ffd2020-04-06 12:42:003320 peg$currPos++;
3321 } else {
Tim van der Lippe16aca392020-11-13 11:37:133322 s5 = peg$FAILED;
3323
3324 {
3325 peg$fail(peg$c43);
3326 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003327 }
Tim van der Lippe16aca392020-11-13 11:37:133328
3329 if (s5 !== peg$FAILED) {
3330 s6 = peg$parseidentifierName();
3331
3332 if (s6 !== peg$FAILED) {
3333 s5 = [s5, s6];
3334 s4 = s5;
3335 } else {
3336 peg$currPos = s4;
3337 s4 = peg$FAILED;
3338 }
3339 } else {
3340 peg$currPos = s4;
3341 s4 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:003342 }
Tim van der Lippe16aca392020-11-13 11:37:133343
3344 while (s4 !== peg$FAILED) {
3345 s3.push(s4);
3346 s4 = peg$currPos;
3347
3348 if (input.charCodeAt(peg$currPos) === 46) {
3349 s5 = peg$c42;
3350 peg$currPos++;
3351 } else {
3352 s5 = peg$FAILED;
3353
3354 {
3355 peg$fail(peg$c43);
3356 }
3357 }
3358
3359 if (s5 !== peg$FAILED) {
3360 s6 = peg$parseidentifierName();
3361
3362 if (s6 !== peg$FAILED) {
3363 s5 = [s5, s6];
3364 s4 = s5;
3365 } else {
3366 peg$currPos = s4;
3367 s4 = peg$FAILED;
3368 }
3369 } else {
3370 peg$currPos = s4;
3371 s4 = peg$FAILED;
3372 }
3373 }
3374
3375 if (s3 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533376 s1 = peg$c78(s2, s3);
Tim van der Lippec8f6ffd2020-04-06 12:42:003377 s0 = s1;
3378 } else {
3379 peg$currPos = s0;
3380 s0 = peg$FAILED;
3381 }
3382 } else {
3383 peg$currPos = s0;
3384 s0 = peg$FAILED;
3385 }
3386 } else {
3387 peg$currPos = s0;
3388 s0 = peg$FAILED;
3389 }
Tim van der Lippe16aca392020-11-13 11:37:133390
3391 peg$resultsCache[key] = {
3392 nextPos: peg$currPos,
3393 result: s0
3394 };
3395 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:003396 }
3397
Tim van der Lippe16aca392020-11-13 11:37:133398 function peg$parsenegation() {
3399 var s0, s1, s2, s3, s4, s5;
3400 var key = peg$currPos * 30 + 22,
3401 cached = peg$resultsCache[key];
Tim van der Lippec8f6ffd2020-04-06 12:42:003402
Tim van der Lippe16aca392020-11-13 11:37:133403 if (cached) {
3404 peg$currPos = cached.nextPos;
3405 return cached.result;
3406 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003407
Tim van der Lippe16aca392020-11-13 11:37:133408 s0 = peg$currPos;
Tim van der Lippec8f6ffd2020-04-06 12:42:003409
Tim van der Lippeb97da6b2021-02-12 14:32:533410 if (input.substr(peg$currPos, 5) === peg$c79) {
3411 s1 = peg$c79;
Tim van der Lippe16aca392020-11-13 11:37:133412 peg$currPos += 5;
3413 } else {
3414 s1 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:003415
Tim van der Lippe16aca392020-11-13 11:37:133416 {
Tim van der Lippeb97da6b2021-02-12 14:32:533417 peg$fail(peg$c80);
Tim van der Lippec8f6ffd2020-04-06 12:42:003418 }
Tim van der Lippe16aca392020-11-13 11:37:133419 }
3420
3421 if (s1 !== peg$FAILED) {
3422 s2 = peg$parse_();
3423
3424 if (s2 !== peg$FAILED) {
3425 s3 = peg$parseselectors();
3426
3427 if (s3 !== peg$FAILED) {
3428 s4 = peg$parse_();
3429
3430 if (s4 !== peg$FAILED) {
3431 if (input.charCodeAt(peg$currPos) === 41) {
Tim van der Lippeb97da6b2021-02-12 14:32:533432 s5 = peg$c68;
Tim van der Lippe16aca392020-11-13 11:37:133433 peg$currPos++;
3434 } else {
3435 s5 = peg$FAILED;
3436
3437 {
Tim van der Lippeb97da6b2021-02-12 14:32:533438 peg$fail(peg$c69);
Tim van der Lippe16aca392020-11-13 11:37:133439 }
3440 }
3441
3442 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533443 s1 = peg$c81(s3);
Tim van der Lippe16aca392020-11-13 11:37:133444 s0 = s1;
3445 } else {
3446 peg$currPos = s0;
3447 s0 = peg$FAILED;
3448 }
Tim van der Lippec8f6ffd2020-04-06 12:42:003449 } else {
Tim van der Lippe16aca392020-11-13 11:37:133450 peg$currPos = s0;
3451 s0 = peg$FAILED;
Tim van der Lippec8f6ffd2020-04-06 12:42:003452 }
3453 } else {
Tim van der Lippe16aca392020-11-13 11:37:133454 peg$currPos = s0;
3455 s0 = peg$FAILED;
3456 }
3457 } else {
3458 peg$currPos = s0;
3459 s0 = peg$FAILED;
3460 }
3461 } else {
3462 peg$currPos = s0;
3463 s0 = peg$FAILED;
3464 }
3465
3466 peg$resultsCache[key] = {
3467 nextPos: peg$currPos,
3468 result: s0
3469 };
3470 return s0;
3471 }
3472
3473 function peg$parsematches() {
3474 var s0, s1, s2, s3, s4, s5;
3475 var key = peg$currPos * 30 + 23,
3476 cached = peg$resultsCache[key];
3477
3478 if (cached) {
3479 peg$currPos = cached.nextPos;
3480 return cached.result;
3481 }
3482
3483 s0 = peg$currPos;
3484
Tim van der Lippeb97da6b2021-02-12 14:32:533485 if (input.substr(peg$currPos, 9) === peg$c82) {
3486 s1 = peg$c82;
Tim van der Lippe16aca392020-11-13 11:37:133487 peg$currPos += 9;
3488 } else {
3489 s1 = peg$FAILED;
3490
3491 {
Tim van der Lippeb97da6b2021-02-12 14:32:533492 peg$fail(peg$c83);
Tim van der Lippe16aca392020-11-13 11:37:133493 }
3494 }
3495
3496 if (s1 !== peg$FAILED) {
3497 s2 = peg$parse_();
3498
3499 if (s2 !== peg$FAILED) {
3500 s3 = peg$parseselectors();
3501
3502 if (s3 !== peg$FAILED) {
3503 s4 = peg$parse_();
3504
3505 if (s4 !== peg$FAILED) {
3506 if (input.charCodeAt(peg$currPos) === 41) {
Tim van der Lippeb97da6b2021-02-12 14:32:533507 s5 = peg$c68;
Tim van der Lippe16aca392020-11-13 11:37:133508 peg$currPos++;
3509 } else {
3510 s5 = peg$FAILED;
3511
3512 {
Tim van der Lippeb97da6b2021-02-12 14:32:533513 peg$fail(peg$c69);
Tim van der Lippe16aca392020-11-13 11:37:133514 }
3515 }
3516
3517 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533518 s1 = peg$c84(s3);
Tim van der Lippe16aca392020-11-13 11:37:133519 s0 = s1;
3520 } else {
3521 peg$currPos = s0;
3522 s0 = peg$FAILED;
3523 }
3524 } else {
3525 peg$currPos = s0;
3526 s0 = peg$FAILED;
3527 }
3528 } else {
3529 peg$currPos = s0;
3530 s0 = peg$FAILED;
3531 }
3532 } else {
3533 peg$currPos = s0;
3534 s0 = peg$FAILED;
3535 }
3536 } else {
3537 peg$currPos = s0;
3538 s0 = peg$FAILED;
3539 }
3540
3541 peg$resultsCache[key] = {
3542 nextPos: peg$currPos,
3543 result: s0
3544 };
3545 return s0;
3546 }
3547
3548 function peg$parsehas() {
3549 var s0, s1, s2, s3, s4, s5;
3550 var key = peg$currPos * 30 + 24,
3551 cached = peg$resultsCache[key];
3552
3553 if (cached) {
3554 peg$currPos = cached.nextPos;
3555 return cached.result;
3556 }
3557
3558 s0 = peg$currPos;
3559
Tim van der Lippeb97da6b2021-02-12 14:32:533560 if (input.substr(peg$currPos, 5) === peg$c85) {
3561 s1 = peg$c85;
Tim van der Lippe16aca392020-11-13 11:37:133562 peg$currPos += 5;
3563 } else {
3564 s1 = peg$FAILED;
3565
3566 {
Tim van der Lippeb97da6b2021-02-12 14:32:533567 peg$fail(peg$c86);
Tim van der Lippe16aca392020-11-13 11:37:133568 }
3569 }
3570
3571 if (s1 !== peg$FAILED) {
3572 s2 = peg$parse_();
3573
3574 if (s2 !== peg$FAILED) {
3575 s3 = peg$parseselectors();
3576
3577 if (s3 !== peg$FAILED) {
3578 s4 = peg$parse_();
3579
3580 if (s4 !== peg$FAILED) {
3581 if (input.charCodeAt(peg$currPos) === 41) {
Tim van der Lippeb97da6b2021-02-12 14:32:533582 s5 = peg$c68;
Tim van der Lippe16aca392020-11-13 11:37:133583 peg$currPos++;
3584 } else {
3585 s5 = peg$FAILED;
3586
3587 {
Tim van der Lippeb97da6b2021-02-12 14:32:533588 peg$fail(peg$c69);
Tim van der Lippe16aca392020-11-13 11:37:133589 }
3590 }
3591
3592 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533593 s1 = peg$c87(s3);
Tim van der Lippe16aca392020-11-13 11:37:133594 s0 = s1;
3595 } else {
3596 peg$currPos = s0;
3597 s0 = peg$FAILED;
3598 }
3599 } else {
3600 peg$currPos = s0;
3601 s0 = peg$FAILED;
3602 }
3603 } else {
3604 peg$currPos = s0;
3605 s0 = peg$FAILED;
3606 }
3607 } else {
3608 peg$currPos = s0;
3609 s0 = peg$FAILED;
3610 }
3611 } else {
3612 peg$currPos = s0;
3613 s0 = peg$FAILED;
3614 }
3615
3616 peg$resultsCache[key] = {
3617 nextPos: peg$currPos,
3618 result: s0
3619 };
3620 return s0;
3621 }
3622
3623 function peg$parsefirstChild() {
3624 var s0, s1;
3625 var key = peg$currPos * 30 + 25,
3626 cached = peg$resultsCache[key];
3627
3628 if (cached) {
3629 peg$currPos = cached.nextPos;
3630 return cached.result;
3631 }
3632
3633 s0 = peg$currPos;
3634
Tim van der Lippeb97da6b2021-02-12 14:32:533635 if (input.substr(peg$currPos, 12) === peg$c88) {
3636 s1 = peg$c88;
Tim van der Lippe16aca392020-11-13 11:37:133637 peg$currPos += 12;
3638 } else {
3639 s1 = peg$FAILED;
3640
3641 {
Tim van der Lippeb97da6b2021-02-12 14:32:533642 peg$fail(peg$c89);
Tim van der Lippe16aca392020-11-13 11:37:133643 }
3644 }
3645
3646 if (s1 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533647 s1 = peg$c90();
Tim van der Lippe16aca392020-11-13 11:37:133648 }
3649
3650 s0 = s1;
3651 peg$resultsCache[key] = {
3652 nextPos: peg$currPos,
3653 result: s0
3654 };
3655 return s0;
3656 }
3657
3658 function peg$parselastChild() {
3659 var s0, s1;
3660 var key = peg$currPos * 30 + 26,
3661 cached = peg$resultsCache[key];
3662
3663 if (cached) {
3664 peg$currPos = cached.nextPos;
3665 return cached.result;
3666 }
3667
3668 s0 = peg$currPos;
3669
Tim van der Lippeb97da6b2021-02-12 14:32:533670 if (input.substr(peg$currPos, 11) === peg$c91) {
3671 s1 = peg$c91;
Tim van der Lippe16aca392020-11-13 11:37:133672 peg$currPos += 11;
3673 } else {
3674 s1 = peg$FAILED;
3675
3676 {
Tim van der Lippeb97da6b2021-02-12 14:32:533677 peg$fail(peg$c92);
Tim van der Lippe16aca392020-11-13 11:37:133678 }
3679 }
3680
3681 if (s1 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533682 s1 = peg$c93();
Tim van der Lippe16aca392020-11-13 11:37:133683 }
3684
3685 s0 = s1;
3686 peg$resultsCache[key] = {
3687 nextPos: peg$currPos,
3688 result: s0
3689 };
3690 return s0;
3691 }
3692
3693 function peg$parsenthChild() {
3694 var s0, s1, s2, s3, s4, s5;
3695 var key = peg$currPos * 30 + 27,
3696 cached = peg$resultsCache[key];
3697
3698 if (cached) {
3699 peg$currPos = cached.nextPos;
3700 return cached.result;
3701 }
3702
3703 s0 = peg$currPos;
3704
Tim van der Lippeb97da6b2021-02-12 14:32:533705 if (input.substr(peg$currPos, 11) === peg$c94) {
3706 s1 = peg$c94;
Tim van der Lippe16aca392020-11-13 11:37:133707 peg$currPos += 11;
3708 } else {
3709 s1 = peg$FAILED;
3710
3711 {
Tim van der Lippeb97da6b2021-02-12 14:32:533712 peg$fail(peg$c95);
Tim van der Lippe16aca392020-11-13 11:37:133713 }
3714 }
3715
3716 if (s1 !== peg$FAILED) {
3717 s2 = peg$parse_();
3718
3719 if (s2 !== peg$FAILED) {
3720 s3 = [];
3721
Tim van der Lippeb97da6b2021-02-12 14:32:533722 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133723 s4 = input.charAt(peg$currPos);
3724 peg$currPos++;
3725 } else {
Tim van der Lippec8f6ffd2020-04-06 12:42:003726 s4 = peg$FAILED;
Tim van der Lippe16aca392020-11-13 11:37:133727
3728 {
Tim van der Lippeb97da6b2021-02-12 14:32:533729 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:133730 }
3731 }
3732
3733 if (s4 !== peg$FAILED) {
3734 while (s4 !== peg$FAILED) {
3735 s3.push(s4);
3736
Tim van der Lippeb97da6b2021-02-12 14:32:533737 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133738 s4 = input.charAt(peg$currPos);
3739 peg$currPos++;
3740 } else {
3741 s4 = peg$FAILED;
3742
3743 {
Tim van der Lippeb97da6b2021-02-12 14:32:533744 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:133745 }
3746 }
3747 }
3748 } else {
3749 s3 = peg$FAILED;
3750 }
3751
3752 if (s3 !== peg$FAILED) {
3753 s4 = peg$parse_();
3754
3755 if (s4 !== peg$FAILED) {
3756 if (input.charCodeAt(peg$currPos) === 41) {
Tim van der Lippeb97da6b2021-02-12 14:32:533757 s5 = peg$c68;
Tim van der Lippe16aca392020-11-13 11:37:133758 peg$currPos++;
3759 } else {
3760 s5 = peg$FAILED;
3761
3762 {
Tim van der Lippeb97da6b2021-02-12 14:32:533763 peg$fail(peg$c69);
Tim van der Lippe16aca392020-11-13 11:37:133764 }
3765 }
3766
3767 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533768 s1 = peg$c96(s3);
Tim van der Lippe16aca392020-11-13 11:37:133769 s0 = s1;
3770 } else {
3771 peg$currPos = s0;
3772 s0 = peg$FAILED;
3773 }
3774 } else {
3775 peg$currPos = s0;
3776 s0 = peg$FAILED;
3777 }
3778 } else {
3779 peg$currPos = s0;
3780 s0 = peg$FAILED;
3781 }
3782 } else {
3783 peg$currPos = s0;
3784 s0 = peg$FAILED;
3785 }
3786 } else {
3787 peg$currPos = s0;
3788 s0 = peg$FAILED;
3789 }
3790
3791 peg$resultsCache[key] = {
3792 nextPos: peg$currPos,
3793 result: s0
3794 };
3795 return s0;
3796 }
3797
3798 function peg$parsenthLastChild() {
3799 var s0, s1, s2, s3, s4, s5;
3800 var key = peg$currPos * 30 + 28,
3801 cached = peg$resultsCache[key];
3802
3803 if (cached) {
3804 peg$currPos = cached.nextPos;
3805 return cached.result;
3806 }
3807
3808 s0 = peg$currPos;
3809
Tim van der Lippeb97da6b2021-02-12 14:32:533810 if (input.substr(peg$currPos, 16) === peg$c97) {
3811 s1 = peg$c97;
Tim van der Lippe16aca392020-11-13 11:37:133812 peg$currPos += 16;
3813 } else {
3814 s1 = peg$FAILED;
3815
3816 {
Tim van der Lippeb97da6b2021-02-12 14:32:533817 peg$fail(peg$c98);
Tim van der Lippe16aca392020-11-13 11:37:133818 }
3819 }
3820
3821 if (s1 !== peg$FAILED) {
3822 s2 = peg$parse_();
3823
3824 if (s2 !== peg$FAILED) {
3825 s3 = [];
3826
Tim van der Lippeb97da6b2021-02-12 14:32:533827 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133828 s4 = input.charAt(peg$currPos);
3829 peg$currPos++;
3830 } else {
3831 s4 = peg$FAILED;
3832
3833 {
Tim van der Lippeb97da6b2021-02-12 14:32:533834 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:133835 }
3836 }
3837
3838 if (s4 !== peg$FAILED) {
3839 while (s4 !== peg$FAILED) {
3840 s3.push(s4);
3841
Tim van der Lippeb97da6b2021-02-12 14:32:533842 if (peg$c60.test(input.charAt(peg$currPos))) {
Tim van der Lippe16aca392020-11-13 11:37:133843 s4 = input.charAt(peg$currPos);
3844 peg$currPos++;
3845 } else {
3846 s4 = peg$FAILED;
3847
3848 {
Tim van der Lippeb97da6b2021-02-12 14:32:533849 peg$fail(peg$c61);
Tim van der Lippe16aca392020-11-13 11:37:133850 }
3851 }
3852 }
3853 } else {
3854 s3 = peg$FAILED;
3855 }
3856
3857 if (s3 !== peg$FAILED) {
3858 s4 = peg$parse_();
3859
3860 if (s4 !== peg$FAILED) {
3861 if (input.charCodeAt(peg$currPos) === 41) {
Tim van der Lippeb97da6b2021-02-12 14:32:533862 s5 = peg$c68;
Tim van der Lippe16aca392020-11-13 11:37:133863 peg$currPos++;
3864 } else {
3865 s5 = peg$FAILED;
3866
3867 {
Tim van der Lippeb97da6b2021-02-12 14:32:533868 peg$fail(peg$c69);
Tim van der Lippe16aca392020-11-13 11:37:133869 }
3870 }
3871
3872 if (s5 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533873 s1 = peg$c99(s3);
Tim van der Lippe16aca392020-11-13 11:37:133874 s0 = s1;
3875 } else {
3876 peg$currPos = s0;
3877 s0 = peg$FAILED;
3878 }
3879 } else {
3880 peg$currPos = s0;
3881 s0 = peg$FAILED;
3882 }
3883 } else {
3884 peg$currPos = s0;
3885 s0 = peg$FAILED;
3886 }
3887 } else {
3888 peg$currPos = s0;
3889 s0 = peg$FAILED;
3890 }
3891 } else {
3892 peg$currPos = s0;
3893 s0 = peg$FAILED;
3894 }
3895
3896 peg$resultsCache[key] = {
3897 nextPos: peg$currPos,
3898 result: s0
3899 };
3900 return s0;
3901 }
3902
3903 function peg$parseclass() {
3904 var s0, s1, s2;
3905 var key = peg$currPos * 30 + 29,
3906 cached = peg$resultsCache[key];
3907
3908 if (cached) {
3909 peg$currPos = cached.nextPos;
3910 return cached.result;
3911 }
3912
3913 s0 = peg$currPos;
3914
3915 if (input.charCodeAt(peg$currPos) === 58) {
Tim van der Lippeb97da6b2021-02-12 14:32:533916 s1 = peg$c100;
Tim van der Lippe16aca392020-11-13 11:37:133917 peg$currPos++;
3918 } else {
3919 s1 = peg$FAILED;
3920
3921 {
Tim van der Lippeb97da6b2021-02-12 14:32:533922 peg$fail(peg$c101);
Tim van der Lippe16aca392020-11-13 11:37:133923 }
3924 }
3925
3926 if (s1 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533927 if (input.substr(peg$currPos, 9).toLowerCase() === peg$c102) {
Tim van der Lippe16aca392020-11-13 11:37:133928 s2 = input.substr(peg$currPos, 9);
3929 peg$currPos += 9;
3930 } else {
3931 s2 = peg$FAILED;
3932
3933 {
Tim van der Lippeb97da6b2021-02-12 14:32:533934 peg$fail(peg$c103);
Tim van der Lippec8f6ffd2020-04-06 12:42:003935 }
3936 }
Tim van der Lippe16aca392020-11-13 11:37:133937
3938 if (s2 === peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533939 if (input.substr(peg$currPos, 10).toLowerCase() === peg$c104) {
Tim van der Lippe16aca392020-11-13 11:37:133940 s2 = input.substr(peg$currPos, 10);
3941 peg$currPos += 10;
3942 } else {
3943 s2 = peg$FAILED;
3944
3945 {
Tim van der Lippeb97da6b2021-02-12 14:32:533946 peg$fail(peg$c105);
Tim van der Lippe16aca392020-11-13 11:37:133947 }
3948 }
3949
3950 if (s2 === peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533951 if (input.substr(peg$currPos, 11).toLowerCase() === peg$c106) {
Tim van der Lippe16aca392020-11-13 11:37:133952 s2 = input.substr(peg$currPos, 11);
3953 peg$currPos += 11;
3954 } else {
3955 s2 = peg$FAILED;
3956
3957 {
Tim van der Lippeb97da6b2021-02-12 14:32:533958 peg$fail(peg$c107);
Tim van der Lippe16aca392020-11-13 11:37:133959 }
3960 }
3961
3962 if (s2 === peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533963 if (input.substr(peg$currPos, 8).toLowerCase() === peg$c108) {
Tim van der Lippe16aca392020-11-13 11:37:133964 s2 = input.substr(peg$currPos, 8);
3965 peg$currPos += 8;
3966 } else {
3967 s2 = peg$FAILED;
3968
3969 {
Tim van der Lippeb97da6b2021-02-12 14:32:533970 peg$fail(peg$c109);
Tim van der Lippe16aca392020-11-13 11:37:133971 }
3972 }
3973
3974 if (s2 === peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533975 if (input.substr(peg$currPos, 7).toLowerCase() === peg$c110) {
Tim van der Lippe16aca392020-11-13 11:37:133976 s2 = input.substr(peg$currPos, 7);
3977 peg$currPos += 7;
3978 } else {
3979 s2 = peg$FAILED;
3980
3981 {
Tim van der Lippeb97da6b2021-02-12 14:32:533982 peg$fail(peg$c111);
Tim van der Lippe16aca392020-11-13 11:37:133983 }
3984 }
3985 }
3986 }
3987 }
3988 }
3989
3990 if (s2 !== peg$FAILED) {
Tim van der Lippeb97da6b2021-02-12 14:32:533991 s1 = peg$c112(s2);
Tim van der Lippec8f6ffd2020-04-06 12:42:003992 s0 = s1;
3993 } else {
3994 peg$currPos = s0;
3995 s0 = peg$FAILED;
3996 }
3997 } else {
3998 peg$currPos = s0;
3999 s0 = peg$FAILED;
4000 }
Tim van der Lippe16aca392020-11-13 11:37:134001
4002 peg$resultsCache[key] = {
4003 nextPos: peg$currPos,
4004 result: s0
4005 };
4006 return s0;
Tim van der Lippec8f6ffd2020-04-06 12:42:004007 }
4008
Tim van der Lippe16aca392020-11-13 11:37:134009 function nth(n) {
4010 return {
4011 type: 'nth-child',
4012 index: {
4013 type: 'literal',
4014 value: n
Tim van der Lippec8f6ffd2020-04-06 12:42:004015 }
Tim van der Lippe16aca392020-11-13 11:37:134016 };
Tim van der Lippec8f6ffd2020-04-06 12:42:004017 }
4018
Tim van der Lippe16aca392020-11-13 11:37:134019 function nthLast(n) {
4020 return {
4021 type: 'nth-last-child',
4022 index: {
4023 type: 'literal',
4024 value: n
Tim van der Lippec8f6ffd2020-04-06 12:42:004025 }
Tim van der Lippe16aca392020-11-13 11:37:134026 };
Tim van der Lippec8f6ffd2020-04-06 12:42:004027 }
4028
Tim van der Lippec8f6ffd2020-04-06 12:42:004029 function strUnescape(s) {
Tim van der Lippe16aca392020-11-13 11:37:134030 return s.replace(/\\(.)/g, function (match, ch) {
4031 switch (ch) {
4032 case 'b':
4033 return '\b';
4034
4035 case 'f':
4036 return '\f';
4037
4038 case 'n':
4039 return '\n';
4040
4041 case 'r':
4042 return '\r';
4043
4044 case 't':
4045 return '\t';
4046
4047 case 'v':
4048 return '\v';
4049
4050 default:
4051 return ch;
Tim van der Lippec8f6ffd2020-04-06 12:42:004052 }
4053 });
4054 }
4055
Tim van der Lippe16aca392020-11-13 11:37:134056 peg$result = peg$startRuleFunction();
Tim van der Lippec8f6ffd2020-04-06 12:42:004057
Tim van der Lippe16aca392020-11-13 11:37:134058 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
4059 return peg$result;
4060 } else {
4061 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
4062 peg$fail(peg$endExpectation());
4063 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004064
Tim van der Lippe16aca392020-11-13 11:37:134065 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));
Tim van der Lippec8f6ffd2020-04-06 12:42:004066 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004067 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004068
Tim van der Lippe16aca392020-11-13 11:37:134069 return {
4070 SyntaxError: peg$SyntaxError,
4071 parse: peg$parse
4072 };
4073 });
Tim van der Lippec8f6ffd2020-04-06 12:42:004074});
4075
Tim van der Lippe16aca392020-11-13 11:37:134076function _objectEntries(obj) {
4077 var entries = [];
4078 var keys = Object.keys(obj);
Tim van der Lippec8f6ffd2020-04-06 12:42:004079
Tim van der Lippe16aca392020-11-13 11:37:134080 for (var k = 0; k < keys.length; k++) entries.push([keys[k], obj[keys[k]]]);
4081
4082 return entries;
4083}
Tim van der Lippec8f6ffd2020-04-06 12:42:004084/**
4085* @typedef {"LEFT_SIDE"|"RIGHT_SIDE"} Side
4086*/
4087
Tim van der Lippe16aca392020-11-13 11:37:134088var LEFT_SIDE = 'LEFT_SIDE';
4089var RIGHT_SIDE = 'RIGHT_SIDE';
Tim van der Lippec8f6ffd2020-04-06 12:42:004090/**
4091 * @external AST
4092 * @see https://esprima.readthedocs.io/en/latest/syntax-tree-format.html
4093 */
4094
4095/**
4096 * One of the rules of `grammar.pegjs`
4097 * @typedef {PlainObject} SelectorAST
4098 * @see grammar.pegjs
4099*/
4100
4101/**
4102 * The `sequence` production of `grammar.pegjs`
4103 * @typedef {PlainObject} SelectorSequenceAST
4104*/
4105
4106/**
4107 * Get the value of a property which may be multiple levels down
4108 * in the object.
4109 * @param {?PlainObject} obj
4110 * @param {string} key
4111 * @returns {undefined|boolean|string|number|external:AST}
4112 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004113
Tim van der Lippe16aca392020-11-13 11:37:134114function getPath(obj, key) {
4115 var keys = key.split('.');
4116
Tim van der Lippeb97da6b2021-02-12 14:32:534117 var _iterator = _createForOfIteratorHelper(keys),
4118 _step;
Tim van der Lippe16aca392020-11-13 11:37:134119
Tim van der Lippeb97da6b2021-02-12 14:32:534120 try {
4121 for (_iterator.s(); !(_step = _iterator.n()).done;) {
4122 var _key = _step.value;
4123
4124 if (obj == null) {
4125 return obj;
4126 }
4127
4128 obj = obj[_key];
4129 }
4130 } catch (err) {
4131 _iterator.e(err);
4132 } finally {
4133 _iterator.f();
Tim van der Lippe16aca392020-11-13 11:37:134134 }
4135
4136 return obj;
4137}
Tim van der Lippec8f6ffd2020-04-06 12:42:004138/**
4139 * Determine whether `node` can be reached by following `path`,
4140 * starting at `ancestor`.
4141 * @param {?external:AST} node
4142 * @param {?external:AST} ancestor
4143 * @param {string[]} path
4144 * @returns {boolean}
4145 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004146
Tim van der Lippe16aca392020-11-13 11:37:134147
4148function inPath(node, ancestor, path) {
4149 if (path.length === 0) {
4150 return node === ancestor;
4151 }
4152
4153 if (ancestor == null) {
4154 return false;
4155 }
4156
4157 var field = ancestor[path[0]];
4158 var remainingPath = path.slice(1);
4159
4160 if (Array.isArray(field)) {
Tim van der Lippeb97da6b2021-02-12 14:32:534161 var _iterator2 = _createForOfIteratorHelper(field),
4162 _step2;
4163
4164 try {
4165 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4166 var component = _step2.value;
4167
4168 if (inPath(node, component, remainingPath)) {
4169 return true;
4170 }
Tim van der Lippe16aca392020-11-13 11:37:134171 }
Tim van der Lippeb97da6b2021-02-12 14:32:534172 } catch (err) {
4173 _iterator2.e(err);
4174 } finally {
4175 _iterator2.f();
Tim van der Lippe16aca392020-11-13 11:37:134176 }
4177
4178 return false;
4179 } else {
4180 return inPath(node, field, remainingPath);
4181 }
4182}
Tim van der Lippec8f6ffd2020-04-06 12:42:004183/**
Tim van der Lippeb97da6b2021-02-12 14:32:534184 * @callback TraverseOptionFallback
4185 * @param {external:AST} node The given node.
4186 * @returns {string[]} An array of visitor keys for the given node.
4187 */
4188
4189/**
4190 * @typedef {object} ESQueryOptions
4191 * @property { { [nodeType: string]: string[] } } [visitorKeys] By passing `visitorKeys` mapping, we can extend the properties of the nodes that traverse the node.
4192 * @property {TraverseOptionFallback} [fallback] By passing `fallback` option, we can control the properties of traversing nodes when encountering unknown nodes.
4193 */
4194
4195/**
Tim van der Lippec8f6ffd2020-04-06 12:42:004196 * Given a `node` and its ancestors, determine if `node` is matched
4197 * by `selector`.
4198 * @param {?external:AST} node
4199 * @param {?SelectorAST} selector
4200 * @param {external:AST[]} [ancestry=[]]
Tim van der Lippeb97da6b2021-02-12 14:32:534201 * @param {ESQueryOptions} [options]
Tim van der Lippec8f6ffd2020-04-06 12:42:004202 * @throws {Error} Unknowns (operator, class name, selector type, or
4203 * selector value type)
4204 * @returns {boolean}
4205 */
Tim van der Lippe16aca392020-11-13 11:37:134206
4207
Tim van der Lippeb97da6b2021-02-12 14:32:534208function matches(node, selector, ancestry, options) {
Tim van der Lippe16aca392020-11-13 11:37:134209 if (!selector) {
4210 return true;
4211 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004212
Tim van der Lippe16aca392020-11-13 11:37:134213 if (!node) {
4214 return false;
4215 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004216
Tim van der Lippe16aca392020-11-13 11:37:134217 if (!ancestry) {
4218 ancestry = [];
4219 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004220
Tim van der Lippe16aca392020-11-13 11:37:134221 switch (selector.type) {
4222 case 'wildcard':
4223 return true;
Tim van der Lippec8f6ffd2020-04-06 12:42:004224
Tim van der Lippe16aca392020-11-13 11:37:134225 case 'identifier':
4226 return selector.value.toLowerCase() === node.type.toLowerCase();
4227
4228 case 'field':
4229 {
4230 var path = selector.name.split('.');
4231 var ancestor = ancestry[path.length - 1];
4232 return inPath(node, ancestor, path);
4233 }
4234
4235 case 'matches':
Tim van der Lippeb97da6b2021-02-12 14:32:534236 var _iterator3 = _createForOfIteratorHelper(selector.selectors),
4237 _step3;
4238
4239 try {
4240 for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
4241 var sel = _step3.value;
4242
4243 if (matches(node, sel, ancestry, options)) {
4244 return true;
4245 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004246 }
Tim van der Lippeb97da6b2021-02-12 14:32:534247 } catch (err) {
4248 _iterator3.e(err);
4249 } finally {
4250 _iterator3.f();
Tim van der Lippe16aca392020-11-13 11:37:134251 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004252
Tim van der Lippe16aca392020-11-13 11:37:134253 return false;
Tim van der Lippec8f6ffd2020-04-06 12:42:004254
Tim van der Lippe16aca392020-11-13 11:37:134255 case 'compound':
Tim van der Lippeb97da6b2021-02-12 14:32:534256 var _iterator4 = _createForOfIteratorHelper(selector.selectors),
4257 _step4;
4258
4259 try {
4260 for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
4261 var _sel = _step4.value;
4262
4263 if (!matches(node, _sel, ancestry, options)) {
4264 return false;
4265 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004266 }
Tim van der Lippeb97da6b2021-02-12 14:32:534267 } catch (err) {
4268 _iterator4.e(err);
4269 } finally {
4270 _iterator4.f();
Tim van der Lippe16aca392020-11-13 11:37:134271 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004272
Tim van der Lippe16aca392020-11-13 11:37:134273 return true;
4274
4275 case 'not':
Tim van der Lippeb97da6b2021-02-12 14:32:534276 var _iterator5 = _createForOfIteratorHelper(selector.selectors),
4277 _step5;
4278
4279 try {
4280 for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
4281 var _sel2 = _step5.value;
4282
4283 if (matches(node, _sel2, ancestry, options)) {
4284 return false;
4285 }
Tim van der Lippe16aca392020-11-13 11:37:134286 }
Tim van der Lippeb97da6b2021-02-12 14:32:534287 } catch (err) {
4288 _iterator5.e(err);
4289 } finally {
4290 _iterator5.f();
Tim van der Lippe16aca392020-11-13 11:37:134291 }
4292
4293 return true;
4294
4295 case 'has':
4296 {
4297 var _ret = function () {
4298 var collector = [];
4299
Tim van der Lippeb97da6b2021-02-12 14:32:534300 var _iterator6 = _createForOfIteratorHelper(selector.selectors),
4301 _step6;
Tim van der Lippec8f6ffd2020-04-06 12:42:004302
Tim van der Lippeb97da6b2021-02-12 14:32:534303 try {
4304 var _loop = function _loop() {
4305 var sel = _step6.value;
4306 var a = [];
4307 estraverse.traverse(node, {
4308 enter: function enter(node, parent) {
4309 if (parent != null) {
4310 a.unshift(parent);
4311 }
Tim van der Lippe16aca392020-11-13 11:37:134312
Tim van der Lippeb97da6b2021-02-12 14:32:534313 if (matches(node, sel, a, options)) {
4314 collector.push(node);
4315 }
4316 },
4317 leave: function leave() {
4318 a.shift();
4319 },
4320 keys: options && options.visitorKeys,
4321 fallback: options && options.fallback || 'iteration'
4322 });
4323 };
4324
4325 for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
4326 _loop();
4327 }
4328 } catch (err) {
4329 _iterator6.e(err);
4330 } finally {
4331 _iterator6.f();
Tim van der Lippe16aca392020-11-13 11:37:134332 }
4333
4334 return {
4335 v: collector.length !== 0
4336 };
4337 }();
4338
4339 if (_typeof(_ret) === "object") return _ret.v;
4340 }
4341
4342 case 'child':
Tim van der Lippeb97da6b2021-02-12 14:32:534343 if (matches(node, selector.right, ancestry, options)) {
4344 return matches(ancestry[0], selector.left, ancestry.slice(1), options);
Tim van der Lippe16aca392020-11-13 11:37:134345 }
4346
4347 return false;
4348
4349 case 'descendant':
Tim van der Lippeb97da6b2021-02-12 14:32:534350 if (matches(node, selector.right, ancestry, options)) {
4351 for (var i = 0, l = ancestry.length; i < l; ++i) {
4352 if (matches(ancestry[i], selector.left, ancestry.slice(i + 1), options)) {
Tim van der Lippe16aca392020-11-13 11:37:134353 return true;
4354 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004355 }
Tim van der Lippe16aca392020-11-13 11:37:134356 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004357
Tim van der Lippe16aca392020-11-13 11:37:134358 return false;
Tim van der Lippec8f6ffd2020-04-06 12:42:004359
Tim van der Lippe16aca392020-11-13 11:37:134360 case 'attribute':
4361 {
4362 var p = getPath(node, selector.name);
Tim van der Lippec8f6ffd2020-04-06 12:42:004363
Tim van der Lippe16aca392020-11-13 11:37:134364 switch (selector.operator) {
4365 case void 0:
4366 return p != null;
4367
4368 case '=':
4369 switch (selector.value.type) {
4370 case 'regexp':
4371 return typeof p === 'string' && selector.value.value.test(p);
4372
4373 case 'literal':
4374 return "".concat(selector.value.value) === "".concat(p);
4375
4376 case 'type':
4377 return selector.value.value === _typeof(p);
Tim van der Lippec8f6ffd2020-04-06 12:42:004378 }
Tim van der Lippec8f6ffd2020-04-06 12:42:004379
Tim van der Lippe16aca392020-11-13 11:37:134380 throw new Error("Unknown selector value type: ".concat(selector.value.type));
4381
4382 case '!=':
4383 switch (selector.value.type) {
4384 case 'regexp':
4385 return !selector.value.value.test(p);
4386
4387 case 'literal':
4388 return "".concat(selector.value.value) !== "".concat(p);
4389
4390 case 'type':
4391 return selector.value.value !== _typeof(p);
4392 }
4393
4394 throw new Error("Unknown selector value type: ".concat(selector.value.type));
4395
4396 case '<=':
4397 return p <= selector.value.value;
4398
4399 case '<':
4400 return p < selector.value.value;
4401
4402 case '>':
4403 return p > selector.value.value;
4404
4405 case '>=':
4406 return p >= selector.value.value;
4407 }
4408
4409 throw new Error("Unknown operator: ".concat(selector.operator));
4410 }
4411
4412 case 'sibling':
Tim van der Lippeb97da6b2021-02-12 14:32:534413 return matches(node, selector.right, ancestry, options) && sibling(node, selector.left, ancestry, LEFT_SIDE, options) || selector.left.subject && matches(node, selector.left, ancestry, options) && sibling(node, selector.right, ancestry, RIGHT_SIDE, options);
Tim van der Lippe16aca392020-11-13 11:37:134414
4415 case 'adjacent':
Tim van der Lippeb97da6b2021-02-12 14:32:534416 return matches(node, selector.right, ancestry, options) && adjacent(node, selector.left, ancestry, LEFT_SIDE, options) || selector.right.subject && matches(node, selector.left, ancestry, options) && adjacent(node, selector.right, ancestry, RIGHT_SIDE, options);
Tim van der Lippe16aca392020-11-13 11:37:134417
4418 case 'nth-child':
Tim van der Lippeb97da6b2021-02-12 14:32:534419 return matches(node, selector.right, ancestry, options) && nthChild(node, ancestry, function () {
Tim van der Lippe16aca392020-11-13 11:37:134420 return selector.index.value - 1;
Tim van der Lippeb97da6b2021-02-12 14:32:534421 }, options);
Tim van der Lippe16aca392020-11-13 11:37:134422
4423 case 'nth-last-child':
Tim van der Lippeb97da6b2021-02-12 14:32:534424 return matches(node, selector.right, ancestry, options) && nthChild(node, ancestry, function (length) {
Tim van der Lippe16aca392020-11-13 11:37:134425 return length - selector.index.value;
Tim van der Lippeb97da6b2021-02-12 14:32:534426 }, options);
Tim van der Lippe16aca392020-11-13 11:37:134427
4428 case 'class':
4429 switch (selector.name.toLowerCase()) {
4430 case 'statement':
4431 if (node.type.slice(-9) === 'Statement') return true;
4432 // fallthrough: interface Declaration <: Statement { }
4433
4434 case 'declaration':
4435 return node.type.slice(-11) === 'Declaration';
4436
4437 case 'pattern':
4438 if (node.type.slice(-7) === 'Pattern') return true;
4439 // fallthrough: interface Expression <: Node, Pattern { }
4440
4441 case 'expression':
4442 return node.type.slice(-10) === 'Expression' || node.type.slice(-7) === 'Literal' || node.type === 'Identifier' && (ancestry.length === 0 || ancestry[0].type !== 'MetaProperty') || node.type === 'MetaProperty';
4443
4444 case 'function':
4445 return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
4446 }
4447
4448 throw new Error("Unknown class name: ".concat(selector.name));
4449 }
4450
4451 throw new Error("Unknown selector type: ".concat(selector.type));
Tim van der Lippec8f6ffd2020-04-06 12:42:004452}
Tim van der Lippec8f6ffd2020-04-06 12:42:004453/**
Tim van der Lippeb97da6b2021-02-12 14:32:534454 * Get visitor keys of a given node.
4455 * @param {external:AST} node The AST node to get keys.
4456 * @param {ESQueryOptions|undefined} options
4457 * @returns {string[]} Visitor keys of the node.
4458 */
4459
4460
4461function getVisitorKeys(node, options) {
4462 var nodeType = node.type;
4463
4464 if (options && options.visitorKeys && options.visitorKeys[nodeType]) {
4465 return options.visitorKeys[nodeType];
4466 }
4467
4468 if (estraverse.VisitorKeys[nodeType]) {
4469 return estraverse.VisitorKeys[nodeType];
4470 }
4471
4472 if (options && typeof options.fallback === 'function') {
4473 return options.fallback(node);
4474 } // 'iteration' fallback
4475
4476
4477 return Object.keys(node).filter(function (key) {
4478 return key !== 'type';
4479 });
4480}
4481/**
4482 * Check whether the given value is an ASTNode or not.
4483 * @param {any} node The value to check.
4484 * @returns {boolean} `true` if the value is an ASTNode.
4485 */
4486
4487
4488function isNode(node) {
4489 return node !== null && _typeof(node) === 'object' && typeof node.type === 'string';
4490}
4491/**
Tim van der Lippec8f6ffd2020-04-06 12:42:004492 * Determines if the given node has a sibling that matches the
4493 * given selector.
4494 * @param {external:AST} node
4495 * @param {SelectorSequenceAST} selector
4496 * @param {external:AST[]} ancestry
4497 * @param {Side} side
Tim van der Lippeb97da6b2021-02-12 14:32:534498 * @param {ESQueryOptions|undefined} options
Tim van der Lippec8f6ffd2020-04-06 12:42:004499 * @returns {boolean}
4500 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004501
Tim van der Lippe16aca392020-11-13 11:37:134502
Tim van der Lippeb97da6b2021-02-12 14:32:534503function sibling(node, selector, ancestry, side, options) {
Tim van der Lippe16aca392020-11-13 11:37:134504 var _ancestry = _slicedToArray(ancestry, 1),
4505 parent = _ancestry[0];
4506
4507 if (!parent) {
4508 return false;
4509 }
4510
Tim van der Lippeb97da6b2021-02-12 14:32:534511 var keys = getVisitorKeys(parent, options);
Tim van der Lippe16aca392020-11-13 11:37:134512
Tim van der Lippeb97da6b2021-02-12 14:32:534513 var _iterator7 = _createForOfIteratorHelper(keys),
4514 _step7;
Tim van der Lippe16aca392020-11-13 11:37:134515
Tim van der Lippeb97da6b2021-02-12 14:32:534516 try {
4517 for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
4518 var key = _step7.value;
4519 var listProp = parent[key];
Tim van der Lippe16aca392020-11-13 11:37:134520
Tim van der Lippeb97da6b2021-02-12 14:32:534521 if (Array.isArray(listProp)) {
4522 var startIndex = listProp.indexOf(node);
Tim van der Lippe16aca392020-11-13 11:37:134523
Tim van der Lippeb97da6b2021-02-12 14:32:534524 if (startIndex < 0) {
4525 continue;
4526 }
Tim van der Lippe16aca392020-11-13 11:37:134527
Tim van der Lippeb97da6b2021-02-12 14:32:534528 var lowerBound = void 0,
4529 upperBound = void 0;
Tim van der Lippe16aca392020-11-13 11:37:134530
Tim van der Lippeb97da6b2021-02-12 14:32:534531 if (side === LEFT_SIDE) {
4532 lowerBound = 0;
4533 upperBound = startIndex;
4534 } else {
4535 lowerBound = startIndex + 1;
4536 upperBound = listProp.length;
4537 }
4538
4539 for (var k = lowerBound; k < upperBound; ++k) {
4540 if (isNode(listProp[k]) && matches(listProp[k], selector, ancestry, options)) {
4541 return true;
4542 }
Tim van der Lippe16aca392020-11-13 11:37:134543 }
4544 }
4545 }
Tim van der Lippeb97da6b2021-02-12 14:32:534546 } catch (err) {
4547 _iterator7.e(err);
4548 } finally {
4549 _iterator7.f();
Tim van der Lippe16aca392020-11-13 11:37:134550 }
4551
4552 return false;
4553}
Tim van der Lippec8f6ffd2020-04-06 12:42:004554/**
4555 * Determines if the given node has an adjacent sibling that matches
4556 * the given selector.
4557 * @param {external:AST} node
4558 * @param {SelectorSequenceAST} selector
4559 * @param {external:AST[]} ancestry
4560 * @param {Side} side
Tim van der Lippeb97da6b2021-02-12 14:32:534561 * @param {ESQueryOptions|undefined} options
Tim van der Lippec8f6ffd2020-04-06 12:42:004562 * @returns {boolean}
4563 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004564
Tim van der Lippe16aca392020-11-13 11:37:134565
Tim van der Lippeb97da6b2021-02-12 14:32:534566function adjacent(node, selector, ancestry, side, options) {
Tim van der Lippe16aca392020-11-13 11:37:134567 var _ancestry2 = _slicedToArray(ancestry, 1),
4568 parent = _ancestry2[0];
4569
4570 if (!parent) {
4571 return false;
4572 }
4573
Tim van der Lippeb97da6b2021-02-12 14:32:534574 var keys = getVisitorKeys(parent, options);
Tim van der Lippe16aca392020-11-13 11:37:134575
Tim van der Lippeb97da6b2021-02-12 14:32:534576 var _iterator8 = _createForOfIteratorHelper(keys),
4577 _step8;
Tim van der Lippe16aca392020-11-13 11:37:134578
Tim van der Lippeb97da6b2021-02-12 14:32:534579 try {
4580 for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
4581 var key = _step8.value;
4582 var listProp = parent[key];
Tim van der Lippe16aca392020-11-13 11:37:134583
Tim van der Lippeb97da6b2021-02-12 14:32:534584 if (Array.isArray(listProp)) {
4585 var idx = listProp.indexOf(node);
Tim van der Lippe16aca392020-11-13 11:37:134586
Tim van der Lippeb97da6b2021-02-12 14:32:534587 if (idx < 0) {
4588 continue;
4589 }
Tim van der Lippe16aca392020-11-13 11:37:134590
Tim van der Lippeb97da6b2021-02-12 14:32:534591 if (side === LEFT_SIDE && idx > 0 && isNode(listProp[idx - 1]) && matches(listProp[idx - 1], selector, ancestry, options)) {
4592 return true;
4593 }
4594
4595 if (side === RIGHT_SIDE && idx < listProp.length - 1 && isNode(listProp[idx + 1]) && matches(listProp[idx + 1], selector, ancestry, options)) {
4596 return true;
4597 }
Tim van der Lippe16aca392020-11-13 11:37:134598 }
4599 }
Tim van der Lippeb97da6b2021-02-12 14:32:534600 } catch (err) {
4601 _iterator8.e(err);
4602 } finally {
4603 _iterator8.f();
Tim van der Lippe16aca392020-11-13 11:37:134604 }
4605
4606 return false;
4607}
Tim van der Lippec8f6ffd2020-04-06 12:42:004608/**
4609* @callback IndexFunction
4610* @param {Integer} len Containing list's length
4611* @returns {Integer}
4612*/
4613
4614/**
4615 * Determines if the given node is the nth child, determined by
4616 * `idxFn`, which is given the containing list's length.
4617 * @param {external:AST} node
4618 * @param {external:AST[]} ancestry
4619 * @param {IndexFunction} idxFn
Tim van der Lippeb97da6b2021-02-12 14:32:534620 * @param {ESQueryOptions|undefined} options
Tim van der Lippec8f6ffd2020-04-06 12:42:004621 * @returns {boolean}
4622 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004623
Tim van der Lippe16aca392020-11-13 11:37:134624
Tim van der Lippeb97da6b2021-02-12 14:32:534625function nthChild(node, ancestry, idxFn, options) {
Tim van der Lippe16aca392020-11-13 11:37:134626 var _ancestry3 = _slicedToArray(ancestry, 1),
4627 parent = _ancestry3[0];
4628
4629 if (!parent) {
4630 return false;
4631 }
4632
Tim van der Lippeb97da6b2021-02-12 14:32:534633 var keys = getVisitorKeys(parent, options);
Tim van der Lippe16aca392020-11-13 11:37:134634
Tim van der Lippeb97da6b2021-02-12 14:32:534635 var _iterator9 = _createForOfIteratorHelper(keys),
4636 _step9;
Tim van der Lippe16aca392020-11-13 11:37:134637
Tim van der Lippeb97da6b2021-02-12 14:32:534638 try {
4639 for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
4640 var key = _step9.value;
4641 var listProp = parent[key];
Tim van der Lippe16aca392020-11-13 11:37:134642
Tim van der Lippeb97da6b2021-02-12 14:32:534643 if (Array.isArray(listProp)) {
4644 var idx = listProp.indexOf(node);
4645
4646 if (idx >= 0 && idx === idxFn(listProp.length)) {
4647 return true;
4648 }
Tim van der Lippe16aca392020-11-13 11:37:134649 }
4650 }
Tim van der Lippeb97da6b2021-02-12 14:32:534651 } catch (err) {
4652 _iterator9.e(err);
4653 } finally {
4654 _iterator9.f();
Tim van der Lippe16aca392020-11-13 11:37:134655 }
4656
4657 return false;
4658}
Tim van der Lippec8f6ffd2020-04-06 12:42:004659/**
4660 * For each selector node marked as a subject, find the portion of the
4661 * selector that the subject must match.
4662 * @param {SelectorAST} selector
4663 * @param {SelectorAST} [ancestor] Defaults to `selector`
4664 * @returns {SelectorAST[]}
4665 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004666
Tim van der Lippe16aca392020-11-13 11:37:134667
4668function subjects(selector, ancestor) {
4669 if (selector == null || _typeof(selector) != 'object') {
4670 return [];
4671 }
4672
4673 if (ancestor == null) {
4674 ancestor = selector;
4675 }
4676
4677 var results = selector.subject ? [ancestor] : [];
4678
Tim van der Lippeb97da6b2021-02-12 14:32:534679 for (var _i = 0, _Object$entries = _objectEntries(selector); _i < _Object$entries.length; _i++) {
4680 var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
Tim van der Lippe16aca392020-11-13 11:37:134681 p = _Object$entries$_i[0],
4682 sel = _Object$entries$_i[1];
4683
4684 results.push.apply(results, _toConsumableArray(subjects(sel, p === 'left' ? sel : ancestor)));
4685 }
4686
4687 return results;
4688}
4689/**
4690* @callback TraverseVisitor
4691* @param {?external:AST} node
4692* @param {?external:AST} parent
4693* @param {external:AST[]} ancestry
4694*/
4695
4696/**
4697 * From a JS AST and a selector AST, collect all JS AST nodes that
4698 * match the selector.
4699 * @param {external:AST} ast
4700 * @param {?SelectorAST} selector
4701 * @param {TraverseVisitor} visitor
Tim van der Lippeb97da6b2021-02-12 14:32:534702 * @param {ESQueryOptions} [options]
Tim van der Lippe16aca392020-11-13 11:37:134703 * @returns {external:AST[]}
4704 */
4705
4706
Tim van der Lippeb97da6b2021-02-12 14:32:534707function traverse(ast, selector, visitor, options) {
Tim van der Lippe16aca392020-11-13 11:37:134708 if (!selector) {
4709 return;
4710 }
4711
4712 var ancestry = [];
4713 var altSubjects = subjects(selector);
4714 estraverse.traverse(ast, {
4715 enter: function enter(node, parent) {
4716 if (parent != null) {
4717 ancestry.unshift(parent);
4718 }
4719
Tim van der Lippeb97da6b2021-02-12 14:32:534720 if (matches(node, selector, ancestry, options)) {
Tim van der Lippe16aca392020-11-13 11:37:134721 if (altSubjects.length) {
4722 for (var i = 0, l = altSubjects.length; i < l; ++i) {
Tim van der Lippeb97da6b2021-02-12 14:32:534723 if (matches(node, altSubjects[i], ancestry, options)) {
Tim van der Lippe16aca392020-11-13 11:37:134724 visitor(node, parent, ancestry);
4725 }
4726
4727 for (var k = 0, m = ancestry.length; k < m; ++k) {
4728 var succeedingAncestry = ancestry.slice(k + 1);
4729
Tim van der Lippeb97da6b2021-02-12 14:32:534730 if (matches(ancestry[k], altSubjects[i], succeedingAncestry, options)) {
Tim van der Lippe16aca392020-11-13 11:37:134731 visitor(ancestry[k], parent, succeedingAncestry);
4732 }
4733 }
4734 }
4735 } else {
4736 visitor(node, parent, ancestry);
4737 }
4738 }
4739 },
4740 leave: function leave() {
4741 ancestry.shift();
4742 },
Tim van der Lippeb97da6b2021-02-12 14:32:534743 keys: options && options.visitorKeys,
4744 fallback: options && options.fallback || 'iteration'
Tim van der Lippe16aca392020-11-13 11:37:134745 });
4746}
Tim van der Lippec8f6ffd2020-04-06 12:42:004747/**
4748 * From a JS AST and a selector AST, collect all JS AST nodes that
4749 * match the selector.
4750 * @param {external:AST} ast
4751 * @param {?SelectorAST} selector
Tim van der Lippeb97da6b2021-02-12 14:32:534752 * @param {ESQueryOptions} [options]
Tim van der Lippec8f6ffd2020-04-06 12:42:004753 * @returns {external:AST[]}
4754 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004755
Tim van der Lippe16aca392020-11-13 11:37:134756
Tim van der Lippeb97da6b2021-02-12 14:32:534757function match(ast, selector, options) {
Tim van der Lippe16aca392020-11-13 11:37:134758 var results = [];
4759 traverse(ast, selector, function (node) {
4760 results.push(node);
Tim van der Lippeb97da6b2021-02-12 14:32:534761 }, options);
Tim van der Lippe16aca392020-11-13 11:37:134762 return results;
4763}
Tim van der Lippec8f6ffd2020-04-06 12:42:004764/**
4765 * Parse a selector string and return its AST.
4766 * @param {string} selector
4767 * @returns {SelectorAST}
4768 */
Tim van der Lippec8f6ffd2020-04-06 12:42:004769
Tim van der Lippe16aca392020-11-13 11:37:134770
4771function parse(selector) {
4772 return parser.parse(selector);
4773}
Tim van der Lippec8f6ffd2020-04-06 12:42:004774/**
4775 * Query the code AST using the selector string.
4776 * @param {external:AST} ast
4777 * @param {string} selector
Tim van der Lippeb97da6b2021-02-12 14:32:534778 * @param {ESQueryOptions} [options]
Tim van der Lippec8f6ffd2020-04-06 12:42:004779 * @returns {external:AST[]}
4780 */
Tim van der Lippe16aca392020-11-13 11:37:134781
4782
Tim van der Lippeb97da6b2021-02-12 14:32:534783function query(ast, selector, options) {
4784 return match(ast, parse(selector), options);
Tim van der Lippec8f6ffd2020-04-06 12:42:004785}
4786
4787query.parse = parse;
4788query.match = match;
Tim van der Lippe16aca392020-11-13 11:37:134789query.traverse = traverse;
Tim van der Lippec8f6ffd2020-04-06 12:42:004790query.matches = matches;
4791query.query = query;
4792
4793export default query;