fix(web): correct childWithDescendant() functionality

This fix allows for more granular address control when marshalling nodes
across WASM. This is necessary for node methods which accept another
node as a parameter (i.e., `childWithDescendant()`)
This commit is contained in:
Riley Bruins 2025-04-14 22:38:32 -07:00 committed by Will Lillis
parent 45a281c962
commit 21390af2dd
4 changed files with 30 additions and 10 deletions

View file

@ -189,6 +189,21 @@ describe('Node', () => {
});
});
describe('.childWithDescendant()', () => {
it('correctly retrieves immediate children', () => {
const sourceCode = 'let x = 1; console.log(x);';
tree = parser.parse(sourceCode)!;
const root = tree.rootNode
const child = root.children[0].children[0]
const a = root.childWithDescendant(child)
expect(a!.startIndex).toBe(0)
const b = a!.childWithDescendant(child)
expect(b).toEqual(child)
const c = b!.childWithDescendant(child)
expect(c).toBeNull()
});
});
describe('.nextSibling and .previousSibling', () => {
it('returns the node\'s next and previous sibling', () => {
tree = parser.parse('x10 + 1000')!;