PseudoElementSelector.js 1.6 KB

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