mirror of https://github.com/vuejs/core.git
refactor(compiler-vapor): extract new block
This commit is contained in:
parent
05f4ade4d9
commit
e42fecb992
|
@ -25,7 +25,7 @@ import {
|
|||
type VaporDirectiveNode,
|
||||
} from './ir'
|
||||
import { isConstantExpression } from './utils'
|
||||
import { newDynamic } from './transforms/utils'
|
||||
import { newBlock, newDynamic } from './transforms/utils'
|
||||
|
||||
export type NodeTransform = (
|
||||
node: RootNode | TemplateChildNode,
|
||||
|
@ -211,14 +211,7 @@ export function transform(
|
|||
source: node.source,
|
||||
template: [],
|
||||
component: new Set(),
|
||||
block: {
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node,
|
||||
dynamic: newDynamic(),
|
||||
effect: [],
|
||||
operation: [],
|
||||
returns: [],
|
||||
},
|
||||
block: newBlock(node),
|
||||
}
|
||||
|
||||
const context = new TransformContext(ir, node, options)
|
||||
|
|
|
@ -9,13 +9,27 @@ import {
|
|||
createSimpleExpression,
|
||||
} from '@vue/compiler-dom'
|
||||
import { extend } from '@vue/shared'
|
||||
import { DynamicFlag, type IRDynamicInfo } from '../ir'
|
||||
import {
|
||||
type BlockIRNode,
|
||||
DynamicFlag,
|
||||
type IRDynamicInfo,
|
||||
IRNodeTypes,
|
||||
} from '../ir'
|
||||
|
||||
export const newDynamic = (): IRDynamicInfo => ({
|
||||
flags: DynamicFlag.REFERENCED,
|
||||
children: [],
|
||||
})
|
||||
|
||||
export const newBlock = (node: BlockIRNode['node']): BlockIRNode => ({
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node,
|
||||
dynamic: newDynamic(),
|
||||
effect: [],
|
||||
operation: [],
|
||||
returns: [],
|
||||
})
|
||||
|
||||
export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {
|
||||
if (node.tagType === ElementTypes.TEMPLATE) {
|
||||
return node
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
type VaporDirectiveNode,
|
||||
} from '../ir'
|
||||
import { findProp, propToExpression } from '../utils'
|
||||
import { newDynamic, wrapTemplate } from './utils'
|
||||
import { newBlock, wrapTemplate } from './utils'
|
||||
|
||||
export const transformVFor = createStructuralDirectiveTransform(
|
||||
'for',
|
||||
|
@ -48,14 +48,7 @@ export function processFor(
|
|||
context.node = node = wrapTemplate(node, ['for'])
|
||||
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT
|
||||
const id = context.reference()
|
||||
const render: BlockIRNode = {
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node,
|
||||
dynamic: newDynamic(),
|
||||
effect: [],
|
||||
operation: [],
|
||||
returns: [],
|
||||
}
|
||||
const render: BlockIRNode = newBlock(node)
|
||||
const exitBlock = context.enterBlock(render, true)
|
||||
context.reference()
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
type VaporDirectiveNode,
|
||||
} from '../ir'
|
||||
import { extend } from '@vue/shared'
|
||||
import { newDynamic, wrapTemplate } from './utils'
|
||||
import { newBlock, wrapTemplate } from './utils'
|
||||
import { getSiblingIf } from './transformComment'
|
||||
|
||||
export const transformVIf = createStructuralDirectiveTransform(
|
||||
|
@ -114,15 +114,7 @@ export function createIfBranch(
|
|||
): [BlockIRNode, () => void] {
|
||||
context.node = node = wrapTemplate(node, ['if', 'else-if', 'else'])
|
||||
|
||||
const branch: BlockIRNode = {
|
||||
type: IRNodeTypes.BLOCK,
|
||||
node,
|
||||
dynamic: newDynamic(),
|
||||
effect: [],
|
||||
operation: [],
|
||||
returns: [],
|
||||
}
|
||||
|
||||
const branch: BlockIRNode = newBlock(node)
|
||||
const exitBlock = context.enterBlock(branch)
|
||||
context.reference()
|
||||
return [branch, exitBlock]
|
||||
|
|
Loading…
Reference in New Issue