/**
 * ts 相关定义
 */ export const enum ReactiveFlags { SKIP = '__v_skip' , IS_REACTIVE = '__v_isReactive' , IS_READONLY = '__v_isReadonly' , RAW = '__v_raw' } export interface Target { [ ReactiveFlags . SKIP ] ? : boolean ; [ ReactiveFlags . IS_REACTIVE ] ? : boolean ; [ ReactiveFlags . IS_READONLY ] ? : boolean ; [ ReactiveFlags . RAW ] ? : any ; } export type KeyToDepMap = Map < any , Dep > ; export type Dep = Set < ReactiveEffect > ; export interface ReactiveEffect < T = any > { ( ) : T ; _isEffect : true ; id : number ; active : boolean ; raw : ( ) => T ; deps : Array < Dep > ; options : ReactiveEffectOptions ; } export type ComputedGetter < T > = ( ctx ? : any ) => T ; export type ComputedSetter < T > = ( v : T ) => void ; export interface WritableComputedOptions < T > { get : ComputedGetter < T > ; set : ComputedSetter < T > ; } export interface ReactiveEffectOptions { lazy ? : boolean ; scheduler ? : ( job : ReactiveEffect ) => void ; } export interface RendererNode { [ key ] : any ; } export interface RendererElement extends RendererNode { } export type RootRenderFunction < HostElement = RendererElement > = ( vnode : VNode , container : HostElement ) => void ; type VNodeChildAtom = VNode | string | number | boolean | null | undefined | void ; export type VNodeArrayChildren = Array < VNodeArrayChildren | VNodeChildAtom > ; export type VNodeChild = VNodeChildAtom | VNodeArrayChildren ; export type VNodeNormalizedChildren = string | VNodeArrayChildren | null ; export interface VNode < HostNode = RendererNode , HostElement = RendererElement , ExtraProps = { [ key ] : any ; } > { [ ReactiveFlags . SKIP ] : true ; type : any ; props : ExtraProps | null ; key : string | number | null ; children : VNodeNormalizedChildren ; component : ComponentInstance | null ; el : HostNode | null ; target : HostElement | null ; shapeFlag : number ; patchFlag : number ; dynamicProps : string [ ] | null ; dynamicChildren : VNode [ ] | null ; } export const enum ShapeFlags { ELEMENT = 1 , FUNCTIONAL_COMPONENT = 1 << 1 , STATEFUL_COMPONENT = 1 << 2 , TEXT_CHILDREN = 1 << 3 , ARRAY_CHILDREN = 1 << 4 , SLOTS_CHILDREN = 1 << 5 , TELEPORT = 1 << 6 , SUSPENSE = 1 << 7 , COMPONENT_SHOULD_KEEP_ALIVE = 1 << 8 , COMPONENT_KEPT_ALIVE = 1 << 9 , COMPONENT = ShapeFlags . STATEFUL_COMPONENT | ShapeFlags . FUNCTIONAL_COMPONENT } export type Data = Record < string , unknown > ; export type PatchFn = ( n1 : VNode | null , n2 : VNode , container : RendererElement , anchor ? : RendererNode | null ) => void ; export type SetupRenderEffectFn = ( instance : ComponentInstance , container : RendererElement ) => void ; export type ComponentFn = ( initialVNode : VNode , container : RendererElement ) => void ; export interface ComponentInstance { type : any ; vnode : VNode ; next : VNode | null ; subTree : VNode ; update : ReactiveEffect ; render : any ; internal effects : ReactiveEffect [ ] | null ; proxy : any ; props : Data ; setupState : Data ; isMounted : boolean ; [ LifecycleHooks . BEFORE_MOUNT ] : LifecycleHook ; [ LifecycleHooks . MOUNTED ] : LifecycleHook ; [ LifecycleHooks . BEFORE_UPDATE ] : LifecycleHook ; [ LifecycleHooks . UPDATED ] : LifecycleHook ; [ LifecycleHooks . BEFORE_UNMOUNT ] : LifecycleHook ; [ LifecycleHooks . UNMOUNTED ] : LifecycleHook ; } export interface RendererOptions < HostNode = RendererNode , HostElement = RendererElement > { insert ( el , parent , anchor ? ) : void ; remove ( el ) : void ; patchProp ( el , key , prevValue , nextValue ) : void ; createElement ( type , isSVG ? , isCustomizedBuiltIn ? ) : HostElement ; createText ( text ) : HostNode ; createComment ( text ) : HostNode ; setText ( node , text ) : void ; setElementText ( node , text ) : void ; parentNode ( node ) : HostElement | null ; nextSibling ( node ) : HostNode | null ; querySelector ? ( selector ) : HostElement | null ; setScopeId ? ( el , id ) : void ; cloneNode ? ( node ) : HostNode ; } export type DOMRenderOptions = RendererOptions < Node , Element > ; export type Style = string | Record < string , string > | null ; export const enum PatchFlags { TEXT = 1 , CLASS = 1 << 1 , STYLE = 1 << 2 , PROPS = 1 << 3 , FULL_PROPS = 1 << 4 , HYDRATE_EVENTS = 1 << 5 , STABLE_FRAGMENT = 1 << 6 , KEYED_FRAGMENT = 1 << 7 , UNKEYED_FRAGMENT = 1 << 8 , NEED_PATCH = 1 << 9 , DYNAMIC_SLOTS = 1 << 10 , DEV_ROOT_FRAGMENT = 1 << 11 , HOISTED = - 1 , BAIL = - 2 } export interface SchedulerJob { ( ) : void ; id ? : number ; allowRecurse ? : boolean ; } export const enum LifecycleHooks { BEFORE_MOUNT = 'bm' , MOUNTED = 'm' , BEFORE_UPDATE = 'bu' , UPDATED = 'u' , BEFORE_UNMOUNT = 'bum' , UNMOUNTED = 'um' } type LifecycleHook = Function [ ] | null ; export interface CreateHook { ( lifecycle ) : < T extends Function = ( ) => any > ( hook : T , target : ComponentInstance | null ) => void ; } export interface ParserContext { options : any ; readonly originalSource : string ; source : string ; offset : number ; line : number ; column : number ; } export interface Position { offset : number ; line : number ; column : number ; } export const enum NodeTypes { ROOT , ELEMENT , TEXT , COMMENT , SIMPLE_EXPRESSION , INTERPOLATION , ATTRIBUTE , DIRECTIVE , COMPOUND_EXPRESSION , IF , IF_BRANCH , FOR , TEXT_CALL , VNODE_CALL , JS_CALL_EXPRESSION , JS_OBJECT_EXPRESSION , JS_PROPERTY , JS_ARRAY_EXPRESSION , JS_FUNCTION_EXPRESSION , JS_CONDITIONAL_EXPRESSION , JS_CACHE_EXPRESSION } export const enum Namespaces { HTML } export interface AttributeNode { type : NodeTypes . ATTRIBUTE | NodeTypes . DIRECTIVE ; name : string ; value ? : any ; exp : any ; arg : any ; loc ? : any ; } export interface SourceLocation { start : Position ; end : Position ; source : string ; } export interface Position { offset : number ; line : number ; column : number ; } export interface Node { type : NodeTypes ; loc : SourceLocation ; props ? : any ; tagType ? : any ; } export type StructuralDirectiveTransform = ( node : Node , dir : any , context : any ) => void | ( ( ) => void ) ; export type NodeTransform = ( node : Node , context : any ) => void | ( ( ) => void ) | ( ( ) => void ) [ ] ; export type JSChildNode = CallExpression ; export interface CallExpression extends Node { type : NodeTypes . JS_CALL_EXPRESSION ; callee : string | symbol ; arguments : ( string | symbol | JSChildNode ) ; } export interface ConditionalExpression extends Node { type : NodeTypes . JS_CONDITIONAL_EXPRESSION ; test : JSChildNode ; consequent : JSChildNode ; alternate : JSChildNode ; newline : boolean ; }