IdSelector.cjs 847 B

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