-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add 'configurable: true' to descriptors in __createBinding and __setModuleDefault #57784
Conversation
Interestingly I'm pretty sure that esbuild's equivalent to this does not make them configurable, in an attempt to more closely match the ESM output (where you can't really do anything to the imported thing). Does jest break with them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec says these should be immutable on a real module, but I don't really care, since it's not like that helps anyone but engines, and engines aren't optimizing these downlevel modules like they are real ones - but overriding these a la jest will definitely break live bindings, and it definitely doesn't work with real esm. So long as we're okay with downlevel being looser than spec... it's fine, I guess.
Jest's ESM support is fairly minimal. Yes, users could write code that doesn't work as an ESM module, but they're still actually running in CJS and are likely using other features that Jest supports differently in ESM vs CommonJS. For instance, in ESM I think that without this, users are just in an ambiguous place as to what works and what doesn't work with jest. That said, I don't have a strong preference for having this vs. closing the issue as working as intended. |
Does this need more discussion or is it ready to merge? Specifically, @jakebailey were your concerns addressed? |
I don't have a principled opinion besides looking at what other tools do (e.g. esbuild makes these non-configurable by not saying |
Following discussion in the Design Meeting, we've decided not to take this fix as we would be inconsistent with esbuild, babel, et al. There are already workarounds for this, such as using |
This adds
configurable: true
to the property descriptors used in the__createBinding
and__setModuleDefualt
helpers to be more compatible with Jest's mocking mechanism.Fixes #43081