Skip to content

Commit

Permalink
chore: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhe141 committed Sep 24, 2024
1 parent 3edffcb commit b709510
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`compiler: v-memo transform > element v-for key expression prefixing + v-memo 1`] = `
"import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, isMemoSame as _isMemoSame, withMemo as _withMemo } from "vue"
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.tableData, (data, __, ___, _cached) => {
const _memo = (_ctx.getLetter(data))
if (_cached && _cached.key === _ctx.getId(data) && _isMemoSame(_cached, _memo)) return _cached
const _item = (_openBlock(), _createElementBlock("span", {
key: _ctx.getId(data)
}))
_item.memo = _memo
return _item
}, _cache, 0), 128 /* KEYED_FRAGMENT */))
]))
}"
`;

exports[`compiler: v-memo transform > on component 1`] = `
"import { resolveComponent as _resolveComponent, createVNode as _createVNode, withMemo as _withMemo, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
Expand Down
23 changes: 0 additions & 23 deletions packages/compiler-core/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,29 +667,6 @@ describe('compiler: v-for', () => {
})
})

test('element v-for key expression prefixing + v-memo', () => {
const {
node: { codegenNode },
} = parseWithForTransform(
'<span v-for="data of tableData" :key="getId(data)" v-memo="getLetter(data)"></span>',
{ prefixIdentifiers: true },
)
const keyExp =
// @ts-expect-error
codegenNode.children.arguments[1].body.body[1].children[2]
expect(keyExp).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
// should prefix outer scope references
{ content: `_ctx.getId` },
`(`,
// should NOT prefix in scope variables
{ content: `data` },
`)`,
],
})
})

test('template v-for key no prefixing on attribute key', () => {
const {
node: { codegenNode },
Expand Down
28 changes: 6 additions & 22 deletions packages/compiler-core/__tests__/transforms/vMemo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NodeTypes, baseCompile } from '../../src'
import { parseWithForTransform } from './vFor.spec'
import { baseCompile } from '../../src'

describe('compiler: v-memo transform', () => {
function compile(content: string) {
Expand Down Expand Up @@ -56,25 +55,10 @@ describe('compiler: v-memo transform', () => {
})

test('element v-for key expression prefixing + v-memo', () => {
const {
node: { codegenNode },
} = parseWithForTransform(
'<span v-for="data of tableData" :key="getId(data)" v-memo="getLetter(data)"></span>',
{ prefixIdentifiers: true },
)
const keyExp =
// @ts-expect-error
codegenNode.children.arguments[1].body.body[1].children[2]
expect(keyExp).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
// should prefix outer scope references
{ content: `_ctx.getId` },
`(`,
// should NOT prefix in scope variables
{ content: `data` },
`)`,
],
})
expect(
compile(
`<span v-for="data of tableData" :key="getId(data)" v-memo="getLetter(data)"></span>`,
),
).toMatchSnapshot()
})
})

0 comments on commit b709510

Please sign in to comment.