|
|
@@ -16,8 +16,6 @@ import {
|
|
|
type TemplateChildNode,
|
|
|
type TextCallNode,
|
|
|
type TransformContext,
|
|
|
- type VNodeCall,
|
|
|
- createArrayExpression,
|
|
|
createCallExpression,
|
|
|
isStaticArgOf,
|
|
|
} from '@vue/compiler-core'
|
|
|
@@ -106,15 +104,23 @@ export const stringifyStatic: HoistTransform = (children, context, parent) => {
|
|
|
String(currentChunk.length),
|
|
|
])
|
|
|
|
|
|
+ const deleteCount = currentChunk.length - 1
|
|
|
+
|
|
|
if (isParentCached) {
|
|
|
- ;((parent.codegenNode as VNodeCall).children as CacheExpression).value =
|
|
|
- createArrayExpression([staticCall])
|
|
|
+ // if the parent is cached, then `children` is also the value of the
|
|
|
+ // CacheExpression. Just replace the corresponding range in the cached
|
|
|
+ // list with staticCall.
|
|
|
+ children.splice(
|
|
|
+ currentIndex - currentChunk.length,
|
|
|
+ currentChunk.length,
|
|
|
+ // @ts-expect-error
|
|
|
+ staticCall,
|
|
|
+ )
|
|
|
} else {
|
|
|
// replace the first node's hoisted expression with the static vnode call
|
|
|
;(currentChunk[0].codegenNode as CacheExpression).value = staticCall
|
|
|
if (currentChunk.length > 1) {
|
|
|
// remove merged nodes from children
|
|
|
- const deleteCount = currentChunk.length - 1
|
|
|
children.splice(currentIndex - currentChunk.length + 1, deleteCount)
|
|
|
// also adjust index for the remaining cache items
|
|
|
const cacheIndex = context.cached.indexOf(
|
|
|
@@ -128,9 +134,9 @@ export const stringifyStatic: HoistTransform = (children, context, parent) => {
|
|
|
}
|
|
|
context.cached.splice(cacheIndex - deleteCount + 1, deleteCount)
|
|
|
}
|
|
|
- return deleteCount
|
|
|
}
|
|
|
}
|
|
|
+ return deleteCount
|
|
|
}
|
|
|
return 0
|
|
|
}
|