diff --git a/packages/uni-mp-compiler/__tests__/slot.spec.ts b/packages/uni-mp-compiler/__tests__/slot.spec.ts index 98931b21283f43b2e44575fcd0e622563ac086ce..241be5429fa86a005ef6802e429e36bcfc4b1722 100644 --- a/packages/uni-mp-compiler/__tests__/slot.spec.ts +++ b/packages/uni-mp-compiler/__tests__/slot.spec.ts @@ -23,6 +23,13 @@ describe('compiler: transform slot', () => { ``, `(_ctx, _cache) => { return { a: _d(_ctx.name) } +}` + ) + assert( + ``, + ``, + `(_ctx, _cache) => { + return { a: _d('title' + _ctx.index), b: _r(_d('title' + _ctx.index), { content: { name: 'name1' } }) } }` ) }) diff --git a/packages/uni-mp-compiler/src/transforms/transformSlot.ts b/packages/uni-mp-compiler/src/transforms/transformSlot.ts index 36fde080ff2122274bef71496779de876d95cd11..462788d022987526f8f9a2fb4e76496545c0b852 100644 --- a/packages/uni-mp-compiler/src/transforms/transformSlot.ts +++ b/packages/uni-mp-compiler/src/transforms/transformSlot.ts @@ -53,15 +53,12 @@ export function rewriteSlot(node: SlotOutletNode, context: TransformContext) { } if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) { if (p.exp) { - p.exp = rewriteExpression( - createCompoundExpression([ - context.helperString(DYNAMIC_SLOT) + '(', - p.exp, - ')', - ]), - context - ) - slotName = p.exp + slotName = createCompoundExpression([ + context.helperString(DYNAMIC_SLOT) + '(', + p.exp, + ')', + ]) + p.exp = rewriteExpression(slotName, context) } } else { if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {