版博士V2.0程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

chunk-WBLV57HP.mjs 808 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // src/core/index.ts
  2. import {
  3. DEFINE_PROPS,
  4. DEFINE_PROPS_DOLLAR,
  5. MagicString,
  6. getTransformResult,
  7. isCallOf,
  8. parseSFC,
  9. walkAST
  10. } from "@vue-macros/common";
  11. function transformDefineProps(code, id) {
  12. if (!code.includes(DEFINE_PROPS_DOLLAR))
  13. return;
  14. const { scriptSetup, getSetupAst } = parseSFC(code, id);
  15. if (!scriptSetup)
  16. return;
  17. const offset = scriptSetup.loc.start.offset;
  18. const s = new MagicString(code);
  19. const setupAst = getSetupAst();
  20. walkAST(setupAst, {
  21. enter(node) {
  22. if (isCallOf(node, DEFINE_PROPS_DOLLAR)) {
  23. s.overwriteNode(
  24. node.callee,
  25. // add space for fixing mapping
  26. ` ${DEFINE_PROPS}`,
  27. { offset }
  28. );
  29. }
  30. }
  31. });
  32. return getTransformResult(s, id);
  33. }
  34. export {
  35. transformDefineProps
  36. };