feat(wasm): add Supertype API
This commit is contained in:
parent
86b507a842
commit
ef39298342
5 changed files with 127 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
const C = Module;
|
||||
const INTERNAL = {};
|
||||
const SIZE_OF_SHORT = 2;
|
||||
const SIZE_OF_INT = 4;
|
||||
const SIZE_OF_CURSOR = 4 * SIZE_OF_INT;
|
||||
const SIZE_OF_NODE = 5 * SIZE_OF_INT;
|
||||
|
|
@ -858,6 +859,40 @@ class Language {
|
|||
return C._ts_language_type_is_visible_wasm(this[0], typeId) ? true : false;
|
||||
}
|
||||
|
||||
get supertypes() {
|
||||
C._ts_language_supertypes_wasm(this[0]);
|
||||
const count = getValue(TRANSFER_BUFFER, 'i32');
|
||||
const buffer = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
const result = new Array(count);
|
||||
|
||||
if (count > 0) {
|
||||
let address = buffer;
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = getValue(address, 'i16');
|
||||
address += SIZE_OF_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
subtypes(supertype) {
|
||||
C._ts_language_subtypes_wasm(this[0], supertype);
|
||||
const count = getValue(TRANSFER_BUFFER, 'i32');
|
||||
const buffer = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
const result = new Array(count);
|
||||
|
||||
if (count > 0) {
|
||||
let address = buffer;
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = getValue(address, 'i16');
|
||||
address += SIZE_OF_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nextState(stateId, typeId) {
|
||||
return C._ts_language_next_state(this[0], stateId, typeId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue