Skip to content

Commit c59359f

Browse files
committed
feat: support multiple spreadAttributes
1 parent e32c04e commit c59359f

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

playground/virtual-dom/App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="tsx" setup>
22
import { ref } from 'vue'
33
import For from './for.vue'
4+
import Bind from './bind.vue'
45
56
const count = ref(1)
67
function Comp({ icon, getChildren }: any, { slots }: any) {
@@ -111,6 +112,11 @@ defineRender((
111112
<Comp3 />
112113
<Comp4 />
113114
115+
<div>
116+
v-bind:
117+
<Bind />
118+
</div>
119+
114120
<div>
115121
v-show:
116122
<span v-show={count.value}>

playground/virtual-dom/bind.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup lang="tsx">
2+
import { ref } from 'vue'
3+
4+
function Comp(props: any) {
5+
return (
6+
<span>
7+
{props}
8+
</span>
9+
)
10+
}
11+
12+
const count = ref(0)
13+
defineRender(
14+
<Comp
15+
id={1}
16+
v-model:value={count.value}
17+
{...{ id: 2 }}
18+
{...{
19+
id: 3,
20+
}}
21+
/>,
22+
)
23+
</script>

src/core/transform.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ export function transformVueJsxVapor(
6868
) {
6969
s.appendLeft(node.end! - 1, 'template')
7070
}
71-
else if (node.type === 'JSXSpreadAttribute') {
72-
s.appendLeft(node.start!, 'v-bind=')
71+
else if (node.type === 'JSXSpreadAttribute' && parent?.type === 'JSXOpeningElement') {
72+
const index = parent.attributes
73+
.filter(attr => attr.type === 'JSXSpreadAttribute')
74+
.findIndex(attr => attr === node)
75+
s.appendLeft(node.start!, `${index ? `:v${index}` : 'v'}-bind=`)
7376
s.overwrite(node.start!, node.argument.start!, '"')
7477
s.overwrite(node.end! - 1, node.end!, '"')
7578
}
@@ -159,6 +162,7 @@ export function transformVueJsxVapor(
159162
code = code
160163
.replace('_cache', '_cache = []')
161164
.replaceAll(/_ctx\.(?!\$slots)/g, '')
165+
.replaceAll(/{ "v\d+\-bind": ([\s\S]*) }/g, '$1')
162166
.replaceAll(/_resolveComponent\("(.*)"\)/g, ($0, $1) => `(() => { try { return ${$1} } catch { return ${$0} } })()`)
163167
return runtime === '"vue"' ? `(${code})()` : code
164168
}

0 commit comments

Comments
 (0)