Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/CustomFunction.js → custom-function.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/// <reference path="./src/renderer/types/modules.d.ts" />
import { transform } from '@babel/standalone'
import { Interpreter, Function } from 'eval5'
Interpreter.global = window

export class CustomFunction {
constructor(...argv) {
constructor(...argv: string[]) {
if (argv.length > 0) {
const lastArg = argv[argv.length - 1]
// 将代码包装在函数中以避免顶层 return 语句报错
Expand All @@ -14,14 +15,14 @@ export class CustomFunction {
})
// 提取转换后的代码,移除包装函数
const transformedCode = res.code
.replace(/^\(function\s*\(\)\s*\{/, '') // 移除开头的包装
?.replace(/^\(function\s*\(\)\s*\{/, '') // 移除开头的包装
.replace(/\}\)\(\);?$/, '') // 移除结尾的包装
.trim()
.trim() || ''
argv[argv.length - 1] = transformedCode
}

const Fn = Function
const Fn = Function as unknown as new (...args: string[]) => Function

return new Fn(...argv)
}
}
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"pub": "pnpm publish --no-git-checks --access=public"
"pub": "pnpm publish --no-git-checks --access=public",
"build:types": "tsc --emitDeclarationOnly",
"type-check": "tsc --noEmit"
},
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/index.js"
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./types": {
"types": "./dist/index.d.ts"
}
},
"repository": {
Expand All @@ -43,20 +50,24 @@
"postcss-selector-parser": "^7.1.0"
},
"devDependencies": {
"@babel/standalone": "^7.23.0",
"@types/babel__core": "^7.20.5",
"@types/lodash": "^4.17.20",
"@types/node": "^20.19.11",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.9.2",
"@opentiny/vue": "3.25.0",
"@opentiny/vue-theme": "3.25.0",
"@opentiny/vue-icon": "3.25.0",
"@opentiny/vue-chart-bar": "~3.14.0",
"@opentiny/vue-chart-histogram": "~3.14.0",
"@opentiny/vue-chart-line": "~3.14.0",
"@opentiny/vue-chart-pie": "~3.14.0",
"@opentiny/vue-chart-radar": "~3.14.0",
"@opentiny/vue-chart-ring": "3.14.0",
"@opentiny/vue-icon": "3.25.0",
"@vitejs/plugin-vue": "^5.1.2",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"eval5": "^1.4.8",
"vite": "^5.4.2",
"vue": "^3.5.0"
}
}
}
136 changes: 0 additions & 136 deletions renderer/RenderMain.js

This file was deleted.

Loading