external imports

This commit is contained in:
Dmitry Vasilev
2022-10-19 03:22:48 +08:00
parent 1bea819b1a
commit 68d7a88ac3
9 changed files with 362 additions and 32 deletions

View File

@@ -235,9 +235,11 @@ const codegen = (node, cxt, parent) => {
}
}
export const eval_modules = (modules, sorted, location) => {
export const eval_modules = (modules, sorted, external_imports, location) => {
// TODO gensym __modules, __exports
// TODO bug if module imported twice, once as external and as regular
const codestring =
`
let children, prev_children
@@ -435,7 +437,7 @@ export const eval_modules = (modules, sorted, location) => {
}
const run = entrypoint => {
const __modules = {}
const __modules = {...external_imports}
let current_call
`
@@ -483,7 +485,13 @@ export const eval_modules = (modules, sorted, location) => {
}
`
const actions = (new Function(codestring))()
const actions = new Function('external_imports', codestring)(
external_imports == null
? null
: map_object(external_imports, (name, {module}) =>
({exports: module, is_external: true})
)
)
const calltree_actions = {
expand_calltree_node: (node) => {
@@ -524,8 +532,10 @@ export const eval_modules = (modules, sorted, location) => {
const assign_code_calltree = (modules, calltree) =>
map_object(
calltree,
(module, {calls, exports}) => {
return {exports, calls: assign_code(modules, calls, modules[module])}
(module, {calls, exports, is_external}) => {
return is_external
? {is_external, exports}
: {exports, calls: assign_code(modules, calls, modules[module])}
}
)