vue源码阅读—07—编译原理之编译入口

https://ustbhuangyi.github.io/vue-analysis/v2/compile/entrance.html#%E6%80%BB%E7%BB%93
编译的入口:
在/entry-runtime-with-compiler.js,通过compileToFuntions方法,把template模板作为参数穿进去,然后通过解构赋值的方法取到render函数;
那么compileToFuntions这个函数是从哪里获取的?
执行createCompiler方法,createCompile就是src/compiler的公共编译模块,
createCompiler函数是通过执行createCompileCreator函数得到的;
到这里我们就找到了createCompiler函数,执行这个函数就会返回一个对象,对象里有compile方法和compileToFunctions属性。
要注意的是,我们传递的baseOptions不同,compile函数由于会引用baseOptions,所以得到的compile函数也是不同的。
又因为createCompileToFuntions会把compile作为参数即回调函数,所以不同的baseOptions会有不同的createCompileToFunctionFn方法;
createCompileToFunctionFn函数内部会调用compile函数,compile函数内部会调用baseCompile函数,
baseCompile函数是真正的编译,主要有是三步,
1.将模板编译为ast树
2.optimize,将ast树优化
3.generate,将ast树转化为render函数;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2021-08-04 Failed to configure a DataSource: 'url' attribute is not specified and no embe...失败配置数据源...
2020-08-04 达梦8———客户端工具使用