wip(compiler-ssr): v-show

This commit is contained in:
Evan You
2020-02-04 21:03:16 -05:00
parent e2c5060fb4
commit 1958314976
4 changed files with 122 additions and 5 deletions

View File

@@ -16,7 +16,8 @@ import {
CallExpression,
createArrayExpression,
ExpressionNode,
JSChildNode
JSChildNode,
ArrayExpression
} from '@vue/compiler-dom'
import { escapeHtml, isBooleanAttr, isSSRSafeAttrName } from '@vue/shared'
import { createSSRCompilerError, SSRErrorCodes } from '../errors'
@@ -210,8 +211,12 @@ function isTextareaWithValue(
}
function mergeCall(call: CallExpression, arg: string | JSChildNode) {
const existing = call.arguments[0] as ExpressionNode
call.arguments[0] = createArrayExpression([existing, arg])
const existing = call.arguments[0] as ExpressionNode | ArrayExpression
if (existing.type === NodeTypes.JS_ARRAY_EXPRESSION) {
existing.elements.push(arg)
} else {
call.arguments[0] = createArrayExpression([existing, arg])
}
}
function removeStaticBinding(

View File

@@ -1,7 +1,33 @@
import { DirectiveTransform } from '@vue/compiler-dom'
import {
DirectiveTransform,
createCompilerError,
DOMErrorCodes,
createObjectProperty,
createSimpleExpression,
createConditionalExpression,
createObjectExpression
} from '@vue/compiler-dom'
export const ssrTransformShow: DirectiveTransform = (dir, node, context) => {
if (!dir.exp) {
context.onError(createCompilerError(DOMErrorCodes.X_V_SHOW_NO_EXPRESSION))
}
return {
props: []
props: [
createObjectProperty(
createSimpleExpression(`style`, true),
createConditionalExpression(
dir.exp!,
createSimpleExpression(`null`, false),
createObjectExpression([
createObjectProperty(
createSimpleExpression(`display`, true),
createSimpleExpression(`none`, true)
)
]),
false /* no newline */
)
)
]
}
}