wip(compiler-ssr): v-bind with static keys
This commit is contained in:
@@ -301,9 +301,10 @@ export interface SequenceExpression extends Node {
|
||||
|
||||
export interface ConditionalExpression extends Node {
|
||||
type: NodeTypes.JS_CONDITIONAL_EXPRESSION
|
||||
test: ExpressionNode
|
||||
test: JSChildNode
|
||||
consequent: JSChildNode
|
||||
alternate: JSChildNode
|
||||
newline: boolean
|
||||
}
|
||||
|
||||
export interface CacheExpression extends Node {
|
||||
@@ -648,13 +649,15 @@ export function createSequenceExpression(
|
||||
export function createConditionalExpression(
|
||||
test: ConditionalExpression['test'],
|
||||
consequent: ConditionalExpression['consequent'],
|
||||
alternate: ConditionalExpression['alternate']
|
||||
alternate: ConditionalExpression['alternate'],
|
||||
newline = true
|
||||
): ConditionalExpression {
|
||||
return {
|
||||
type: NodeTypes.JS_CONDITIONAL_EXPRESSION,
|
||||
test,
|
||||
consequent,
|
||||
alternate,
|
||||
newline,
|
||||
loc: locStub
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ function genConditionalExpression(
|
||||
node: ConditionalExpression,
|
||||
context: CodegenContext
|
||||
) {
|
||||
const { test, consequent, alternate } = node
|
||||
const { test, consequent, alternate, newline: needNewline } = node
|
||||
const { push, indent, deindent, newline } = context
|
||||
if (test.type === NodeTypes.SIMPLE_EXPRESSION) {
|
||||
const needsParens = !isSimpleIdentifier(test.content)
|
||||
@@ -694,15 +694,15 @@ function genConditionalExpression(
|
||||
needsParens && push(`)`)
|
||||
} else {
|
||||
push(`(`)
|
||||
genCompoundExpression(test, context)
|
||||
genNode(test, context)
|
||||
push(`)`)
|
||||
}
|
||||
indent()
|
||||
needNewline && indent()
|
||||
context.indentLevel++
|
||||
push(`? `)
|
||||
genNode(consequent, context)
|
||||
context.indentLevel--
|
||||
newline()
|
||||
needNewline && newline()
|
||||
push(`: `)
|
||||
const isNested = alternate.type === NodeTypes.JS_CONDITIONAL_EXPRESSION
|
||||
if (!isNested) {
|
||||
@@ -712,7 +712,7 @@ function genConditionalExpression(
|
||||
if (!isNested) {
|
||||
context.indentLevel--
|
||||
}
|
||||
deindent(true /* without newline */)
|
||||
needNewline && deindent(true /* without newline */)
|
||||
}
|
||||
|
||||
function genSequenceExpression(
|
||||
@@ -748,15 +748,17 @@ function genCacheExpression(node: CacheExpression, context: CodegenContext) {
|
||||
function genTemplateLiteral(node: TemplateLiteral, context: CodegenContext) {
|
||||
const { push, indent, deindent } = context
|
||||
push('`')
|
||||
for (let i = 0; i < node.elements.length; i++) {
|
||||
const l = node.elements.length
|
||||
const multilines = l > 3
|
||||
for (let i = 0; i < l; i++) {
|
||||
const e = node.elements[i]
|
||||
if (isString(e)) {
|
||||
push(e.replace(/`/g, '\\`'))
|
||||
} else {
|
||||
push('${')
|
||||
indent()
|
||||
if (multilines) indent()
|
||||
genNode(e, context)
|
||||
deindent()
|
||||
if (multilines) deindent()
|
||||
push('}')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ export { noopDirectiveTransform } from './transforms/noopDirectiveTransform'
|
||||
// expose transforms so higher-order compilers can import and extend them
|
||||
export { transformModel } from './transforms/vModel'
|
||||
export { transformOn } from './transforms/vOn'
|
||||
export { transformBind } from './transforms/vBind'
|
||||
|
||||
// exported for compiler-ssr
|
||||
export { processIfBranches } from './transforms/vIf'
|
||||
|
||||
Reference in New Issue
Block a user