AtrulePrelude.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var SEMICOLON = TYPE.Semicolon;
  3. var LEFTCURLYBRACKET = TYPE.LeftCurlyBracket;
  4. module.exports = {
  5. name: 'AtrulePrelude',
  6. structure: {
  7. children: [[]]
  8. },
  9. parse: function(name) {
  10. var children = null;
  11. if (name !== null) {
  12. name = name.toLowerCase();
  13. }
  14. this.scanner.skipSC();
  15. if (this.atrule.hasOwnProperty(name) &&
  16. typeof this.atrule[name].prelude === 'function') {
  17. // custom consumer
  18. children = this.atrule[name].prelude.call(this);
  19. } else {
  20. // default consumer
  21. children = this.readSequence(this.scope.AtrulePrelude);
  22. }
  23. this.scanner.skipSC();
  24. if (this.scanner.eof !== true &&
  25. this.scanner.tokenType !== LEFTCURLYBRACKET &&
  26. this.scanner.tokenType !== SEMICOLON) {
  27. this.error('Semicolon or block is expected');
  28. }
  29. if (children === null) {
  30. children = this.createList();
  31. }
  32. return {
  33. type: 'AtrulePrelude',
  34. loc: this.getLocationFromList(children),
  35. children: children
  36. };
  37. },
  38. generate: function(node) {
  39. this.children(node);
  40. },
  41. walkContext: 'atrulePrelude'
  42. };