MCPcopy Create free account
hub / github.com/tensorflow/tfjs / transform

Function transform

tfjs-backend-wasm/scripts/patch_wechat_webassembly.ts:27–61  ·  view source on GitHub ↗
(code, file)

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…