Merge pull request #2466 from tom95/add-field-name-for-child

Web Bindings: Expose fieldNameForChild C function
This commit is contained in:
Amaan Qureshi 2023-08-18 12:20:39 -04:00 committed by GitHub
commit 7d953eb5ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View file

@ -282,6 +282,17 @@ class Node {
return unmarshalNode(this.tree);
}
fieldNameForChild(index) {
marshalNode(this);
const address = C._ts_node_field_name_for_child_wasm(this.tree[0], index);
if (!address) {
return null;
}
const result = AsciiToString(address);
// must not free, the string memory is owned by the language
return result;
}
namedChild(index) {
marshalNode(this);
C._ts_node_named_child_wasm(this.tree[0], index);