web: Add bindings for remaining field APIs

This commit is contained in:
Max Brunsfeld 2019-06-18 20:36:24 -07:00
parent 30e73505e1
commit 82fab90c0b
5 changed files with 81 additions and 5 deletions

View file

@ -302,6 +302,17 @@ class Node {
return unmarshalNode(this.tree);
}
childForFieldId(fieldId) {
marshalNode(this);
C._ts_node_child_by_field_id_wasm(this.tree[0], fieldId);
return unmarshalNode(this.tree);
}
childForFieldName(fieldName) {
const fieldId = this.tree.language.fields.indexOf(fieldName);
if (fieldId !== -1) return this.childForFieldId(fieldId);
}
get childCount() {
marshalNode(this);
return C._ts_node_child_count_wasm(this.tree[0]);
@ -586,10 +597,13 @@ class TreeCursor {
return unmarshalNode(this.tree);
}
currentFieldName() {
currentFieldId() {
marshalTreeCursor(this);
const fieldId = C._ts_tree_cursor_current_field_id_wasm(this.tree[0]);
return this.tree.language.fields[fieldId];
return C._ts_tree_cursor_current_field_id_wasm(this.tree[0]);
}
currentFieldName() {
return this.tree.language.fields[this.currentFieldId()];
}
gotoFirstChild() {
@ -641,6 +655,23 @@ class Language {
return C._ts_language_version(this[0]);
}
get fieldCount() {
return this.fields.length - 1;
}
fieldIdForName(fieldName) {
const result = this.fields.indexOf(fieldName);
if (result !== -1) {
return result;
} else {
return null;
}
}
fieldNameForId(fieldId) {
return this.fields[fieldName] || null;
}
static load(url) {
let bytes;
if (