@@ -24,22 +24,22 @@ var visitors = require('./fbtransform/visitors').transformVisitors;
24
24
var transform = transform . bind ( null , visitors . react ) ;
25
25
var docblock = require ( './fbtransform/lib/docblock' ) ;
26
26
27
+ var headEl = document . getElementsByTagName ( 'head' ) [ 0 ] ;
28
+
27
29
exports . transform = transform ;
30
+
28
31
exports . exec = function ( code ) {
29
32
return eval ( transform ( code ) ) ;
30
33
} ;
34
+
31
35
var run = exports . run = function ( code ) {
32
- var moduleName =
33
- docblock . parseAsObject ( docblock . extract ( code ) ) . providesModule ;
34
- var jsx =
35
- docblock . parseAsObject ( docblock . extract ( code ) ) . jsx ;
36
+ var jsx = docblock . parseAsObject ( docblock . extract ( code ) ) . jsx ;
36
37
37
- window . moduleLoads = ( window . moduleLoads || [ ] ) . concat ( moduleName ) ;
38
- window . startTime = Date . now ( ) ;
39
38
var functionBody = jsx ? transform ( code ) . code : code ;
40
- Function ( 'require' , 'module' , 'exports' , functionBody ) ( require , module , exports ) ;
41
- window . endTime = Date . now ( ) ;
42
- require [ moduleName ] = module . exports ;
39
+ var scriptEl = document . createElement ( 'script' ) ;
40
+
41
+ scriptEl . innerHTML = functionBody ;
42
+ headEl . appendChild ( scriptEl ) ;
43
43
} ;
44
44
45
45
if ( typeof window === "undefined" || window === null ) {
@@ -48,15 +48,17 @@ if (typeof window === "undefined" || window === null) {
48
48
49
49
var load = exports . load = function ( url , callback ) {
50
50
var xhr ;
51
- xhr = window . ActiveXObject ? new window . ActiveXObject ( 'Microsoft.XMLHTTP' ) : new XMLHttpRequest ( ) ;
51
+ xhr = window . ActiveXObject ? new window . ActiveXObject ( 'Microsoft.XMLHTTP' )
52
+ : new XMLHttpRequest ( ) ;
53
+ // Disable async since we need to execute scripts in the order they are in the
54
+ // DOM to mirror normal script loading.
52
55
xhr . open ( 'GET' , url , false ) ;
53
56
if ( 'overrideMimeType' in xhr ) {
54
57
xhr . overrideMimeType ( 'text/plain' ) ;
55
58
}
56
59
xhr . onreadystatechange = function ( ) {
57
- var _ref ;
58
60
if ( xhr . readyState === 4 ) {
59
- if ( ( _ref = xhr . status ) === 0 || _ref === 200 ) {
61
+ if ( xhr . status === 0 || xhr . status === 200 ) {
60
62
run ( xhr . responseText ) ;
61
63
} else {
62
64
throw new Error ( "Could not load " + url ) ;
@@ -70,37 +72,19 @@ var load = exports.load = function(url, callback) {
70
72
} ;
71
73
72
74
runScripts = function ( ) {
73
- var jsxes , execute , index , length , s , scripts ;
74
- scripts = document . getElementsByTagName ( 'script' ) ;
75
- jsxes = ( function ( ) {
76
- var _i , _len , _results ;
77
- _results = [ ] ;
78
- for ( _i = 0 , _len = scripts . length ; _i < _len ; _i ++ ) {
79
- s = scripts [ _i ] ;
80
- if ( s . type === 'text/jsx' ) {
81
- _results . push ( s ) ;
82
- }
83
- }
84
- return _results ;
85
- } ) ( ) ;
86
- index = 0 ;
87
- length = jsxes . length ;
88
- ( execute = function ( j ) {
89
- var script ;
90
- script = jsxes [ j ] ;
91
- if ( ( script != null ? script . type : void 0 ) === 'text/jsx' ) {
92
- if ( script . src ) {
93
- return load ( script . src , execute ) ;
94
- } else {
95
- run ( script . innerHTML ) ;
96
- return execute ( ) ;
97
- }
75
+ var scripts = document . getElementsByTagName ( 'script' ) ;
76
+ scripts = Array . prototype . slice . call ( scripts ) ;
77
+ var jsxScripts = scripts . filter ( function ( script ) {
78
+ return script . type === 'text/jsx' ;
79
+ } ) ;
80
+
81
+ jsxScripts . forEach ( function ( script ) {
82
+ if ( script . src ) {
83
+ load ( script . src ) ;
84
+ } else {
85
+ run ( script . innerHTML ) ;
98
86
}
99
87
} ) ;
100
- for ( var i = 0 ; i < jsxes . length ; i ++ ) {
101
- execute ( i ) ;
102
- }
103
- return null ;
104
88
} ;
105
89
106
90
if ( window . addEventListener ) {
0 commit comments