UNPKG

@rttist/ts-loader-wasm

Version:

TypeScript loader transforming source code allowing usage of advanced RTTIST reflection features.

422 lines (352 loc) 12.3 kB
let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextDecoder, TextEncoder } = require(`util`); let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); let cachedUint8Memory0 = null; function getUint8Memory0() { if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8Memory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } const heap = new Array(128).fill(undefined); heap.push(undefined, null, true, false); let heap_next = heap.length; function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } function getObject(idx) { return heap[idx]; } function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } let WASM_VECTOR_LEN = 0; let cachedTextEncoder = new TextEncoder('utf-8'); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8Memory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; } WASM_VECTOR_LEN = offset; return ptr; } let cachedInt32Memory0 = null; function getInt32Memory0() { if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachedInt32Memory0; } function getCachedStringFromWasm0(ptr, len) { if (ptr === 0) { return getObject(len); } else { return getStringFromWasm0(ptr, len); } } function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); } return instance.ptr; } /** * @param {string} source_code * @param {string} path * @param {PackageInfo} package_info * @returns {string} */ module.exports.transform = function(source_code, path, package_info) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(source_code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; _assertClass(package_info, PackageInfo); var ptr2 = package_info.__destroy_into_raw(); wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; var r3 = getInt32Memory0()[retptr / 4 + 3]; if (r3) { throw takeObject(r2); } var v4 = getCachedStringFromWasm0(r0, r1); if (r0 !== 0) { wasm.__wbindgen_free(r0, r1); } return v4; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; /** * @param {string} path * @param {PackageInfo} package_info * @returns {string} */ module.exports.load = function(path, package_info) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; _assertClass(package_info, PackageInfo); var ptr1 = package_info.__destroy_into_raw(); wasm.load(retptr, ptr0, len0, ptr1); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; var r3 = getInt32Memory0()[retptr / 4 + 3]; if (r3) { throw takeObject(r2); } var v3 = getCachedStringFromWasm0(r0, r1); if (r0 !== 0) { wasm.__wbindgen_free(r0, r1); } return v3; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } }; function handleError(f, args) { try { return f.apply(this, args); } catch (e) { wasm.__wbindgen_exn_store(addHeapObject(e)); } } /** */ class PackageInfo { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(PackageInfo.prototype); obj.__wbg_ptr = ptr; return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_packageinfo_free(ptr); } /** * @param {string} name * @param {string} root_dir */ constructor(name, root_dir) { const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len0 = WASM_VECTOR_LEN; const ptr1 = passStringToWasm0(root_dir, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; const ret = wasm.packageinfo_new(ptr0, len0, ptr1, len1); return PackageInfo.__wrap(ret); } /** * @returns {string} */ get name() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.packageinfo_name(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getCachedStringFromWasm0(r0, r1); if (r0 !== 0) { wasm.__wbindgen_free(r0, r1); } return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * @returns {string} */ get root_dir() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.packageinfo_root_dir(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getCachedStringFromWasm0(r0, r1); if (r0 !== 0) { wasm.__wbindgen_free(r0, r1); } return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } module.exports.PackageInfo = PackageInfo; module.exports.__wbindgen_string_new = function(arg0, arg1) { const ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; module.exports.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () { const ret = self.self; return addHeapObject(ret); }, arguments) }; module.exports.__wbg_window_5f4faef6c12b79ec = function() { return handleError(function () { const ret = window.window; return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; module.exports.__wbg_globalThis_1d39714405582d3c = function() { return handleError(function () { const ret = globalThis.globalThis; return addHeapObject(ret); }, arguments) }; module.exports.__wbg_global_651f05c6a0944d1c = function() { return handleError(function () { const ret = global.global; return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_is_undefined = function(arg0) { const ret = getObject(arg0) === undefined; return ret; }; module.exports.__wbg_newnoargs_581967eacc0e2604 = function(arg0, arg1) { var v0 = getCachedStringFromWasm0(arg0, arg1); const ret = new Function(v0); return addHeapObject(ret); }; module.exports.__wbg_call_cb65541d95d71282 = function() { return handleError(function (arg0, arg1) { const ret = getObject(arg0).call(getObject(arg1)); return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_object_clone_ref = function(arg0) { const ret = getObject(arg0); return addHeapObject(ret); }; module.exports.__wbg_crypto_c48a774b022d20ac = function(arg0) { const ret = getObject(arg0).crypto; return addHeapObject(ret); }; module.exports.__wbindgen_is_object = function(arg0) { const val = getObject(arg0); const ret = typeof(val) === 'object' && val !== null; return ret; }; module.exports.__wbg_process_298734cf255a885d = function(arg0) { const ret = getObject(arg0).process; return addHeapObject(ret); }; module.exports.__wbg_versions_e2e78e134e3e5d01 = function(arg0) { const ret = getObject(arg0).versions; return addHeapObject(ret); }; module.exports.__wbg_node_1cd7a5d853dbea79 = function(arg0) { const ret = getObject(arg0).node; return addHeapObject(ret); }; module.exports.__wbindgen_is_string = function(arg0) { const ret = typeof(getObject(arg0)) === 'string'; return ret; }; module.exports.__wbg_msCrypto_bcb970640f50a1e8 = function(arg0) { const ret = getObject(arg0).msCrypto; return addHeapObject(ret); }; module.exports.__wbg_newwithlength_e5d69174d6984cd7 = function(arg0) { const ret = new Uint8Array(arg0 >>> 0); return addHeapObject(ret); }; module.exports.__wbg_require_8f08ceecec0f4fee = function() { return handleError(function () { const ret = module.require; return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_is_function = function(arg0) { const ret = typeof(getObject(arg0)) === 'function'; return ret; }; module.exports.__wbindgen_memory = function() { const ret = wasm.memory; return addHeapObject(ret); }; module.exports.__wbg_buffer_085ec1f694018c4f = function(arg0) { const ret = getObject(arg0).buffer; return addHeapObject(ret); }; module.exports.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function(arg0, arg1, arg2) { const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; module.exports.__wbg_randomFillSync_dc1e9a60c158336d = function() { return handleError(function (arg0, arg1) { getObject(arg0).randomFillSync(takeObject(arg1)); }, arguments) }; module.exports.__wbg_subarray_13db269f57aa838d = function(arg0, arg1, arg2) { const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); return addHeapObject(ret); }; module.exports.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) { getObject(arg0).getRandomValues(getObject(arg1)); }, arguments) }; module.exports.__wbg_new_8125e318e6245eed = function(arg0) { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); }; module.exports.__wbg_set_5cf90238115182c3 = function(arg0, arg1, arg2) { getObject(arg0).set(getObject(arg1), arg2 >>> 0); }; module.exports.__wbg_call_01734de55d61e11d = function() { return handleError(function (arg0, arg1, arg2) { const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); return addHeapObject(ret); }, arguments) }; module.exports.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; const path = require('path').join(__dirname, 'rttist_ts_loader_wasm_bg.wasm'); const bytes = require('fs').readFileSync(path); const wasmModule = new WebAssembly.Module(bytes); const wasmInstance = new WebAssembly.Instance(wasmModule, imports); wasm = wasmInstance.exports; module.exports.__wasm = wasm;