UNPKG

@ordojs/core

Version:

Core compiler and runtime for OrdoJS framework

171 lines 4.25 kB
/** * @fileoverview OrdoJS Dependency Analyzer - Tracks reactive variable usage and builds dependency graphs */ import { OptimizationError, type ComponentAST, type ReactiveVariableNode, type SourceRange } from '../types/index.js'; /** * Dependency relationship between variables */ export interface Dependency { from: string; to: string; type: DependencyType; location: SourceRange; } /** * Types of dependencies */ export declare enum DependencyType { READ = "READ",// Variable is read WRITE = "WRITE",// Variable is written to COMPUTED = "COMPUTED",// Variable is used in computed expression EVENT = "EVENT",// Variable is used in event handler INTERPOLATION = "INTERPOLATION" } /** * Dependency graph node */ export interface DependencyNode { name: string; variable: ReactiveVariableNode; dependencies: Set<string>; dependents: Set<string>; updateOrder: number; isCircular: boolean; } /** * Dependency graph structure */ export interface DependencyGraph { nodes: Map<string, DependencyNode>; edges: Dependency[]; updateOrder: string[]; circularDependencies: string[][]; } /** * Update function metadata */ export interface UpdateFunction { variableName: string; targetElements: string[]; updateType: UpdateType; code: string; dependencies: string[]; } /** * Types of DOM updates */ export declare enum UpdateType { TEXT_CONTENT = "TEXT_CONTENT", ATTRIBUTE = "ATTRIBUTE", PROPERTY = "PROPERTY", CLASS = "CLASS", STYLE = "STYLE", CONDITIONAL = "CONDITIONAL", LIST = "LIST" } /** * Dependency analyzer for reactive variables */ export declare class DependencyAnalyzer { private graph; private currentComponent; private errors; constructor(); /** * Analyze dependencies in a component AST */ analyze(ast: ComponentAST): DependencyGraph; /** * Generate efficient update functions for reactive changes */ generateUpdateFunctions(ast: ComponentAST): UpdateFunction[]; /** * Get analysis errors */ getErrors(): OptimizationError[]; /** * Reset analyzer state */ private reset; /** * Build initial dependency nodes from reactive variables */ private buildDependencyNodes; /** * Analyze variable usage throughout the component */ private analyzeVariableUsage; /** * Analyze markup block for variable dependencies */ private analyzeMarkupBlock; /** * Analyze HTML element for variable dependencies */ private analyzeHTMLElement; /** * Analyze attribute for variable dependencies */ private analyzeAttribute; /** * Analyze interpolation for variable dependencies */ private analyzeInterpolation; /** * Analyze client block for variable dependencies */ private analyzeClientBlock; /** * Analyze expression for variable dependencies */ private analyzeExpressionDependencies; /** * Add a dependency relationship */ private addDependency; /** * Detect circular dependencies using depth-first search */ private detectCircularDependencies; /** * Depth-first search for circular dependency detection */ private dfsCircularDetection; /** * Calculate optimal update order using topological sort */ private calculateUpdateOrder; /** * Generate update function for a specific variable */ private generateUpdateFunction; /** * Determine the type of update needed for a variable */ private determineUpdateType; /** * Generate text content update code */ private generateTextContentUpdate; /** * Generate attribute update code */ private generateAttributeUpdate; /** * Generate property update code */ private generatePropertyUpdate; /** * Generate class update code */ private generateClassUpdate; /** * Generate style update code */ private generateStyleUpdate; /** * Generate generic update code */ private generateGenericUpdate; } //# sourceMappingURL=dependency-analyzer.d.ts.map