You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide SourceTextModule sync versions of link and evaluate methods #59656
Allow to reimplement require(esm) logic with custom require. Current logic in jest covers only require(cjs) and native modules and to support require(esm) there is need of SourceTextModule sync version with sync link and evaluate methods.
The synchronous linking method is implemented in #59000
I am not sure if evalauteSync is entirely necessary - evaluation is already synchronous if the module does not contain a top-level await and the returned promise would be synchronously fulfilled with undefined, as specified in ECMA262 (in this case, the promise is just like a maybe, you can just assume that it's already fulfilled in synchronous code).
I think to be able to implement userland require(esm) on top of vm.SourceTextModule, there must be a way to detect if the module graph is async (like, if it and its dependencies contain TLA or not), so that a userland framework can do:
functionrequireEsm(){constmod=newvm.SourceTextModule(...);mod.linkRequests(mod.moduleRequests.map(resolve));mod.instantiate();// This is missingif(mod.isGraphAsync){thrownewError('Module graph is async');}mod.evaluate();if(mod.status==='errored'){throwmod.error;}returnmod.namespace;}
Activity
joyeecheung commentedon Aug 28, 2025
The synchronous linking method is implemented in #59000
I am not sure if evalauteSync is entirely necessary - evaluation is already synchronous if the module does not contain a top-level await and the returned promise would be synchronously fulfilled with undefined, as specified in ECMA262 (in this case, the promise is just like a maybe, you can just assume that it's already fulfilled in synchronous code).
legendecas commentedon Aug 29, 2025
I think to be able to implement userland
require(esm)on top ofvm.SourceTextModule, there must be a way to detect if the module graph is async (like, if it and its dependencies contain TLA or not), so that a userland framework can do:vm: expose hasTopLevelAwait on SourceTextModule
vm: expose hasTopLevelAwait on SourceTextModule
vm: expose hasTopLevelAwait on SourceTextModule
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous