selector.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var DELIM = TYPE.Delim;
  3. var IDENT = TYPE.Ident;
  4. var DIMENSION = TYPE.Dimension;
  5. var PERCENTAGE = TYPE.Percentage;
  6. var NUMBER = TYPE.Number;
  7. var HASH = TYPE.Hash;
  8. var COLON = TYPE.Colon;
  9. var LEFTSQUAREBRACKET = TYPE.LeftSquareBracket;
  10. var NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
  11. var ASTERISK = 0x002A; // U+002A ASTERISK (*)
  12. var PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
  13. var SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
  14. var FULLSTOP = 0x002E; // U+002E FULL STOP (.)
  15. var GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
  16. var VERTICALLINE = 0x007C; // U+007C VERTICAL LINE (|)
  17. var TILDE = 0x007E; // U+007E TILDE (~)
  18. function getNode(context) {
  19. switch (this.scanner.tokenType) {
  20. case LEFTSQUAREBRACKET:
  21. return this.AttributeSelector();
  22. case HASH:
  23. return this.IdSelector();
  24. case COLON:
  25. if (this.scanner.lookupType(1) === COLON) {
  26. return this.PseudoElementSelector();
  27. } else {
  28. return this.PseudoClassSelector();
  29. }
  30. case IDENT:
  31. return this.TypeSelector();
  32. case NUMBER:
  33. case PERCENTAGE:
  34. return this.Percentage();
  35. case DIMENSION:
  36. // throws when .123ident
  37. if (this.scanner.source.charCodeAt(this.scanner.tokenStart) === FULLSTOP) {
  38. this.error('Identifier is expected', this.scanner.tokenStart + 1);
  39. }
  40. break;
  41. case DELIM:
  42. var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
  43. switch (code) {
  44. case PLUSSIGN:
  45. case GREATERTHANSIGN:
  46. case TILDE:
  47. context.space = null;
  48. context.ignoreWSAfter = true;
  49. return this.Combinator();
  50. case SOLIDUS: // /deep/
  51. return this.Combinator();
  52. case FULLSTOP:
  53. return this.ClassSelector();
  54. case ASTERISK:
  55. case VERTICALLINE:
  56. return this.TypeSelector();
  57. case NUMBERSIGN:
  58. return this.IdSelector();
  59. }
  60. break;
  61. }
  62. };
  63. module.exports = {
  64. getNode: getNode
  65. };