Nth.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module.exports = {
  2. name: 'Nth',
  3. structure: {
  4. nth: ['AnPlusB', 'Identifier'],
  5. selector: ['SelectorList', null]
  6. },
  7. parse: function(allowOfClause) {
  8. this.scanner.skipSC();
  9. var start = this.scanner.tokenStart;
  10. var end = start;
  11. var selector = null;
  12. var query;
  13. if (this.scanner.lookupValue(0, 'odd') || this.scanner.lookupValue(0, 'even')) {
  14. query = this.Identifier();
  15. } else {
  16. query = this.AnPlusB();
  17. }
  18. this.scanner.skipSC();
  19. if (allowOfClause && this.scanner.lookupValue(0, 'of')) {
  20. this.scanner.next();
  21. selector = this.SelectorList();
  22. if (this.needPositions) {
  23. end = this.getLastListNode(selector.children).loc.end.offset;
  24. }
  25. } else {
  26. if (this.needPositions) {
  27. end = query.loc.end.offset;
  28. }
  29. }
  30. return {
  31. type: 'Nth',
  32. loc: this.getLocation(start, end),
  33. nth: query,
  34. selector: selector
  35. };
  36. },
  37. generate: function(node) {
  38. this.node(node.nth);
  39. if (node.selector !== null) {
  40. this.chunk(' of ');
  41. this.node(node.selector);
  42. }
  43. }
  44. };