Nth.js 943 B

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