diff --git a/packages/compiler-vapor/src/transforms/transformText.ts b/packages/compiler-vapor/src/transforms/transformText.ts index dd81bec1e80..da4845e02d0 100644 --- a/packages/compiler-vapor/src/transforms/transformText.ts +++ b/packages/compiler-vapor/src/transforms/transformText.ts @@ -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 @@ -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, ) } else if (hasInterp) { @@ -112,35 +108,17 @@ function processInterpolation(context: TransformContext) { 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[], +export function processTextContainer( + values: SimpleExpressionNode[], context: TransformContext, -) { - const values = processTextLikeChildren(children, context) - +): void { const literals = values.map(getLiteralExpressionValue) if (literals.every(l => l != null)) { diff --git a/packages/compiler-vapor/src/transforms/vText.ts b/packages/compiler-vapor/src/transforms/vText.ts index 0832398e12a..7685cdba22f 100644 --- a/packages/compiler-vapor/src/transforms/vText.ts +++ b/packages/compiler-vapor/src/transforms/vText.ts @@ -1,9 +1,8 @@ import { DOMErrorCodes, createDOMCompilerError } from '@vue/compiler-dom' -import { IRNodeTypes } from '../ir' import { EMPTY_EXPRESSION } from './utils' import type { DirectiveTransform } from '../transform' -import { getLiteralExpressionValue } from '../utils' import { isVoidTag } from '../../../shared/src' +import { processTextContainer } from './transformText' export const transformVText: DirectiveTransform = (dir, node, context) => { let { exp, loc } = dir @@ -25,20 +24,5 @@ export const transformVText: DirectiveTransform = (dir, node, context) => { return } - const literal = getLiteralExpressionValue(exp) - if (literal != null) { - context.childrenTemplate = [String(literal)] - } else { - context.childrenTemplate = [' '] - context.registerOperation({ - type: IRNodeTypes.GET_TEXT_CHILD, - parent: context.reference(), - }) - context.registerEffect([exp], { - type: IRNodeTypes.SET_TEXT, - element: context.reference(), - values: [exp], - generated: true, - }) - } + processTextContainer([exp], context) } diff --git a/packages/compiler-vapor/src/utils.ts b/packages/compiler-vapor/src/utils.ts index 728281914fd..e61cfe6d693 100644 --- a/packages/compiler-vapor/src/utils.ts +++ b/packages/compiler-vapor/src/utils.ts @@ -1,4 +1,3 @@ -import type { BigIntLiteral, NumericLiteral, StringLiteral } from '@babel/types' import { isGloballyAllowed } from '@vue/shared' import { type AttributeNode, @@ -75,10 +74,10 @@ export function resolveExpression( export function getLiteralExpressionValue( exp: SimpleExpressionNode, -): number | string | boolean | null { +): string | null { if (exp.ast) { if (exp.ast.type === 'StringLiteral') { - return (exp.ast as StringLiteral | NumericLiteral | BigIntLiteral).value + return exp.ast.value } else if ( exp.ast.type === 'TemplateLiteral' && exp.ast.expressions.length === 0