Recent discussions have led us to consider the idea of shimmed ES modules as an alternative to the more traditional bundling-by-rewire. I started to document the work in more detail and will try to update this thread as I make progress.
Brief
Previous experimental work to look into the viability of retaining the semantics of a module’s top-level scope inside a nested scope (ie with (module.scope) { … }
) lead to some exciting outcomes along with some unknowns worthy of further effort.
The unknowns that come to mind:
- Reliable and efficient way to tokenize at runtime (or if it is even needed).
- Throwing if an imported binding is being shadowed by a top-level declaration.
- Effective instrumentation of code and repair of scoped authorities (ie
eval
) - Additional proxy work to retain scoping behaviours against realms.
The exciting outcomes that come to mind:
- Minimal rewrite is needed when demoting module code to scoped code.
- Minimal proxy hooks are required to affect scoping behaviours (ESM is always
strict
). - Minimal shimming artifacts (obtrusion/restrictions limited to the single
$h_exports
or similar). - Effective cross-compatibility and re/portability (ie unbundled or bundled with rollup).