版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

93 lines
2.5 KiB

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