You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
946 B

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