chore(compiler-core): reduce unnecessary cache inside v-once (#4112)

This commit is contained in:
fishDog
2021-07-16 04:50:54 +08:00
committed by Evan You
parent e5a4412764
commit eca4d7891a
7 changed files with 37 additions and 2 deletions

View File

@@ -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>',

View File

@@ -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,

View File

@@ -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>`, {