refactor(compiler-vapor): cleanup

This commit is contained in:
三咲智子 Kevin Deng 2024-04-28 03:14:10 +09:00
parent d535c647be
commit 17d598f743
No known key found for this signature in database
2 changed files with 8 additions and 12 deletions

View File

@ -23,16 +23,15 @@ import { transformVOn } from './transforms/vOn'
import { transformVShow } from './transforms/vShow'
import { transformRef } from './transforms/transformRef'
import { transformText } from './transforms/transformText'
import type { HackOptions } from './ir'
import { transformVModel } from './transforms/vModel'
import { transformVIf } from './transforms/vIf'
import { transformVFor } from './transforms/vFor'
import { transformComment } from './transforms/transformComment'
import type { HackOptions } from './ir'
export { wrapTemplate } from './transforms/utils'
// TODO: copied from @vue/compiler-core
// code/AST -> IR -> JS codegen
// code/AST -> IR (transform) -> JS (generate)
export function compile(
source: string | RootNode,
options: CompilerOptions = {},

View File

@ -89,10 +89,7 @@ export class TransformContext<T extends AllNode = AllNode> {
this.root = this as TransformContext<RootNode>
}
enterBlock(
ir: TransformContext['block'],
isVFor: boolean = false,
): () => void {
enterBlock(ir: BlockIRNode, isVFor: boolean = false): () => void {
const { block, template, dynamic, childrenTemplate } = this
this.block = ir
this.dynamic = ir.dynamic
@ -205,18 +202,18 @@ const defaultOptions = {
// AST -> IR
export function transform(
root: RootNode,
node: RootNode,
options: TransformOptions = {},
): RootIRNode {
const ir: RootIRNode = {
type: IRNodeTypes.ROOT,
node: root,
source: root.source,
node,
source: node.source,
template: [],
component: new Set(),
block: {
type: IRNodeTypes.BLOCK,
node: root,
node,
dynamic: newDynamic(),
effect: [],
operation: [],
@ -224,7 +221,7 @@ export function transform(
},
}
const context = new TransformContext(ir, root, options)
const context = new TransformContext(ir, node, options)
transformNode(context)