@@ -88,20 +88,26 @@ Root.prototype.load = function load(filename, options, callback) {
8888 options = undefined ;
8989 }
9090 var self = this ;
91- if ( ! callback )
91+ if ( ! callback ) {
9292 return util . asPromise ( load , self , filename , options ) ;
93+ }
9394
9495 var sync = callback === SYNC ; // undocumented
9596
9697 // Finishes loading by calling the callback (exactly once)
9798 function finish ( err , root ) {
9899 /* istanbul ignore if */
99- if ( ! callback )
100+ if ( ! callback ) {
100101 return ;
101- if ( sync )
102+ }
103+ if ( sync ) {
102104 throw err ;
105+ }
103106 var cb = callback ;
104107 callback = null ;
108+ if ( root ) {
109+ root . resolveAll ( ) ;
110+ }
105111 cb ( err , root ) ;
106112 }
107113
@@ -139,24 +145,26 @@ Root.prototype.load = function load(filename, options, callback) {
139145 } catch ( err ) {
140146 finish ( err ) ;
141147 }
142- if ( ! sync && ! queued )
148+ if ( ! sync && ! queued ) {
143149 finish ( null , self ) ; // only once anyway
150+ }
144151 }
145152
146153 // Fetches a single file
147154 function fetch ( filename , weak ) {
148155 filename = getBundledFileName ( filename ) || filename ;
149156
150157 // Skip if already loaded / attempted
151- if ( self . files . indexOf ( filename ) > - 1 )
158+ if ( self . files . indexOf ( filename ) > - 1 ) {
152159 return ;
160+ }
153161 self . files . push ( filename ) ;
154162
155163 // Shortcut bundled definitions
156164 if ( filename in common ) {
157- if ( sync )
165+ if ( sync ) {
158166 process ( filename , common [ filename ] ) ;
159- else {
167+ } else {
160168 ++ queued ;
161169 setTimeout ( function ( ) {
162170 -- queued ;
@@ -182,8 +190,9 @@ Root.prototype.load = function load(filename, options, callback) {
182190 self . fetch ( filename , function ( err , source ) {
183191 -- queued ;
184192 /* istanbul ignore if */
185- if ( ! callback )
193+ if ( ! callback ) {
186194 return ; // terminated meanwhile
195+ }
187196 if ( err ) {
188197 /* istanbul ignore else */
189198 if ( ! weak )
@@ -200,17 +209,21 @@ Root.prototype.load = function load(filename, options, callback) {
200209
201210 // Assembling the root namespace doesn't require working type
202211 // references anymore, so we can load everything in parallel
203- if ( util . isString ( filename ) )
212+ if ( util . isString ( filename ) ) {
204213 filename = [ filename ] ;
214+ }
205215 for ( var i = 0 , resolved ; i < filename . length ; ++ i )
206216 if ( resolved = self . resolvePath ( "" , filename [ i ] ) )
207217 fetch ( resolved ) ;
208218 self . resolveAll ( ) ;
209- if ( sync )
219+ if ( sync ) {
210220 return self ;
211- if ( ! queued )
221+ }
222+ if ( ! queued ) {
212223 finish ( null , self ) ;
213- return undefined ;
224+ }
225+
226+ return self ;
214227} ;
215228// function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
216229
0 commit comments