2
0
Эх сурвалжийг харах

refactor(compiler-vapor): move `hasDeferredVShow` tracking to root IR

daiwei 5 сар өмнө
parent
commit
8fa2a4b1cd

+ 3 - 0
packages/compiler-vapor/src/generate.ts

@@ -201,6 +201,9 @@ export function generate(
       `const ${setTemplateRefIdent} = ${context.helper('createTemplateRefSetter')}()`,
     )
   }
+  if (ir.hasDeferredVShow) {
+    push(NEWLINE, `const deferredApplyVShows = []`)
+  }
   push(...genBlockContent(ir.block, context, true))
   push(INDENT_END, NEWLINE)
 

+ 1 - 5
packages/compiler-vapor/src/generators/block.ts

@@ -43,10 +43,6 @@ export function genBlockContent(
   const { dynamic, effect, operation, returns, key } = block
   const resetBlock = context.enterBlock(block)
 
-  if (block.hasDeferredVShow) {
-    push(NEWLINE, `const deferredApplyVShows = []`)
-  }
-
   if (root) {
     for (let name of context.ir.component) {
       const id = toValidAssetId(name, 'component')
@@ -78,7 +74,7 @@ export function genBlockContent(
   push(...genOperations(operation, context))
   push(...genEffects(effect, context, genEffectsExtraFrag))
 
-  if (block.hasDeferredVShow) {
+  if (root && context.ir.hasDeferredVShow) {
     push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`)
   }
 

+ 1 - 1
packages/compiler-vapor/src/ir/index.ts

@@ -54,7 +54,6 @@ export interface BlockIRNode extends BaseIRNode {
   effect: IREffect[]
   operation: OperationNode[]
   returns: number[]
-  hasDeferredVShow: boolean
 }
 
 export interface RootIRNode {
@@ -68,6 +67,7 @@ export interface RootIRNode {
   directive: Set<string>
   block: BlockIRNode
   hasTemplateRef: boolean
+  hasDeferredVShow: boolean
 }
 
 export interface IfIRNode extends BaseIRNode {

+ 1 - 0
packages/compiler-vapor/src/transform.ts

@@ -256,6 +256,7 @@ export function transform(
     directive: new Set(),
     block: newBlock(node),
     hasTemplateRef: false,
+    hasDeferredVShow: false,
   }
 
   const context = new TransformContext(ir, node, options)

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

@@ -30,7 +30,6 @@ export const newBlock = (node: BlockIRNode['node']): BlockIRNode => ({
   operation: [],
   returns: [],
   tempId: 0,
-  hasDeferredVShow: false,
 })
 
 export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {

+ 1 - 1
packages/compiler-vapor/src/transforms/vShow.ts

@@ -39,7 +39,7 @@ export const transformVShow: DirectiveTransform = (dir, node, context) => {
     )
 
     if (shouldDeferred) {
-      context.parent!.parent!.block.hasDeferredVShow = true
+      context.ir.hasDeferredVShow = true
     }
   }