/** * San 项目 * * 一个 SanProject 实例表示一个 San 项目,同一个项目中多次编译可以复用一些已经建立好的对象。 * 尤其对于从 TypeScript 源码开始 SSR 的情况,多次编译之间,整个 TypeScript 项目里的所有(包括类型)文件是可以缓存的。 * * 对使用者建议如下: * * 1. 简单的 SSR 可以直接用 src/index.ts 里的 compileToRenderer 和 compileToSource。 * 2. 复杂的编译过程建议使用 SanProject,它提供了更精细的 API。上述两个 API 其实是 SanProject 一个包装。 */ import type { Component, DefinedComponentClass } from 'san'; import type { TypedSanSourceFile, DynamicSanSourceFile, SanSourceFile, JSSanSourceFile } from '../models/san-source-file'; import type { parseSanSourceFileOptions, RenderOptions } from '../compilers/renderer-options'; import type { Renderer } from './renderer'; import type { CompileOptions } from '../target-js/compilers/compile-options'; import type { TargetCodeGenerator } from '../models/target-code-generator'; import type { CompilerOptions } from 'typescript'; import { Project } from 'ts-morph'; import { ComponentClass, FileDescriptor, CompileInput } from './options'; type TargetCodeGeneratorClass = { new (project: SanProject): T; }; /** * SanProject 对应于 TypeScript 项目,即 tsconfig.json 及其引用的所有文件构成的集合。 */ export declare class SanProject { tsConfigFilePath: null | string | undefined; tsProject?: Project; private compilers; constructor(tsConfigFilePath?: null | string | undefined); /** * 兼容旧版用法 * @alias SanProject.compileToSource */ compile(input: CompileInput, target?: string | TargetCodeGeneratorClass, options?: {}): string; /** * 源文件/组件类编译到源代码 */ compileToSource(input: CompileInput, target?: string | TargetCodeGeneratorClass, options?: RenderOptions): string; /** * 解析 CompileInput 实例中的 San 相关信息 * * CompileInput 可以是 JS、TS 源文件,也可以是组件类,得到的 SanSourceFile 里包含这个文件里 * San 相关的信息,比如有多少个组件?每个组件有哪些方法?以及得到 template 对应的 ANode 树。 */ parseSanSourceFile(componentClass: ComponentClass, options?: parseSanSourceFileOptions): DynamicSanSourceFile; parseSanSourceFile(fileDescriptor: FileDescriptor, options?: parseSanSourceFileOptions): TypedSanSourceFile; parseSanSourceFile(filecontent: string, options?: parseSanSourceFileOptions): JSSanSourceFile; parseSanSourceFile(input: CompileInput, options?: parseSanSourceFileOptions): SanSourceFile; private checkAndFormatParseSanSourceFileOptions; /** * 编译成当前 JavaScript 进程里的 render 函数 * * * `target` 固定为 "js" * * `options.bareFunction` 固定为 true */ compileToRenderer(componentClass: Component | DefinedComponentClass, options?: CompileOptions): Renderer; /** * 输出工具库:组件渲染时需要使用的公共工具。 */ emitHelpers(target: string, options?: any): string; getCompilerOptionsOrThrow(): CompilerOptions; /** * 得到目标代码生成器的实例 * * 如果不存在就去加载一个,如果已经加载过就把它存起来。 */ getOrCreateTargetCodeGenerator(target: string | TargetCodeGeneratorClass): T; /** * 加载目标代码生成器 * * 如果是 san-ssr-target-js,直接从当前仓库的子目录下加载。 * 如果是其他的 target,用 require.resolve 来找。 */ private loadTargetCodeGenerator; } export {};