import { compile } from '../src' describe('ssr: components', () => { test('basic', () => { expect(compile(``).code).toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, { id: \\"a\\", prop: _ctx.b }, null, _parent)) }" `) }) test('dynamic component', () => { expect(compile(``).code) .toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, { prop: \\"b\\" }, null, _parent)) }" `) expect(compile(``).code) .toMatchInlineSnapshot(` "const { resolveDynamicComponent: _resolveDynamicComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { _push(_ssrRenderComponent(_resolveDynamicComponent(_ctx.foo, _ctx.$), { prop: \\"b\\" }, null, _parent)) }" `) }) describe('slots', () => { test('implicit default slot', () => { expect(compile(`hello
`).code).toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent, createVNode: _createVNode, createTextVNode: _createTextVNode } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, { default: (_, _push, _parent, _scopeId) => { if (_push) { _push(\`hello
\`) } else { return [ _createTextVNode(\\"hello\\"), _createVNode(\\"div\\") ] } }, _: 1 }, _parent)) }" `) }) test('explicit default slot', () => { expect(compile(`{{ msg + outer }}`).code) .toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent, createTextVNode: _createTextVNode } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, { default: ({ msg }, _push, _parent, _scopeId) => { if (_push) { _push(\`\${_ssrInterpolate(msg + _ctx.outer)}\`) } else { return [ _createTextVNode(_toDisplayString(msg + _ctx.outer)) ] } }, _: 1 }, _parent)) }" `) }) test('named slots', () => { expect( compile(` `).code ).toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent, createTextVNode: _createTextVNode } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, { default: (_, _push, _parent, _scopeId) => { if (_push) { _push(\`foo\`) } else { return [ _createTextVNode(\\"foo\\") ] } }, named: (_, _push, _parent, _scopeId) => { if (_push) { _push(\`bar\`) } else { return [ _createTextVNode(\\"bar\\") ] } }, _: 1 }, _parent)) }" `) }) test('v-if slot', () => { expect( compile(` `).code ).toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent, createTextVNode: _createTextVNode, createSlots: _createSlots } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, _createSlots({ _: 1 }, [ (_ctx.ok) ? { name: \\"named\\", fn: (_, _push, _parent, _scopeId) => { if (_push) { _push(\`foo\`) } else { return [ _createTextVNode(\\"foo\\") ] } } } : undefined ]), _parent)) }" `) }) test('v-for slot', () => { expect( compile(` `).code ).toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent, createTextVNode: _createTextVNode, renderList: _renderList, createSlots: _createSlots } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, _createSlots({ _: 1 }, [ _renderList(_ctx.names, (key) => { return { name: key, fn: ({ msg }, _push, _parent, _scopeId) => { if (_push) { _push(\`\${_ssrInterpolate(msg + key + _ctx.bar)}\`) } else { return [ _createTextVNode(_toDisplayString(msg + _ctx.key + _ctx.bar)) ] } } } }) ]), _parent)) }" `) }) test('nested transform scoping in vnode branch', () => { expect( compile(` `).code ).toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent, renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode, createCommentVNode: _createCommentVNode } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent, ssrRenderList: _ssrRenderList } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, { foo: ({ list }, _push, _parent, _scopeId) => { if (_push) { if (_ctx.ok) { _push(\`\`) _ssrRenderList(list, (i) => { _push(\`\`) }) _push(\`\`) } else { _push(\`\`) } } else { return [ (_ctx.ok) ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, [ (_openBlock(true), _createBlock(_Fragment, null, _renderList(list, (i) => { return (_openBlock(), _createBlock(\\"span\\")) }), 256 /* UNKEYED_FRAGMENT */)) ])) : _createCommentVNode(\\"v-if\\", true) ] } }, bar: ({ ok }, _push, _parent, _scopeId) => { if (_push) { if (ok) { _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`\`) }) _push(\`\`) } else { _push(\`\`) } } else { return [ ok ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, [ (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (i) => { return (_openBlock(), _createBlock(\\"span\\")) }), 256 /* UNKEYED_FRAGMENT */)) ])) : _createCommentVNode(\\"v-if\\", true) ] } }, _: 1 }, _parent)) }" `) }) test('built-in fallthroughs', () => { // no fragment expect(compile(`
`).code) .toMatchInlineSnapshot(` " return function ssrRender(_ctx, _push, _parent) { _push(\`
\`) }" `) // wrap with fragment expect(compile(`
`).code) .toMatchInlineSnapshot(` " return function ssrRender(_ctx, _push, _parent) { _push(\`
\`) }" `) // no fragment expect(compile(``).code) .toMatchInlineSnapshot(` "const { resolveComponent: _resolveComponent } = require(\\"vue\\") const { ssrRenderComponent: _ssrRenderComponent } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent) { const _component_foo = _resolveComponent(\\"foo\\") _push(_ssrRenderComponent(_component_foo, null, null, _parent)) }" `) // wrap with fragment expect(compile(`
`).code) .toMatchInlineSnapshot(` " return function ssrRender(_ctx, _push, _parent) { _push(\`
\`) }" `) }) }) })