Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support template props omitted #265

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`compile > bindings 1`] = `
"import { renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_renderEffect(() => _setText(n0, "count is ", _ctx.count, "."))
return n0
Expand All @@ -15,7 +15,7 @@ exports[`compile > custom directive > basic 1`] = `
"import { resolveDirective as _resolveDirective, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const _directive_test = _resolveDirective("test")
const _directive_hello = _resolveDirective("hello")
const n0 = t0()
Expand All @@ -28,7 +28,7 @@ exports[`compile > custom directive > component 1`] = `
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, createComponent as _createComponent, withDirectives as _withDirectives, insert as _insert, createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const _component_Bar = _resolveComponent("Bar")
const _component_Comp = _resolveComponent("Comp")
const _directive_hello = _resolveDirective("hello")
Expand Down Expand Up @@ -56,7 +56,7 @@ exports[`compile > directives > custom directive > basic 1`] = `
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample]])
return n0
Expand All @@ -67,7 +67,7 @@ exports[`compile > directives > custom directive > binding value 1`] = `
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample, () => _ctx.msg]])
return n0
Expand All @@ -78,7 +78,7 @@ exports[`compile > directives > custom directive > dynamic parameters 1`] = `
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample, () => _ctx.msg, _ctx.foo]])
return n0
Expand All @@ -89,7 +89,7 @@ exports[`compile > directives > custom directive > modifiers 1`] = `
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample, () => _ctx.msg, void 0, { bar: true }]])
return n0
Expand All @@ -100,7 +100,7 @@ exports[`compile > directives > custom directive > modifiers w/o binding 1`] = `
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample, void 0, void 0, { "foo-bar": true }]])
return n0
Expand All @@ -111,7 +111,7 @@ exports[`compile > directives > custom directive > static parameters 1`] = `
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample, () => _ctx.msg, "foo"]])
return n0
Expand All @@ -122,7 +122,7 @@ exports[`compile > directives > custom directive > static parameters and modifie
"import { withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_withDirectives(n0, [[_ctx.vExample, () => _ctx.msg, "foo", { bar: true }]])
return n0
Expand All @@ -133,7 +133,7 @@ exports[`compile > directives > v-cloak > basic 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div>test</div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
return n0
}"
Expand All @@ -143,7 +143,7 @@ exports[`compile > directives > v-pre > basic 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
return n0
}"
Expand All @@ -154,7 +154,7 @@ exports[`compile > directives > v-pre > should not affect siblings after it 1`]
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>")
const t1 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const _component_Comp = _resolveComponent("Comp")
const n0 = t0()
const n3 = t1()
Expand All @@ -169,7 +169,7 @@ export function render(_ctx) {
exports[`compile > dynamic root 1`] = `
"import { createTextNode as _createTextNode } from 'vue/vapor';

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = _createTextNode([1, 2])
return n0
}"
Expand All @@ -180,7 +180,7 @@ exports[`compile > dynamic root nodes and interpolation 1`] = `
const t0 = _template("<button></button>")
_delegateEvents("click")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
_delegate(n0, "click", () => _ctx.handleClick)
_renderEffect(() => _setText(n0, _ctx.count, "foo", _ctx.count, "foo", _ctx.count))
Expand Down Expand Up @@ -210,18 +210,29 @@ const t0 = _template("<p></p>")
const t1 = _template("<span></span>")
const t2 = _template("<div></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
const n1 = t1()
const n2 = t2()
return [n0, n1, n2]
}"
`;

exports[`compile > props bindings 1`] = `
"import { renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div>count</div>")

export function render(_ctx, $props) {
const n0 = t0()
_renderEffect(() => _setDynamicProp(n0, "count", $props.count))
return n0
}"
`;

exports[`compile > static + dynamic root 1`] = `
"import { createTextNode as _createTextNode } from 'vue/vapor';

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = _createTextNode([1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B'])
return n0
}"
Expand All @@ -231,7 +242,7 @@ exports[`compile > static template 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div><p>hello</p><input><span></span></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n0 = t0()
return n0
}"
Expand Down
9 changes: 9 additions & 0 deletions packages/compiler-vapor/__tests__/compile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe('compile', () => {
expect(code).matchSnapshot()
})

test('props bindings', () => {
const code = compile(`<div :count="count">count</div>`, {
bindingMetadata: {
count: BindingTypes.PROPS,
},
})
expect(code).matchSnapshot()
})

describe('directives', () => {
describe('v-pre', () => {
test('basic', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`compiler: children transform > children & sibling references 1`] = `
"import { next as _next, createTextNode as _createTextNode, insert as _insert, renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div><p></p> <!><p></p></div>")

export function render(_ctx) {
export function render(_ctx, $props) {
const n4 = t0()
const n0 = n4.firstChild
const n3 = _next(n0, 2)
Expand Down
Loading
Loading