DeclarationList.cjs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
  4. function consumeRaw() {
  5. return this.Raw(this.consumeUntilSemicolonIncluded, true);
  6. }
  7. const name = 'DeclarationList';
  8. const structure = {
  9. children: [[
  10. 'Declaration',
  11. 'Atrule',
  12. 'Rule'
  13. ]]
  14. };
  15. function parse() {
  16. const children = this.createList();
  17. while (!this.eof) {
  18. switch (this.tokenType) {
  19. case types.WhiteSpace:
  20. case types.Comment:
  21. case types.Semicolon:
  22. this.next();
  23. break;
  24. case types.AtKeyword:
  25. children.push(this.parseWithFallback(this.Atrule.bind(this, true), consumeRaw));
  26. break;
  27. default:
  28. if (this.isDelim(AMPERSAND)) {
  29. children.push(this.parseWithFallback(this.Rule, consumeRaw));
  30. } else {
  31. children.push(this.parseWithFallback(this.Declaration, consumeRaw));
  32. }
  33. }
  34. }
  35. return {
  36. type: 'DeclarationList',
  37. loc: this.getLocationFromList(children),
  38. children
  39. };
  40. }
  41. function generate(node) {
  42. this.children(node, prev => {
  43. if (prev.type === 'Declaration') {
  44. this.token(types.Semicolon, ';');
  45. }
  46. });
  47. }
  48. exports.generate = generate;
  49. exports.name = name;
  50. exports.parse = parse;
  51. exports.structure = structure;