版博士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.
 
 
 
 

38 lines
808 B

  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. };