Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Dec 31, 2024
1 parent b0a2ce5 commit 1dbd642
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export function render(_ctx) {
const _directive_test = _resolveDirective("test")
const n4 = _createComponentWithFallback(_component_Comp, null, {
"default": () => {
const n0 = _createIf(() => (true) && (() => {
const n0 = _createIf(() => (true) ? () => {
const n3 = t0()
const n2 = _createComponentWithFallback(_component_Bar)
_withDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
_insert(n2, n3)
return n3
}))
} : undefined)
return n0
}
}, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const t0 = _template("<div></div>", true)
export function render(_ctx) {
const _setTemplateRef = _createTemplateRefSetter()
const n0 = _createIf(() => (true) && (() => {
const n0 = _createIf(() => (true) ? () => {
const n2 = t0()
_setTemplateRef(n2, "foo")
return n2
}))
} : undefined)
return n0
}"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports[`compiler: v-if > basic v-if 1`] = `
const t0 = _template("<div></div>", true)
export function render(_ctx) {
const n0 = _createIf(() => (_ctx.ok) && (() => {
const n0 = _createIf(() => (_ctx.ok) ? () => {
const n2 = t0()
_renderEffect(() => _setText(n2, _ctx.msg))
return n2
}))
} : undefined)
return n0
}"
`;
Expand Down Expand Up @@ -47,14 +47,14 @@ exports[`compiler: v-if > dedupe same template 1`] = `
const t0 = _template("<div>hello</div>")
export function render(_ctx) {
const n0 = _createIf(() => (_ctx.ok) && (() => {
const n0 = _createIf(() => (_ctx.ok) ? () => {
const n2 = t0()
return n2
}))
const n3 = _createIf(() => (_ctx.ok) && (() => {
} : undefined)
const n3 = _createIf(() => (_ctx.ok) ? () => {
const n5 = t0()
return n5
}))
} : undefined)
return [n0, n3]
}"
`;
Expand All @@ -66,13 +66,13 @@ const t1 = _template("hello")
const t2 = _template("<p></p>", true)
export function render(_ctx) {
const n0 = _createIf(() => (_ctx.ok) && (() => {
const n0 = _createIf(() => (_ctx.ok) ? () => {
const n2 = t0()
const n3 = t1()
const n4 = t2()
_renderEffect(() => _setText(n4, _ctx.msg))
return [n2, n3, n4]
}))
} : undefined)
return n0
}"
`;
Expand Down Expand Up @@ -124,10 +124,10 @@ export function render(_ctx) {
const n0 = _createIf(() => (_ctx.ok) ? () => {
const n2 = t0()
return n2
} : () => (_ctx.orNot) && (() => {
} : () => (_ctx.orNot) ? () => {
const n4 = t1()
return n4
}))
} : undefined)
return n0
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ exports[`compiler: v-once > with v-if 1`] = `
const t0 = _template("<div></div>", true)
export function render(_ctx) {
const n0 = _createIf(() => (_ctx.expr) && (() => {
const n0 = _createIf(() => (_ctx.expr) ? () => {
const n2 = t0()
return n2
}), true)
} : undefined, true)
return n0
}"
`;
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-vapor/src/generators/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function genIf(
negativeArg.push(...genIf(negative!, context, true))
}
} else {
positiveArg.unshift(' && (')
positiveArg.push(')')
positiveArg.unshift(' ? ')
positiveArg.push(' : undefined')
}

codes.push(...positiveArg)
Expand Down
29 changes: 14 additions & 15 deletions packages/runtime-vapor/__tests__/apiLifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ describe('api: lifecycle hooks', () => {
const { render, host } = define({
setup() {
// @ts-expect-error
const n0 = createIf(
() => toggle.value,
() => createComponent(Child),
const n0 = createIf(() =>
toggle.value ? () => createComponent(Child) : undefined,
)
return n0
},
Expand Down Expand Up @@ -172,9 +171,8 @@ describe('api: lifecycle hooks', () => {
const { render, host } = define({
setup() {
// @ts-expect-error
const n0 = createIf(
() => toggle.value,
() => createComponent(Child),
const n0 = createIf(() =>
toggle.value ? () => createComponent(Child) : undefined,
)
return n0
},
Expand Down Expand Up @@ -206,9 +204,8 @@ describe('api: lifecycle hooks', () => {
const { render, host } = define({
setup() {
// @ts-expect-error
const n0 = createIf(
() => toggle.value,
() => createComponent(Child),
const n0 = createIf(() =>
toggle.value ? () => createComponent(Child) : undefined,
)
return n0
},
Expand Down Expand Up @@ -249,9 +246,10 @@ describe('api: lifecycle hooks', () => {
onUnmounted(() => calls.push('onUnmounted'))

// @ts-expect-error
const n0 = createIf(
() => toggle.value,
() => createComponent(Mid, { count: () => count.value }),
const n0 = createIf(() =>
toggle.value
? () => createComponent(Mid, { count: () => count.value })
: undefined,
)
return n0
},
Expand Down Expand Up @@ -428,9 +426,10 @@ describe('api: lifecycle hooks', () => {
const { render } = define({
setup() {
// @ts-expect-error
return createIf(
() => toggle.value,
() => [createComponent(Child), createComponent(Child)],
return createIf(() =>
toggle.value
? () => [createComponent(Child), createComponent(Child)]
: undefined,
)
},
})
Expand Down
11 changes: 6 additions & 5 deletions packages/runtime-vapor/__tests__/componentSlots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,12 @@ describe('component: slots', () => {
setup() {
return createComponent(Child, null, {
default: () => {
return createIf(
() => toggle.value,
() => {
return document.createTextNode('content')
},
return createIf(() =>
toggle.value
? () => {
return document.createTextNode('content')
}
: () => [],
)
},
})
Expand Down
144 changes: 74 additions & 70 deletions packages/runtime-vapor/__tests__/dom/templateRef.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ describe('api: template ref', () => {
},
render() {
const setRef = createTemplateRefSetter()
const n0 = createIf(
() => toggle.value,
() => {
const n1 = t0()
setRef(n1 as Element, 'refKey')
return n1
},
const n0 = createIf(() =>
toggle.value
? () => {
const n1 = t0()
setRef(n1 as Element, 'refKey')
return n1
}
: undefined,
)
return n0
},
Expand Down Expand Up @@ -160,13 +161,14 @@ describe('api: template ref', () => {
const t0 = template('<div></div>')
const { render } = define({
render() {
const n0 = createIf(
() => toggle.value,
() => {
const n1 = t0()
createTemplateRefSetter()(n1 as Element, fn)
return n1
},
const n0 = createIf(() =>
toggle.value
? () => {
const n1 = t0()
createTemplateRefSetter()(n1 as Element, fn)
return n1
}
: undefined,
)
return n0
},
Expand Down Expand Up @@ -371,18 +373,18 @@ describe('api: template ref', () => {
render() {
const instance = currentInstance!
const setRef = createTemplateRefSetter()
const n0 = createIf(
() => refToggle.value,
() => {
const n1 = t0()
setRef(n1 as Element, 'foo')
return n1
},
() => {
const n1 = t1()
setRef(n1 as Element, 'foo')
return n1
},
const n0 = createIf(() =>
refToggle.value
? () => {
const n1 = t0()
setRef(n1 as Element, 'foo')
return n1
}
: () => {
const n1 = t1()
setRef(n1 as Element, 'foo')
return n1
},
)
watchEffect(
() => {
Expand Down Expand Up @@ -416,30 +418,31 @@ describe('api: template ref', () => {
const t1 = template('<li></li>')
const { render } = define({
render() {
const n0 = createIf(
() => show.value,
() => {
const n1 = t0()
const n2 = createFor(
() => list,
state => {
const n1 = t1()
createTemplateRefSetter()(
n1 as Element,
listRefs,
undefined,
true,
const n0 = createIf(() =>
show.value
? () => {
const n1 = t0()
const n2 = createFor(
() => list,
state => {
const n1 = t1()
createTemplateRefSetter()(
n1 as Element,
listRefs,
undefined,
true,
)
renderEffect(() => {
const [item] = state
setText(n1, item)
})
return n1
},
)
renderEffect(() => {
const [item] = state
setText(n1, item)
})
insert(n2, n1 as ParentNode)
return n1
},
)
insert(n2, n1 as ParentNode)
return n1
},
}
: undefined,
)
return n0
},
Expand Down Expand Up @@ -479,30 +482,31 @@ describe('api: template ref', () => {
return { listRefs }
},
render() {
const n0 = createIf(
() => show.value,
() => {
const n1 = t0()
const n2 = createFor(
() => list,
state => {
const n1 = t1()
createTemplateRefSetter()(
n1 as Element,
'listRefs',
undefined,
true,
const n0 = createIf(() =>
show.value
? () => {
const n1 = t0()
const n2 = createFor(
() => list,
state => {
const n1 = t1()
createTemplateRefSetter()(
n1 as Element,
'listRefs',
undefined,
true,
)
renderEffect(() => {
const [item] = state
setText(n1, item)
})
return n1
},
)
renderEffect(() => {
const [item] = state
setText(n1, item)
})
insert(n2, n1 as ParentNode)
return n1
},
)
insert(n2, n1 as ParentNode)
return n1
},
}
: undefined,
)
return n0
},
Expand Down
Loading

0 comments on commit 1dbd642

Please sign in to comment.