PseudoElementSelector.cjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const name = 'PseudoElementSelector';
  4. const walkContext = 'function';
  5. const structure = {
  6. name: String,
  7. children: [['Raw'], null]
  8. };
  9. // :: [ <ident> | <function-token> <any-value>? ) ]
  10. function parse() {
  11. const start = this.tokenStart;
  12. let children = null;
  13. let name;
  14. let nameLowerCase;
  15. this.eat(types.Colon);
  16. this.eat(types.Colon);
  17. if (this.tokenType === types.Function) {
  18. name = this.consumeFunctionName();
  19. nameLowerCase = name.toLowerCase();
  20. if (this.lookupNonWSType(0) == types.RightParenthesis) {
  21. children = this.createList();
  22. } else if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
  23. this.skipSC();
  24. children = this.pseudo[nameLowerCase].call(this);
  25. this.skipSC();
  26. } else {
  27. children = this.createList();
  28. children.push(
  29. this.Raw(null, false)
  30. );
  31. }
  32. this.eat(types.RightParenthesis);
  33. } else {
  34. name = this.consume(types.Ident);
  35. }
  36. return {
  37. type: 'PseudoElementSelector',
  38. loc: this.getLocation(start, this.tokenStart),
  39. name,
  40. children
  41. };
  42. }
  43. function generate(node) {
  44. this.token(types.Colon, ':');
  45. this.token(types.Colon, ':');
  46. if (node.children === null) {
  47. this.token(types.Ident, node.name);
  48. } else {
  49. this.token(types.Function, node.name + '(');
  50. this.children(node);
  51. this.token(types.RightParenthesis, ')');
  52. }
  53. }
  54. exports.generate = generate;
  55. exports.name = name;
  56. exports.parse = parse;
  57. exports.structure = structure;
  58. exports.walkContext = walkContext;