> CommonJS allows you to dynamically alter module.exports anywhere within your module
It's certainly a risk, but that isn't a common practice.
It's certainly a risk, but that isn't a common practice.
if(Math.round(Math.random()) === 1) {
export let foo = bar; // have fun debugging!
}
I think it would also be fine to execute modules to see what's in module.exports, while some modules might have side effects like writing to /etc/passwd without calling any method, it's not the norm.(I assume you meant to write your example in CommonJS style, because that's not valid a ES6 export, they must be top-level).
Doesn't your example highlight exactly why even executing the code wouldn't even help you there?
You can't, at least not in this way. A module's imported and exported names are statically determined. Of course, you can just export a single object, and then make that object arbitrarily complex depending on runtime behavior.
> Like being able to require modules locally
Not sure what this means.