Quellcode durchsuchen

chore: update codegen

test: add test
daiwei vor 1 Jahr
Ursprung
Commit
92bf78e48e

+ 2 - 2
packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts

@@ -11,7 +11,7 @@ describe('transition-group', () => {
       "const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer")
 
       return function ssrRender(_ctx, _push, _parent, _attrs) {
-        const _tag = _attrs && _attrs.tag
+        const _tag = (_attrs && typeof _attrs.tag === 'string') ? _attrs.tag : ''
         if (_tag) {
           _push(\`<\${_tag}>\`)
         }
@@ -121,7 +121,7 @@ describe('transition-group', () => {
       "const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer")
 
       return function ssrRender(_ctx, _push, _parent, _attrs) {
-        const _tag = _attrs && _attrs.tag
+        const _tag = (_attrs && typeof _attrs.tag === 'string') ? _attrs.tag : ''
         if (_tag) {
           _push(\`<\${_tag}>\`)
         }

+ 4 - 2
packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts

@@ -115,7 +115,7 @@ export function ssrProcessTransitionGroup(
       context.pushStringPart(`</${tag.value!.content}>`)
     }
   } else {
-    // #12827 _attrs fallthrough may contain tag property
+    // _attrs may contain tag property
     const hasFallthroughAttrs = node.props.some(
       p =>
         p.type === NodeTypes.DIRECTIVE &&
@@ -126,7 +126,9 @@ export function ssrProcessTransitionGroup(
     )
     if (hasFallthroughAttrs) {
       context.pushStatement(
-        createSimpleExpression('const _tag = _attrs && _attrs.tag'),
+        createSimpleExpression(
+          `const _tag = (_attrs && typeof _attrs.tag === 'string') ? _attrs.tag : ''`,
+        ),
       )
       context.pushStatement(
         createIfStatement(

+ 16 - 0
packages/server-renderer/__tests__/ssrAttrFallthrough.spec.ts

@@ -75,4 +75,20 @@ describe('ssr: attr fallthrough', () => {
       `<div id="foo" class="bar baz"></div>`,
     )
   })
+
+  // #12827
+  test('with transition-group tag name', async () => {
+    expect(
+      await renderToString(
+        createApp({
+          components: {
+            one: {
+              template: `<TransitionGroup><slot/></TransitionGroup>`,
+            },
+          },
+          template: `<one tag="div"><p v-for="i in 2">{{i}}</p></one>`,
+        }),
+      ),
+    ).toBe(`<div><!--[--><p>1</p><p>2</p><!--]--></div>`)
+  })
 })