@@ -262,14 +262,14 @@ function logloads(loads) {
262
262
if ( load . status != 'loading' )
263
263
return ;
264
264
265
- var depsList ;
266
265
if ( instantiateResult === undefined ) {
267
266
load . address = load . address || 'anon' + ++ anonCnt ;
268
267
load . kind = 'declarative' ;
269
- depsList = loader . loaderObj . parse ( load ) ;
268
+ // parse sets load.declare, load.depsList
269
+ loader . loaderObj . parse ( load ) ;
270
270
}
271
271
else if ( typeof instantiateResult == 'object' ) {
272
- depsList = instantiateResult . deps || [ ] ;
272
+ load . depsList = instantiateResult . deps || [ ] ;
273
273
load . execute = instantiateResult . execute ;
274
274
load . kind = 'dynamic' ;
275
275
}
@@ -278,7 +278,7 @@ function logloads(loads) {
278
278
279
279
// 15.2.4.6 ProcessLoadDependencies
280
280
load . dependencies = [ ] ;
281
- load . depsList = depsList ;
281
+ var depsList = load . depsList ;
282
282
283
283
var loadPromises = [ ] ;
284
284
for ( var i = 0 , l = depsList . length ; i < l ; i ++ ) ( function ( request , index ) {
@@ -1012,6 +1012,58 @@ function logloads(loads) {
1012
1012
1013
1013
var _newModule = Loader . prototype . newModule ;
1014
1014
1015
+
1016
+ /*
1017
+ * Traceur-specific Parsing Code for Loader
1018
+ */
1019
+ ( function ( ) {
1020
+ function checkForErrors ( output , load ) {
1021
+ if ( output . errors . length ) {
1022
+ for ( var i = 0 , l = output . errors . length ; i < l ; i ++ )
1023
+ console . error ( output . errors [ i ] ) ;
1024
+ throw new Error ( 'Parse of ' + load . name + ', ' + load . address + ' failed, ' + output . errors . length ) ;
1025
+ }
1026
+ }
1027
+
1028
+ // parse function is used to parse a load record
1029
+ // Returns an array of ModuleSpecifiers
1030
+ Loader . prototype . parse = function ( load ) {
1031
+ if ( ! traceur ) {
1032
+ if ( typeof window == 'undefined' )
1033
+ traceur = require ( 'traceur' ) ;
1034
+ else if ( __global . traceur )
1035
+ traceur = __global . traceur ;
1036
+ else
1037
+ throw new TypeError ( 'Include Traceur for module syntax support' ) ;
1038
+ }
1039
+
1040
+ console . assert ( load . source , 'Non-empty source' ) ;
1041
+
1042
+ var depsList ;
1043
+
1044
+ load . kind = 'declarative' ;
1045
+
1046
+ var compiler = new traceur . Compiler ( ) ;
1047
+ var options = System . traceurOptions || { } ;
1048
+ options . modules = 'instantiate' ;
1049
+ var output = compiler . stringToTree ( { content : load . source , options : options } ) ;
1050
+ checkForErrors ( output ) ;
1051
+
1052
+ output = compiler . treeToTree ( output ) ;
1053
+ checkForErrors ( output ) ;
1054
+
1055
+ output = compiler . treeToString ( output ) ;
1056
+ checkForErrors ( output ) ;
1057
+ var source = output . js ;
1058
+ var sourceMap = output . generatedSourceMap ;
1059
+
1060
+ if ( __global . btoa && sourceMap )
1061
+ source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa ( unescape ( encodeURIComponent ( sourceMap ) ) ) + '\n' ;
1062
+
1063
+ __eval ( source , __global , load ) ;
1064
+ }
1065
+ } ) ( ) ;
1066
+
1015
1067
if ( typeof exports === 'object' )
1016
1068
module . exports = Loader ;
1017
1069
@@ -1022,4 +1074,32 @@ function logloads(loads) {
1022
1074
1023
1075
} ) ( ) ;
1024
1076
1077
+ // Define our eval outside of the scope of any other reference defined in this
1078
+ // file to avoid adding those references to the evaluation scope.
1079
+ var __curRegister ;
1080
+ function __eval ( __source , __global , load ) {
1081
+ // Hijack System.register to set declare function
1082
+ __curRegister = System . register ;
1083
+ System . register = function ( name , deps , declare ) {
1084
+ if ( typeof name != 'string' ) {
1085
+ declare = deps ;
1086
+ deps = name ;
1087
+ }
1088
+ // store the registered declaration as load.declare
1089
+ // store the deps as load.deps
1090
+ load . declare = declare ;
1091
+ load . depsList = deps ;
1092
+ }
1093
+ try {
1094
+ eval ( 'var __moduleName = "' + ( load . name || '' ) . replace ( '"' , '\"' ) + '"; (function() { ' + __source + ' \n }).call(__global);' ) ;
1095
+ }
1096
+ catch ( e ) {
1097
+ if ( e . name == 'SyntaxError' || e . name == 'TypeError' )
1098
+ e . message = 'Evaluating ' + ( load . name || load . address ) + '\n\t' + e . message ;
1099
+ throw e ;
1100
+ }
1101
+
1102
+ System . register = __curRegister ;
1103
+ }
1104
+
1025
1105
} ) ( typeof global !== 'undefined' ? global : this ) ;
0 commit comments