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