From 3da257b8ea2fd76b6b1907f415fe4d15b03a52dc Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Thu, 13 Jan 2022 18:33:55 +0800 Subject: [PATCH 1/2] refactor(compiler-core): improve the readability --- packages/compiler-core/src/transforms/transformText.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/compiler-core/src/transforms/transformText.ts b/packages/compiler-core/src/transforms/transformText.ts index 2ab6805c6a7..1cbbf2e6487 100644 --- a/packages/compiler-core/src/transforms/transformText.ts +++ b/packages/compiler-core/src/transforms/transformText.ts @@ -11,6 +11,7 @@ import { isText } from '../utils' import { CREATE_TEXT } from '../runtimeHelpers' import { PatchFlags, PatchFlagNames } from '@vue/shared' import { getConstantType } from './hoistStatic' +import { createCompoundExpression } from '../ast' // Merge adjacent text nodes and expressions into a single expression // e.g.
abc {{ d }} {{ e }}
should have a single expression node as child. @@ -36,11 +37,10 @@ export const transformText: NodeTransform = (node, context) => { const next = children[j] if (isText(next)) { if (!currentContainer) { - currentContainer = children[i] = { - type: NodeTypes.COMPOUND_EXPRESSION, - loc: child.loc, - children: [child] - } + currentContainer = children[i] = createCompoundExpression( + [child], + child.loc + ) } // merge adjacent text node into current currentContainer.children.push(` + `, next) From cda45bb43fa8d71e5aa71201938fdb8e7ae10fa5 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 May 2022 04:37:01 -0400 Subject: [PATCH 2/2] Update transformText.ts --- packages/compiler-core/src/transforms/transformText.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/src/transforms/transformText.ts b/packages/compiler-core/src/transforms/transformText.ts index 1cbbf2e6487..2c8ab384fd8 100644 --- a/packages/compiler-core/src/transforms/transformText.ts +++ b/packages/compiler-core/src/transforms/transformText.ts @@ -5,13 +5,13 @@ import { createCallExpression, CallExpression, ElementTypes, - ConstantTypes + ConstantTypes, + createCompoundExpression } from '../ast' import { isText } from '../utils' import { CREATE_TEXT } from '../runtimeHelpers' import { PatchFlags, PatchFlagNames } from '@vue/shared' import { getConstantType } from './hoistStatic' -import { createCompoundExpression } from '../ast' // Merge adjacent text nodes and expressions into a single expression // e.g.
abc {{ d }} {{ e }}
should have a single expression node as child.