Files
bun.sh/docs
Claude Bot 94d3703d8b feat(bundler): add property name mangling support
Add `--mangle-props` CLI flag and `mangleProps` JavaScript API option to mangle
object property names matching a regex pattern, similar to esbuild's implementation.

## Features

- **CLI**: `bun build --mangle-props='_$'` mangles properties ending with underscore
- **JavaScript API**: `Bun.build({ mangleProps: /_$/ })`
- **mangleQuoted option**: Also mangle quoted properties and bracket notation
- **Cross-file consistency**: Same property name gets same mangled name across all files

## Examples

```js
// Input
const obj = { secret_: 42, public: 1 };
console.log(obj.secret_);

// Output (with --mangle-props='_$')
const obj = { a: 42, public: 1 };
console.log(obj.a);
```

Cross-file example:
```js
// file1.js
export const config = { secret_: 42 };

// file2.js
import { config } from "./file1";
console.log(config.secret_);  // Both secret_ become "a"
```

## Constraints

- Properties are only mangled if they match the provided regex pattern
- Reserved properties are never mangled: `__proto__`, `constructor`, `prototype`
- JavaScript keywords are never used as mangled names
- Quoted properties require `--mangle-quoted` flag to be mangled
- Most frequently used properties get shortest names (a, b, c, ...)

## Implementation Details

- Parser identifies properties matching the pattern and creates mangled_prop symbols
- Linker merges symbols with same name across files using symbol linking
- Printer looks up mangled names via the symbol's canonical ref

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-19 00:54:59 +00:00
..
2025-11-10 17:38:48 -08:00
2025-11-21 14:22:28 -08:00
2025-11-21 14:22:28 -08:00

Logo

Bun Documentation

Official documentation for Bun: the fast, all-in-one JavaScript runtime.

Development

Install the Mintlify CLI to preview the documentation locally:

bun install -g mint

Run the development server:

mint dev

The site will be available at http://localhost:3000.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.