Nth.js 1.3 KB

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