Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhe141 committed Aug 29, 2024
1 parent a87987c commit d5c9c13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 19 additions & 1 deletion packages/compiler-core/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ describe('compiler: v-for', () => {
expect(onError).toHaveBeenCalledTimes(1)
})

test('the value in binding metadata cannot be used as a parameter.', () => {
test('the parameter name cannot be the same as the component name.', () => {
const onError1 = vi.fn()
parseWithForTransform('<Comp v-for="Comp of list" />', {
onError: onError1,
Expand All @@ -342,6 +342,24 @@ describe('compiler: v-for', () => {
code: ErrorCodes.X_V_FOR_PARAMS,
}),
)

const onError3 = vi.fn()
parseWithForTransform(
`<div v-for="Comp of list">
<div>
<Comp>{{ Comp }}</Comp>
</div>
</div>`,
{
onError: onError3,
},
)
expect(onError3).toHaveBeenCalledTimes(1)
expect(onError3).toHaveBeenCalledWith(
expect.objectContaining({
code: ErrorCodes.X_V_FOR_PARAMS,
}),
)
})
})

Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ function findTag(
node: VNodeCall | ElementNode,
name: string,
): VNodeCall | ElementNode | undefined {
if (node.tag === `$setup["${name}"]` || node.tag === `_component_${name}`)
if (
node.tag === name ||
node.tag === `$setup["${name}"]` ||
node.tag === `_component_${name}`
)
return node
if (node.children) {
const children = node.children as TemplateChildNode[]
Expand Down

0 comments on commit d5c9c13

Please sign in to comment.