Rule.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { LeftCurlyBracket } from '../../tokenizer/index.js';
  2. function consumeRaw() {
  3. return this.Raw(this.consumeUntilLeftCurlyBracket, true);
  4. }
  5. function consumePrelude() {
  6. const prelude = this.SelectorList();
  7. if (prelude.type !== 'Raw' &&
  8. this.eof === false &&
  9. this.tokenType !== LeftCurlyBracket) {
  10. this.error();
  11. }
  12. return prelude;
  13. }
  14. export const name = 'Rule';
  15. export const walkContext = 'rule';
  16. export const structure = {
  17. prelude: ['SelectorList', 'Raw'],
  18. block: ['Block']
  19. };
  20. export function parse() {
  21. const startToken = this.tokenIndex;
  22. const startOffset = this.tokenStart;
  23. let prelude;
  24. let block;
  25. if (this.parseRulePrelude) {
  26. prelude = this.parseWithFallback(consumePrelude, consumeRaw);
  27. } else {
  28. prelude = consumeRaw.call(this, startToken);
  29. }
  30. block = this.Block(true);
  31. return {
  32. type: 'Rule',
  33. loc: this.getLocation(startOffset, this.tokenStart),
  34. prelude,
  35. block
  36. };
  37. }
  38. export function generate(node) {
  39. this.node(node.prelude);
  40. this.node(node.block);
  41. }