mirror of https://github.com/vuejs/core.git
refactor(compiler-vapor): cleanup
This commit is contained in:
parent
d535c647be
commit
17d598f743
|
@ -23,16 +23,15 @@ import { transformVOn } from './transforms/vOn'
|
||||||
import { transformVShow } from './transforms/vShow'
|
import { transformVShow } from './transforms/vShow'
|
||||||
import { transformRef } from './transforms/transformRef'
|
import { transformRef } from './transforms/transformRef'
|
||||||
import { transformText } from './transforms/transformText'
|
import { transformText } from './transforms/transformText'
|
||||||
import type { HackOptions } from './ir'
|
|
||||||
import { transformVModel } from './transforms/vModel'
|
import { transformVModel } from './transforms/vModel'
|
||||||
import { transformVIf } from './transforms/vIf'
|
import { transformVIf } from './transforms/vIf'
|
||||||
import { transformVFor } from './transforms/vFor'
|
import { transformVFor } from './transforms/vFor'
|
||||||
import { transformComment } from './transforms/transformComment'
|
import { transformComment } from './transforms/transformComment'
|
||||||
|
import type { HackOptions } from './ir'
|
||||||
|
|
||||||
export { wrapTemplate } from './transforms/utils'
|
export { wrapTemplate } from './transforms/utils'
|
||||||
|
|
||||||
// TODO: copied from @vue/compiler-core
|
// code/AST -> IR (transform) -> JS (generate)
|
||||||
// code/AST -> IR -> JS codegen
|
|
||||||
export function compile(
|
export function compile(
|
||||||
source: string | RootNode,
|
source: string | RootNode,
|
||||||
options: CompilerOptions = {},
|
options: CompilerOptions = {},
|
||||||
|
|
|
@ -89,10 +89,7 @@ export class TransformContext<T extends AllNode = AllNode> {
|
||||||
this.root = this as TransformContext<RootNode>
|
this.root = this as TransformContext<RootNode>
|
||||||
}
|
}
|
||||||
|
|
||||||
enterBlock(
|
enterBlock(ir: BlockIRNode, isVFor: boolean = false): () => void {
|
||||||
ir: TransformContext['block'],
|
|
||||||
isVFor: boolean = false,
|
|
||||||
): () => void {
|
|
||||||
const { block, template, dynamic, childrenTemplate } = this
|
const { block, template, dynamic, childrenTemplate } = this
|
||||||
this.block = ir
|
this.block = ir
|
||||||
this.dynamic = ir.dynamic
|
this.dynamic = ir.dynamic
|
||||||
|
@ -205,18 +202,18 @@ const defaultOptions = {
|
||||||
|
|
||||||
// AST -> IR
|
// AST -> IR
|
||||||
export function transform(
|
export function transform(
|
||||||
root: RootNode,
|
node: RootNode,
|
||||||
options: TransformOptions = {},
|
options: TransformOptions = {},
|
||||||
): RootIRNode {
|
): RootIRNode {
|
||||||
const ir: RootIRNode = {
|
const ir: RootIRNode = {
|
||||||
type: IRNodeTypes.ROOT,
|
type: IRNodeTypes.ROOT,
|
||||||
node: root,
|
node,
|
||||||
source: root.source,
|
source: node.source,
|
||||||
template: [],
|
template: [],
|
||||||
component: new Set(),
|
component: new Set(),
|
||||||
block: {
|
block: {
|
||||||
type: IRNodeTypes.BLOCK,
|
type: IRNodeTypes.BLOCK,
|
||||||
node: root,
|
node,
|
||||||
dynamic: newDynamic(),
|
dynamic: newDynamic(),
|
||||||
effect: [],
|
effect: [],
|
||||||
operation: [],
|
operation: [],
|
||||||
|
@ -224,7 +221,7 @@ export function transform(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const context = new TransformContext(ir, root, options)
|
const context = new TransformContext(ir, node, options)
|
||||||
|
|
||||||
transformNode(context)
|
transformNode(context)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue