chore(compiler-core): reduce unnecessary cache inside v-once (#4112)
This commit is contained in:
@@ -425,6 +425,18 @@ describe('compiler: transform v-model', () => {
|
||||
).not.toBe(NodeTypes.JS_CACHE_EXPRESSION)
|
||||
})
|
||||
|
||||
test('should not cache update handler if it inside v-once', () => {
|
||||
const root = parseWithVModel(
|
||||
'<div v-once><input v-model="foo" /></div>',
|
||||
{
|
||||
prefixIdentifiers: true,
|
||||
cacheHandlers: true
|
||||
}
|
||||
)
|
||||
expect(root.cached).not.toBe(2)
|
||||
expect(root.cached).toBe(1)
|
||||
})
|
||||
|
||||
test('should mark update handler dynamic if it refers slot scope variables', () => {
|
||||
const root = parseWithVModel(
|
||||
'<Comp v-slot="{ foo }"><input v-model="foo.bar"/></Comp>',
|
||||
|
||||
@@ -530,6 +530,15 @@ describe('compiler: transform v-on', () => {
|
||||
expect(root.cached).toBe(0)
|
||||
})
|
||||
|
||||
test('should not be cached inside v-once', () => {
|
||||
const { root } = parseWithVOn(`<div v-once><div v-on:click="foo"/></div>`, {
|
||||
prefixIdentifiers: true,
|
||||
cacheHandlers: true
|
||||
})
|
||||
expect(root.cached).not.toBe(2)
|
||||
expect(root.cached).toBe(1)
|
||||
})
|
||||
|
||||
test('inline function expression handler', () => {
|
||||
const { root, node } = parseWithVOn(`<div v-on:click="() => foo()" />`, {
|
||||
prefixIdentifiers: true,
|
||||
|
||||
@@ -80,6 +80,13 @@ describe('compiler: v-once transform', () => {
|
||||
expect(generate(root).code).toMatchSnapshot()
|
||||
})
|
||||
|
||||
// v-once inside v-once should not be cached
|
||||
test('inside v-once', () => {
|
||||
const root = transformWithOnce(`<div v-once><div v-once/></div>`)
|
||||
expect(root.cached).not.toBe(2)
|
||||
expect(root.cached).toBe(1)
|
||||
})
|
||||
|
||||
// cached nodes should be ignored by hoistStatic transform
|
||||
test('with hoistStatic: true', () => {
|
||||
const root = transformWithOnce(`<div><div v-once /></div>`, {
|
||||
|
||||
Reference in New Issue
Block a user