@@ -88,20 +88,26 @@ Root.prototype.load = function load(filename, options, callback) {
88
88
options = undefined ;
89
89
}
90
90
var self = this ;
91
- if ( ! callback )
91
+ if ( ! callback ) {
92
92
return util . asPromise ( load , self , filename , options ) ;
93
+ }
93
94
94
95
var sync = callback === SYNC ; // undocumented
95
96
96
97
// Finishes loading by calling the callback (exactly once)
97
98
function finish ( err , root ) {
98
99
/* istanbul ignore if */
99
- if ( ! callback )
100
+ if ( ! callback ) {
100
101
return ;
101
- if ( sync )
102
+ }
103
+ if ( sync ) {
102
104
throw err ;
105
+ }
103
106
var cb = callback ;
104
107
callback = null ;
108
+ if ( root ) {
109
+ root . resolveAll ( ) ;
110
+ }
105
111
cb ( err , root ) ;
106
112
}
107
113
@@ -139,24 +145,26 @@ Root.prototype.load = function load(filename, options, callback) {
139
145
} catch ( err ) {
140
146
finish ( err ) ;
141
147
}
142
- if ( ! sync && ! queued )
148
+ if ( ! sync && ! queued ) {
143
149
finish ( null , self ) ; // only once anyway
150
+ }
144
151
}
145
152
146
153
// Fetches a single file
147
154
function fetch ( filename , weak ) {
148
155
filename = getBundledFileName ( filename ) || filename ;
149
156
150
157
// Skip if already loaded / attempted
151
- if ( self . files . indexOf ( filename ) > - 1 )
158
+ if ( self . files . indexOf ( filename ) > - 1 ) {
152
159
return ;
160
+ }
153
161
self . files . push ( filename ) ;
154
162
155
163
// Shortcut bundled definitions
156
164
if ( filename in common ) {
157
- if ( sync )
165
+ if ( sync ) {
158
166
process ( filename , common [ filename ] ) ;
159
- else {
167
+ } else {
160
168
++ queued ;
161
169
setTimeout ( function ( ) {
162
170
-- queued ;
@@ -182,8 +190,9 @@ Root.prototype.load = function load(filename, options, callback) {
182
190
self . fetch ( filename , function ( err , source ) {
183
191
-- queued ;
184
192
/* istanbul ignore if */
185
- if ( ! callback )
193
+ if ( ! callback ) {
186
194
return ; // terminated meanwhile
195
+ }
187
196
if ( err ) {
188
197
/* istanbul ignore else */
189
198
if ( ! weak )
@@ -200,17 +209,21 @@ Root.prototype.load = function load(filename, options, callback) {
200
209
201
210
// Assembling the root namespace doesn't require working type
202
211
// references anymore, so we can load everything in parallel
203
- if ( util . isString ( filename ) )
212
+ if ( util . isString ( filename ) ) {
204
213
filename = [ filename ] ;
214
+ }
205
215
for ( var i = 0 , resolved ; i < filename . length ; ++ i )
206
216
if ( resolved = self . resolvePath ( "" , filename [ i ] ) )
207
217
fetch ( resolved ) ;
208
218
self . resolveAll ( ) ;
209
- if ( sync )
219
+ if ( sync ) {
210
220
return self ;
211
- if ( ! queued )
221
+ }
222
+ if ( ! queued ) {
212
223
finish ( null , self ) ;
213
- return undefined ;
224
+ }
225
+
226
+ return self ;
214
227
} ;
215
228
// function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
216
229
0 commit comments