web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4801 lines
127 KiB

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