Skip to content

Commit

Permalink
wip: refactor vapor vBind codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 12, 2024
1 parent dfe06f8 commit 4505727
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const t0 = _template("<div></div>")
export function render(_ctx, $props, $emit, $attrs, $slots) {
const n0 = t0()
let _count
_renderEffect(() => _count !== _ctx.count && _setText(n0, "count is ", (_count = _ctx.count), "."))
_renderEffect(() => _setText(n0, "count is ", _ctx.count, "."))
return n0
}"
`;
Expand Down Expand Up @@ -149,7 +148,7 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
`;
exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, createTextNode as _createTextNode, insert as _insert, setDOMProp as _setDOMProp, renderEffect as _renderEffect, template as _template } from 'vue';
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, createTextNode as _createTextNode, insert as _insert, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>")
const t1 = _template("<div></div>")
Expand All @@ -160,8 +159,7 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
const n1 = _createComponentWithFallback(_component_Comp)
const n2 = _createTextNode(() => [_ctx.bar])
_insert([n1, n2], n3)
let _foo
_renderEffect(() => _foo !== _ctx.foo && _setDOMProp(n3, "id", (_foo = _ctx.foo)))
_renderEffect(() => _setProp(n3, "id", _ctx.foo))
return [n0, n3]
}"
`;
Expand All @@ -176,20 +174,16 @@ export function render(_ctx) {
`;
exports[`compile > dynamic root nodes and interpolation 1`] = `
"import { delegate as _delegate, setText as _setText, setDOMProp as _setDOMProp, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue';
"import { delegate as _delegate, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue';
const t0 = _template("<button></button>")
_delegateEvents("click")
export function render(_ctx) {
const n0 = t0()
_delegate(n0, "click", () => _ctx.handleClick)
let _count
_renderEffect(() => {
if(_count !== _ctx.count) {
_setText(n0, _ctx.count, "foo", _ctx.count, "foo", _ctx.count)
_setDOMProp(n0, "id", _ctx.count)
_count = _ctx.count
}
_setText(n0, _ctx.count, "foo", _ctx.count, "foo", _ctx.count)
_setProp(n0, "id", _ctx.count)
})
return n0
}"
Expand All @@ -205,8 +199,7 @@ exports[`compile > expression parsing > interpolation 1`] = `
exports[`compile > expression parsing > v-bind 1`] = `
"
const n0 = t0()
let _key_value, _foo, _key_value_foo
_renderEffect(() => (_key_value !== key.value || _foo !== _unref(foo)) && (_key_value_foo = _setDynamicProps(n0, _key_value_foo, [{ [key.value+1]: _unref(foo)[key.value+1]() }], true)))
_renderEffect(() => _setDynamicProps(n0, [{ [key.value+1]: _unref(foo)[key.value+1]() }], true))
return n0
"
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-vapor/__tests__/compile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('compile', () => {
expect(code).matchSnapshot()
expect(code).contains('key.value+1')
expect(code).contains(
'(_key_value !== key.value || _foo !== _unref(foo)) && (_key_value_foo = _setDynamicProps(n0, _key_value_foo, [{ [key.value+1]: _unref(foo)[key.value+1]() }], true))',
'_setDynamicProps(n0, [{ [key.value+1]: _unref(foo)[key.value+1]() }], true)',
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export function render(_ctx) {
const n2 = n3.nextSibling
const n1 = _createTextNode(() => [_ctx.second, " ", _ctx.third, " "])
_insert(n1, n4, n3)
let _first, _forth
_renderEffect(() => {
_first !== _ctx.first && _setText(n0, (_first = _ctx.first))
_forth !== _ctx.forth && _setText(n2, (_forth = _ctx.forth))
_setText(n0, _ctx.first)
_setText(n2, _ctx.forth)
})
return n4
}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,12 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > props merging: class 1`] = `
"import { setClass as _setClass, renderEffect as _renderEffect, template as _template } from 'vue';
"import { setClassIncremental as _setClassIncremental, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
let _isBar
_renderEffect(() => _isBar !== _ctx.isBar && _setClass(n0, ["foo", { bar: (_isBar = _ctx.isBar) }], true))
_renderEffect(() => _setClassIncremental(n0, ["foo", { bar: _ctx.isBar }]))
return n0
}"
`;
Expand All @@ -322,12 +321,12 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > props merging: style 1`] = `
"import { setStyle as _setStyle, renderEffect as _renderEffect, template as _template } from 'vue';
"import { setStyleIncremental as _setStyleIncremental, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
_renderEffect(() => _setStyle(n0, ["color: green", { color: 'red' }], true))
_renderEffect(() => _setStyleIncremental(n0, ["color: green", { color: 'red' }]))
return n0
}"
`;
Expand All @@ -348,8 +347,7 @@ const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
let _obj
_renderEffect(() => _obj !== _ctx.obj && (_obj = _setDynamicProps(n0, _obj, [_ctx.obj], true)))
_renderEffect(() => _setDynamicProps(n0, [_ctx.obj], true))
return n0
}"
`;
Expand All @@ -360,8 +358,7 @@ const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
let _obj
_renderEffect(() => _obj !== _ctx.obj && (_obj = _setDynamicProps(n0, _obj, [{ id: "foo" }, _ctx.obj], true)))
_renderEffect(() => _setDynamicProps(n0, [{ id: "foo" }, _ctx.obj], true))
return n0
}"
`;
Expand All @@ -372,8 +369,7 @@ const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
let _obj
_renderEffect(() => _obj !== _ctx.obj && (_obj = _setDynamicProps(n0, _obj, [_ctx.obj, { id: "foo" }], true)))
_renderEffect(() => _setDynamicProps(n0, [_ctx.obj, { id: "foo" }], true))
return n0
}"
`;
Expand All @@ -384,8 +380,7 @@ const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
let _obj
_renderEffect(() => _obj !== _ctx.obj && (_obj = _setDynamicProps(n0, _obj, [{ id: "foo" }, _ctx.obj, { class: "bar" }], true)))
_renderEffect(() => _setDynamicProps(n0, [{ id: "foo" }, _ctx.obj, { class: "bar" }], true))
return n0
}"
`;
Expand Down
Loading

0 comments on commit 4505727

Please sign in to comment.