web: Don't require Parser.init to be called immediately

This commit is contained in:
Max Brunsfeld 2019-06-03 16:18:49 -07:00
parent e195f27d68
commit 1cef6d4550
2 changed files with 7 additions and 12 deletions

View file

@ -10,19 +10,16 @@ var MIN_COMPATIBLE_VERSION;
var TRANSFER_BUFFER;
var currentParseCallback;
var currentLogCallback;
var initPromise;
var initPromise = new Promise(resolve => {
Module.onRuntimeInitialized = resolve
}).then(() => {
TRANSFER_BUFFER = C._ts_init();
VERSION = getValue(TRANSFER_BUFFER, 'i32');
MIN_COMPATIBLE_VERSION = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
});
class Parser {
static init() {
if (!initPromise) {
initPromise = new Promise(resolve => {
Module.onRuntimeInitialized = resolve
}).then(() => {
TRANSFER_BUFFER = C._ts_init();
VERSION = getValue(TRANSFER_BUFFER, 'i32');
MIN_COMPATIBLE_VERSION = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
});
}
return initPromise;
}

View file

@ -3,8 +3,6 @@
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
// module.exports.init();
// delete module.exports.init;
} else {
window.TreeSitter = factory();
}