-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
562 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/compiler-core/__tests__/transforms/__snapshots__/vMemo.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
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\\" | ||
export function render(_ctx, _cache) { | ||
const _component_Comp = _resolveComponent(\\"Comp\\") | ||
return (_openBlock(), _createElementBlock(\\"div\\", null, [ | ||
_withMemo([_ctx.x], () => _createVNode(_component_Comp), _cache, 0) | ||
])) | ||
}" | ||
`; | ||
|
||
exports[`compiler: v-memo transform on normal element 1`] = ` | ||
"import { openBlock as _openBlock, createElementBlock as _createElementBlock, withMemo as _withMemo } from \\"vue\\" | ||
export function render(_ctx, _cache) { | ||
return (_openBlock(), _createElementBlock(\\"div\\", null, [ | ||
_withMemo([_ctx.x], () => (_openBlock(), _createElementBlock(\\"div\\")), _cache, 0) | ||
])) | ||
}" | ||
`; | ||
|
||
exports[`compiler: v-memo transform on root element 1`] = ` | ||
"import { openBlock as _openBlock, createElementBlock as _createElementBlock, withMemo as _withMemo } from \\"vue\\" | ||
export function render(_ctx, _cache) { | ||
return _withMemo([_ctx.x], () => (_openBlock(), _createElementBlock(\\"div\\")), _cache, 0) | ||
}" | ||
`; | ||
|
||
exports[`compiler: v-memo transform on template v-for 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.list, ({ x, y }, __, ___, _cached) => { | ||
const _memo = ([x, y === z]) | ||
if (_cached && _cached.key === x && _isMemoSame(_cached.memo, _memo)) return _cached | ||
const _item = (_openBlock(), _createElementBlock(\\"span\\", { key: x }, \\"foobar\\")) | ||
_item.memo = _memo | ||
return _item | ||
}, _cache, 0), 128 /* KEYED_FRAGMENT */)) | ||
])) | ||
}" | ||
`; | ||
|
||
exports[`compiler: v-memo transform on v-for 1`] = ` | ||
"import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, createElementVNode as _createElementVNode, 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.list, ({ x, y }, __, ___, _cached) => { | ||
const _memo = ([x, y === _ctx.z]) | ||
if (_cached && _cached.key === x && _isMemoSame(_cached.memo, _memo)) return _cached | ||
const _item = (_openBlock(), _createElementBlock(\\"div\\", { key: x }, [ | ||
_createElementVNode(\\"span\\", null, \\"foobar\\") | ||
])) | ||
_item.memo = _memo | ||
return _item | ||
}, _cache, 0), 128 /* KEYED_FRAGMENT */)) | ||
])) | ||
}" | ||
`; | ||
|
||
exports[`compiler: v-memo transform on v-if 1`] = ` | ||
"import { createElementVNode as _createElementVNode, createTextVNode as _createTextVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, withMemo as _withMemo, createCommentVNode as _createCommentVNode, resolveComponent as _resolveComponent, createBlock as _createBlock } from \\"vue\\" | ||
export function render(_ctx, _cache) { | ||
const _component_Comp = _resolveComponent(\\"Comp\\") | ||
return (_openBlock(), _createElementBlock(\\"div\\", null, [ | ||
(_ctx.ok) | ||
? _withMemo([_ctx.x], () => (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, [ | ||
_createElementVNode(\\"span\\", null, \\"foo\\"), | ||
_createTextVNode(\\"bar\\") | ||
])), _cache, 0) | ||
: _withMemo([_ctx.x], () => (_openBlock(), _createBlock(_component_Comp, { key: 1 })), _cache, 1) | ||
])) | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { baseCompile } from '../../src' | ||
|
||
describe('compiler: v-memo transform', () => { | ||
function compile(content: string) { | ||
return baseCompile(`<div>${content}</div>`, { | ||
mode: 'module', | ||
prefixIdentifiers: true | ||
}).code | ||
} | ||
|
||
test('on root element', () => { | ||
expect( | ||
baseCompile(`<div v-memo="[x]"></div>`, { | ||
mode: 'module', | ||
prefixIdentifiers: true | ||
}).code | ||
).toMatchSnapshot() | ||
}) | ||
|
||
test('on normal element', () => { | ||
expect(compile(`<div v-memo="[x]"></div>`)).toMatchSnapshot() | ||
}) | ||
|
||
test('on component', () => { | ||
expect(compile(`<Comp v-memo="[x]"></Comp>`)).toMatchSnapshot() | ||
}) | ||
|
||
test('on v-if', () => { | ||
expect( | ||
compile( | ||
`<div v-if="ok" v-memo="[x]"><span>foo</span>bar</div> | ||
<Comp v-else v-memo="[x]"></Comp>` | ||
) | ||
).toMatchSnapshot() | ||
}) | ||
|
||
test('on v-for', () => { | ||
expect( | ||
compile( | ||
`<div v-for="{ x, y } in list" :key="x" v-memo="[x, y === z]"> | ||
<span>foobar</span> | ||
</div>` | ||
) | ||
).toMatchSnapshot() | ||
}) | ||
|
||
test('on template v-for', () => { | ||
expect( | ||
compile( | ||
`<template v-for="{ x, y } in list" :key="x" v-memo="[x, y === z]"> | ||
<span>foobar</span> | ||
</template>` | ||
) | ||
).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.