vue-sfc-scripts.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const language_core_1 = require("@volar/language-core");
  4. const scriptFormatReg = /^(.*)\.script_format\.([^.]+)$/;
  5. const scriptSetupFormatReg = /^(.*)\.scriptSetup_format\.([^.]+)$/;
  6. const plugin = () => {
  7. return {
  8. version: 1,
  9. getEmbeddedFileNames(fileName, sfc) {
  10. const names = [];
  11. if (sfc.script) {
  12. names.push(fileName + '.script_format.' + sfc.script.lang);
  13. }
  14. if (sfc.scriptSetup) {
  15. names.push(fileName + '.scriptSetup_format.' + sfc.scriptSetup.lang);
  16. }
  17. return names;
  18. },
  19. resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
  20. const scriptMatch = embeddedFile.fileName.match(scriptFormatReg);
  21. const scriptSetupMatch = embeddedFile.fileName.match(scriptSetupFormatReg);
  22. const script = scriptMatch ? sfc.script : scriptSetupMatch ? sfc.scriptSetup : undefined;
  23. if (script) {
  24. embeddedFile.kind = language_core_1.FileKind.TextFile;
  25. embeddedFile.capabilities = {
  26. ...language_core_1.FileCapabilities.full,
  27. diagnostic: false,
  28. codeAction: false,
  29. inlayHint: false,
  30. };
  31. embeddedFile.content.push([
  32. script.content,
  33. script.name,
  34. 0,
  35. {},
  36. ]);
  37. }
  38. },
  39. };
  40. };
  41. exports.default = plugin;
  42. //# sourceMappingURL=vue-sfc-scripts.js.map