Skip to content
New issue

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

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

Already on GitHub? # to your account

Const enums inlined when bundling, but expressions not optimized #3416

Closed
maximelkin opened this issue Oct 2, 2023 · 0 comments
Closed

Const enums inlined when bundling, but expressions not optimized #3416

maximelkin opened this issue Oct 2, 2023 · 0 comments

Comments

@maximelkin
Copy link

https://esbuild.github.io/try/#YgAwLjE5LjQALS1taW5pZnkgZW50cnkudHMgLS1idW5kbGUAAGVudHJ5LnRzAGltcG9ydCB7QX0gZnJvbSAnLi9lbnVtLnRzJwoKaWYgKCdiJyA9PT0gQS5CKSB7Y29uc29sZS5sb2coMil9IGVsc2Uge2NvbnNvbGUubG9nKDMpfQonYScgPT09IEEuQiA/IGNvbnNvbGUubG9nKDIpIDogY29uc29sZS5sb2coMykAAGVudW0udHMAZXhwb3J0IGNvbnN0IGVudW0gQSB7QiA9ICdiJywgQyA9ICdjJ30K

// enum.ts
export const enum A {B = 'b', C = 'c'}
// entry.ts
import {A} from './enum.ts'

if ('b' === A.B) {console.log(2)} else {console.log(3)}
'a' === A.B ? console.log(2) : console.log(3)

Expected result:

(()=>{
 console.log(2);console.log(3);
})();

Got:

(()=>{
 "b"==="b"?console.log(2):console.log(3);"b"==="a"?console.log(2):console.log(3);
})();

If const enum in same file, all works perfectly

@evanw evanw closed this as completed in 9e2f304 May 24, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants