|
|
@@ -87,7 +87,8 @@ export const transformText: NodeTransform = (node, context) => {
|
|
|
}
|
|
|
|
|
|
function processInterpolation(context: TransformContext<InterpolationNode>) {
|
|
|
- const children = context.parent!.node.children
|
|
|
+ const parentNode = context.parent!.node
|
|
|
+ const children = parentNode.children
|
|
|
const nexts = children.slice(context.index)
|
|
|
const idx = nexts.findIndex(n => !isTextLike(n))
|
|
|
const nodes = (idx > -1 ? nexts.slice(0, idx) : nexts) as Array<TextLike>
|
|
|
@@ -97,10 +98,18 @@ function processInterpolation(context: TransformContext<InterpolationNode>) {
|
|
|
if (prev && prev.type === NodeTypes.TEXT) {
|
|
|
nodes.unshift(prev)
|
|
|
}
|
|
|
+ const values = processTextLikeChildren(nodes, context)
|
|
|
+
|
|
|
+ if (values.length === 0 && parentNode.type !== NodeTypes.ROOT) {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
context.template += ' '
|
|
|
const id = context.reference()
|
|
|
- const values = nodes.map(node => createTextLikeExpression(node, context))
|
|
|
+
|
|
|
+ if (values.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
const nonConstantExps = values.filter(v => !isConstantExpression(v))
|
|
|
const isStatic =
|
|
|
@@ -129,8 +138,10 @@ function processTextContainer(
|
|
|
children: TextLike[],
|
|
|
context: TransformContext<ElementNode>,
|
|
|
) {
|
|
|
- const values = children.map(child => createTextLikeExpression(child, context))
|
|
|
+ const values = processTextLikeChildren(children, context)
|
|
|
+
|
|
|
const literals = values.map(getLiteralExpressionValue)
|
|
|
+
|
|
|
if (literals.every(l => l != null)) {
|
|
|
context.childrenTemplate = literals.map(l => String(l))
|
|
|
} else {
|
|
|
@@ -149,13 +160,22 @@ function processTextContainer(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function createTextLikeExpression(node: TextLike, context: TransformContext) {
|
|
|
- markNonTemplate(node, context)
|
|
|
- if (node.type === NodeTypes.TEXT) {
|
|
|
- return createSimpleExpression(node.content, true, node.loc)
|
|
|
- } else {
|
|
|
- return node.content as SimpleExpressionNode
|
|
|
+function processTextLikeChildren(nodes: TextLike[], context: TransformContext) {
|
|
|
+ const exps: SimpleExpressionNode[] = []
|
|
|
+ for (const node of nodes) {
|
|
|
+ let exp: SimpleExpressionNode
|
|
|
+ markNonTemplate(node, context)
|
|
|
+
|
|
|
+ if (node.type === NodeTypes.TEXT) {
|
|
|
+ exp = createSimpleExpression(node.content, true, node.loc)
|
|
|
+ } else {
|
|
|
+ exp = node.content as SimpleExpressionNode
|
|
|
+ }
|
|
|
+
|
|
|
+ if (exp.content) exps.push(exp)
|
|
|
}
|
|
|
+
|
|
|
+ return exps
|
|
|
}
|
|
|
|
|
|
function isTextLike(node: TemplateChildNode): node is TextLike {
|