/** * 组件信息 * * 概念:每个 San 组件都对应一个 ComponentInfo。 * * 关系:通常通过 src/parsers 下的解析器从 SSR 的输入得到 SanSourceFile。 * 一个 SanSourceFile 中可能包含若干个 ComponentInfo。 * * 类型:对于 TS 源码输入,解析得到的是 TypedComponentInfo, * 对于其他输入,解析得到的是 JSComponentInfo。 */ import type { ANode, Component, ComponentDefineOptions, DefinedComponentClass } from 'san'; import { FunctionDefinition } from '../ast/renderer-ast-dfn'; import type { ClassDeclaration } from 'ts-morph'; import type { Node } from 'acorn'; import { ComponentReference, DynamicComponentReference } from './component-reference'; import type { RenderOptions } from '../compilers/renderer-options'; export type TagName = string; export type ComponentSSRType = 'client-render' | 'render-only' | 'render-hydrate' | undefined; export type ComponentInheritAttrs = false | true | undefined; export type ComponentAutoFillStyleAndId = false | true | undefined; export type ComponentType = 'normal' | 'template'; /** * 所有类型的 ComponentInfo,都需要实现如下接口 */ export interface ComponentInfo { id: string; root: ANode; childComponents: Map; componentType: ComponentType; ssrType: ComponentSSRType; inheritAttrs: ComponentInheritAttrs; autoFillStyleAndId: ComponentAutoFillStyleAndId; hasMethod(name: string): boolean; getComputedNames(): string[]; getFilterNames(): string[]; hasDynamicComponent(): boolean; compileToRenderer(options: RenderOptions): FunctionDefinition; } /** * 提供一个组件信息的封装,包括: * - computed name 列表、filters name 列表、root ANode * - 从 TypeScript 来的还有 sourceFile、classDeclaration 等 * * 注意: * - 这里只是存数据,它的创建由具体 parser 负责 * - 这个工具类只为了方便实现具体的 ComponentInfo,不暴露作为接口 */ declare abstract class ComponentInfoImpl { /** * 见 component-reference.ts 的说明 */ readonly id: string; readonly root: ANode; readonly childComponents: Map; readonly componentType: ComponentType; readonly ssrType: ComponentSSRType; readonly inheritAttrs: ComponentInheritAttrs; readonly autoFillStyleAndId: ComponentAutoFillStyleAndId; constructor( /** * 见 component-reference.ts 的说明 */ id: string, root: ANode, childComponents: Map, componentType: ComponentType, ssrType: ComponentSSRType, inheritAttrs: ComponentInheritAttrs, autoFillStyleAndId: ComponentAutoFillStyleAndId); abstract hasMethod(name: string): boolean; abstract getComputedNames(): string[]; abstract getFilterNames(): string[]; hasDynamicComponent(): boolean; compileToRenderer(options: RenderOptions): FunctionDefinition; } export declare class DynamicComponentInfo extends ComponentInfoImpl implements ComponentInfo { readonly componentClass: Component<{}> | DefinedComponentClass<{}>; /** * 归一化的 proto。 * * 确保 computed 等属性都出现在 proto 上, * 用于 compileToRenderer() 和 compileToSource() */ readonly proto: Component<{}> & ComponentDefineOptions<{}>; constructor(id: string, root: ANode, childComponents: Map, componentType: ComponentType, ssrType: ComponentSSRType, inheritAttrs: ComponentInheritAttrs, autoFillStyleAndId: ComponentAutoFillStyleAndId, componentClass: Component<{}> | DefinedComponentClass<{}>); hasMethod(name: string): boolean; getComputedNames(): string[]; getFilterNames(): string[]; } export declare class JSComponentInfo extends ComponentInfoImpl implements ComponentInfo { readonly className: string; readonly sourceCode: string; readonly isRawObject: boolean; private readonly properties; constructor(id: string, className: string, properties: Map, sourceCode: string, componentType?: ComponentType, isRawObject?: boolean); hasMethod(name: string): boolean; getComputedNames(): string[]; getFilterNames(): string[]; getComponentsDelcarations(): Generator<[string, Node]>; private getObjectPropertyKeys; } export declare class TypedComponentInfo extends ComponentInfoImpl implements ComponentInfo { readonly classDeclaration: ClassDeclaration; private computedNames; private filterNames; constructor(id: string, root: ANode, childComponents: Map, ssrType: ComponentSSRType, inheritAttrs: ComponentInheritAttrs, autoFillStyleAndId: ComponentAutoFillStyleAndId, classDeclaration: ClassDeclaration, componentType?: ComponentType); hasMethod(name: string): boolean; getComputedNames(): string[]; getFilterNames(): string[]; } export {};