wip: more consistent compiler-sfc usage + inline mode for ssr
This commit is contained in:
@@ -9,7 +9,7 @@ const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"hello\\", -1 /*
|
||||
const _hoisted_2 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"world\\", -1 /* HOISTED */)
|
||||
_popScopeId()
|
||||
|
||||
export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
|
||||
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
|
||||
return (_openBlock(), _createBlock(\\"div\\", null, [
|
||||
_hoisted_1,
|
||||
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */),
|
||||
@@ -22,7 +22,7 @@ exports[`scopeId compiler support should wrap default slot 1`] = `
|
||||
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
|
||||
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
|
||||
|
||||
export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
|
||||
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
|
||||
const _component_Child = _resolveComponent(\\"Child\\")
|
||||
|
||||
return (_openBlock(), _createBlock(_component_Child, null, {
|
||||
@@ -38,7 +38,7 @@ exports[`scopeId compiler support should wrap dynamic slots 1`] = `
|
||||
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, renderList as _renderList, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
|
||||
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
|
||||
|
||||
export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
|
||||
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
|
||||
const _component_Child = _resolveComponent(\\"Child\\")
|
||||
|
||||
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 2 }, [
|
||||
@@ -66,7 +66,7 @@ exports[`scopeId compiler support should wrap named slots 1`] = `
|
||||
"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createVNode as _createVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
|
||||
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
|
||||
|
||||
export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
|
||||
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
|
||||
const _component_Child = _resolveComponent(\\"Child\\")
|
||||
|
||||
return (_openBlock(), _createBlock(_component_Child, null, {
|
||||
@@ -85,7 +85,7 @@ exports[`scopeId compiler support should wrap render function 1`] = `
|
||||
"import { createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
|
||||
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
|
||||
|
||||
export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
|
||||
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
|
||||
return (_openBlock(), _createBlock(\\"div\\"))
|
||||
})"
|
||||
`;
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('scopeId compiler support', () => {
|
||||
expect(ast.helpers).toContain(WITH_SCOPE_ID)
|
||||
expect(code).toMatch(`const _withId = /*#__PURE__*/_withScopeId("test")`)
|
||||
expect(code).toMatch(
|
||||
`export const render = /*#__PURE__*/_withId(function render(`
|
||||
`export const render = /*#__PURE__*/_withId((_ctx, _cache) => {`
|
||||
)
|
||||
expect(code).toMatchSnapshot()
|
||||
})
|
||||
|
||||
@@ -203,7 +203,7 @@ export function generate(
|
||||
const hasHelpers = ast.helpers.length > 0
|
||||
const useWithBlock = !prefixIdentifiers && mode !== 'module'
|
||||
const genScopeId = !__BROWSER__ && scopeId != null && mode === 'module'
|
||||
const isSetupInlined = !!options.inline
|
||||
const isSetupInlined = !__BROWSER__ && !!options.inline
|
||||
|
||||
// preambles
|
||||
// in setup() inline mode, the preamble is generated in a sub context
|
||||
@@ -217,6 +217,8 @@ export function generate(
|
||||
genFunctionPreamble(ast, preambleContext)
|
||||
}
|
||||
|
||||
// enter render function
|
||||
const functionName = ssr ? `ssrRender` : `render`
|
||||
const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache']
|
||||
if (!__BROWSER__ && options.bindingMetadata && !options.inline) {
|
||||
// binding optimization args
|
||||
@@ -226,24 +228,18 @@ export function generate(
|
||||
!__BROWSER__ && options.isTS
|
||||
? args.map(arg => `${arg}: any`).join(',')
|
||||
: args.join(', ')
|
||||
// enter render function
|
||||
if (!ssr) {
|
||||
|
||||
if (genScopeId) {
|
||||
if (isSetupInlined) {
|
||||
if (genScopeId) {
|
||||
push(`${PURE_ANNOTATION}_withId(`)
|
||||
}
|
||||
push(`(${signature}) => {`)
|
||||
push(`${PURE_ANNOTATION}_withId(`)
|
||||
} else {
|
||||
if (genScopeId) {
|
||||
push(`const render = ${PURE_ANNOTATION}_withId(`)
|
||||
}
|
||||
push(`function render(${signature}) {`)
|
||||
push(`const ${functionName} = ${PURE_ANNOTATION}_withId(`)
|
||||
}
|
||||
}
|
||||
if (isSetupInlined || genScopeId) {
|
||||
push(`(${signature}) => {`)
|
||||
} else {
|
||||
if (genScopeId) {
|
||||
push(`const ssrRender = ${PURE_ANNOTATION}_withId(`)
|
||||
}
|
||||
push(`function ssrRender(${signature}) {`)
|
||||
push(`function ${functionName}(${signature}) {`)
|
||||
}
|
||||
indent()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user