-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual module cannot express "export function x" #70
Comments
Indeed. The initialization of modules has two steps: Both steps are especially meaningful with circular dependencies. Currently virtual modules only have one step, a function which is named But I would prefer virtual modules to have two explicit hooks: |
The problem with 2 separate hooks they're not in the same lexical context. const a = module {
export function a()
a()
} Two separate hooks are not friendly to down-level compiling. const a = {
initialize(env) {
function a() {}
env.a = a
},
execute(env) {
a() // Oops!
}
} By this form, it can naturally inherit the lexical context. initialize(env, context) {
function a() {}
env.a = a
// this runs when VirtualModuleRecord.[[InitializeEnvironment]]
return () => {
// this runs when VirtualModuleRecord.[[ExecuteModule]]
a() // Fine!
}
} |
Would it make sense to have separate protocols for exec and init+exec? I’m inclined to rename the existing |
can't a transpiler just introduce a new unique variable? babel does that all over the place. |
@devsnek To have separate Babel compiles to SystemJS (the only module system that can emulate ESM) in a similar way to what's proposed in #70 (comment): System.register([], function (_export, _context) {
"use strict";
function a() {}
_export("a", a);
return {
setters: [],
execute: function () {
a();
}
};
}); |
Current format only allows
export var x = function
equivalent.In order to support
export function x
, we need to add an extra stage on initialization.The text was updated successfully, but these errors were encountered: