/** * Grammar loader for web-tree-sitter. * * Handles environment detection, WASM loading, and in-process caching. * * `web-tree-sitter` is an **optional** peer dependency — if it is not * installed, every function here returns `null` gracefully and the * structural merge is silently skipped. */ /** A loaded tree-sitter Language (opaque to callers). */ export type Language = unknown; /** A ready-to-use tree-sitter Parser (opaque to callers). */ export type TSParser = unknown; export type Environment = "node" | "tauri" | "browser"; export interface LoaderOptions { /** Base URL used by the browser adapter to locate grammar WASM files. */ grammarBaseUrl?: string; /** Directory used by the Tauri adapter to locate grammar WASM files. */ grammarDir?: string; /** * URL for `web-tree-sitter.wasm` — the web-tree-sitter runtime WASM. * Pass this when the runtime cannot auto-discover the file (e.g. inside a * Vite bundle where the hashed asset URL is not predictable). * Example: `"/grammars/web-tree-sitter.wasm"`. * * Internally mapped to `locateFile` for web-tree-sitter v0.26+ (Emscripten). */ wasmPath?: string; /** * Custom WASM bytes loader — overrides environment detection entirely. * Receives the grammar name (e.g. "tree-sitter-typescript") and must * return the raw WASM bytes. */ customLoader?: (grammarName: string) => Promise; } /** * Detect the current runtime environment. * Priority: Tauri (window.__TAURI_INTERNALS__) > Node.js (process.versions.node) > browser. */ export declare function detectEnvironment(): Environment; /** * Ensure web-tree-sitter's WASM runtime is initialized. * * Idempotent — safe to call multiple times; initialization runs only once. * * @returns The Parser class, or `null` if web-tree-sitter is unavailable. */ export declare function ensureParserInitialized(_opts?: LoaderOptions): Promise; /** * Load and cache a tree-sitter grammar by name. * * Returns `null` (never throws) if: * - `web-tree-sitter` is not installed * - The grammar WASM file cannot be found or loaded * * @param grammarName - e.g. "tree-sitter-typescript" * @param opts - Optional WASM path / loader overrides */ export declare function loadGrammar(grammarName: string, opts?: LoaderOptions): Promise; /** * Create a configured tree-sitter Parser instance. * * Returns `null` if web-tree-sitter is unavailable. * * @param language - A language object returned by `loadGrammar()` * @param opts - Loader options (passed to `ensureParserInitialized`) */ export declare function createParser(language: Language, opts?: LoaderOptions): Promise; /** * Reset the in-process grammar cache and initialization state. * Intended for use in tests only. */ export declare function _resetCache(): void; //# sourceMappingURL=loader.d.ts.map