mirror of https://github.com/vuejs/core.git
chore: update
This commit is contained in:
parent
b0a2ce5b0e
commit
1dbd642492
|
@ -35,13 +35,13 @@ export function render(_ctx) {
|
||||||
const _directive_test = _resolveDirective("test")
|
const _directive_test = _resolveDirective("test")
|
||||||
const n4 = _createComponentWithFallback(_component_Comp, null, {
|
const n4 = _createComponentWithFallback(_component_Comp, null, {
|
||||||
"default": () => {
|
"default": () => {
|
||||||
const n0 = _createIf(() => (true) && (() => {
|
const n0 = _createIf(() => (true) ? () => {
|
||||||
const n3 = t0()
|
const n3 = t0()
|
||||||
const n2 = _createComponentWithFallback(_component_Bar)
|
const n2 = _createComponentWithFallback(_component_Bar)
|
||||||
_withDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
|
_withDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
|
||||||
_insert(n2, n3)
|
_insert(n2, n3)
|
||||||
return n3
|
return n3
|
||||||
}))
|
} : undefined)
|
||||||
return n0
|
return n0
|
||||||
}
|
}
|
||||||
}, true)
|
}, true)
|
||||||
|
|
|
@ -34,11 +34,11 @@ const t0 = _template("<div></div>", true)
|
||||||
|
|
||||||
export function render(_ctx) {
|
export function render(_ctx) {
|
||||||
const _setTemplateRef = _createTemplateRefSetter()
|
const _setTemplateRef = _createTemplateRefSetter()
|
||||||
const n0 = _createIf(() => (true) && (() => {
|
const n0 = _createIf(() => (true) ? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
_setTemplateRef(n2, "foo")
|
_setTemplateRef(n2, "foo")
|
||||||
return n2
|
return n2
|
||||||
}))
|
} : undefined)
|
||||||
return n0
|
return n0
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -5,11 +5,11 @@ exports[`compiler: v-if > basic v-if 1`] = `
|
||||||
const t0 = _template("<div></div>", true)
|
const t0 = _template("<div></div>", true)
|
||||||
|
|
||||||
export function render(_ctx) {
|
export function render(_ctx) {
|
||||||
const n0 = _createIf(() => (_ctx.ok) && (() => {
|
const n0 = _createIf(() => (_ctx.ok) ? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
_renderEffect(() => _setText(n2, _ctx.msg))
|
_renderEffect(() => _setText(n2, _ctx.msg))
|
||||||
return n2
|
return n2
|
||||||
}))
|
} : undefined)
|
||||||
return n0
|
return n0
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
@ -47,14 +47,14 @@ exports[`compiler: v-if > dedupe same template 1`] = `
|
||||||
const t0 = _template("<div>hello</div>")
|
const t0 = _template("<div>hello</div>")
|
||||||
|
|
||||||
export function render(_ctx) {
|
export function render(_ctx) {
|
||||||
const n0 = _createIf(() => (_ctx.ok) && (() => {
|
const n0 = _createIf(() => (_ctx.ok) ? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
return n2
|
return n2
|
||||||
}))
|
} : undefined)
|
||||||
const n3 = _createIf(() => (_ctx.ok) && (() => {
|
const n3 = _createIf(() => (_ctx.ok) ? () => {
|
||||||
const n5 = t0()
|
const n5 = t0()
|
||||||
return n5
|
return n5
|
||||||
}))
|
} : undefined)
|
||||||
return [n0, n3]
|
return [n0, n3]
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
@ -66,13 +66,13 @@ const t1 = _template("hello")
|
||||||
const t2 = _template("<p></p>", true)
|
const t2 = _template("<p></p>", true)
|
||||||
|
|
||||||
export function render(_ctx) {
|
export function render(_ctx) {
|
||||||
const n0 = _createIf(() => (_ctx.ok) && (() => {
|
const n0 = _createIf(() => (_ctx.ok) ? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
const n3 = t1()
|
const n3 = t1()
|
||||||
const n4 = t2()
|
const n4 = t2()
|
||||||
_renderEffect(() => _setText(n4, _ctx.msg))
|
_renderEffect(() => _setText(n4, _ctx.msg))
|
||||||
return [n2, n3, n4]
|
return [n2, n3, n4]
|
||||||
}))
|
} : undefined)
|
||||||
return n0
|
return n0
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
@ -124,10 +124,10 @@ export function render(_ctx) {
|
||||||
const n0 = _createIf(() => (_ctx.ok) ? () => {
|
const n0 = _createIf(() => (_ctx.ok) ? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
return n2
|
return n2
|
||||||
} : () => (_ctx.orNot) && (() => {
|
} : () => (_ctx.orNot) ? () => {
|
||||||
const n4 = t1()
|
const n4 = t1()
|
||||||
return n4
|
return n4
|
||||||
}))
|
} : undefined)
|
||||||
return n0
|
return n0
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -78,10 +78,10 @@ exports[`compiler: v-once > with v-if 1`] = `
|
||||||
const t0 = _template("<div></div>", true)
|
const t0 = _template("<div></div>", true)
|
||||||
|
|
||||||
export function render(_ctx) {
|
export function render(_ctx) {
|
||||||
const n0 = _createIf(() => (_ctx.expr) && (() => {
|
const n0 = _createIf(() => (_ctx.expr) ? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
return n2
|
return n2
|
||||||
}), true)
|
} : undefined, true)
|
||||||
return n0
|
return n0
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -31,8 +31,8 @@ export function genIf(
|
||||||
negativeArg.push(...genIf(negative!, context, true))
|
negativeArg.push(...genIf(negative!, context, true))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
positiveArg.unshift(' && (')
|
positiveArg.unshift(' ? ')
|
||||||
positiveArg.push(')')
|
positiveArg.push(' : undefined')
|
||||||
}
|
}
|
||||||
|
|
||||||
codes.push(...positiveArg)
|
codes.push(...positiveArg)
|
||||||
|
|
|
@ -138,9 +138,8 @@ describe('api: lifecycle hooks', () => {
|
||||||
const { render, host } = define({
|
const { render, host } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value ? () => createComponent(Child) : undefined,
|
||||||
() => createComponent(Child),
|
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -172,9 +171,8 @@ describe('api: lifecycle hooks', () => {
|
||||||
const { render, host } = define({
|
const { render, host } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value ? () => createComponent(Child) : undefined,
|
||||||
() => createComponent(Child),
|
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -206,9 +204,8 @@ describe('api: lifecycle hooks', () => {
|
||||||
const { render, host } = define({
|
const { render, host } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value ? () => createComponent(Child) : undefined,
|
||||||
() => createComponent(Child),
|
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -249,9 +246,10 @@ describe('api: lifecycle hooks', () => {
|
||||||
onUnmounted(() => calls.push('onUnmounted'))
|
onUnmounted(() => calls.push('onUnmounted'))
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value
|
||||||
() => createComponent(Mid, { count: () => count.value }),
|
? () => createComponent(Mid, { count: () => count.value })
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -428,9 +426,10 @@ describe('api: lifecycle hooks', () => {
|
||||||
const { render } = define({
|
const { render } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return createIf(
|
return createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value
|
||||||
() => [createComponent(Child), createComponent(Child)],
|
? () => [createComponent(Child), createComponent(Child)]
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -447,11 +447,12 @@ describe('component: slots', () => {
|
||||||
setup() {
|
setup() {
|
||||||
return createComponent(Child, null, {
|
return createComponent(Child, null, {
|
||||||
default: () => {
|
default: () => {
|
||||||
return createIf(
|
return createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value
|
||||||
() => {
|
? () => {
|
||||||
return document.createTextNode('content')
|
return document.createTextNode('content')
|
||||||
},
|
}
|
||||||
|
: () => [],
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -89,13 +89,14 @@ describe('api: template ref', () => {
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const setRef = createTemplateRefSetter()
|
const setRef = createTemplateRefSetter()
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value
|
||||||
() => {
|
? () => {
|
||||||
const n1 = t0()
|
const n1 = t0()
|
||||||
setRef(n1 as Element, 'refKey')
|
setRef(n1 as Element, 'refKey')
|
||||||
return n1
|
return n1
|
||||||
},
|
}
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -160,13 +161,14 @@ describe('api: template ref', () => {
|
||||||
const t0 = template('<div></div>')
|
const t0 = template('<div></div>')
|
||||||
const { render } = define({
|
const { render } = define({
|
||||||
render() {
|
render() {
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => toggle.value,
|
toggle.value
|
||||||
() => {
|
? () => {
|
||||||
const n1 = t0()
|
const n1 = t0()
|
||||||
createTemplateRefSetter()(n1 as Element, fn)
|
createTemplateRefSetter()(n1 as Element, fn)
|
||||||
return n1
|
return n1
|
||||||
},
|
}
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -371,14 +373,14 @@ describe('api: template ref', () => {
|
||||||
render() {
|
render() {
|
||||||
const instance = currentInstance!
|
const instance = currentInstance!
|
||||||
const setRef = createTemplateRefSetter()
|
const setRef = createTemplateRefSetter()
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => refToggle.value,
|
refToggle.value
|
||||||
() => {
|
? () => {
|
||||||
const n1 = t0()
|
const n1 = t0()
|
||||||
setRef(n1 as Element, 'foo')
|
setRef(n1 as Element, 'foo')
|
||||||
return n1
|
return n1
|
||||||
},
|
}
|
||||||
() => {
|
: () => {
|
||||||
const n1 = t1()
|
const n1 = t1()
|
||||||
setRef(n1 as Element, 'foo')
|
setRef(n1 as Element, 'foo')
|
||||||
return n1
|
return n1
|
||||||
|
@ -416,9 +418,9 @@ describe('api: template ref', () => {
|
||||||
const t1 = template('<li></li>')
|
const t1 = template('<li></li>')
|
||||||
const { render } = define({
|
const { render } = define({
|
||||||
render() {
|
render() {
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => show.value,
|
show.value
|
||||||
() => {
|
? () => {
|
||||||
const n1 = t0()
|
const n1 = t0()
|
||||||
const n2 = createFor(
|
const n2 = createFor(
|
||||||
() => list,
|
() => list,
|
||||||
|
@ -439,7 +441,8 @@ describe('api: template ref', () => {
|
||||||
)
|
)
|
||||||
insert(n2, n1 as ParentNode)
|
insert(n2, n1 as ParentNode)
|
||||||
return n1
|
return n1
|
||||||
},
|
}
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
@ -479,9 +482,9 @@ describe('api: template ref', () => {
|
||||||
return { listRefs }
|
return { listRefs }
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const n0 = createIf(
|
const n0 = createIf(() =>
|
||||||
() => show.value,
|
show.value
|
||||||
() => {
|
? () => {
|
||||||
const n1 = t0()
|
const n1 = t0()
|
||||||
const n2 = createFor(
|
const n2 = createFor(
|
||||||
() => list,
|
() => list,
|
||||||
|
@ -502,7 +505,8 @@ describe('api: template ref', () => {
|
||||||
)
|
)
|
||||||
insert(n2, n1 as ParentNode)
|
insert(n2, n1 as ParentNode)
|
||||||
return n1
|
return n1
|
||||||
},
|
}
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return n0
|
return n0
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,17 +38,17 @@ describe('createIf', () => {
|
||||||
const n0 = t0()
|
const n0 = t0()
|
||||||
|
|
||||||
insert(
|
insert(
|
||||||
createIf(
|
createIf(() =>
|
||||||
spyConditionFn,
|
spyConditionFn()
|
||||||
// v-if
|
? // v-if
|
||||||
(spyIfFn ||= vi.fn(() => {
|
(spyIfFn ||= vi.fn(() => {
|
||||||
const n2 = t1()
|
const n2 = t1()
|
||||||
renderEffect(() => {
|
renderEffect(() => {
|
||||||
setText(n2, count.value)
|
setText(n2, count.value)
|
||||||
})
|
})
|
||||||
return n2
|
return n2
|
||||||
})),
|
}))
|
||||||
// v-else
|
: // v-else
|
||||||
(spyElseFn ||= vi.fn(() => {
|
(spyElseFn ||= vi.fn(() => {
|
||||||
const n4 = t2()
|
const n4 = t2()
|
||||||
return n4
|
return n4
|
||||||
|
@ -61,7 +61,7 @@ describe('createIf', () => {
|
||||||
|
|
||||||
expect(host.innerHTML).toBe('<div><p>zero</p><!--if--></div>')
|
expect(host.innerHTML).toBe('<div><p>zero</p><!--if--></div>')
|
||||||
expect(spyConditionFn).toHaveBeenCalledTimes(1)
|
expect(spyConditionFn).toHaveBeenCalledTimes(1)
|
||||||
expect(spyIfFn!).toHaveBeenCalledTimes(0)
|
expect(spyIfFn!).toBeUndefined()
|
||||||
expect(spyElseFn!).toHaveBeenCalledTimes(1)
|
expect(spyElseFn!).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
count.value++
|
count.value++
|
||||||
|
@ -98,19 +98,21 @@ describe('createIf', () => {
|
||||||
const t0 = template('Vapor')
|
const t0 = template('Vapor')
|
||||||
const t1 = template('Hello ')
|
const t1 = template('Hello ')
|
||||||
const { host } = define(() => {
|
const { host } = define(() => {
|
||||||
const n1 = createIf(
|
const n1 = createIf(() =>
|
||||||
() => ok1.value,
|
ok1.value
|
||||||
() => {
|
? () => {
|
||||||
const n2 = t1()
|
const n2 = t1()
|
||||||
const n3 = createIf(
|
const n3 = createIf(() =>
|
||||||
() => ok2.value,
|
ok2.value
|
||||||
() => {
|
? () => {
|
||||||
const n4 = t0()
|
const n4 = t0()
|
||||||
return n4
|
return n4
|
||||||
},
|
}
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return [n2, n3]
|
return [n2, n3]
|
||||||
},
|
}
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
return n1
|
return n1
|
||||||
}).render()
|
}).render()
|
||||||
|
@ -158,24 +160,24 @@ describe('createIf', () => {
|
||||||
|
|
||||||
const t0 = template('<p></p>')
|
const t0 = template('<p></p>')
|
||||||
const { instance } = define(() => {
|
const { instance } = define(() => {
|
||||||
const n1 = createIf(
|
const n1 = createIf(() =>
|
||||||
spyConditionFn1,
|
spyConditionFn1()
|
||||||
() => {
|
? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
withDirectives(children(n2, 0), [
|
withDirectives(children(n2, 0), [
|
||||||
[vDirective, () => (update.value, '1')],
|
[vDirective, () => (update.value, '1')],
|
||||||
])
|
])
|
||||||
return n2
|
return n2
|
||||||
},
|
}
|
||||||
() =>
|
: () =>
|
||||||
createIf(
|
createIf(() =>
|
||||||
spyConditionFn2,
|
spyConditionFn2()
|
||||||
() => {
|
? () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
withDirectives(children(n2, 0), [[vDirective, () => '2']])
|
withDirectives(children(n2, 0), [[vDirective, () => '2']])
|
||||||
return n2
|
return n2
|
||||||
},
|
}
|
||||||
() => {
|
: () => {
|
||||||
const n2 = t0()
|
const n2 = t0()
|
||||||
withDirectives(children(n2, 0), [[vDirective, () => '3']])
|
withDirectives(children(n2, 0), [[vDirective, () => '3']])
|
||||||
return n2
|
return n2
|
||||||
|
|
|
@ -2,15 +2,15 @@ import { type BlockFn, DynamicFragment } from './block'
|
||||||
import { renderEffect } from './renderEffect'
|
import { renderEffect } from './renderEffect'
|
||||||
|
|
||||||
export function createIf(
|
export function createIf(
|
||||||
ifBlockFn: () => BlockFn,
|
ifBlockGetter: () => BlockFn | undefined,
|
||||||
once?: boolean,
|
once?: boolean,
|
||||||
// hydrationNode?: Node,
|
// hydrationNode?: Node,
|
||||||
): DynamicFragment {
|
): DynamicFragment {
|
||||||
const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
|
const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
|
||||||
if (once) {
|
if (once) {
|
||||||
frag.update(ifBlockFn())
|
frag.update(ifBlockGetter())
|
||||||
} else {
|
} else {
|
||||||
renderEffect(() => frag.update(ifBlockFn()))
|
renderEffect(() => frag.update(ifBlockGetter()))
|
||||||
}
|
}
|
||||||
return frag
|
return frag
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue