nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
72 stars 27 forks source link

iitm wrappers copy exported primitives #118

Closed timfish closed 5 months ago

timfish commented 5 months ago

When you export primitives in ESM, they are exposed as references which means they can be written to from elsewhere within the module. A reproduction of this behaviour can be seen in #113.

Because the iitm wrappers assign each export to a variable before re-exporting, primitive exports have their original value copied and the reference is lost.

This is where the code generation does that: https://github.com/nodejs/import-in-the-middle/blob/57d2459748492abd55e04a679d8b5752b90dfab4/hook.js#L189-L190

timfish commented 5 months ago

Ah, just realised this is a duplicate of #38