IdSelector.js 747 B

1234567891011121314151617181920212223242526
  1. import { Hash, Delim } from '../../tokenizer/index.js';
  2. export const name = 'IdSelector';
  3. export const structure = {
  4. name: String
  5. };
  6. export function parse() {
  7. const start = this.tokenStart;
  8. // TODO: check value is an ident
  9. this.eat(Hash);
  10. return {
  11. type: 'IdSelector',
  12. loc: this.getLocation(start, this.tokenStart),
  13. name: this.substrToCursor(start + 1)
  14. };
  15. }
  16. export function generate(node) {
  17. // Using Delim instead of Hash is a hack to avoid for a whitespace between ident and id-selector
  18. // in safe mode (e.g. "a#id"), because IE11 doesn't allow a sequence <ident-token> <hash-token>
  19. // without a whitespace in values (e.g. "1px solid#000")
  20. this.token(Delim, '#' + node.name);
  21. }