Comment.js 946 B

123456789101112131415161718192021222324252627282930313233343536
  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. };