Nth.cjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const name = 'Nth';
  4. const structure = {
  5. nth: ['AnPlusB', 'Identifier'],
  6. selector: ['SelectorList', null]
  7. };
  8. function parse() {
  9. this.skipSC();
  10. const start = this.tokenStart;
  11. let end = start;
  12. let selector = null;
  13. let nth;
  14. if (this.lookupValue(0, 'odd') || this.lookupValue(0, 'even')) {
  15. nth = this.Identifier();
  16. } else {
  17. nth = this.AnPlusB();
  18. }
  19. end = this.tokenStart;
  20. this.skipSC();
  21. if (this.lookupValue(0, 'of')) {
  22. this.next();
  23. selector = this.SelectorList();
  24. end = this.tokenStart;
  25. }
  26. return {
  27. type: 'Nth',
  28. loc: this.getLocation(start, end),
  29. nth,
  30. selector
  31. };
  32. }
  33. function generate(node) {
  34. this.node(node.nth);
  35. if (node.selector !== null) {
  36. this.token(types.Ident, 'of');
  37. this.node(node.selector);
  38. }
  39. }
  40. exports.generate = generate;
  41. exports.name = name;
  42. exports.parse = parse;
  43. exports.structure = structure;