bun icon indicating copy to clipboard operation
bun copied to clipboard

Implement `--keep-names` to prevent mangling function `.name` accesses

Open mangs opened this issue 8 months ago • 3 comments

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}`);
  1. 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',
}
  1. Run the code with bun dist/index.mjs
  2. 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

mangs avatar Jul 02 '24 20:07 mangs