Browse Source

refactor(compiler-vapor): simplify register template

三咲智子 Kevin Deng 2 years ago
parent
commit
823e47ca62

+ 4 - 3
packages/compiler-vapor/src/transform.ts

@@ -190,6 +190,7 @@ function createRootContext(
     template: '',
     childrenTemplate: [],
     registerTemplate() {
+      this.template += this.childrenTemplate.filter(Boolean).join('')
       let templateNode: TemplateFactoryIRNode | FragmentFactoryIRNode
 
       const existing = root.template.findIndex(t =>
@@ -261,7 +262,6 @@ export function transform(
   const context = createRootContext(ir, root, options)
 
   transformNode(context)
-  context.registerTemplate()
 
   return ir
 }
@@ -311,8 +311,9 @@ function transformNode(
     exitFns[i]()
   }
 
-  if (context.node.type === NodeTypes.ROOT)
-    context.template += context.childrenTemplate.filter(Boolean).join('')
+  if (context.node.type === NodeTypes.ROOT) {
+    context.registerTemplate()
+  }
 }
 
 function transformChildren(context: TransformContext<RootNode | ElementNode>) {

+ 0 - 1
packages/compiler-vapor/src/transforms/vFor.ts

@@ -62,7 +62,6 @@ export function processFor(
   context.reference()
 
   return () => {
-    context.template += context.childrenTemplate.filter(Boolean).join('')
     context.registerTemplate()
     exitBlock()
     context.registerOperation({

+ 0 - 1
packages/compiler-vapor/src/transforms/vIf.ts

@@ -158,7 +158,6 @@ export function createIfBranch(
   const exitBlock = context.enterBlock(branch)
   context.reference()
   const onExit = () => {
-    context.template += context.childrenTemplate.filter(Boolean).join('')
     context.registerTemplate()
     exitBlock()
   }