oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.87k stars 2.56k forks source link

Bundler minifies function names when accessed via .name #12304

Open mangs opened 1 week ago

mangs commented 1 week ago

What version of Bun is running?

1.1.17+bb66bba1b

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

  1. Create a simple app that accesses a function's name via .name. For example:
    
    function testFunction() {}

console.log(Function name: ${testFunction.name});

2. Bundle the code with the following options:

const buildConfiguration = { define: {}, entrypoints: ['./path/to/example/file.mjs'], external: [], format: 'esm', loader: {}, minify: true, naming: { chunk: '[name].[hash].mjs', entry: '[name].mjs', }, outdir: './dist', plugins: [], publicPath: '', root: '.', sourcemap: 'external', splitting: true, target: 'bun', }


3. Run the code with `bun dist/index.mjs`
4. See the function's reported name is `n` or something similar rather than the expected `testFunction`

### What is the expected behavior?

The function's `.name` should be `testFunction`

### What do you see instead?

`n` or a similar one character value

### Additional information

_No response_
paperdave commented 1 week ago

--minify includes --minify-identifiers, which will rename functions. For use cases that depend on function.name and class.name to be as is, there is https://esbuild.github.io/api/#keep-names, which bun does not have yet. changing this to a feature request.

mangs commented 6 days ago

--minify includes --minify-identifiers, which will rename functions. For use cases that depend on function.name and class.name to be as is, there is https://esbuild.github.io/api/#keep-names, which bun does not have yet. changing this to a feature request.

Thank you Dave. Looking forward to it.