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.

62 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: 'PseudoElementSelector',
  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. this.eat(COLON);
  20. if (this.scanner.tokenType === FUNCTION) {
  21. name = this.consumeFunctionName();
  22. nameLowerCase = name.toLowerCase();
  23. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  24. this.scanner.skipSC();
  25. children = this.pseudo[nameLowerCase].call(this);
  26. this.scanner.skipSC();
  27. } else {
  28. children = this.createList();
  29. children.push(
  30. this.Raw(this.scanner.tokenIndex, null, false)
  31. );
  32. }
  33. this.eat(RIGHTPARENTHESIS);
  34. } else {
  35. name = this.consume(IDENT);
  36. }
  37. return {
  38. type: 'PseudoElementSelector',
  39. loc: this.getLocation(start, this.scanner.tokenStart),
  40. name: name,
  41. children: children
  42. };
  43. },
  44. generate: function(node) {
  45. this.chunk('::');
  46. this.chunk(node.name);
  47. if (node.children !== null) {
  48. this.chunk('(');
  49. this.children(node);
  50. this.chunk(')');
  51. }
  52. },
  53. walkContext: 'function'
  54. };