-
Notifications
You must be signed in to change notification settings - Fork 66
WRT PR #3 - CJS <-> ES import/export conversion #10
Comments
Invariants of the interoperabilityIn order to facilitate the discussion, so folks will not have to dig into 262 and loader specs, here are the details and the current invariants: CJS requiring ES ModulesA ModuleNamespace is an exotic namespace object, somewhat equivalent to this: let ns = Object.create(null, {
foo: {
enumerable: true,
get: () { /* return some internal value the module environment record */ }
}
});
Object.freeze(ns); Obviously, this is a module with only one named export, you could add as many exports, including the ES importing CJS modulesIn order to consume CJS from an ES module, a new representation of the CJS module as a ES Module Record has to be made, it can't be a source text module record, it can only be a reflective module record, as follow: let exports = require('the-cjs-module');
let o = Object.create(null);
Object.keys(otherModule).forEach(key => {
o[key] = Reflect.Module.Export.from(otherModule, key);
});
let moduleRecord = new Reflect.Module(o); Obviously, that code does not cover the interoperability aspect of it (what if Additionally, to make that module available via |
Does this differ from the implementation we specified in the PR? |
This is discussed in https://github.com/bmeck/node-eps/blob/es6-module/002-es6-modules.md#default-imports . We do not do direct copying, we merely set
Punt on this issue to the PR itself. It doesn't really have anything to argue. |
We should get that merged today or tomorrow in the loader spec, here are the details: whatwg/loader#129 |
This is the place to discuss specifics of how imports and exports are wrapped / converted between the CommonJS (CJS) and EcmaScript (ES) module systems. The proposal itself can be seen in PR #3.
Discussions here should regard:
It should not discuss module path resolution, evaluation ordering, or detecting file mode.
The text was updated successfully, but these errors were encountered: