def build_wasm()

in playground/tree-sitter/build.py [0:0]


def build_wasm(grammar_dir: Path, name: str) -> Path:
    """Build WASM file for a grammar."""
    print(f"Building WASM for {name}")

    # Note that we have to use tree-sitter CLI 0.24 since the main tree-sitter and grammars
    # we use in Piranha are old and not compatible with the latest tree-sitter CLI.
    # TODO: remove this restriction once we upstream all our changes to tree-sitter grammars
    #  and upgrade to latest tree-sitter in Piranha.
    try:
        proc = run_command(["tree-sitter", "--version"])
        version = proc.stdout.strip().split()[1]
        if not version.startswith("0.24"):
            raise RuntimeError(f"tree-sitter CLI version {version} not supported")
    except (subprocess.CalledProcessError, FileNotFoundError, RuntimeError):
        raise RuntimeError(
            "tree-sitter CLI version 0.24.x is required. Install with: cargo install tree-sitter-cli --version 0.24.4"
        )

    print(f"Using tree-sitter CLI version: {proc.stdout.strip()}")

    run_command(["tree-sitter", "build", "--wasm"], cwd=grammar_dir)

    wasm_file = grammar_dir / f"{name}.wasm"
    if not wasm_file.exists():
        raise FileNotFoundError(f"WASM file not found for {name}")

    return wasm_file