Skip to content

Commit e32c04e

Browse files
committed
refactor: use inline compile
1 parent 78178de commit e32c04e

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

playground/vapor/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
},
1010
"devDependencies": {
1111
"@vitejs/plugin-vue": "^5.0.2",
12-
"@vue-macros/define-render": "^1.5.1",
13-
"@vue-macros/reactivity-transform": "^0.4.2",
1412
"@vue-macros/volar": "^0.18.10",
1513
"unplugin-vue-jsx-vapor": "workspace:*",
1614
"vite": "^5.0.4",

playground/vapor/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
plugins: [
1111
Vue(),
1212
VueJsxVapor({
13-
compile: compile as any,
13+
compile,
1414
}),
1515
defineRender(),
1616
Inspect(),

pnpm-lock.yaml

Lines changed: 13 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/transform.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,18 @@ export function transformVueJsxVapor(
149149
: node,
150150
)
151151
if (options?.compile && isJSXExpression(node)) {
152-
let { code } = options.compile(content, { mode: 'module' })
152+
let { code, preamble } = options.compile(content, { mode: 'module', inline: true })
153+
preamble.match(/(\w+ as \w+)/g)?.forEach(s => importSet.add(s))
154+
runtime = preamble.match(/(["'].*["'])/)![1]
153155
if (content.includes('<slot ')) {
154156
code = code.replace('_ctx', '_ctx = _getCurrentInstance().ctx')
155157
importSet.add('getCurrentInstance as _getCurrentInstance')
156158
}
157-
return `(${
158-
code
159-
.replace('_cache)', '_cache = []) => ')
159+
code = code
160+
.replace('_cache', '_cache = []')
160161
.replaceAll(/_ctx\.(?!\$slots)/g, '')
161162
.replaceAll(/_resolveComponent\("(.*)"\)/g, ($0, $1) => `(() => { try { return ${$1} } catch { return ${$0} } })()`)
162-
.replace(/(?:import {(.*)} from (.*))?[\s\S]*export function render/, (_, $1, $2) => {
163-
$1?.split(',').map((s: string) => importSet.add(s.trim()))
164-
runtime = $2
165-
return ''
166-
})
167-
})()`
163+
return runtime === '"vue"' ? `(${code})()` : code
168164
}
169165
else {
170166
return content

0 commit comments

Comments
 (0)