4 ms·
You haven't considered optimization -- with closed modules, the compiler can statically know, for instance, that "Math.sin" is actually the sine function and ca
by ootachi 15y ago
You haven't considered optimization -- with closed modules, the compiler can statically know, for instance, that "Math.sin" is actually the sine function and can compile that straight down to the hardware instruction. No speculation or guards are necessary.
Additionally, your static analysis must be unsound if modules are mutable. The problem is not figuring out which module is being imported, it's figuring out whether the bindings are mutated. CommonJS cannot guarantee that modules haven't been mutated.
And yes, you can rename imports. Why is "var { foo: bar } = require('baz')" so much better than "import { foo: bar } from baz;"? They look the same to me, except that the ES6 one is better for static analysis and better for optimization.
- RobertWHurst 15y agoI don't think you get it. The right way to require a module in commonjs is var baz = require('baz'). The reason its better is because I can accomplish just as much as the ridiculous ES6 modules and its simple. We don't need to add complexity if it doesn't get us anywhere. I'm not convinced that static analysis is worth it. Existing module systems work just fine without this shit.