refactor(compiler-core): hoist static text calls between elements

This commit is contained in:
Evan You
2020-02-10 18:32:11 -05:00
parent 12fcf9ab95
commit f4c54a888b
5 changed files with 42 additions and 38 deletions

View File

@@ -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 ---------------------------------------------------------------

View File

@@ -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)
}
}
}