Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit d17c40a

Browse files
committed
restrict bindings to declarative modules only
1 parent 1701415 commit d17c40a

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

lib/loader.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,16 @@ function logloads(loads) {
264264

265265
if (instantiateResult === undefined) {
266266
load.address = load.address || 'anon' + ++anonCnt;
267-
load.kind = 'declarative';
267+
268+
// NB instead of load.kind, use load.isDeclarative
269+
load.isDeclarative = true;
268270
// parse sets load.declare, load.depsList
269271
loader.loaderObj.parse(load);
270272
}
271273
else if (typeof instantiateResult == 'object') {
272274
load.depsList = instantiateResult.deps || [];
273275
load.execute = instantiateResult.execute;
274-
load.kind = 'dynamic';
276+
load.isDeclarative = false;
275277
}
276278
else
277279
throw TypeError('Invalid instantiate return value');
@@ -473,7 +475,7 @@ function logloads(loads) {
473475
var loads = [].concat(linkSet.loads);
474476
for (var i = 0, l = loads.length; i < l; i++) {
475477
var load = loads[i];
476-
load.module = load.kind == 'dynamic' ? {
478+
load.module = !load.isDeclarative ? {
477479
module: _newModule({})
478480
} : {
479481
name: load.name,
@@ -538,7 +540,7 @@ function logloads(loads) {
538540
address: load.address,
539541
metadata: load.metadata,
540542
source: load.source,
541-
kind: load.kind
543+
kind: load.isDeclarative ? 'declarative' : 'dynamic'
542544
};
543545
}
544546
// if not anonymous, add to the module table
@@ -586,7 +588,7 @@ function logloads(loads) {
586588

587589
// if it is a group transition, the index of the dependency has gone up
588590
// otherwise it is the same as the parent
589-
var loadDepGroupIndex = load.groupIndex + (loadDep.kind != load.kind);
591+
var loadDepGroupIndex = load.groupIndex + (loadDep.isDeclarative != load.isDeclarative);
590592

591593
// the group index of an entry is always the maximum
592594
if (loadDep.groupIndex === undefined || loadDep.groupIndex < loadDepGroupIndex) {
@@ -631,7 +633,7 @@ function logloads(loads) {
631633
buildLinkageGroups(startingLoad, linkSet.loads, groups, loader);
632634

633635
// determine the kind of the bottom group
634-
var curGroupDeclarative = (startingLoad.kind == 'declarative') == groups.length % 2;
636+
var curGroupDeclarative = startingLoad.isDeclarative == groups.length % 2;
635637

636638
// run through the groups from bottom to top
637639
for (var i = groups.length - 1; i >= 0; i--) {
@@ -670,8 +672,7 @@ function logloads(loads) {
670672
name: name,
671673
dependencies: [],
672674
module: new Module(), // start from an empty module and extend
673-
importers: [],
674-
evaluated: false
675+
importers: []
675676
});
676677
}
677678

@@ -703,33 +704,40 @@ function logloads(loads) {
703704
});
704705

705706
// setup our setters and execution function
706-
load.module.setters = registryEntry.setters;
707-
load.module.execute = registryEntry.execute;
707+
module.setters = registryEntry.setters;
708+
module.execute = registryEntry.execute;
708709

709710
// now link all the module dependencies
710711
// amending the depMap as we go
711712
for (var i = 0, l = load.dependencies.length; i < l; i++) {
712713
var depName = load.dependencies[i].value;
713-
var depModule = getOrCreateModuleRecord(depName);
714-
715-
depModule.importers.push(module);
716-
module.dependencies.push(depModule);
717-
718-
// if not already a module in the registry, try and link it now
719-
if (!loader.modules[depName]) {
714+
var depModule = loader.modules[depName];
720715

716+
// if dependency not already in the module registry
717+
// then try and link it now
718+
if (!depModule) {
721719
// get the dependency load record
722720
for (var j = 0; j < loads.length; j++) {
723721
if (loads[j].name != depName)
724722
continue;
725723

726724
// only link if already not already started linking (stops at circular / dynamic)
727-
if (!loads[j].module)
725+
if (!loads[j].module) {
728726
linkDeclarativeModule(loads[j], loads, loader);
727+
depModule = loads[j].module;
728+
}
729+
// if circular, create the module record
730+
else {
731+
depModule = getOrCreateModuleRecord(depName);
732+
}
729733
}
730734
}
731735

732-
console.assert(depModule, 'Dependency module not found!');
736+
// only declarative modules have dynamic bindings
737+
if (depModule.importers) {
738+
depModule.importers.push(module);
739+
module.dependencies.push(depModule);
740+
}
733741

734742
// run the setter for this dependency
735743
if (module.setters[i])
@@ -1041,7 +1049,7 @@ function logloads(loads) {
10411049

10421050
var depsList;
10431051

1044-
load.kind = 'declarative';
1052+
load.isDeclarative = true;
10451053

10461054
var compiler = new traceur.Compiler();
10471055
var options = System.traceurOptions || {};

0 commit comments

Comments
 (0)