Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(compiler-vapor): add index test for v-for #13004

Open
wants to merge 4 commits into
base: vapor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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("<div> </div>", 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("<div> </div>", true)
Expand Down
26 changes: 26 additions & 0 deletions packages/compiler-vapor/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ describe('compiler: v-for', () => {
})
})

test('object value, key and index', () => {
const { code, ir } = compileWithVFor(
`<div v-for="(value, key, index) in list" :key="key">{{ value + key + index }}</div>`,
)
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(
'<span v-for="({ id, value }) in items" :key="id">{{ id }}{{ value }}</span>',
Expand Down