feat(web)!: use the WASM module in the bindings, and not the other way around

Parser is no longer the default export, but you *must* call
`Parser.init()` before doing anything still
This commit is contained in:
Amaan Qureshi 2025-01-19 15:15:01 -05:00
parent b1e39d2dba
commit be7716dfa7
29 changed files with 613 additions and 662 deletions

View file

@ -1,5 +1,5 @@
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
import type { default as ParserType, Language, Tree, Query, QueryCapture, QueryMatch } from 'web-tree-sitter';
import type { Parser as ParserType, Language, Tree, Query, QueryMatch, QueryCapture } from '../src';
import helper from './helper';
let Parser: typeof ParserType;
@ -576,12 +576,11 @@ function formatMatches(matches: QueryMatch[]): QueryMatch[] {
}));
}
function formatCaptures(captures: QueryCapture[]): QueryCapture[] {
function formatCaptures(captures: QueryCapture[]): (QueryCapture & { text: string })[] {
return captures.map((c) => {
const node = c.node;
// @ts-expect-error We're not interested in the node object for these tests
delete c.node;
c.text = node.text;
return c;
return { ...c, text: node.text };
});
}