You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

4 years ago
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var IDENT = TYPE.Ident;
  3. var FUNCTION = TYPE.Function;
  4. var COLON = TYPE.Colon;
  5. var RIGHTPARENTHESIS = TYPE.RightParenthesis;
  6. // : [ <ident> | <function-token> <any-value>? ) ]
  7. module.exports = {
  8. name: 'PseudoClassSelector',
  9. structure: {
  10. name: String,
  11. children: [['Raw'], null]
  12. },
  13. parse: function() {
  14. var start = this.scanner.tokenStart;
  15. var children = null;
  16. var name;
  17. var nameLowerCase;
  18. this.eat(COLON);
  19. if (this.scanner.tokenType === FUNCTION) {
  20. name = this.consumeFunctionName();
  21. nameLowerCase = name.toLowerCase();
  22. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  23. this.scanner.skipSC();
  24. children = this.pseudo[nameLowerCase].call(this);
  25. this.scanner.skipSC();
  26. } else {
  27. children = this.createList();
  28. children.push(
  29. this.Raw(this.scanner.tokenIndex, null, false)
  30. );
  31. }
  32. this.eat(RIGHTPARENTHESIS);
  33. } else {
  34. name = this.consume(IDENT);
  35. }
  36. return {
  37. type: 'PseudoClassSelector',
  38. loc: this.getLocation(start, this.scanner.tokenStart),
  39. name: name,
  40. children: children
  41. };
  42. },
  43. generate: function(node) {
  44. this.chunk(':');
  45. this.chunk(node.name);
  46. if (node.children !== null) {
  47. this.chunk('(');
  48. this.children(node);
  49. this.chunk(')');
  50. }
  51. },
  52. walkContext: 'function'
  53. };