PseudoClassSelector.cjs 1.6 KB

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