AtrulePrelude.js 1.0 KB

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