1 of 8

Module Ordering Invariants

Bradley Farias

2 of 8

Should Abstract Module Records be "hoistable"

import "a"; // ESM

import "b"; // should "b" ever be allowed to evaluate before "a"

3 of 8

Should Abstract Module Records be "hoistable"

import "b";

import "a";

import "a";

import "b";

Acts equivalent to alternate for some Abstract Module Record "b"

4 of 8

Previous work

5 of 8

Node

  • `import()` removes zebra striping w/ CJS

  • Still does not provide way to live bind against CJS post eval
    • Could use Proxy-like implementation to achieve this but that is a breaking change to Node�
  • Hoistability comes from investigation into ways to allow "named" exports from CJS `module.exports`
    • Diffrent from "Late Binding"

6 of 8

Add invariant explicitly

  • https://tc39.github.io/ecma262/#sec-abstract-module-records
  • Add note that the order of Instantiate and Evaluate must not be reordered within the module subgraph starting from the TopLevelModuleEvaluationJob
    • Note: the ordering across graphs has never been guaranteed due to races

7 of 8

Invariant

  • Add "Note"s to Abstract Module Record?�
    • Only intended to instantiate for integration with ESM lifecycle
      • Instantiate
      • Evaluate�
  • Add "Note"s to Source Text Module Record?�
    • Order must be preserved
      • Difficult to phrase into concrete semantics

8 of 8

Abstract Module Record

  • Has their own Instantiate and Evaluate methods�
  • Should these be allowed to be called in "hoisted" order?