From: zhiyuanzmj <260480378@qq.com> Date: Thu, 15 May 2025 06:43:02 +0000 (+0800) Subject: test(compiler-vapor): add index test for v-for (#13004) X-Git-Tag: v3.6.0-alpha.1~16^2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5036f91ca4c2fa0ee2bcb7b12693977b2f3916de;p=thirdparty%2Fvuejs%2Fcore.git test(compiler-vapor): add index test for v-for (#13004) --- diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap index cb14f56afd..e3631f1589 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap @@ -115,6 +115,21 @@ export function render(_ctx) { }" `; +exports[`compiler: v-for > object value, key and index 1`] = ` +"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +const t0 = _template("
", true) + +export function render(_ctx) { + const n0 = _createFor(() => (_ctx.list), (_for_item0, _for_key0, _for_index0) => { + const n2 = t0() + const x2 = _child(n2) + _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value + _for_key0.value + _for_index0.value))) + return n2 + }, (value, key, index) => (key)) + return n0 +}" +`; + exports[`compiler: v-for > v-for aliases w/ complex expressions 1`] = ` "import { getDefaultValue as _getDefaultValue, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template("
", true) diff --git a/packages/compiler-vapor/__tests__/transforms/vFor.spec.ts b/packages/compiler-vapor/__tests__/transforms/vFor.spec.ts index 0008df7f4c..47a110fdba 100644 --- a/packages/compiler-vapor/__tests__/transforms/vFor.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vFor.spec.ts @@ -119,6 +119,32 @@ describe('compiler: v-for', () => { }) }) + test('object value, key and index', () => { + const { code, ir } = compileWithVFor( + `
{{ value + key + index }}
`, + ) + expect(code).matchSnapshot() + expect(ir.block.operation[0]).toMatchObject({ + type: IRNodeTypes.FOR, + source: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: 'list', + }, + value: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: 'value', + }, + key: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: 'key', + }, + index: { + type: NodeTypes.SIMPLE_EXPRESSION, + content: 'index', + }, + }) + }) + test('object de-structured value', () => { const { code, ir } = compileWithVFor( '{{ id }}{{ value }}',