wip: transform KeepAlive to VaporKeepAlive

This commit is contained in:
daiwei 2025-04-14 16:26:56 +08:00
parent 6efc7ec3a7
commit c9de3fb540
3 changed files with 27 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import { genEventHandler } from './event'
import { genDirectiveModifiers, genDirectivesForElement } from './directive'
import { genBlock } from './block'
import { genModelHandler } from './vModel'
import { isBuiltInComponent } from '../utils'
export function genCreateComponent(
operation: CreateComponentIRNode,
@ -92,8 +93,15 @@ export function genCreateComponent(
} else if (operation.asset) {
return toValidAssetId(operation.tag, 'component')
} else {
const { tag } = operation
const builtInTag = isBuiltInComponent(tag)
if (builtInTag) {
// @ts-expect-error
helper(builtInTag)
return `_${builtInTag}`
}
return genExpression(
extend(createSimpleExpression(operation.tag, false), { ast: null }),
extend(createSimpleExpression(tag, false), { ast: null }),
context,
)
}

View File

@ -36,7 +36,7 @@ import {
type VaporDirectiveNode,
} from '../ir'
import { EMPTY_EXPRESSION } from './utils'
import { findProp } from '../utils'
import { findProp, isBuiltInComponent } from '../utils'
export const isReservedProp: (key: string) => boolean = /*#__PURE__*/ makeMap(
// the leading comma is intentional so empty string "" is also included
@ -109,6 +109,12 @@ function transformComponentElement(
asset = false
}
const builtInTag = isBuiltInComponent(tag)
if (builtInTag) {
tag = builtInTag
asset = false
}
const dotIndex = tag.indexOf('.')
if (dotIndex > 0) {
const ns = resolveSetupReference(tag.slice(0, dotIndex), context)

View File

@ -88,3 +88,14 @@ export function getLiteralExpressionValue(
}
return exp.isStatic ? exp.content : null
}
export function isKeepAliveTag(tag: string): boolean {
tag = tag.toLowerCase()
return tag === 'keepalive' || tag === 'vaporkeepalive'
}
export function isBuiltInComponent(tag: string): string | undefined {
if (isKeepAliveTag(tag)) {
return 'VaporKeepAlive'
}
}