Comment.js 750 B

123456789101112131415161718192021222324252627282930313233
  1. import { Comment } from '../../tokenizer/index.js';
  2. const ASTERISK = 0x002A; // U+002A ASTERISK (*)
  3. const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
  4. export const name = 'Comment';
  5. export const structure = {
  6. value: String
  7. };
  8. export function parse() {
  9. const start = this.tokenStart;
  10. let end = this.tokenEnd;
  11. this.eat(Comment);
  12. if ((end - start + 2) >= 2 &&
  13. this.charCodeAt(end - 2) === ASTERISK &&
  14. this.charCodeAt(end - 1) === SOLIDUS) {
  15. end -= 2;
  16. }
  17. return {
  18. type: 'Comment',
  19. loc: this.getLocation(start, this.tokenStart),
  20. value: this.substring(start + 2, end)
  21. };
  22. }
  23. export function generate(node) {
  24. this.token(Comment, '/*' + node.value + '*/');
  25. }