diff --git a/packages/uni-mp-compiler/__tests__/vFor.spec.ts b/packages/uni-mp-compiler/__tests__/vFor.spec.ts index 0d21865c12fdb135bf1ec4d937e001b91e4ab94f..7b7a8109da288e5aceb723b2fb706091e6180cbc 100644 --- a/packages/uni-mp-compiler/__tests__/vFor.spec.ts +++ b/packages/uni-mp-compiler/__tests__/vFor.spec.ts @@ -32,7 +32,14 @@ describe(`compiler: v-for`, () => { test(`number expression`, () => { assert( ``, - ``, + ``, + `(_ctx, _cache) => { + return { a: _f(5, (index, k0, i0) => { return {}; }) } +}` + ) + assert( + ``, + ``, `(_ctx, _cache) => { return { a: _f(5, (index, k0, i0) => { return {}; }) } }` diff --git a/packages/uni-mp-compiler/src/template/codegen.ts b/packages/uni-mp-compiler/src/template/codegen.ts index ad6ce923af5a6564350fea6fbcd5f77b0e639256..3ba4222c93f646157805d2016ee81ddf0d3ab68a 100644 --- a/packages/uni-mp-compiler/src/template/codegen.ts +++ b/packages/uni-mp-compiler/src/template/codegen.ts @@ -123,11 +123,15 @@ function genVFor( node: ForElementNode, { push, directive }: TemplateCodegenContext ) { - const { sourceCode, valueAlias } = node.vFor + const { sourceCode, valueAlias, indexAlias } = node.vFor push(` ${directive}for="${sourceCode}"`) + debugger if (valueAlias) { push(` ${directive}for-item="${valueAlias}"`) } + if (valueAlias === 'index') { + push(` ${directive}for-index="${indexAlias}"`) + } const keyProp = findProp(node, 'key', true) if (keyProp) { const key = ((keyProp as DirectiveNode).exp as SimpleExpressionNode).content