Rule.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var rawMode = require('./Raw').mode;
  3. var LEFTCURLYBRACKET = TYPE.LeftCurlyBracket;
  4. function consumeRaw(startToken) {
  5. return this.Raw(startToken, rawMode.leftCurlyBracket, true);
  6. }
  7. function consumePrelude() {
  8. var prelude = this.SelectorList();
  9. if (prelude.type !== 'Raw' &&
  10. this.scanner.eof === false &&
  11. this.scanner.tokenType !== LEFTCURLYBRACKET) {
  12. this.error();
  13. }
  14. return prelude;
  15. }
  16. module.exports = {
  17. name: 'Rule',
  18. structure: {
  19. prelude: ['SelectorList', 'Raw'],
  20. block: ['Block']
  21. },
  22. parse: function() {
  23. var startToken = this.scanner.tokenIndex;
  24. var startOffset = this.scanner.tokenStart;
  25. var prelude;
  26. var block;
  27. if (this.parseRulePrelude) {
  28. prelude = this.parseWithFallback(consumePrelude, consumeRaw);
  29. } else {
  30. prelude = consumeRaw.call(this, startToken);
  31. }
  32. block = this.Block(true);
  33. return {
  34. type: 'Rule',
  35. loc: this.getLocation(startOffset, this.scanner.tokenStart),
  36. prelude: prelude,
  37. block: block
  38. };
  39. },
  40. generate: function(node) {
  41. this.node(node.prelude);
  42. this.node(node.block);
  43. },
  44. walkContext: 'rule'
  45. };