/** * Process-wide parse cache for `oxc-parser.parseSync`. * * @remarks * Several build plugins (eco-component-meta, client-graph-boundary, * browser-runtime) each call `parseSync` on the same source file with * overlapping options. This cache memoizes the parse result keyed by * `(absolute path, source, options)`. When the source is unchanged, * subsequent calls return the cached result without re-parsing. * * The cache is LRU-bounded (10 000 entries) and key-stable across a * single HMR session. It is **content-hashed** rather than * mtime-hashed so that `touch`/`utimes` does not invalidate a * still-valid parse. */ import { type ParseResult, type ParserOptions } from 'oxc-parser'; export type ModuleParseOptions = ParserOptions & { /** * Optional parser language override. If omitted, derived from the file * extension at lookup time. Set this explicitly if your caller already * computed the language (avoids re-deriving inside the cache). */ lang?: ParserOptions['lang']; }; export type ParserLanguage = 'js' | 'jsx' | 'ts' | 'tsx'; /** Resolves the Oxc dialect for a source module from its file extension. */ export declare function parserLanguageForFile(filePath: string): ParserLanguage; /** Parses an ECMAScript module with the shared, normalized cache contract. */ export declare function parseModuleSource(filePath: string, source: string, options?: ModuleParseOptions): ParseResult; /** * LRU-bounded module parse cache. * * Single instance shared across the process. Constructed lazily; use * {@link moduleParseCache} for the default shared instance. */ export declare class ModuleParseCache { private readonly entries; private readonly maxEntries; private hits; private misses; constructor(maxEntries?: number); /** * Parse `source` for `filePath`, memoizing by (filePath, source, options). * * @returns the {@link ParseResult} from `oxc-parser.parseSync`. */ getOrParse(filePath: string, source: string, options?: ModuleParseOptions): ParseResult; /** Clear all cached entries. Useful in tests and on full-rebuild signals. */ clear(): void; /** Current cache size (for observability). */ get size(): number; /** Cumulative hit/miss counters (for observability). */ stats(): { hits: number; misses: number; size: number; hitRate: number; }; } /** * Default shared cache. Use this from plugin code so the cache is * amortized across plugins and build invocations. */ export declare const moduleParseCache: ModuleParseCache; /** * Drop-in replacement for `oxc-parser.parseSync` that uses the shared * {@link moduleParseCache}. Use everywhere we currently call `parseSync` * on user/source files during a build. */ export declare function cachedParseSync(filePath: string, source: string, options?: ModuleParseOptions): ParseResult;