Comment.cjs 854 B

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