@@ -264,14 +264,16 @@ function logloads(loads) {
264
264
265
265
if ( instantiateResult === undefined ) {
266
266
load . address = load . address || 'anon' + ++ anonCnt ;
267
- load . kind = 'declarative' ;
267
+
268
+ // NB instead of load.kind, use load.isDeclarative
269
+ load . isDeclarative = true ;
268
270
// parse sets load.declare, load.depsList
269
271
loader . loaderObj . parse ( load ) ;
270
272
}
271
273
else if ( typeof instantiateResult == 'object' ) {
272
274
load . depsList = instantiateResult . deps || [ ] ;
273
275
load . execute = instantiateResult . execute ;
274
- load . kind = 'dynamic' ;
276
+ load . isDeclarative = false ;
275
277
}
276
278
else
277
279
throw TypeError ( 'Invalid instantiate return value' ) ;
@@ -473,7 +475,7 @@ function logloads(loads) {
473
475
var loads = [ ] . concat ( linkSet . loads ) ;
474
476
for ( var i = 0 , l = loads . length ; i < l ; i ++ ) {
475
477
var load = loads [ i ] ;
476
- load . module = load . kind == 'dynamic' ? {
478
+ load . module = ! load . isDeclarative ? {
477
479
module : _newModule ( { } )
478
480
} : {
479
481
name : load . name ,
@@ -538,7 +540,7 @@ function logloads(loads) {
538
540
address : load . address ,
539
541
metadata : load . metadata ,
540
542
source : load . source ,
541
- kind : load . kind
543
+ kind : load . isDeclarative ? 'declarative' : 'dynamic'
542
544
} ;
543
545
}
544
546
// if not anonymous, add to the module table
@@ -586,7 +588,7 @@ function logloads(loads) {
586
588
587
589
// if it is a group transition, the index of the dependency has gone up
588
590
// 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 ) ;
590
592
591
593
// the group index of an entry is always the maximum
592
594
if ( loadDep . groupIndex === undefined || loadDep . groupIndex < loadDepGroupIndex ) {
@@ -631,7 +633,7 @@ function logloads(loads) {
631
633
buildLinkageGroups ( startingLoad , linkSet . loads , groups , loader ) ;
632
634
633
635
// determine the kind of the bottom group
634
- var curGroupDeclarative = ( startingLoad . kind == 'declarative' ) == groups . length % 2 ;
636
+ var curGroupDeclarative = startingLoad . isDeclarative == groups . length % 2 ;
635
637
636
638
// run through the groups from bottom to top
637
639
for ( var i = groups . length - 1 ; i >= 0 ; i -- ) {
@@ -670,8 +672,7 @@ function logloads(loads) {
670
672
name : name ,
671
673
dependencies : [ ] ,
672
674
module : new Module ( ) , // start from an empty module and extend
673
- importers : [ ] ,
674
- evaluated : false
675
+ importers : [ ]
675
676
} ) ;
676
677
}
677
678
@@ -703,33 +704,40 @@ function logloads(loads) {
703
704
} ) ;
704
705
705
706
// 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 ;
708
709
709
710
// now link all the module dependencies
710
711
// amending the depMap as we go
711
712
for ( var i = 0 , l = load . dependencies . length ; i < l ; i ++ ) {
712
713
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 ] ;
720
715
716
+ // if dependency not already in the module registry
717
+ // then try and link it now
718
+ if ( ! depModule ) {
721
719
// get the dependency load record
722
720
for ( var j = 0 ; j < loads . length ; j ++ ) {
723
721
if ( loads [ j ] . name != depName )
724
722
continue ;
725
723
726
724
// only link if already not already started linking (stops at circular / dynamic)
727
- if ( ! loads [ j ] . module )
725
+ if ( ! loads [ j ] . module ) {
728
726
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
+ }
729
733
}
730
734
}
731
735
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
+ }
733
741
734
742
// run the setter for this dependency
735
743
if ( module . setters [ i ] )
@@ -1041,7 +1049,7 @@ function logloads(loads) {
1041
1049
1042
1050
var depsList ;
1043
1051
1044
- load . kind = 'declarative' ;
1052
+ load . isDeclarative = true ;
1045
1053
1046
1054
var compiler = new traceur . Compiler ( ) ;
1047
1055
var options = System . traceurOptions || { } ;
0 commit comments