mirror of https://github.com/vuejs/core.git
chore: update
This commit is contained in:
parent
a952b03358
commit
c23d63582e
|
@ -76,7 +76,7 @@ export class TransformContext<T extends AllNode = AllNode> {
|
||||||
|
|
||||||
inVOnce: boolean = false
|
inVOnce: boolean = false
|
||||||
inVFor: number = 0
|
inVFor: number = 0
|
||||||
inSlot: number = 0
|
inSlot: boolean = false
|
||||||
|
|
||||||
comment: CommentNode[] = []
|
comment: CommentNode[] = []
|
||||||
component: Set<string> = this.ir.component
|
component: Set<string> = this.ir.component
|
||||||
|
|
|
@ -5,7 +5,6 @@ import {
|
||||||
ErrorCodes,
|
ErrorCodes,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
type SimpleExpressionNode,
|
type SimpleExpressionNode,
|
||||||
type TemplateChildNode,
|
|
||||||
createCompilerError,
|
createCompilerError,
|
||||||
createSimpleExpression,
|
createSimpleExpression,
|
||||||
isStaticArgOf,
|
isStaticArgOf,
|
||||||
|
@ -100,16 +99,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const {
|
if (context.inSlot) context.ir.hasForwardedSlot = true
|
||||||
block: { node: slotNode },
|
|
||||||
inSlot,
|
|
||||||
} = context
|
|
||||||
const forwarded =
|
|
||||||
inSlot !== 0 &&
|
|
||||||
slotNode.type === NodeTypes.ELEMENT &&
|
|
||||||
hasForwardedSlots(slotNode.children)
|
|
||||||
if (forwarded) context.ir.hasForwardedSlot = true
|
|
||||||
|
|
||||||
exitBlock && exitBlock()
|
exitBlock && exitBlock()
|
||||||
context.dynamic.operation = {
|
context.dynamic.operation = {
|
||||||
type: IRNodeTypes.SLOT_OUTLET_NODE,
|
type: IRNodeTypes.SLOT_OUTLET_NODE,
|
||||||
|
@ -117,7 +107,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
|
||||||
name: slotName,
|
name: slotName,
|
||||||
props: irProps,
|
props: irProps,
|
||||||
fallback,
|
fallback,
|
||||||
forwarded,
|
forwarded: context.inSlot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,20 +133,3 @@ function createFallback(
|
||||||
context.reference()
|
context.reference()
|
||||||
return [fallback, exitBlock]
|
return [fallback, exitBlock]
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasForwardedSlots(children: TemplateChildNode[]): boolean {
|
|
||||||
for (let i = 0; i < children.length; i++) {
|
|
||||||
const child = children[i]
|
|
||||||
switch (child.type) {
|
|
||||||
case NodeTypes.ELEMENT:
|
|
||||||
if (
|
|
||||||
child.tagType === ElementTypes.SLOT ||
|
|
||||||
hasForwardedSlots(child.children)
|
|
||||||
) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
|
@ -237,11 +237,11 @@ function createSlotBlock(
|
||||||
const block: SlotBlockIRNode = newBlock(slotNode)
|
const block: SlotBlockIRNode = newBlock(slotNode)
|
||||||
block.props = dir && dir.exp
|
block.props = dir && dir.exp
|
||||||
const exitBlock = context.enterBlock(block)
|
const exitBlock = context.enterBlock(block)
|
||||||
context.inSlot++
|
context.inSlot = true
|
||||||
return [
|
return [
|
||||||
block,
|
block,
|
||||||
() => {
|
() => {
|
||||||
context.inSlot--
|
context.inSlot = false
|
||||||
exitBlock()
|
exitBlock()
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -554,5 +554,56 @@ describe('component: slots', () => {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
|
expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('mixed with non-forwarded slot', async () => {
|
||||||
|
const Child = defineVaporComponent({
|
||||||
|
setup() {
|
||||||
|
return [createSlot('foo', null)]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const Parent = defineVaporComponent({
|
||||||
|
setup() {
|
||||||
|
const createForwardedSlot = forwardedSlotCreator()
|
||||||
|
const n2 = createComponent(Child, null, {
|
||||||
|
foo: () => {
|
||||||
|
const n0 = createForwardedSlot('foo', null)
|
||||||
|
return n0
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const n3 = createSlot('default', null)
|
||||||
|
return [n2, n3]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const foo = ref('foo')
|
||||||
|
const { host } = define({
|
||||||
|
setup() {
|
||||||
|
const n2 = createComponent(
|
||||||
|
Parent,
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
foo: () => {
|
||||||
|
const n0 = template(' ')() as any
|
||||||
|
renderEffect(() => setText(n0, foo.value))
|
||||||
|
return n0
|
||||||
|
},
|
||||||
|
default: () => {
|
||||||
|
const n3 = template(' ')() as any
|
||||||
|
renderEffect(() => setText(n3, foo.value))
|
||||||
|
return n3
|
||||||
|
},
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
return n2
|
||||||
|
},
|
||||||
|
}).render()
|
||||||
|
|
||||||
|
expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->foo<!--slot-->')
|
||||||
|
|
||||||
|
foo.value = 'bar'
|
||||||
|
await nextTick()
|
||||||
|
expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->bar<!--slot-->')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -93,11 +93,8 @@ export function forwardedSlotCreator(): (
|
||||||
fallback?: VaporSlot,
|
fallback?: VaporSlot,
|
||||||
) => Block {
|
) => Block {
|
||||||
const instance = currentInstance as VaporComponentInstance
|
const instance = currentInstance as VaporComponentInstance
|
||||||
return (
|
return (name, rawProps, fallback) =>
|
||||||
name: string | (() => string),
|
createSlot(name, rawProps, fallback, instance)
|
||||||
rawProps?: LooseRawProps | null,
|
|
||||||
fallback?: VaporSlot,
|
|
||||||
) => createSlot(name, rawProps, fallback, instance)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createSlot(
|
export function createSlot(
|
||||||
|
|
Loading…
Reference in New Issue