Closed nicolo-ribaudo closed 4 months ago
I must admit I did prefer the pure model framing in https://github.com/tc39/proposal-defer-import-eval/issues/19#issuecomment-1567647857 in making this an error. I understand if detecting the list is tricky in unbound tooling workflows, but I'm not completely sure I agree that justifies omitting the error.
I will prepare a PR for that — I don't have a super strong preference between these possible behaviours
but the ecosystem also uses module[__esModule]
to interop
Since it's a known string it can be easily worked around. For example, the webpack implementation doesn't trigger evaluation on __esModule.
This change solves a few problem:
import defer * as ns
, but the solution in this PR also has the benefit in (2).import defer *
in tool, it's not always easy to know the list of bindings exported by a module at runtime without evaluating it. Examples are Webpack and Babel, that get the list of exports from properties of an object populated by the module evaluation. It would be possible in some cases to hard-code the list of exports, but it introduces additional complexity and duplicated information in the generated bundle.Symbols still do not trigger evaluation, because: a. it's guaranteed that exports of a module have string names b.
module[Symbol.toStringTag] === "Module"
can still be used to detect probable namespace objects without forcing their evaluation.