Skip to content

Commit c3cb610

Browse files
committed
chore: update
1 parent 2328f91 commit c3cb610

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

packages/compiler-core/src/ast.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export interface SkipNode extends Node {
416416
consequent: IfBranchNode | CallExpression
417417
alternate: IfBranchNode
418418
newline: boolean
419-
codegenNode?: ConditionalExpression
419+
codegenNode: ConditionalExpression | undefined
420420
}
421421

422422
export interface ConditionalExpression extends Node {

packages/compiler-core/src/transforms/vSkip.ts

+17-24
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,18 @@ export function processSkip(
128128
processAsSkipNode = true
129129
children = node.children
130130
} else if (isComponent) {
131-
;({ processAsSkipNode, children } = resolveDefaultSlot(
132-
node,
133-
context,
134-
processAsSkipNode,
135-
children,
136-
loc,
137-
))
131+
const { hasDynamicSlots, defaultSlot } = resolveDefaultSlot(node, context)
132+
if (!hasDynamicSlots) {
133+
if (defaultSlot) {
134+
processAsSkipNode = true
135+
// using the cloned node for ssr VNode-based slot
136+
children = context.inSSR ? clone(defaultSlot) : defaultSlot
137+
} else {
138+
context.onError(
139+
createCompilerError(ErrorCodes.X_V_SKIP_UNEXPECTED_SLOT, loc),
140+
)
141+
}
142+
}
138143
}
139144

140145
let skipNode: SkipNode | undefined
@@ -155,6 +160,7 @@ export function processSkip(
155160
consequent,
156161
alternate: createBranchNode(node, node.loc, [node]),
157162
newline: true,
163+
codegenNode: undefined,
158164
}
159165

160166
context.replaceNode(skipNode)
@@ -163,17 +169,11 @@ export function processSkip(
163169
if (processCodegen) return processCodegen(skipNode)
164170
}
165171

166-
function resolveDefaultSlot(
167-
node: ComponentNode,
168-
context: TransformContext,
169-
processAsSkipNode: boolean,
170-
children: TemplateChildNode[],
171-
loc: SourceLocation,
172-
) {
172+
function resolveDefaultSlot(node: ComponentNode, context: TransformContext) {
173+
let defaultSlot: TemplateChildNode[] | undefined = undefined
173174
const { slots, hasDynamicSlots } = buildSlots(node, context, undefined, true)
174175
// find default slot without slot props if not has dynamic slots
175176
if (!hasDynamicSlots && slots.type === NodeTypes.JS_OBJECT_EXPRESSION) {
176-
processAsSkipNode = true
177177
const prop = slots.properties.find(
178178
p =>
179179
p.type === NodeTypes.JS_PROPERTY &&
@@ -182,17 +182,10 @@ function resolveDefaultSlot(
182182
p.value.params === undefined,
183183
)
184184
if (prop) {
185-
const slotNode = prop.value.returns as TemplateChildNode[]
186-
// using the cloned node for ssr VNode-based slot
187-
children = context.inSSR ? clone(slotNode) : slotNode
188-
} else {
189-
context.onError(
190-
createCompilerError(ErrorCodes.X_V_SKIP_UNEXPECTED_SLOT, loc),
191-
)
185+
defaultSlot = prop.value.returns as TemplateChildNode[]
192186
}
193187
}
194-
195-
return { processAsSkipNode, children }
188+
return { hasDynamicSlots, defaultSlot }
196189
}
197190

198191
function createBranchNode(

0 commit comments

Comments
 (0)