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

Panic when transforming optional chaining with define #3551

Closed
hi-ogawa opened this issue Dec 17, 2023 · 1 comment · Fixed by #3554
Closed

Panic when transforming optional chaining with define #3551

hi-ogawa opened this issue Dec 17, 2023 · 1 comment · Fixed by #3554

Comments

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 17, 2023

Esbuild panics when transforming globalThis.process?.env.something with { define: { "globalThis.process.env": "{}" } } and this seems to be the cause of the issue on Vite vitejs/vite#15367.

Here is a playground link for a minimal repro:

I'm not sure what's the expected behavior (whether replace it or not since they don't exactly match syntactically), but I suppose panic is not expected to happen regardless.

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Dec 17, 2023

It looks like OptionalChainContinue case seems tricky:

// "a?.b.c" => ".c" is OptionalChainContinue
// "(a?.b).c" => ".c" is OptionalChainNone
OptionalChainContinue

I tested with OptionalChainNone version and actually define is applied for this case without panic:

https://esbuild.github.io/try/#dAAwLjE5LjkAeyBkZWZpbmU6IHsgImEuYiI6ICJ7fSIgfSB9AC8vIHBhbmljCi8vIGE/LmIuYwoKLy8gb2sKKGE/LmIpLmMKCi8vIG9rCi8vIGEuYi5j

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant