feat(portal): SSR support for portal disabled prop

This commit is contained in:
Evan You
2020-03-27 23:45:50 -04:00
parent 8ce3da0104
commit 9ed9bf3687
7 changed files with 126 additions and 23 deletions

View File

@@ -1,11 +1,11 @@
import {
ComponentNode,
findProp,
JSChildNode,
NodeTypes,
createSimpleExpression,
createFunctionExpression,
createCallExpression
createCallExpression,
ExpressionNode
} from '@vue/compiler-dom'
import {
SSRTransformContext,
@@ -27,12 +27,14 @@ export function ssrProcessPortal(
return
}
let target: JSChildNode
if (targetProp.type === NodeTypes.ATTRIBUTE && targetProp.value) {
target = createSimpleExpression(targetProp.value.content, true)
} else if (targetProp.type === NodeTypes.DIRECTIVE && targetProp.exp) {
target = targetProp.exp
let target: ExpressionNode | undefined
if (targetProp.type === NodeTypes.ATTRIBUTE) {
target =
targetProp.value && createSimpleExpression(targetProp.value.content, true)
} else {
target = targetProp.exp
}
if (!target) {
context.onError(
createSSRCompilerError(
SSRErrorCodes.X_SSR_NO_PORTAL_TARGET,
@@ -42,6 +44,13 @@ export function ssrProcessPortal(
return
}
const disabledProp = findProp(node, 'disabled', false, true /* allow empty */)
const disabled = disabledProp
? disabledProp.type === NodeTypes.ATTRIBUTE
? `true`
: disabledProp.exp || `false`
: `false`
const contentRenderFn = createFunctionExpression(
[`_push`],
undefined, // Body is added later
@@ -55,6 +64,7 @@ export function ssrProcessPortal(
`_push`,
contentRenderFn,
target,
disabled,
`_parent`
])
)