wip(compiler-ssr): v-show
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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 */
|
||||
)
|
||||
)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user