computedMappings.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.computedMappings = void 0;
  4. const language_core_1 = require("@volar/language-core");
  5. const muggle = require("muggle-string");
  6. const computeds_1 = require("computeds");
  7. function computedMappings(snapshot, sfc) {
  8. return (0, computeds_1.computed)(() => {
  9. const str = [[snapshot().getText(0, snapshot().getLength()), undefined, 0, language_core_1.FileRangeCapabilities.full]];
  10. for (const block of [
  11. sfc.script,
  12. sfc.scriptSetup,
  13. sfc.template,
  14. ...sfc.styles,
  15. ...sfc.customBlocks,
  16. ]) {
  17. if (block) {
  18. muggle.replaceSourceRange(str, undefined, block.startTagEnd, block.endTagStart, [
  19. block.content,
  20. undefined,
  21. block.startTagEnd,
  22. {},
  23. ]);
  24. }
  25. }
  26. return str.map((m) => {
  27. const text = m[0];
  28. const start = m[2];
  29. const end = start + text.length;
  30. return {
  31. sourceRange: [start, end],
  32. generatedRange: [start, end],
  33. data: m[3],
  34. };
  35. });
  36. });
  37. }
  38. exports.computedMappings = computedMappings;
  39. //# sourceMappingURL=computedMappings.js.map