From: daiwei Date: Sat, 8 Feb 2025 07:55:43 +0000 (+0800) Subject: chore: update codegen X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bac645bb0cf8c3e95f512ab8359f89c43b2b2d05;p=thirdparty%2Fvuejs%2Fcore.git chore: update codegen --- diff --git a/packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts b/packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts index 99a9933f1e..cd98d8c7e2 100644 --- a/packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts @@ -11,16 +11,17 @@ describe('transition-group', () => { "const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer") return function ssrRender(_ctx, _push, _parent, _attrs) { - if (_attrs && _attrs.tag) { - _push(\`<\${_attrs.tag}>\`) + const _tag = _attrs && _attrs.tag + if (_tag) { + _push(\`<\${_tag}>\`) } _push(\`\`) _ssrRenderList(_ctx.list, (i) => { _push(\`
\`) }) _push(\`\`) - if (_attrs && _attrs.tag) { - _push(\`\`) + if (_tag) { + _push(\`\`) } }" `) @@ -120,8 +121,9 @@ describe('transition-group', () => { "const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer") return function ssrRender(_ctx, _push, _parent, _attrs) { - if (_attrs && _attrs.tag) { - _push(\`<\${_attrs.tag}>\`) + const _tag = _attrs && _attrs.tag + if (_tag) { + _push(\`<\${_tag}>\`) } _push(\`\`) _ssrRenderList(10, (i) => { @@ -134,8 +136,8 @@ describe('transition-group', () => { _push(\`
ok
\`) } _push(\`\`) - if (_attrs && _attrs.tag) { - _push(\`\`) + if (_tag) { + _push(\`\`) } }" `) diff --git a/packages/compiler-ssr/src/ssrCodegenTransform.ts b/packages/compiler-ssr/src/ssrCodegenTransform.ts index 536cbb5c1e..0d09887317 100644 --- a/packages/compiler-ssr/src/ssrCodegenTransform.ts +++ b/packages/compiler-ssr/src/ssrCodegenTransform.ts @@ -4,6 +4,7 @@ import { type CompilerError, type CompilerOptions, ElementTypes, + type ExpressionNode, type IfStatement, type JSChildNode, NodeTypes, @@ -84,7 +85,7 @@ export interface SSRTransformContext { onError: (error: CompilerError) => void helper(name: T): T pushStringPart(part: TemplateLiteral['elements'][0]): void - pushStatement(statement: IfStatement | CallExpression): void + pushStatement(statement: IfStatement | CallExpression | ExpressionNode): void } function createSSRTransformContext( diff --git a/packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts b/packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts index 4945d1e3a8..e1669a5940 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts @@ -125,12 +125,13 @@ export function ssrProcessTransitionGroup( p.exp.content === '_attrs', ) if (hasFallthroughAttrs) { + context.pushStatement( + createSimpleExpression('const _tag = _attrs && _attrs.tag'), + ) context.pushStatement( createIfStatement( - createSimpleExpression('_attrs && _attrs.tag'), - createBlockStatement([ - createSimpleExpression('_push(`<${_attrs.tag}>`)'), - ]), + createSimpleExpression('_tag'), + createBlockStatement([createSimpleExpression('_push(`<${_tag}>`)')]), ), ) } @@ -140,10 +141,8 @@ export function ssrProcessTransitionGroup( if (hasFallthroughAttrs) { context.pushStatement( createIfStatement( - createSimpleExpression('_attrs && _attrs.tag'), - createBlockStatement([ - createSimpleExpression('_push(``)'), - ]), + createSimpleExpression('_tag'), + createBlockStatement([createSimpleExpression('_push(``)')]), ), ) }