Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit aba4e57

Browse files
committed
handle v-for to singleRoot
1 parent da75dd9 commit aba4e57

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
transformElement,
77
transformText,
88
transformVBind,
9+
transformVFor,
910
transformVOn,
1011
} from '../../src'
1112
import {
@@ -15,7 +16,12 @@ import {
1516
} from '@vue/compiler-core'
1617

1718
const compileWithElementTransform = makeCompile({
18-
nodeTransforms: [transformElement, transformChildren, transformText],
19+
nodeTransforms: [
20+
transformVFor,
21+
transformElement,
22+
transformChildren,
23+
transformText,
24+
],
1925
directiveTransforms: {
2026
bind: transformVBind,
2127
on: transformVOn,
@@ -185,6 +191,16 @@ describe('compiler: element transform', () => {
185191
expect(code).contains('_createComponent(_ctx.Comp, null, null, true)')
186192
})
187193

194+
test('generate root component with v-for', () => {
195+
const { code } = compileWithElementTransform(
196+
`<Comp v-for="i in 1000"/>`,
197+
{
198+
bindingMetadata: { Comp: BindingTypes.SETUP_CONST },
199+
},
200+
)
201+
expect(code).contains('_createComponent(_ctx.Comp)')
202+
})
203+
188204
test('generate multi root component', () => {
189205
const { code } = compileWithElementTransform(`<Comp/>123`, {
190206
bindingMetadata: { Comp: BindingTypes.SETUP_CONST },

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const transformElement: NodeTransform = (node, context) => {
7575
}
7676
const singleRoot =
7777
context.root === parent &&
78+
!parent.ir.source.includes('v-for') &&
7879
parent.node.children.filter(child => child.type !== NodeTypes.COMMENT)
7980
.length === 1
8081

0 commit comments

Comments
 (0)