Raw.cjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. function getOffsetExcludeWS() {
  4. if (this.tokenIndex > 0) {
  5. if (this.lookupType(-1) === types.WhiteSpace) {
  6. return this.tokenIndex > 1
  7. ? this.getTokenStart(this.tokenIndex - 1)
  8. : this.firstCharOffset;
  9. }
  10. }
  11. return this.tokenStart;
  12. }
  13. const name = 'Raw';
  14. const structure = {
  15. value: String
  16. };
  17. function parse(consumeUntil, excludeWhiteSpace) {
  18. const startOffset = this.getTokenStart(this.tokenIndex);
  19. let endOffset;
  20. this.skipUntilBalanced(this.tokenIndex, consumeUntil || this.consumeUntilBalanceEnd);
  21. if (excludeWhiteSpace && this.tokenStart > startOffset) {
  22. endOffset = getOffsetExcludeWS.call(this);
  23. } else {
  24. endOffset = this.tokenStart;
  25. }
  26. return {
  27. type: 'Raw',
  28. loc: this.getLocation(startOffset, endOffset),
  29. value: this.substring(startOffset, endOffset)
  30. };
  31. }
  32. function generate(node) {
  33. this.tokenize(node.value);
  34. }
  35. exports.generate = generate;
  36. exports.name = name;
  37. exports.parse = parse;
  38. exports.structure = structure;