Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
transformElement,
transformText,
transformVBind,
transformVFor,
transformVOn,
} from '../../src'
import {
Expand All @@ -15,7 +16,12 @@ import {
} from '@vue/compiler-core'

const compileWithElementTransform = makeCompile({
nodeTransforms: [transformElement, transformChildren, transformText],
nodeTransforms: [
transformVFor,
transformElement,
transformChildren,
transformText,
],
directiveTransforms: {
bind: transformVBind,
on: transformVOn,
Expand Down Expand Up @@ -185,6 +191,16 @@ describe('compiler: element transform', () => {
expect(code).contains('_createComponent(_ctx.Comp, null, null, true)')
})

test('generate root component with v-for', () => {
const { code } = compileWithElementTransform(
`<Comp v-for="i in 1000"/>`,
{
bindingMetadata: { Comp: BindingTypes.SETUP_CONST },
},
)
expect(code).contains('_createComponent(_ctx.Comp)')
})

test('generate multi root component', () => {
const { code } = compileWithElementTransform(`<Comp/>123`, {
bindingMetadata: { Comp: BindingTypes.SETUP_CONST },
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const transformElement: NodeTransform = (node, context) => {
}
const singleRoot =
context.root === parent &&
!parent.ir.source.includes('v-for') &&
parent.node.children.filter(child => child.type !== NodeTypes.COMMENT)
.length === 1

Expand Down