From 9a8645d0c5599302aa7ecb2a6bd881cfcdad7838 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 8 Dec 2024 11:02:11 +0800 Subject: [PATCH] wip: adjust slot props compilation --- .../src/generators/component.ts | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/compiler-vapor/src/generators/component.ts b/packages/compiler-vapor/src/generators/component.ts index 4ab96d3b6..8f5407304 100644 --- a/packages/compiler-vapor/src/generators/component.ts +++ b/packages/compiler-vapor/src/generators/component.ts @@ -342,7 +342,7 @@ function genSlotBlockWithProps(oper: SlotBlockIRNode, context: CodegenContext) { rawProps = props.content if ((isDestructureAssignment = !!props.ast)) { ;[depth, exitScope] = context.enterScope() - propsName = `_ctx${depth}` + propsName = `_slotProps${depth}` walkIdentifiers( props.ast, (id, _, __, ___, isLocal) => { @@ -357,26 +357,17 @@ function genSlotBlockWithProps(oper: SlotBlockIRNode, context: CodegenContext) { const idMap: Record = {} - Array.from(idsOfProps).forEach( - (id, idIndex) => - (idMap[id] = isDestructureAssignment ? `${propsName}[${idIndex}]` : null), + idsOfProps.forEach( + id => + (idMap[id] = isDestructureAssignment + ? `${propsName}[${JSON.stringify(id)}]` + : null), ) - let blockFn = context.withId( + const blockFn = context.withId( () => genBlock(oper, context, [propsName]), idMap, ) exitScope && exitScope() - if (isDestructureAssignment) { - const idMap: Record = {} - idsOfProps.forEach(id => (idMap[id] = null)) - - blockFn = genCall( - context.vaporHelper('withDestructure'), - ['(', rawProps, ') => ', ...genMulti(DELIMITERS_ARRAY, ...idsOfProps)], - blockFn, - ) - } - return blockFn }