Open guybedford opened 1 year ago
It seems reasonable to me to disallow defer
when no bindings are present?
I don't think it's a problem. The [[Get]] (or [[GetOwnPropertyDescriptor]]) on the ModuleNamespace exotic object can trigger the module execution, so accessing a non-existed property should be able to trigger the execution too.
@Jack-Works right but in this case there is no module namespace object (for static; and it'd be weird for dynamic for any random .foo
to be the encouraged mechanism to evaluate it imo)
I like @ljharb's proposal. The only reason modules without exports exist is because they have side effects, such as some initial setup of the environment. On the other hand, deferred imports are for "pure" modules, i.e. modules that don't have significant side effects so you can very safely delay their initialization.
If your module only executes side effects, and these side effects are not for the initial setup of the application, it should just export a function that can be later called at any time.
Was just wondering about the case for a module without any exports, say only imports, where that module represents some ordered execution that should take place.
Currently the deferral would work, but there would be no way to trigger the execution without a named export.