Add TreeCursor.currentFieldName to wasm binding

This commit is contained in:
Max Brunsfeld 2019-02-08 17:53:21 -08:00
parent c90a532d8f
commit 1a33f1a665
4 changed files with 51 additions and 0 deletions

View file

@ -525,6 +525,12 @@ class TreeCursor {
return unmarshalNode(this.tree);
}
currentFieldName() {
marshalTreeCursor(this);
const fieldId = C._ts_tree_cursor_current_field_id_wasm(this.tree[0]);
return this.tree.language.fields[fieldId];
}
gotoFirstChild() {
marshalTreeCursor(this);
const result = C._ts_tree_cursor_goto_first_child_wasm(this.tree[0]);
@ -559,6 +565,15 @@ class Language {
this.types[i] = UTF8ToString(C._ts_language_symbol_name(this[0], i));
}
}
this.fields = new Array(C._ts_language_field_count(this[0]) + 1);
for (let i = 0, n = this.fields.length; i < n; i++) {
const fieldName = C._ts_language_field_name_for_id(this[0], i);
if (fieldName !== 0) {
this.fields[i] = UTF8ToString(fieldName);
} else {
this.fields[i] = null;
}
}
}
get version() {