import.cjs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. function parseWithFallback(parse, fallback) {
  4. return this.parseWithFallback(
  5. () => {
  6. try {
  7. return parse.call(this);
  8. } finally {
  9. this.skipSC();
  10. if (this.lookupNonWSType(0) !== types.RightParenthesis) {
  11. this.error();
  12. }
  13. }
  14. },
  15. fallback || (() => this.Raw(null, true))
  16. );
  17. }
  18. const parseFunctions = {
  19. layer() {
  20. this.skipSC();
  21. const children = this.createList();
  22. const node = parseWithFallback.call(this, this.Layer);
  23. if (node.type !== 'Raw' || node.value !== '') {
  24. children.push(node);
  25. }
  26. return children;
  27. },
  28. supports() {
  29. this.skipSC();
  30. const children = this.createList();
  31. const node = parseWithFallback.call(
  32. this,
  33. this.Declaration,
  34. () => parseWithFallback.call(this, () => this.Condition('supports'))
  35. );
  36. if (node.type !== 'Raw' || node.value !== '') {
  37. children.push(node);
  38. }
  39. return children;
  40. }
  41. };
  42. const importAtrule = {
  43. parse: {
  44. prelude() {
  45. const children = this.createList();
  46. switch (this.tokenType) {
  47. case types.String:
  48. children.push(this.String());
  49. break;
  50. case types.Url:
  51. case types.Function:
  52. children.push(this.Url());
  53. break;
  54. default:
  55. this.error('String or url() is expected');
  56. }
  57. this.skipSC();
  58. if (this.tokenType === types.Ident &&
  59. this.cmpStr(this.tokenStart, this.tokenEnd, 'layer')) {
  60. children.push(this.Identifier());
  61. } else if (
  62. this.tokenType === types.Function &&
  63. this.cmpStr(this.tokenStart, this.tokenEnd, 'layer(')
  64. ) {
  65. children.push(this.Function(null, parseFunctions));
  66. }
  67. this.skipSC();
  68. if (this.tokenType === types.Function &&
  69. this.cmpStr(this.tokenStart, this.tokenEnd, 'supports(')) {
  70. children.push(this.Function(null, parseFunctions));
  71. }
  72. if (this.lookupNonWSType(0) === types.Ident ||
  73. this.lookupNonWSType(0) === types.LeftParenthesis) {
  74. children.push(this.MediaQueryList());
  75. }
  76. return children;
  77. },
  78. block: null
  79. }
  80. };
  81. module.exports = importAtrule;