https://leanpub.com/understandinges6/read#leanpub-auto-chang...
// non-strict mode top-level code
function foo (complex = eval("1+1"), moreComplex = (function(){ with (this) { return bar; } }())) {
"use strict"; // go back and parse the parameters again but this time with strict mode semantics
// ...
}[1] https://www.nczonline.net/blog/2016/10/the-ecmascript-2016-c...
- [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Modules and classes are always in strict mode. In practice, it really isn't an issue.
If you have to execute code, things get messy.
(If so) CommonJS allows you to dynamically alter module.exports anywhere within your module. You can't determine what those exports are just by parsing, you'd need to execute the code.
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.