}"
`;
+exports[`compiler: transform slot > nested component should not inherit parent slots 1`] = `
+"import { resolveComponent as _resolveComponent, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback } from 'vue';
+
+export function render(_ctx) {
+ const _component_Bar = _resolveComponent("Bar")
+ const _component_Foo = _resolveComponent("Foo")
+ const n2 = _createComponentWithFallback(_component_Foo, null, {
+ "header": _withVaporCtx(() => {
+ return null
+ }),
+ "default": _withVaporCtx(() => {
+ const n1 = _createComponentWithFallback(_component_Bar)
+ return n1
+ })
+ }, true)
+ return n2
+}"
+`;
+
exports[`compiler: transform slot > nested component slot 1`] = `
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, withVaporCtx as _withVaporCtx } from 'vue';
})
})
+ test('nested component should not inherit parent slots', () => {
+ const { code } = compileWithSlots(`
+ <Foo>
+ <template #header></template>
+ <Bar />
+ </Foo>
+ `)
+ expect(code).toMatchSnapshot()
+ })
+
test('named slots w/ implicit default slot', () => {
const { ir, code } = compileWithSlots(
`<Comp>
type IRProps,
type IRPropsDynamicAttribute,
type IRPropsStatic,
+ type IRSlots,
type VaporDirectiveNode,
} from '../ir'
import { EMPTY_EXPRESSION } from './utils'
export const transformElement: NodeTransform = (node, context) => {
let effectIndex = context.block.effect.length
const getEffectIndex = () => effectIndex++
+
+ // If the element is a component, we need to isolate its slots context.
+ // This ensures that slots defined for this component are not accidentally
+ // inherited by its children components.
+ let parentSlots: IRSlots[] | undefined
+ if (
+ node.type === NodeTypes.ELEMENT &&
+ (node.tagType === ElementTypes.COMPONENT ||
+ context.options.isCustomElement(node.tag))
+ ) {
+ parentSlots = context.slots
+ context.slots = []
+ }
+
return function postTransformElement() {
;({ node } = context)
if (
getEffectIndex,
)
}
+
+ if (parentSlots) {
+ context.slots = parentSlots
+ }
}
}