Closed bakkot closed 10 months ago
Thanks for raising this. Yes -- this is a concern with the current strategy. You mentioned other strategies, I am wondering, do you have something specific in mind already? I would like to keep this as open to other solutions as possible.
The obvious alternative that comes to mind is that you'd have an import
form which gave you a thunk for the namespace object, which the importing script could force if/when it wanted evaluation to happen. (This would have the same issue with top-level await, of course.)
The proposal is now going in the direction of only supporting deferred imports through namespace imports, so that side effects only happen on property access.
We've generally tried to avoid having access to local variables be side effecting, a property which is useful both for engines and for humans reading the code. (Obviously you can break that property using
with
, and it does not hold for global variables.) If I'm reading this proposal correctly - if the module evaluation would happen when the bindings were first referenced - that would no longer be true for lazy-loaded module bindings. I think that's worrisome.This isn't a blocker for stage 1, since this is a concern only about that specific strategy, and there are other possible strategies for lazy loading.