/** * 生命周期处理文件 * AST 处理 * 大部分 AST 利用了引用类型数据的处理方式,需要格外注意 */ import * as babel from '@babel/core'; import { NodePath } from '@babel/traverse'; /** * 主函数,对包内的文件,处理子包的生命周期 * @param subPackagePath 包路径 */ export declare function handleLifecycle(subPackageName: string): Promise; /** * 根据子包获取 app.json 注册的页面 * @param subPackageName 子包名 */ export declare function getPagesByAppJSON(subPackageName: string): Promise; /** * 重写 sub-app.js,以模拟各个生命周期的执行 * @param subAppFilePath sub-app.js 的路径 */ export declare function rewriteSubAppJs(subAppFilePath: string): Promise; /** * 重写 page.js,以插入各个生命周期 * @param filePath page.js 的路径 * @param subAppFilePath sub-app.js 的路径 */ export declare function rewritePageJs(filePath: string, subAppFilePath: string): Promise; /** * 插入引入模块 * @param fileAst page.js 的AST * @param relativePath 相对路径 */ export declare function injectRequireModule(fileAst: babel.ParseResult, relativePath: string): Promise; /** * 获取 app.js 内的 globalData * @param appJsFilePath app.js文件路径 */ export declare function getGlobalData(appJsFilePath: string): Promise; /** * 将新的 globalData 替换原来的 globalData * @param appJsFilePath appJs 文件路径 * @param globalData 新的 globalData */ export declare function setGlobalData(appJsFilePath: string, globalData: Record): Promise; /** * 重写子包的 onLaunch 方法,让该函数只执行一次 * 具体做法就是在最后塞入 module.exports.onLaunch = null * TODO 当前 sub-app.js 没有 onLaunch 方法 * @param filePath string 文件地址 */ export declare function rewriteSubAppJsOnLaunch(subAppJsAst: babel.ParseResult): Promise; /** * generate AST,重置为空函数 * 带上 onShow / onHide / onError * module.exports.onLaunch = function() {} * TODO 这里的监听器会随着子包点击加载越来越多,需要考虑判断函数内部是否有内容再决定是否监听 */ export declare function getClearOnLaunchAst(): babel.types.BlockStatement | babel.types.DoWhileStatement | babel.types.ForInStatement | babel.types.ForStatement | babel.types.FunctionDeclaration | babel.types.SwitchStatement | babel.types.WhileStatement | babel.types.ForOfStatement | babel.types.BreakStatement | babel.types.ClassDeclaration | babel.types.ContinueStatement | babel.types.ReturnStatement | babel.types.ThrowStatement | babel.types.IfStatement | babel.types.DebuggerStatement | babel.types.VariableDeclaration | babel.types.ExportAllDeclaration | babel.types.ExportDefaultDeclaration | babel.types.ExportNamedDeclaration | babel.types.ImportDeclaration | babel.types.DeclareClass | babel.types.DeclareFunction | babel.types.DeclareInterface | babel.types.DeclareModule | babel.types.DeclareModuleExports | babel.types.DeclareTypeAlias | babel.types.DeclareOpaqueType | babel.types.DeclareVariable | babel.types.DeclareExportDeclaration | babel.types.DeclareExportAllDeclaration | babel.types.InterfaceDeclaration | babel.types.OpaqueType | babel.types.TypeAlias | babel.types.TSDeclareFunction | babel.types.TSInterfaceDeclaration | babel.types.TSTypeAliasDeclaration | babel.types.TSEnumDeclaration | babel.types.TSModuleDeclaration | babel.types.EmptyStatement | babel.types.ExpressionStatement | babel.types.LabeledStatement | babel.types.TryStatement | babel.types.WithStatement | babel.types.TSImportEqualsDeclaration | babel.types.TSExportAssignment | babel.types.TSNamespaceExportDeclaration | babel.types.Statement[]; /** * 让 page 的 onLoad 函数执行 sub-app 的 onLaunch 方法 * @param filePath 文件地址 */ export declare function rewritePageJsOnLaunch(fileAst: babel.ParseResult): Promise; /** * 生成 onLaunch 的执行一次的模版 */ export declare function getSubAppLaunchCalleeAst(): babel.types.Statement; /** * 获取一个全新带 Launch 的 onLoad AST */ export declare function getOnLoadWithLaunchAst(): NodePath; /** * 通过模版快速生成 require('module') 的 AST * @param name 模块名 * @param filePath 引用路径 */ export declare function getRequireModuleAst(name: string, filePath: string): babel.types.Statement; /** * 通过文件路径,获取文件的 AST * @param filePath 文件路径 */ export declare function getASTByFile(filePath: string): Promise; //# sourceMappingURL=lifecycle.d.ts.map