-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
js: make certain only one copy of the exports is used per each module #2773
Conversation
This is inline with ESM and works for source code modules, but not for modules written in go as teh code was never made to work with it. This also lets (as the test suggests) change what `k6/http`.get is across the VU just as it should be possible.
a31b09e
to
f0324f7
Compare
I will try to disassemble Bundle, BundleInstance and InitContext in some way that I can have only 1 place that we cache the exports and can get them from because this is getting pretty bad :( |
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.
Besides my confusion about the duplicate caches below, I'm confused and surprised this is allowed behavior for ESM. I thought this sort of monkeypatching was reserved to Ruby and Python, and I'm not sure it's even possible there 😄
While it's convenient, there are many things that could go wrong if we allow modules to change global properties of other modules at runtime 😅
I did a quick test with Node v16, and this behavior doesn't seem possible. Replicating your test I get:
TypeError: Cannot assign to read only property 'group' of object '[object Module]'
Which seems like the sane thing to do.
Can you link us to the relevant part of the ES spec that mentions this should be allowed?
Given how this is more or less how the whole language is designed from day one - to be able to extend properties of objects, I would argue it is the most natural thing 🤣
This particular change doesn't change if that is possible just makes go modules inline with js modules ;) You can see how node (specifically) both allows this and has a way to restore the original state - a functionality that I don't think we need at this point.
Yeah, unfortunately hurrying to write the test for both js modules and go ones I did use the one syntax that prevents this by specification. And of course babel does not prevent it 🤦. Good catch 👍 🙇
There really isn't a place where it says that it is forbidden so it is allowed. Default exports are just an object most of the time so unless something makes them immutable it won't matter. The only part of the specification around ESM that does this is the one around module namespaces (the |
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.
Given how this is more or less how the whole language is designed from day one - to be able to extend properties of objects, I would argue it is the most natural thing
Right, this is not unlike being able to change the prototype of an object globally 😄
The only part of the specification around ESM that does this ...
Thanks, though I don't know why I asked for links to the ES spec 😅 It's absolutely unreadable 🙈
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.
Looking good (albeit weird, and rubyish 💎 , I agree, pun intended)! 🎉 👍🏻
The Javascript voices are impenetrable 🙏🏻
This is inline with ESM and works for source code modules, but not for modules written in go as teh code was never made to work with it.
This also lets (as the test suggests) change what
k6/http
.get is across the VU just as it should be possible.