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