Skip to content

Commit 60fbaac

Browse files
committed
fix:优化代码
1 parent 1c6f60b commit 60fbaac

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

core/src/utils/transform.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ export const getTransformValue = (str: string, filename: string, funName: string
1111
const isReact = /import React.+from ("|')react("|')/.test(str);
1212
// 先判断 是否引入 react
1313
const tran = isReact ? str : `import React from "react"\n ${str}`;
14-
const code = `${babelTransform(tran, `${filename}`).code}`
15-
.replace(`Object.defineProperty(exports, \"__esModule\", {\n value: true\n});`, '')
16-
.replace(`exports["default"] = void 0;`, '')
17-
.replace(`exports["default"] = _default;`, `return _react["default"].createElement(_default)`);
14+
/** 先把默认导出 export default 进行替换 **/
15+
const newCode = `${tran.replace('export default', 'const _default = ')}\n`;
16+
const code = `${babelTransform(newCode, `${filename}`).code}\n return _react["default"].createElement(_default)`;
1817

1918
return `function ${funName}(){
2019
${code}

0 commit comments

Comments
 (0)