Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions packages/compiler-vapor/src/transforms/transformText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
} from '@vue/compiler-dom'
import type { NodeTransform, TransformContext } from '../transform'
import { DynamicFlag, IRNodeTypes } from '../ir'
import {
getLiteralExpressionValue,
isConstantExpression,
isStaticExpression,
} from '../utils'
import { getLiteralExpressionValue } from '../utils'
import { escapeHtml } from '@vue/shared'

type TextLike = TextNode | InterpolationNode
Expand Down Expand Up @@ -62,7 +58,7 @@ export const transformText: NodeTransform = (node, context) => {
// all text like with interpolation
if (!isFragment && isAllTextLike && hasInterp) {
processTextContainer(
node.children as TextLike[],
processTextLikeChildren(node.children as TextLike[], context),
context as TransformContext<ElementNode>,
)
} else if (hasInterp) {
Expand Down Expand Up @@ -112,35 +108,17 @@ function processInterpolation(context: TransformContext<InterpolationNode>) {
return
}

const nonConstantExps = values.filter(v => !isConstantExpression(v))
const isStatic =
!nonConstantExps.length ||
nonConstantExps.every(e =>
isStaticExpression(e, context.options.bindingMetadata),
) ||
context.inVOnce

if (isStatic) {
context.registerOperation({
type: IRNodeTypes.SET_TEXT,
element: id,
values,
})
} else {
context.registerEffect(values, {
type: IRNodeTypes.SET_TEXT,
element: id,
values,
})
}
context.registerEffect(values, {
type: IRNodeTypes.SET_TEXT,
element: id,
values,
})
}

function processTextContainer(
children: TextLike[],
values: SimpleExpressionNode[],
context: TransformContext<ElementNode>,
) {
const values = processTextLikeChildren(children, context)

): void {
const literals = values.map(getLiteralExpressionValue)

if (literals.every(l => l != null)) {
Expand Down
Loading