Add several bindings for Language

This commit is contained in:
hvithrafn 2021-02-01 11:10:19 -07:00
parent 460ce72312
commit 752372ee09
5 changed files with 145 additions and 0 deletions

View file

@ -646,6 +646,32 @@ class Language {
return this.fields[fieldId] || null;
}
idForNodeType(type, named) {
const typeLength = lengthBytesUTF8(type);
const typeAddress = C._malloc(typeLength + 1);
stringToUTF8(type, typeAddress, typeLength + 1);
const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named);
C._free(typeAddress);
return result;
}
get nodeTypeCount() {
return C._ts_language_symbol_count(this[0]);
}
nodeTypeForId(typeId) {
const name = C._ts_language_symbol_name(this[0], typeId);
return name ? UTF8ToString(name) : null;
}
nodeTypeIsNamed(typeId) {
return C._ts_language_type_is_named_wasm(this[0], typeId) ? true : false;
}
nodeTypeIsVisible(typeId) {
return C._ts_language_type_is_visible_wasm(this[0], typeId) ? true : false;
}
query(source) {
const sourceLength = lengthBytesUTF8(source);
const sourceAddress = C._malloc(sourceLength + 1);