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

empty enum got undefined #15958

Closed
7 tasks done
fixiabis opened this issue Feb 19, 2024 · 5 comments
Closed
7 tasks done

empty enum got undefined #15958

fixiabis opened this issue Feb 19, 2024 · 5 comments
Labels
bug: upstream Bug in a dependency of Vite p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@fixiabis
Copy link

Describe the bug

I am using typescript module augmentation for enum, but got error if enum is empty at the beginning (enum would be undefined)

image

Reproduction

https://stackblitz.com/edit/vitejs-vite-abyiyv?file=main.js&terminal=dev

Steps to reproduce

just check reproduction link, enum would be undefined after compilation

image

System Info

not so important

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Feb 19, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red
Copy link
Member

For this input,

export enum Opcode {}

export function extendOpcode(key: string, value: string) {
  Object.assign(Opcode, { [key]: value });
}

TypeScript outputs (ts playground):

export var Opcode;
(function (Opcode) {
})(Opcode || (Opcode = {}));
export function extendOpcode(key, value) {
    Object.assign(Opcode, { [key]: value });
}

and esbuild outputs (esbuild try):

export var Opcode = /* @__PURE__ */ ((Opcode2) => {
})(Opcode || {});
export function extendOpcode(key, value) {
  Object.assign(Opcode, { [key]: value });
}

I don't find any bug in esbuild here. The code is working as expected (Opcode should be undefined).
If you think it's a bug, please report to TypeScript instead.

@fixiabis
Copy link
Author

It looks like esbuild's bug, I'll report it to esbuild, Thanks 🙏

@sapphi-red
Copy link
Member

Ah, I overlooked the Opcode = {} part 😅
Since the fix is likely to be released in esbuild 0.20.x, it won't be included in Vite 5.1.x (uses esbuild 0.19.x). It would be included in 5.2.x.

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Feb 20, 2024
@fixiabis
Copy link
Author

Ah, I overlooked the Opcode = {} part 😅 Since the fix is likely to be released in esbuild 0.20.x, it won't be included in Vite 5.1.x (uses esbuild 0.19.x). It would be included in 5.2.x.

Thank you for your information! 🙏

@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

No branches or pull requests

2 participants