Not convincingly.
Firstly, static imports are markedly different to top-level require due to module scoping: e.g. tree-shaking isn't stable with most "statically-analysed" top-level requires due to potential side-effects.
Secondly, handwaving dynamic imports as the ES Modules equivalent to non-top-level require doesn't pass the smell test. Dynamic imports are a deliberately separate syntax and mechanism to static imports, whereas require isn't differentiated. They are also, notably, async.
var x = strange_thing()
but suddenly can not when “x” is renamed to “exports”? module.exports = {foo: 3};
setImmediate(() => module.exports[Math.random() > 0.5 ? 'foo' : 'bar'] = 5);
This is impossible for ES modules, because exports are static and known at parse time.Few widely used packages do something like:
enhanceWithAdditionalProperties(module.exports, mixin); export var foo = 3
setImmediate(() => {foo = Math.random()})
Under ESM, exported values are still not known at parse time, and may be changed by the library (but not created nor deleted). And given that exported may be changed, what prevents library makers from doing: export default var exports = { }
enhance(exports, mixin)
and you are left with heuristics again?I see these subtle differences, but fail to see how they are a solution to the problem of “doing strange things to exports”.