You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6 KiB

4 years ago
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var WHITESPACE = TYPE.WhiteSpace;
  3. var COMMENT = TYPE.Comment;
  4. var IDENT = TYPE.Ident;
  5. var LEFTPARENTHESIS = TYPE.LeftParenthesis;
  6. module.exports = {
  7. name: 'MediaQuery',
  8. structure: {
  9. children: [[
  10. 'Identifier',
  11. 'MediaFeature',
  12. 'WhiteSpace'
  13. ]]
  14. },
  15. parse: function() {
  16. this.scanner.skipSC();
  17. var children = this.createList();
  18. var child = null;
  19. var space = null;
  20. scan:
  21. while (!this.scanner.eof) {
  22. switch (this.scanner.tokenType) {
  23. case COMMENT:
  24. this.scanner.next();
  25. continue;
  26. case WHITESPACE:
  27. space = this.WhiteSpace();
  28. continue;
  29. case IDENT:
  30. child = this.Identifier();
  31. break;
  32. case LEFTPARENTHESIS:
  33. child = this.MediaFeature();
  34. break;
  35. default:
  36. break scan;
  37. }
  38. if (space !== null) {
  39. children.push(space);
  40. space = null;
  41. }
  42. children.push(child);
  43. }
  44. if (child === null) {
  45. this.error('Identifier or parenthesis is expected');
  46. }
  47. return {
  48. type: 'MediaQuery',
  49. loc: this.getLocationFromList(children),
  50. children: children
  51. };
  52. },
  53. generate: function(node) {
  54. this.children(node);
  55. }
  56. };