\begin{quote}
Rewrite a WASM binary \end{quote}
Replace in-\/place an AST node in the binary.\hypertarget{md_sfcode_node_modules__webassemblyjs_wasm_edit_README_autotoc_md2292}{}\doxysection{Installation}\label{md_sfcode_node_modules__webassemblyjs_wasm_edit_README_autotoc_md2292}

\begin{DoxyCode}{0}
\DoxyCodeLine{yarn add @webassemblyjs/wasm-\/edit }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__webassemblyjs_wasm_edit_README_autotoc_md2293}{}\doxysection{Usage}\label{md_sfcode_node_modules__webassemblyjs_wasm_edit_README_autotoc_md2293}
Update\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ edit \} from "{}@webassemblyjs/wasm-\/edit"{};}
\DoxyCodeLine{}
\DoxyCodeLine{const binary = [/*...*/];}
\DoxyCodeLine{}
\DoxyCodeLine{const visitors = \{}
\DoxyCodeLine{  ModuleImport(\{ node \}) \{}
\DoxyCodeLine{    node.module = "{}foo"{};}
\DoxyCodeLine{    node.name = "{}bar"{};}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{const newBinary = edit(binary, visitors); }

\end{DoxyCode}


Replace\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ edit \} from "{}@webassemblyjs/wasm-\/edit"{};}
\DoxyCodeLine{}
\DoxyCodeLine{const binary = [/*...*/];}
\DoxyCodeLine{}
\DoxyCodeLine{const visitors = \{}
\DoxyCodeLine{  Instr(path) \{}
\DoxyCodeLine{    const newNode = t.callInstruction(t.indexLiteral(0));}
\DoxyCodeLine{    path.replaceWith(newNode);}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{const newBinary = edit(binary, visitors); }

\end{DoxyCode}


Remove\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ edit \} from "{}@webassemblyjs/wasm-\/edit"{};}
\DoxyCodeLine{}
\DoxyCodeLine{const binary = [/*...*/];}
\DoxyCodeLine{}
\DoxyCodeLine{const visitors = \{}
\DoxyCodeLine{  ModuleExport(\{ node \}) \{}
\DoxyCodeLine{    path.remove()}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{const newBinary = edit(binary, visitors); }

\end{DoxyCode}


Insert\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{import \{ add \} from "{}@webassemblyjs/wasm-\/edit"{};}
\DoxyCodeLine{}
\DoxyCodeLine{const binary = [/*...*/];}
\DoxyCodeLine{}
\DoxyCodeLine{const newBinary = add(actualBinary, [}
\DoxyCodeLine{  t.moduleImport("{}env"{}, "{}mem"{}, t.memory(t.limit(1)))}
\DoxyCodeLine{]); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules__webassemblyjs_wasm_edit_README_autotoc_md2294}{}\doxysection{Providing the AST}\label{md_sfcode_node_modules__webassemblyjs_wasm_edit_README_autotoc_md2294}
Providing an AST allows you to handle the decoding yourself, here is the API\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{addWithAST(Program, ArrayBuffer, Array<Node>): ArrayBuffer;}
\DoxyCodeLine{editWithAST(Program, ArrayBuffer, visitors): ArrayBuffer; }

\end{DoxyCode}


Note that the AST will be updated in-\/place. 