Explorar el Código

refactor(compiler-vapor): cleanup

三咲智子 Kevin Deng hace 2 años
padre
commit
17d598f743

+ 2 - 3
packages/compiler-vapor/src/compile.ts

@@ -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 = {},

+ 6 - 9
packages/compiler-vapor/src/transform.ts

@@ -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)