let _temp0
_push(\`<textarea\${
- _ssrRenderAttrs(_temp0 = _ctx.obj)
+ _ssrRenderAttrs(_temp0 = _ctx.obj, \\"textarea\\")
}>\${
_ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"fallback\\")
}</textarea>\`)
}"
`)
})
+
+ test('should pass tag to custom elements w/ dynamic v-bind', () => {
+ expect(
+ compile(`<my-foo v-bind="obj"></my-foo>`, {
+ isCustomElement: () => true
+ }).code
+ ).toMatchInlineSnapshot(`
+ "const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
+
+ return function ssrRender(_ctx, _push, _parent) {
+ _push(\`<my-foo\${_ssrRenderAttrs(_ctx.obj, \\"my-foo\\")}></my-foo>\`)
+ }"
+ `)
+ })
})
describe('attrs', () => {
// element
// generate the template literal representing the open tag.
const openTag: TemplateLiteral['elements'] = [`<${node.tag}`]
+ // some tags need to be pasesd to runtime for special checks
+ const needTagForRuntime =
+ node.tag === 'textarea' || node.tag.indexOf('-') > 0
// v-bind="obj" or v-bind:[key] can potentially overwrite other static
// attrs and can affect final rendering result, so when they are present
// assign the merged props to a temp variable, and check whether
// it contains value (if yes, render is as children).
const tempId = `_temp${context.temps++}`
- propsExp.arguments[0] = createAssignmentExpression(
- createSimpleExpression(tempId, false),
- props
- )
+ propsExp.arguments = [
+ createAssignmentExpression(
+ createSimpleExpression(tempId, false),
+ props
+ )
+ ]
const existingText = node.children[0] as TextNode | undefined
rawChildrenMap.set(
node,
}
}
+ if (needTagForRuntime) {
+ propsExp.arguments.push(`"${node.tag}"`)
+ }
+
openTag.push(propsExp)
}
}
// dynamic key attr
// this branch is only encountered for custom directive
// transforms that returns properties with dynamic keys
+ const args: CallExpression['arguments'] = [key, value]
+ if (needTagForRuntime) {
+ args.push(`"${node.tag}"`)
+ }
openTag.push(
createCallExpression(
context.helper(SSR_RENDER_DYNAMIC_ATTR),
- [key, value]
+ args
)
)
}