import { transformOn } from '../../src/transforms/vOn'
import { transformBind } from '../../src/transforms/vBind'
import { transformExpression } from '../../src/transforms/transformExpression'
+import { transformSlotOutlet } from '../../src/transforms/transformSlotOutlet'
import {
trackSlotScopes,
trackVForSlotScopes
...(options.prefixIdentifiers
? [trackVForSlotScopes, transformExpression]
: []),
+ transformSlotOutlet,
transformElement,
trackSlotScopes
],
expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot()
})
- test('generate flag on forwarded slots', () => {
- const { slots } = parseWithSlots(`<Comp><slot/></Comp>`)
- expect(slots).toMatchObject({
+ describe('forwarded slots', () => {
+ const toMatch = {
type: NodeTypes.JS_OBJECT_EXPRESSION,
properties: [
{
value: { content: `3 /* FORWARDED */` }
}
]
+ }
+ test('<slot> tag only', () => {
+ const { slots } = parseWithSlots(`<Comp><slot/></Comp>`)
+ expect(slots).toMatchObject(toMatch)
+ })
+
+ test('<slot> tag w/ v-if', () => {
+ const { slots } = parseWithSlots(`<Comp><slot v-if="ok"/></Comp>`)
+ expect(slots).toMatchObject(toMatch)
+ })
+
+ test('<slot> tag w/ v-for', () => {
+ const { slots } = parseWithSlots(`<Comp><slot v-for="a in b"/></Comp>`)
+ expect(slots).toMatchObject(toMatch)
})
})
function hasForwardedSlots(children: TemplateChildNode[]): boolean {
for (let i = 0; i < children.length; i++) {
const child = children[i]
- if (child.type === NodeTypes.ELEMENT) {
- if (
- child.tagType === ElementTypes.SLOT ||
- (child.tagType === ElementTypes.ELEMENT &&
- hasForwardedSlots(child.children))
- ) {
- return true
- }
+ switch (child.type) {
+ case NodeTypes.ELEMENT:
+ if (
+ child.tagType === ElementTypes.SLOT ||
+ (child.tagType === ElementTypes.ELEMENT &&
+ hasForwardedSlots(child.children))
+ ) {
+ return true
+ }
+ break
+ case NodeTypes.IF:
+ if (hasForwardedSlots(child.branches)) return true
+ break
+ case NodeTypes.IF_BRANCH:
+ case NodeTypes.FOR:
+ if (hasForwardedSlots(child.children)) return true
+ break
+ default:
+ break
}
}
return false