(code, file)
| 25 | return { |
| 26 | name: 'patchWechatWebAssembly', |
| 27 | transform(code, file) { |
| 28 | // remove node imports |
| 29 | if ( |
| 30 | file.endsWith('tfjs-backend-wasm-threaded-simd.worker.js') || |
| 31 | file.endsWith('tfjs-backend-wasm-threaded-simd.js') |
| 32 | ) { |
| 33 | code = code.replace(`require("worker_threads")`, 'null'); |
| 34 | code = code.replace(`require("perf_hooks")`, 'null'); |
| 35 | } |
| 36 | |
| 37 | // it is not a nice way, but WebAssembly.validate not working and SIMD is not support in WXWebAssembly |
| 38 | // tf.env().set('WASM_HAS_SIMD_SUPPORT', false) will be done in tfjs-wechat or application code |
| 39 | // so does the WASM_HAS_MULTITHREAD_SUPPORT |
| 40 | if (file.endsWith('backend_wasm.ts')) { |
| 41 | const ast = (this as {parse: (code: string) => BaseNode}).parse(code); |
| 42 | walk(ast, { |
| 43 | enter(node: NodeType) { |
| 44 | if ( |
| 45 | node.type === 'FunctionDeclaration' && |
| 46 | 'id' in node && |
| 47 | node.id.name === 'createInstantiateWasmFunc' |
| 48 | ) { |
| 49 | code = code.replace( |
| 50 | code.slice(node.start, node.end), |
| 51 | createInstantiateWasmFuncString, |
| 52 | ); |
| 53 | } |
| 54 | }, |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | code = code.replace(/WebAssembly\./g, `WXWebAssembly.`); |
| 59 | code = code.replace(/typeof WebAssembly/g, `typeof WXWebAssembly`); |
| 60 | return { code, map: null }; |
| 61 | }, |
| 62 | }; |
| 63 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…