You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came to your interesting package in searching of a lighter esm to cjs transformer.
But I noticed the code is semantically wrong which can lead to logic error.
Your example
// inputimport{resolveasresolvePath}from"path";resolvePath("./hello")// what i wantedconst{resolve: resolvePath}=require("path");resolvePath("./hello")
Translated the esm import to a simple variable, this is wrong in esm semantic. There is a reason why all babel/TS transforms esm import into verbose a_namespace.an_exported_name, because in esm standard, the import does not create a local JS variable, it's a read-only property on the namespace of that esm module.
Consider following proof, create two local files: foo.mjs
You're right. I didn't think of it this way. Thanks for reporting!
Unfortunately, I don't think I will fix this, as I don't use this project anymore and it has served me well the way I used it. PR welcome though. I'll add it in readme otherwise.
Edit: Documented in readme.
I came to your interesting package in searching of a lighter esm to cjs transformer.
But I noticed the code is semantically wrong which can lead to logic error.
Your example
Translated the esm import to a simple variable, this is wrong in esm semantic. There is a reason why all babel/TS transforms esm import into verbose
a_namespace.an_exported_name
, because in esm standard, the import does not create a local JS variable, it's a read-only property on the namespace of that esm module.Consider following proof, create two local files:
foo.mjs
index.mjs
Then use nodejs v12 or above
It prints out:
You can see that
foo
insideindex.mjs
is not a local variable, otherwise it cannot be mutated.The text was updated successfully, but these errors were encountered: