2020-02-07 06:45:34 +08:00
|
|
|
import { compile } from '../src'
|
|
|
|
|
|
|
|
const scopeId = 'data-v-xxxxxxx'
|
|
|
|
|
|
|
|
describe('ssr: scopeId', () => {
|
|
|
|
test('basic', () => {
|
|
|
|
expect(
|
|
|
|
compile(`<div><span>hello</span></div>`, {
|
2020-06-27 12:25:07 +08:00
|
|
|
scopeId,
|
|
|
|
mode: 'module'
|
2020-02-07 06:45:34 +08:00
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2021-09-23 22:08:28 +08:00
|
|
|
"import { ssrRenderAttrs as _ssrRenderAttrs } from \\"vue/server-renderer\\"
|
2020-06-27 02:23:50 +08:00
|
|
|
|
2021-07-14 22:04:35 +08:00
|
|
|
export function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-06-27 02:23:50 +08:00
|
|
|
_push(\`<div\${_ssrRenderAttrs(_attrs)} data-v-xxxxxxx><span data-v-xxxxxxx>hello</span></div>\`)
|
2021-07-17 00:24:30 +08:00
|
|
|
}"
|
2020-02-07 06:45:34 +08:00
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('inside slots (only text)', () => {
|
|
|
|
// should have no branching inside slot
|
|
|
|
expect(
|
|
|
|
compile(`<foo>foo</foo>`, {
|
2020-06-27 12:25:07 +08:00
|
|
|
scopeId,
|
|
|
|
mode: 'module'
|
2020-02-07 06:45:34 +08:00
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2021-09-01 23:30:34 +08:00
|
|
|
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createTextVNode as _createTextVNode } from \\"vue\\"
|
2021-09-23 22:08:28 +08:00
|
|
|
import { ssrRenderComponent as _ssrRenderComponent } from \\"vue/server-renderer\\"
|
2020-02-07 06:45:34 +08:00
|
|
|
|
2021-07-14 22:04:35 +08:00
|
|
|
export function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-08 08:04:55 +08:00
|
|
|
const _component_foo = _resolveComponent(\\"foo\\")
|
2020-02-07 06:45:34 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
_push(_ssrRenderComponent(_component_foo, _attrs, {
|
2021-07-15 06:12:38 +08:00
|
|
|
default: _withCtx((_, _push, _parent, _scopeId) => {
|
2020-02-07 14:06:51 +08:00
|
|
|
if (_push) {
|
|
|
|
_push(\`foo\`)
|
|
|
|
} else {
|
|
|
|
return [
|
2020-02-08 08:04:55 +08:00
|
|
|
_createTextVNode(\\"foo\\")
|
2020-02-07 14:06:51 +08:00
|
|
|
]
|
|
|
|
}
|
2020-03-17 01:06:37 +08:00
|
|
|
}),
|
2020-12-01 04:11:58 +08:00
|
|
|
_: 1 /* STABLE */
|
2020-02-07 07:03:14 +08:00
|
|
|
}, _parent))
|
2021-07-17 00:24:30 +08:00
|
|
|
}"
|
2020-02-07 06:45:34 +08:00
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('inside slots (with elements)', () => {
|
|
|
|
expect(
|
|
|
|
compile(`<foo><span>hello</span></foo>`, {
|
2020-06-27 12:25:07 +08:00
|
|
|
scopeId,
|
|
|
|
mode: 'module'
|
2020-02-07 06:45:34 +08:00
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2021-09-01 23:30:34 +08:00
|
|
|
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\"
|
2021-09-23 22:08:28 +08:00
|
|
|
import { ssrRenderComponent as _ssrRenderComponent } from \\"vue/server-renderer\\"
|
2020-02-07 06:45:34 +08:00
|
|
|
|
2021-07-14 22:04:35 +08:00
|
|
|
export function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-08 08:04:55 +08:00
|
|
|
const _component_foo = _resolveComponent(\\"foo\\")
|
2020-02-07 06:45:34 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
_push(_ssrRenderComponent(_component_foo, _attrs, {
|
2021-07-15 06:12:38 +08:00
|
|
|
default: _withCtx((_, _push, _parent, _scopeId) => {
|
2020-02-07 14:06:51 +08:00
|
|
|
if (_push) {
|
|
|
|
_push(\`<span data-v-xxxxxxx\${_scopeId}>hello</span>\`)
|
2020-02-07 06:45:34 +08:00
|
|
|
} else {
|
2020-02-07 14:06:51 +08:00
|
|
|
return [
|
2020-02-08 08:04:55 +08:00
|
|
|
_createVNode(\\"span\\", null, \\"hello\\")
|
2020-02-07 14:06:51 +08:00
|
|
|
]
|
2020-02-07 06:45:34 +08:00
|
|
|
}
|
2020-03-17 01:06:37 +08:00
|
|
|
}),
|
2020-12-01 04:11:58 +08:00
|
|
|
_: 1 /* STABLE */
|
2020-02-07 07:03:14 +08:00
|
|
|
}, _parent))
|
2021-07-17 00:24:30 +08:00
|
|
|
}"
|
2020-02-07 06:45:34 +08:00
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('nested slots', () => {
|
|
|
|
expect(
|
|
|
|
compile(`<foo><span>hello</span><bar><span/></bar></foo>`, {
|
2020-06-27 12:25:07 +08:00
|
|
|
scopeId,
|
|
|
|
mode: 'module'
|
2020-02-07 06:45:34 +08:00
|
|
|
}).code
|
|
|
|
).toMatchInlineSnapshot(`
|
2021-09-01 23:30:34 +08:00
|
|
|
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\"
|
2021-09-23 22:08:28 +08:00
|
|
|
import { ssrRenderComponent as _ssrRenderComponent } from \\"vue/server-renderer\\"
|
2020-02-07 06:45:34 +08:00
|
|
|
|
2021-07-14 22:04:35 +08:00
|
|
|
export function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-08 08:04:55 +08:00
|
|
|
const _component_foo = _resolveComponent(\\"foo\\")
|
|
|
|
const _component_bar = _resolveComponent(\\"bar\\")
|
2020-02-07 06:45:34 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
_push(_ssrRenderComponent(_component_foo, _attrs, {
|
2021-07-15 06:12:38 +08:00
|
|
|
default: _withCtx((_, _push, _parent, _scopeId) => {
|
2020-02-07 14:06:51 +08:00
|
|
|
if (_push) {
|
|
|
|
_push(\`<span data-v-xxxxxxx\${_scopeId}>hello</span>\`)
|
2020-02-07 07:03:14 +08:00
|
|
|
_push(_ssrRenderComponent(_component_bar, null, {
|
2021-07-15 06:12:38 +08:00
|
|
|
default: _withCtx((_, _push, _parent, _scopeId) => {
|
2020-02-07 14:06:51 +08:00
|
|
|
if (_push) {
|
|
|
|
_push(\`<span data-v-xxxxxxx\${_scopeId}></span>\`)
|
2020-02-07 06:45:34 +08:00
|
|
|
} else {
|
2020-02-07 14:06:51 +08:00
|
|
|
return [
|
2020-02-08 08:04:55 +08:00
|
|
|
_createVNode(\\"span\\")
|
2020-02-07 14:06:51 +08:00
|
|
|
]
|
2020-02-07 06:45:34 +08:00
|
|
|
}
|
2020-03-17 01:06:37 +08:00
|
|
|
}),
|
2020-12-01 04:11:58 +08:00
|
|
|
_: 1 /* STABLE */
|
2021-03-06 00:10:06 +08:00
|
|
|
}, _parent, _scopeId))
|
2020-02-07 06:45:34 +08:00
|
|
|
} else {
|
2020-02-07 14:06:51 +08:00
|
|
|
return [
|
2020-02-08 08:04:55 +08:00
|
|
|
_createVNode(\\"span\\", null, \\"hello\\"),
|
|
|
|
_createVNode(_component_bar, null, {
|
2021-07-15 06:12:38 +08:00
|
|
|
default: _withCtx(() => [
|
2020-02-08 08:04:55 +08:00
|
|
|
_createVNode(\\"span\\")
|
2020-03-17 01:06:37 +08:00
|
|
|
]),
|
2020-12-01 04:11:58 +08:00
|
|
|
_: 1 /* STABLE */
|
2020-02-07 14:06:51 +08:00
|
|
|
})
|
|
|
|
]
|
2020-02-07 06:45:34 +08:00
|
|
|
}
|
2020-03-17 01:06:37 +08:00
|
|
|
}),
|
2020-12-01 04:11:58 +08:00
|
|
|
_: 1 /* STABLE */
|
2020-02-07 07:03:14 +08:00
|
|
|
}, _parent))
|
2021-07-17 00:24:30 +08:00
|
|
|
}"
|
2020-02-07 06:45:34 +08:00
|
|
|
`)
|
|
|
|
})
|
|
|
|
})
|