wip: adjust slot props compilation

This commit is contained in:
Evan You 2024-12-08 11:02:11 +08:00
parent f8a7046e65
commit 9a8645d0c5
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 7 additions and 16 deletions

View File

@ -342,7 +342,7 @@ function genSlotBlockWithProps(oper: SlotBlockIRNode, context: CodegenContext) {
rawProps = props.content rawProps = props.content
if ((isDestructureAssignment = !!props.ast)) { if ((isDestructureAssignment = !!props.ast)) {
;[depth, exitScope] = context.enterScope() ;[depth, exitScope] = context.enterScope()
propsName = `_ctx${depth}` propsName = `_slotProps${depth}`
walkIdentifiers( walkIdentifiers(
props.ast, props.ast,
(id, _, __, ___, isLocal) => { (id, _, __, ___, isLocal) => {
@ -357,26 +357,17 @@ function genSlotBlockWithProps(oper: SlotBlockIRNode, context: CodegenContext) {
const idMap: Record<string, string | null> = {} const idMap: Record<string, string | null> = {}
Array.from(idsOfProps).forEach( idsOfProps.forEach(
(id, idIndex) => id =>
(idMap[id] = isDestructureAssignment ? `${propsName}[${idIndex}]` : null), (idMap[id] = isDestructureAssignment
? `${propsName}[${JSON.stringify(id)}]`
: null),
) )
let blockFn = context.withId( const blockFn = context.withId(
() => genBlock(oper, context, [propsName]), () => genBlock(oper, context, [propsName]),
idMap, idMap,
) )
exitScope && exitScope() exitScope && exitScope()
if (isDestructureAssignment) {
const idMap: Record<string, null> = {}
idsOfProps.forEach(id => (idMap[id] = null))
blockFn = genCall(
context.vaporHelper('withDestructure'),
['(', rawProps, ') => ', ...genMulti(DELIMITERS_ARRAY, ...idsOfProps)],
blockFn,
)
}
return blockFn return blockFn
} }