refactor(compiler-vapor): new dynamic info

This commit is contained in:
三咲智子 Kevin Deng 2024-04-28 03:06:20 +09:00
parent 784310d4dc
commit d535c647be
No known key found for this signature in database
4 changed files with 9 additions and 18 deletions

View File

@ -25,7 +25,7 @@ import {
type VaporDirectiveNode,
} from './ir'
import { isConstantExpression } from './utils'
import { genDefaultDynamic } from './transforms/utils'
import { newDynamic } from './transforms/utils'
export type NodeTransform = (
node: RootNode | TemplateChildNode,
@ -174,7 +174,7 @@ export class TransformContext<T extends AllNode = AllNode> {
template: '',
childrenTemplate: [],
dynamic: genDefaultDynamic(),
dynamic: newDynamic(),
} satisfies Partial<TransformContext<T>>)
}
}
@ -217,9 +217,7 @@ export function transform(
block: {
type: IRNodeTypes.BLOCK,
node: root,
dynamic: extend(genDefaultDynamic(), {
flags: DynamicFlag.REFERENCED,
} satisfies Partial<IRDynamicInfo>),
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],

View File

@ -11,8 +11,8 @@ import {
import { extend } from '@vue/shared'
import { DynamicFlag, type IRDynamicInfo } from '../ir'
export const genDefaultDynamic = (): IRDynamicInfo => ({
flags: DynamicFlag.NONE,
export const newDynamic = (): IRDynamicInfo => ({
flags: DynamicFlag.REFERENCED,
children: [],
})

View File

@ -11,13 +11,11 @@ import {
import {
type BlockIRNode,
DynamicFlag,
type IRDynamicInfo,
IRNodeTypes,
type VaporDirectiveNode,
} from '../ir'
import { extend } from '@vue/shared'
import { findProp, propToExpression } from '../utils'
import { genDefaultDynamic, wrapTemplate } from './utils'
import { newDynamic, wrapTemplate } from './utils'
export const transformVFor = createStructuralDirectiveTransform(
'for',
@ -53,9 +51,7 @@ export function processFor(
const render: BlockIRNode = {
type: IRNodeTypes.BLOCK,
node,
dynamic: extend(genDefaultDynamic(), {
flags: DynamicFlag.REFERENCED,
} satisfies Partial<IRDynamicInfo>),
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],

View File

@ -11,12 +11,11 @@ import {
import {
type BlockIRNode,
DynamicFlag,
type IRDynamicInfo,
IRNodeTypes,
type VaporDirectiveNode,
} from '../ir'
import { extend } from '@vue/shared'
import { genDefaultDynamic, wrapTemplate } from './utils'
import { newDynamic, wrapTemplate } from './utils'
import { getSiblingIf } from './transformComment'
export const transformVIf = createStructuralDirectiveTransform(
@ -118,9 +117,7 @@ export function createIfBranch(
const branch: BlockIRNode = {
type: IRNodeTypes.BLOCK,
node,
dynamic: extend(genDefaultDynamic(), {
flags: DynamicFlag.REFERENCED,
} satisfies Partial<IRDynamicInfo>),
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],