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

Commit da8c015

Browse files
committed
fix: error with v-show
1 parent af855de commit da8c015

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,28 @@ describe('compiler: transform <slot> outlets', () => {
368368
})
369369
})
370370

371+
test(`error on unexpected v-show on <slot>`, () => {
372+
const onError = vi.fn()
373+
const source = `<slot v-show />`
374+
parseWithSlots(source, { onError })
375+
const index = source.indexOf('v-show')
376+
expect(onError.mock.calls[0][0]).toMatchObject({
377+
code: ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
378+
loc: {
379+
start: {
380+
offset: index,
381+
line: 1,
382+
column: index + 1,
383+
},
384+
end: {
385+
offset: index + 5,
386+
line: 1,
387+
column: index + 6,
388+
},
389+
},
390+
})
391+
})
392+
371393
test(`error on unexpected custom directive on <slot>`, () => {
372394
const onError = vi.fn()
373395
const source = `<slot v-foo />`

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import {
1818
IRNodeTypes,
1919
type IRProps,
2020
type VaporDirectiveNode,
21+
type WithDirectiveIRNode,
2122
} from '../ir'
22-
import { camelize, extend, isBuiltInDirective } from '@vue/shared'
23+
import { camelize, extend } from '@vue/shared'
2324
import { newBlock } from './utils'
2425
import { buildProps } from './transformElement'
2526

@@ -37,7 +38,6 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
3738

3839
let name: SimpleExpressionNode | undefined
3940
const nonNameProps: (AttributeNode | DirectiveNode)[] = []
40-
const directives: DirectiveNode[] = []
4141
for (const prop of props) {
4242
if (prop.type === NodeTypes.ATTRIBUTE) {
4343
if (prop.value) {
@@ -59,8 +59,6 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
5959
)
6060
name.ast = null
6161
}
62-
} else if (!isBuiltInDirective(prop.name)) {
63-
directives.push(prop)
6462
} else {
6563
const nonProp = extend({}, prop)
6664
if (nonProp.name === 'bind' && nonProp.arg && isStaticExp(nonProp.arg)) {
@@ -72,15 +70,6 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
7270
}
7371
}
7472

75-
if (directives.length) {
76-
context.options.onError(
77-
createCompilerError(
78-
ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
79-
directives[0].loc,
80-
),
81-
)
82-
}
83-
8473
name ||= createSimpleExpression('default', true)
8574
let irProps: IRProps[] = []
8675
if (nonNameProps.length > 0) {
@@ -90,6 +79,20 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
9079
true,
9180
)
9281
irProps = isDynamic ? props : [props]
82+
83+
const { operation } = context.block
84+
const directives = operation.filter(
85+
oper => oper.type === IRNodeTypes.WITH_DIRECTIVE,
86+
) as WithDirectiveIRNode[]
87+
88+
if (directives.length) {
89+
context.options.onError(
90+
createCompilerError(
91+
ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
92+
directives[0].dir.loc,
93+
),
94+
)
95+
}
9396
}
9497

9598
return () => {

0 commit comments

Comments
 (0)