版博士V2.0程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chunk-SC6F2W53.js 1.5 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/index.ts
  2. var _common = require('@vue-macros/common');
  3. function transformDefineRender(code, id) {
  4. if (!code.includes(_common.DEFINE_RENDER))
  5. return;
  6. const lang = _common.getLang.call(void 0, id);
  7. const program = _common.babelParse.call(void 0, code, lang === "vue" ? "js" : lang);
  8. const nodes = [];
  9. _common.walkAST.call(void 0, program, {
  10. enter(node, parent) {
  11. if (node.type !== "ExpressionStatement" || !_common.isCallOf.call(void 0, node.expression, _common.DEFINE_RENDER) || parent.type !== "BlockStatement")
  12. return;
  13. nodes.push({
  14. parent,
  15. node,
  16. arg: node.expression.arguments[0]
  17. });
  18. }
  19. });
  20. if (nodes.length === 0)
  21. return;
  22. const s = new (0, _common.MagicString)(code);
  23. for (const { parent, node, arg } of nodes) {
  24. const returnStmt = parent.body.find(
  25. (node2) => node2.type === "ReturnStatement"
  26. );
  27. if (returnStmt)
  28. s.removeNode(returnStmt);
  29. const index = returnStmt ? returnStmt.start : parent.end - 1;
  30. const shouldAddFn = !_common.isFunctionType.call(void 0, arg) && arg.type !== "Identifier";
  31. s.appendLeft(index, `return ${shouldAddFn ? "() => (" : ""}`);
  32. s.moveNode(arg, index);
  33. if (shouldAddFn)
  34. s.appendRight(index, `)`);
  35. s.remove(node.start, arg.start);
  36. s.remove(arg.end, node.end);
  37. }
  38. return _common.getTransformResult.call(void 0, s, id);
  39. }
  40. exports.transformDefineRender = transformDefineRender;