Skip to content

Commit fcd2860

Browse files
committed
Defer module.derive’s copy to a microtask.
Fixes #178.
1 parent be9bd9a commit fcd2860

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/module.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ function module_derive(injects, injectModule) {
6565
if (inject.alias == null) inject.alias = inject.name;
6666
injectByAlias.set(inject.alias, inject);
6767
});
68-
return this._copy(injectByAlias, injectModule, new Map);
68+
var copy = new Module(this._runtime);
69+
Promise.resolve().then(() => this._copy(copy, injectByAlias, injectModule, new Map));
70+
return copy;
6971
}
7072

71-
function module_copy(injectByAlias, injectModule, map) {
72-
var copy = new Module(this._runtime);
73+
function module_copy(copy, injectByAlias, injectModule, map) {
7374
map.set(this, copy);
7475
this._scope.forEach(function(source, name) {
7576
var target = new Variable(source._type, copy), inject;
@@ -78,7 +79,7 @@ function module_copy(injectByAlias, injectModule, map) {
7879
} else if (source._definition === identity) { // import!
7980
var sourceInput = source._inputs[0],
8081
sourceModule = sourceInput._module,
81-
targetModule = map.get(sourceModule) || sourceModule._copy(none, null, map);
82+
targetModule = map.get(sourceModule) || sourceModule._copy(new Module(copy._runtime), none, null, map);
8283
target.import(sourceInput._name, name, targetModule);
8384
} else {
8485
target.define(name, source._inputs.map(variable_name), source._definition);

0 commit comments

Comments
 (0)