]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-vapor): dedpue fragment
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Sat, 27 Jan 2024 17:39:16 +0000 (01:39 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Sat, 27 Jan 2024 17:39:21 +0000 (01:39 +0800)
packages/compiler-vapor/src/transform.ts

index f3b66da6d29adfd8846253fd7026c1efe965c194..0c81c5e4c45f0db474a2339ac9d013aa04abd58f 100644 (file)
@@ -174,16 +174,17 @@ function createRootContext(
     registerTemplate() {
       let templateNode: TemplateFactoryIRNode | FragmentFactoryIRNode
 
-      if (this.template) {
-        const idx = root.template.findIndex(
-          (t) =>
-            t.type === IRNodeTypes.TEMPLATE_FACTORY &&
-            t.template === this.template,
-        )
-        if (idx !== -1) {
-          return (this.block.templateIndex = idx)
-        }
+      const existing = root.template.findIndex((t) =>
+        this.template
+          ? t.type === IRNodeTypes.TEMPLATE_FACTORY &&
+            t.template === this.template
+          : t.type === IRNodeTypes.FRAGMENT_FACTORY,
+      )
+      if (existing !== -1) {
+        return (this.block.templateIndex = existing)
+      }
 
+      if (this.template) {
         templateNode = {
           type: IRNodeTypes.TEMPLATE_FACTORY,
           template: this.template,