computedVueSfc.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.computedVueSfc = void 0;
  4. const computeds_1 = require("computeds");
  5. function computedVueSfc(plugins, fileName, snapshot) {
  6. let cache;
  7. return (0, computeds_1.computed)(() => {
  8. // incremental update
  9. if (cache?.plugin.updateSFC) {
  10. const change = snapshot().getChangeRange(cache.snapshot);
  11. if (change) {
  12. const newSfc = cache.plugin.updateSFC(cache.sfc, {
  13. start: change.span.start,
  14. end: change.span.start + change.span.length,
  15. newText: snapshot().getText(change.span.start, change.span.start + change.newLength),
  16. });
  17. if (newSfc) {
  18. cache.snapshot = snapshot();
  19. // force dirty
  20. cache.sfc = JSON.parse(JSON.stringify(newSfc));
  21. return cache.sfc;
  22. }
  23. }
  24. }
  25. for (const plugin of plugins) {
  26. const sfc = plugin.parseSFC?.(fileName, snapshot().getText(0, snapshot().getLength()));
  27. if (sfc) {
  28. if (!sfc.errors.length) {
  29. cache = {
  30. snapshot: snapshot(),
  31. sfc,
  32. plugin,
  33. };
  34. }
  35. return sfc;
  36. }
  37. }
  38. });
  39. }
  40. exports.computedVueSfc = computedVueSfc;
  41. //# sourceMappingURL=computedVueSfc.js.map