# @webassemblyjs/wasm-edit

> > Rewrite a WASM binary

Latest version **1.14.1** (published 2024-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @webassemblyjs/wasm-edit
pnpm add @webassemblyjs/wasm-edit
yarn add @webassemblyjs/wasm-edit
bun add @webassemblyjs/wasm-edit
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.14.1 |
| Published | 2024-11-06 |
| First published | 2018-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 33.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 834 |
| Author | Sven Sauleau |
| Maintainers | xtuc |

## Links

- npm: https://www.npmjs.com/package/@webassemblyjs/wasm-edit
- Repository: https://github.com/xtuc/webassemblyjs
- Homepage: https://github.com/xtuc/webassemblyjs#readme
- Issues: https://github.com/xtuc/webassemblyjs/issues
- npm.io page: https://npm.io/package/@webassemblyjs/wasm-edit

## Dependencies (8)

- [@webassemblyjs/ast](https://npm.io/package/@webassemblyjs/ast.md) 1.14.1
- [@webassemblyjs/wasm-gen](https://npm.io/package/@webassemblyjs/wasm-gen.md) 1.14.1
- [@webassemblyjs/wasm-opt](https://npm.io/package/@webassemblyjs/wasm-opt.md) 1.14.1
- [@webassemblyjs/wasm-parser](https://npm.io/package/@webassemblyjs/wasm-parser.md) 1.14.1
- [@webassemblyjs/wast-printer](https://npm.io/package/@webassemblyjs/wast-printer.md) 1.14.1
- [@webassemblyjs/helper-buffer](https://npm.io/package/@webassemblyjs/helper-buffer.md) 1.14.1
- [@webassemblyjs/helper-wasm-section](https://npm.io/package/@webassemblyjs/helper-wasm-section.md) 1.14.1
- [@webassemblyjs/helper-wasm-bytecode](https://npm.io/package/@webassemblyjs/helper-wasm-bytecode.md) 1.13.2

## Recent versions

- 1.14.1 (latest) — 2024-11-06
- 1.13.2 — 2024-11-06
- 1.13.1 — 2024-11-06
- 1.12.1 — 2024-03-13
- 1.11.6 — 2023-05-09
- 1.11.5 — 2023-04-16
- 1.11.3 — 2022-07-02
- 1.11.1 — 2021-07-05
- 1.11.0 — 2021-01-07
- 1.10.1 — 2021-01-07
- 1.10.0 — 2021-01-07
- 1.9.1 — 2020-10-03
- 1.9.0 — 2020-02-01
- 1.8.5 — 2019-02-24
- 1.8.4 — 2019-02-19
- … 69 more at https://npm.io/package/@webassemblyjs/wasm-edit/versions

## README

# @webassemblyjs/wasm-edit

> Rewrite a WASM binary

Replace in-place an AST node in the binary.

## Installation

```sh
yarn add @webassemblyjs/wasm-edit
```

## Usage

Update:

```js
import { edit } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const visitors = {
  ModuleImport({ node }) {
    node.module = "foo";
    node.name = "bar";
  }
};

const newBinary = edit(binary, visitors);
```

Replace:

```js
import { edit } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const visitors = {
  Instr(path) {
    const newNode = t.callInstruction(t.indexLiteral(0));
    path.replaceWith(newNode);
  }
};

const newBinary = edit(binary, visitors);
```

Remove:

```js
import { edit } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const visitors = {
  ModuleExport({ node }) {
    path.remove()
  }
};

const newBinary = edit(binary, visitors);
```

Insert:

```js
import { add } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const newBinary = add(actualBinary, [
  t.moduleImport("env", "mem", t.memory(t.limit(1)))
]);
```

## Providing the AST

Providing an AST allows you to handle the decoding yourself, here is the API:

```js
addWithAST(Program, ArrayBuffer, Array<Node>): ArrayBuffer;
editWithAST(Program, ArrayBuffer, visitors): ArrayBuffer;
```

Note that the AST will be updated in-place.

---
_Source: https://npm.io/package/@webassemblyjs/wasm-edit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
