Skip to content

Commit c9de3fb

Browse files
committed
wip: transform KeepAlive to VaporKeepAlive
1 parent 6efc7ec commit c9de3fb

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/compiler-vapor/src/generators/component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { genEventHandler } from './event'
3939
import { genDirectiveModifiers, genDirectivesForElement } from './directive'
4040
import { genBlock } from './block'
4141
import { genModelHandler } from './vModel'
42+
import { isBuiltInComponent } from '../utils'
4243

4344
export function genCreateComponent(
4445
operation: CreateComponentIRNode,
@@ -92,8 +93,15 @@ export function genCreateComponent(
9293
} else if (operation.asset) {
9394
return toValidAssetId(operation.tag, 'component')
9495
} else {
96+
const { tag } = operation
97+
const builtInTag = isBuiltInComponent(tag)
98+
if (builtInTag) {
99+
// @ts-expect-error
100+
helper(builtInTag)
101+
return `_${builtInTag}`
102+
}
95103
return genExpression(
96-
extend(createSimpleExpression(operation.tag, false), { ast: null }),
104+
extend(createSimpleExpression(tag, false), { ast: null }),
97105
context,
98106
)
99107
}

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
type VaporDirectiveNode,
3737
} from '../ir'
3838
import { EMPTY_EXPRESSION } from './utils'
39-
import { findProp } from '../utils'
39+
import { findProp, isBuiltInComponent } from '../utils'
4040

4141
export const isReservedProp: (key: string) => boolean = /*#__PURE__*/ makeMap(
4242
// the leading comma is intentional so empty string "" is also included
@@ -109,6 +109,12 @@ function transformComponentElement(
109109
asset = false
110110
}
111111

112+
const builtInTag = isBuiltInComponent(tag)
113+
if (builtInTag) {
114+
tag = builtInTag
115+
asset = false
116+
}
117+
112118
const dotIndex = tag.indexOf('.')
113119
if (dotIndex > 0) {
114120
const ns = resolveSetupReference(tag.slice(0, dotIndex), context)

packages/compiler-vapor/src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,14 @@ export function getLiteralExpressionValue(
8888
}
8989
return exp.isStatic ? exp.content : null
9090
}
91+
92+
export function isKeepAliveTag(tag: string): boolean {
93+
tag = tag.toLowerCase()
94+
return tag === 'keepalive' || tag === 'vaporkeepalive'
95+
}
96+
97+
export function isBuiltInComponent(tag: string): string | undefined {
98+
if (isKeepAliveTag(tag)) {
99+
return 'VaporKeepAlive'
100+
}
101+
}

0 commit comments

Comments
 (0)