Raw.js 1.0 KB

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