2025-02-08 13:06:44 -05:00
|
|
|
import createModule, { type MainModule } from '../lib/web-tree-sitter';
|
2025-01-20 02:43:52 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
import { type Parser } from './parser';
|
2025-01-19 15:15:01 -05:00
|
|
|
|
|
|
|
|
export let Module: MainModule | null = null;
|
|
|
|
|
|
2025-01-20 02:43:52 -05:00
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*
|
|
|
|
|
* Initialize the Tree-sitter WASM module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
|
|
|
|
*/
|
2025-01-19 23:06:02 -05:00
|
|
|
export async function initializeBinding(moduleOptions?: EmscriptenModule): Promise<MainModule> {
|
2025-01-19 15:15:01 -05:00
|
|
|
if (!Module) {
|
|
|
|
|
Module = await createModule(moduleOptions);
|
|
|
|
|
}
|
|
|
|
|
return Module;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-20 02:43:52 -05:00
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*
|
|
|
|
|
* Checks if the Tree-sitter WASM module has been initialized.
|
|
|
|
|
*/
|
2025-01-19 15:15:01 -05:00
|
|
|
export function checkModule(): boolean {
|
|
|
|
|
return !!Module;
|
|
|
|
|
}
|