refactor(compiler-core): hoist static text calls between elements
This commit is contained in:
@@ -243,7 +243,7 @@ export interface ForNode extends Node {
|
||||
export interface TextCallNode extends Node {
|
||||
type: NodeTypes.TEXT_CALL
|
||||
content: TextNode | InterpolationNode | CompoundExpressionNode
|
||||
codegenNode: CallExpression
|
||||
codegenNode: CallExpression | SimpleExpressionNode // when hoisted
|
||||
}
|
||||
|
||||
// JS Node Types ---------------------------------------------------------------
|
||||
|
||||
@@ -21,6 +21,8 @@ export function hoistStatic(root: RootNode, context: TransformContext) {
|
||||
root.children,
|
||||
context,
|
||||
new Map(),
|
||||
// Root node is unfortuantely non-hoistable due to potential parent
|
||||
// fallthrough attributes.
|
||||
isSingleElementRoot(root, root.children[0])
|
||||
)
|
||||
}
|
||||
@@ -86,6 +88,11 @@ function walk(
|
||||
// Do not hoist v-if single child because it has to be a block
|
||||
walk(branchChildren, context, resultCache, branchChildren.length === 1)
|
||||
}
|
||||
} else if (
|
||||
child.type === NodeTypes.TEXT_CALL &&
|
||||
isStaticNode(child.content, resultCache)
|
||||
) {
|
||||
child.codegenNode = context.hoist(child.codegenNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user