Browse Source

refactor(compiler-vapor): dedpue fragment

三咲智子 Kevin Deng 2 years ago
parent
commit
9c9e9b2862
1 changed files with 10 additions and 9 deletions
  1. 10 9
      packages/compiler-vapor/src/transform.ts

+ 10 - 9
packages/compiler-vapor/src/transform.ts

@@ -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,