Scope.cjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const name = 'Scope';
  4. const structure = {
  5. root: ['SelectorList', 'Raw', null],
  6. limit: ['SelectorList', 'Raw', null]
  7. };
  8. function parse() {
  9. let root = null;
  10. let limit = null;
  11. this.skipSC();
  12. const startOffset = this.tokenStart;
  13. if (this.tokenType === types.LeftParenthesis) {
  14. this.next();
  15. this.skipSC();
  16. root = this.parseWithFallback(
  17. this.SelectorList,
  18. () => this.Raw(false, true)
  19. );
  20. this.skipSC();
  21. this.eat(types.RightParenthesis);
  22. }
  23. if (this.lookupNonWSType(0) === types.Ident) {
  24. this.skipSC();
  25. this.eatIdent('to');
  26. this.skipSC();
  27. this.eat(types.LeftParenthesis);
  28. this.skipSC();
  29. limit = this.parseWithFallback(
  30. this.SelectorList,
  31. () => this.Raw(false, true)
  32. );
  33. this.skipSC();
  34. this.eat(types.RightParenthesis);
  35. }
  36. return {
  37. type: 'Scope',
  38. loc: this.getLocation(startOffset, this.tokenStart),
  39. root,
  40. limit
  41. };
  42. }
  43. function generate(node) {
  44. if (node.root) {
  45. this.token(types.LeftParenthesis, '(');
  46. this.node(node.root);
  47. this.token(types.RightParenthesis, ')');
  48. }
  49. if (node.limit) {
  50. this.token(types.Ident, 'to');
  51. this.token(types.LeftParenthesis, '(');
  52. this.node(node.limit);
  53. this.token(types.RightParenthesis, ')');
  54. }
  55. }
  56. exports.generate = generate;
  57. exports.name = name;
  58. exports.parse = parse;
  59. exports.structure = structure;