Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun minified build produces invalid javascript when importing negative const enum values and using as object keys #14687

Open
zimmed opened this issue Oct 19, 2024 · 0 comments · May be fixed by #14947
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@zimmed
Copy link

zimmed commented Oct 19, 2024

What version of Bun is running?

1.1.31

What platform is your computer?

Darwin 22.3.0 arm64 arm

What steps can reproduce the bug?

With the following files:

// enum.ts
export const enum Foo {
  foo = -1,
  bar = 1,
}
// index.ts
import { Foo } from './enum';

export const FooRecord = {
  [Foo.foo]: 'foo',
  [Foo.bar]: 'bar',
}
// build.ts
await Bun.build({ entrypoints: ['index.ts'], minify: true, outdir: '.' });

Run

bun run build.ts

What is the expected behavior?

The output should be:

var a={[-1]:"foo",[1]:"bar"};export{a as FooRecord};

What do you see instead?

The output is:

var a={-1:"foo",1:"bar"};export{a as FooRecord};

Which produces syntax errors due to the unwrapped -1 property key.

Additional information

It is important to note that this does not happen for either of the following conditions:

  • The build is not minified
  • The enum is in the same file as the object

The same issue exists in v1.1.30, so it doesn't appear to be a regression.

@zimmed zimmed added bug Something isn't working needs triage labels Oct 19, 2024
@nektro nektro added bundler Something to do with the bundler and removed needs triage labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants