fix(web): correct type errors, improve build

(cherry picked from commit 4db3edadf4)
This commit is contained in:
vemoo 2025-08-30 22:51:41 +02:00 committed by ObserverOfTime
parent 59f3cb91c2
commit bb82b94ded
10 changed files with 1132 additions and 428 deletions

View file

@ -1,4 +1,4 @@
export {
export type {
Point,
Range,
Edit,
@ -7,8 +7,8 @@ export {
LogCallback,
} from './constants';
export {
ParseOptions,
ParseState,
type ParseOptions,
type ParseState,
LANGUAGE_VERSION,
MIN_COMPATIBLE_VERSION,
Parser,
@ -18,14 +18,14 @@ export { Tree } from './tree';
export { Node } from './node';
export { TreeCursor } from './tree_cursor';
export {
QueryOptions,
QueryState,
QueryProperties,
QueryPredicate,
QueryCapture,
QueryMatch,
type QueryOptions,
type QueryState,
type QueryProperties,
type QueryPredicate,
type QueryCapture,
type QueryMatch,
CaptureQuantifier,
PredicateStep,
type PredicateStep,
Query,
} from './query';
} from './query';
export { LookaheadIterator } from './lookahead_iterator';

View file

@ -6,7 +6,7 @@ import { Query } from './query';
const LANGUAGE_FUNCTION_REGEX = /^tree_sitter_\w+$/;
export class LanguageMetadata {
export interface LanguageMetadata {
readonly major_version: number;
readonly minor_version: number;
readonly patch_version: number;

View file

@ -168,10 +168,9 @@ export function marshalEdit(edit: Edit, address = TRANSFER_BUFFER) {
*
* Unmarshals a {@link LanguageMetadata} from the transfer buffer.
*/
export function unmarshalLanguageMetadata(address: number): LanguageMetadata {
const result = {} as LanguageMetadata;
result.major_version = C.getValue(address, 'i32'); address += SIZE_OF_INT;
result.minor_version = C.getValue(address, 'i32'); address += SIZE_OF_INT;
result.field_count = C.getValue(address, 'i32');
return result;
export function unmarshalLanguageMetadata(address: number): LanguageMetadata {
const major_version = C.getValue(address, 'i32');
const minor_version = C.getValue(address += SIZE_OF_INT, 'i32');
const patch_version = C.getValue(address += SIZE_OF_INT, 'i32');
return { major_version, minor_version, patch_version };
}

View file

@ -9,7 +9,8 @@ import { TRANSFER_BUFFER } from './parser';
/** A single node within a syntax {@link Tree}. */
export class Node {
/** @internal */
private [0] = 0; // Internal handle for WASM
// @ts-expect-error: never read
private [0] = 0; // Internal handle for Wasm
/** @internal */
private _children?: (Node | null)[];
@ -635,7 +636,7 @@ export class Node {
}
/** Get the S-expression representation of this node. */
toString() {
toString(): string {
marshalNode(this);
const address = C._ts_node_to_string_wasm(this.tree[0]);
const result = C.AsciiToString(address);

View file

@ -7,16 +7,20 @@ import { getText, Tree } from './tree';
/** A stateful object for walking a syntax {@link Tree} efficiently. */
export class TreeCursor {
/** @internal */
private [0] = 0; // Internal handle for WASM
// @ts-expect-error: never read
private [0] = 0; // Internal handle for Wasm
/** @internal */
private [1] = 0; // Internal handle for WASM
// @ts-expect-error: never read
private [1] = 0; // Internal handle for Wasm
/** @internal */
private [2] = 0; // Internal handle for WASM
// @ts-expect-error: never read
private [2] = 0; // Internal handle for Wasm
/** @internal */
private [3] = 0; // Internal handle for WASM
// @ts-expect-error: never read
private [3] = 0; // Internal handle for Wasm
/** @internal */
private tree: Tree;