版博士V2.0程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

chunk-4UG6XAEW.mjs 2.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {
  2. babelParse
  3. } from "./chunk-FUD65UAQ.mjs";
  4. import {
  5. getLang
  6. } from "./chunk-X26ALPRY.mjs";
  7. import {
  8. REGEX_VUE_SFC
  9. } from "./chunk-TDSRBKSQ.mjs";
  10. // src/vue.ts
  11. import { parse } from "@vue/compiler-sfc";
  12. function parseSFC(code, id) {
  13. var _a;
  14. const sfc = parse(code, {
  15. filename: id
  16. });
  17. const { descriptor, errors } = sfc;
  18. const lang = (_a = descriptor.script || descriptor.scriptSetup) == null ? void 0 : _a.lang;
  19. return {
  20. sfc,
  21. ...descriptor,
  22. lang,
  23. errors,
  24. getSetupAst() {
  25. if (!descriptor.scriptSetup)
  26. return;
  27. return babelParse(descriptor.scriptSetup.content, lang);
  28. },
  29. getScriptAst() {
  30. if (!descriptor.script)
  31. return;
  32. return babelParse(descriptor.script.content, lang);
  33. }
  34. };
  35. }
  36. function getFileCodeAndLang(code, id) {
  37. var _a;
  38. if (!REGEX_VUE_SFC.test(id))
  39. return { code, lang: getLang(id) };
  40. const sfc = parseSFC(code, id);
  41. const scriptCode = ((_a = sfc.script) == null ? void 0 : _a.content) ?? "";
  42. return {
  43. code: sfc.scriptSetup ? `${scriptCode}
  44. ;
  45. ${sfc.scriptSetup.content}` : scriptCode,
  46. lang: sfc.lang ?? "js"
  47. };
  48. }
  49. function addNormalScript({ script, lang }, s) {
  50. return {
  51. start() {
  52. if (script)
  53. return script.loc.end.offset;
  54. const attrs = lang ? ` lang="${lang}"` : "";
  55. s.prependLeft(0, `<script${attrs}>`);
  56. return 0;
  57. },
  58. end() {
  59. if (!script)
  60. s.appendRight(0, `
  61. </script>
  62. `);
  63. }
  64. };
  65. }
  66. var imported = /* @__PURE__ */ new WeakMap();
  67. var HELPER_PREFIX = "__MACROS_";
  68. function importHelperFn(s, offset, name, from) {
  69. var _a;
  70. const cacheKey = `${from}@${name}`;
  71. if (!((_a = imported.get(s)) == null ? void 0 : _a.has(cacheKey))) {
  72. s.appendLeft(
  73. offset,
  74. `
  75. import { ${name} as ${HELPER_PREFIX}${name} } from '${from}';`
  76. );
  77. if (!imported.has(s)) {
  78. imported.set(s, /* @__PURE__ */ new Set([cacheKey]));
  79. } else {
  80. imported.get(s).add(cacheKey);
  81. }
  82. }
  83. }
  84. export {
  85. parseSFC,
  86. getFileCodeAndLang,
  87. addNormalScript,
  88. HELPER_PREFIX,
  89. importHelperFn
  90. };