Skip to content

Commit 8fa2a4b

Browse files
committed
refactor(compiler-vapor): move hasDeferredVShow tracking to root IR
1 parent 498ce69 commit 8fa2a4b

File tree

6 files changed

+7
-8
lines changed

6 files changed

+7
-8
lines changed

packages/compiler-vapor/src/generate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export function generate(
201201
`const ${setTemplateRefIdent} = ${context.helper('createTemplateRefSetter')}()`,
202202
)
203203
}
204+
if (ir.hasDeferredVShow) {
205+
push(NEWLINE, `const deferredApplyVShows = []`)
206+
}
204207
push(...genBlockContent(ir.block, context, true))
205208
push(INDENT_END, NEWLINE)
206209

packages/compiler-vapor/src/generators/block.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export function genBlockContent(
4343
const { dynamic, effect, operation, returns, key } = block
4444
const resetBlock = context.enterBlock(block)
4545

46-
if (block.hasDeferredVShow) {
47-
push(NEWLINE, `const deferredApplyVShows = []`)
48-
}
49-
5046
if (root) {
5147
for (let name of context.ir.component) {
5248
const id = toValidAssetId(name, 'component')
@@ -78,7 +74,7 @@ export function genBlockContent(
7874
push(...genOperations(operation, context))
7975
push(...genEffects(effect, context, genEffectsExtraFrag))
8076

81-
if (block.hasDeferredVShow) {
77+
if (root && context.ir.hasDeferredVShow) {
8278
push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`)
8379
}
8480

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export interface BlockIRNode extends BaseIRNode {
5454
effect: IREffect[]
5555
operation: OperationNode[]
5656
returns: number[]
57-
hasDeferredVShow: boolean
5857
}
5958

6059
export interface RootIRNode {
@@ -68,6 +67,7 @@ export interface RootIRNode {
6867
directive: Set<string>
6968
block: BlockIRNode
7069
hasTemplateRef: boolean
70+
hasDeferredVShow: boolean
7171
}
7272

7373
export interface IfIRNode extends BaseIRNode {

packages/compiler-vapor/src/transform.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export function transform(
256256
directive: new Set(),
257257
block: newBlock(node),
258258
hasTemplateRef: false,
259+
hasDeferredVShow: false,
259260
}
260261

261262
const context = new TransformContext(ir, node, options)

packages/compiler-vapor/src/transforms/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const newBlock = (node: BlockIRNode['node']): BlockIRNode => ({
3030
operation: [],
3131
returns: [],
3232
tempId: 0,
33-
hasDeferredVShow: false,
3433
})
3534

3635
export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const transformVShow: DirectiveTransform = (dir, node, context) => {
3939
)
4040

4141
if (shouldDeferred) {
42-
context.parent!.parent!.block.hasDeferredVShow = true
42+
context.ir.hasDeferredVShow = true
4343
}
4444
}
4545

0 commit comments

Comments
 (0)