@@ -72,11 +72,8 @@ function printNumber(val: number): string {
7272function printFunction ( val : Function , printFunctionName : boolean ) : string {
7373 if ( ! printFunctionName ) {
7474 return '[Function]' ;
75- } else if ( val . name === '' ) {
76- return '[Function anonymous]' ;
77- } else {
78- return '[Function ' + val . name + ']' ;
7975 }
76+ return '[Function ' + ( val . name || 'anonymous' ) + ']' ;
8077}
8178
8279function printSymbol ( val : Symbol ) : string {
@@ -155,7 +152,7 @@ function printBasicValue(
155152 return null ;
156153}
157154
158- function printList (
155+ function printListItems (
159156 list : any ,
160157 config : Config ,
161158 indentation : string ,
@@ -186,7 +183,7 @@ function printList(
186183 return result ;
187184}
188185
189- function printMap (
186+ function printMapEntries (
190187 val : Map < any , any > ,
191188 config : Config ,
192189 indentation : string ,
@@ -203,7 +200,13 @@ function printMap(
203200 const indentationNext = indentation + config . indent ;
204201
205202 while ( ! current . done ) {
206- const key = print ( current . value [ 0 ] , config , indentationNext , depth , refs ) ;
203+ const name = print (
204+ current . value [ 0 ] ,
205+ config ,
206+ indentationNext ,
207+ depth ,
208+ refs ,
209+ ) ;
207210 const value = print (
208211 current . value [ 1 ] ,
209212 config ,
@@ -212,7 +215,7 @@ function printMap(
212215 refs ,
213216 ) ;
214217
215- result += indentationNext + key + ' => ' + value ;
218+ result += indentationNext + name + ' => ' + value ;
216219
217220 current = iterator . next ( ) ;
218221
@@ -229,7 +232,7 @@ function printMap(
229232 return result ;
230233}
231234
232- function printObject (
235+ function printObjectProperties (
233236 val : Object ,
234237 config : Config ,
235238 indentation : string ,
@@ -269,15 +272,15 @@ function printObject(
269272 return result ;
270273}
271274
272- function printSet (
275+ function printSetValues (
273276 val : Set < any > ,
274277 config : Config ,
275278 indentation : string ,
276279 depth : number ,
277280 refs : Refs ,
278281) : string {
279282 let result = '' ;
280- const iterator = val . entries ( ) ;
283+ const iterator = val . values ( ) ;
281284 let current = iterator . next ( ) ;
282285
283286 if ( ! current . done ) {
@@ -288,7 +291,7 @@ function printSet(
288291 while ( ! current . done ) {
289292 result +=
290293 indentationNext +
291- print ( current . value [ 1 ] , config , indentationNext , depth , refs ) ;
294+ print ( current . value , config , indentationNext , depth , refs ) ;
292295
293296 current = iterator . next ( ) ;
294297
@@ -312,12 +315,11 @@ function printComplexValue(
312315 depth : number ,
313316 refs : Refs ,
314317) : string {
315- refs = refs . slice ( ) ;
316- if ( refs . indexOf ( val ) > - 1 ) {
318+ if ( refs . indexOf ( val ) !== - 1 ) {
317319 return '[Circular]' ;
318- } else {
319- refs . push ( val ) ;
320320 }
321+ refs = refs . slice ( ) ;
322+ refs . push ( val ) ;
321323
322324 const hitMaxDepth = ++ depth > config . maxDepth ;
323325 const min = config . min ;
@@ -337,30 +339,33 @@ function printComplexValue(
337339 ? '[Arguments]'
338340 : ( min ? '' : 'Arguments ' ) +
339341 '[' +
340- printList ( val , config , indentation , depth , refs ) +
342+ printListItems ( val , config , indentation , depth , refs ) +
341343 ']' ;
342- } else if ( isToStringedArrayType ( toStringed ) ) {
344+ }
345+ if ( isToStringedArrayType ( toStringed ) ) {
343346 return hitMaxDepth
344347 ? '[' + val . constructor . name + ']'
345348 : ( min ? '' : val . constructor . name + ' ' ) +
346349 '[' +
347- printList ( val , config , indentation , depth , refs ) +
350+ printListItems ( val , config , indentation , depth , refs ) +
348351 ']' ;
349- } else if ( toStringed === '[object Map]' ) {
352+ }
353+ if ( toStringed === '[object Map]' ) {
350354 return hitMaxDepth
351355 ? '[Map]'
352- : 'Map {' + printMap ( val , config , indentation , depth , refs ) + '}' ;
353- } else if ( toStringed === '[object Set]' ) {
356+ : 'Map {' + printMapEntries ( val , config , indentation , depth , refs ) + '}' ;
357+ }
358+ if ( toStringed === '[object Set]' ) {
354359 return hitMaxDepth
355360 ? '[Set]'
356- : 'Set {' + printSet ( val , config , indentation , depth , refs ) + '}' ;
361+ : 'Set {' + printSetValues ( val , config , indentation , depth , refs ) + '}' ;
357362 }
358363
359364 return hitMaxDepth
360365 ? '[' + ( val . constructor ? val . constructor . name : 'Object' ) + ']'
361366 : ( min ? '' : ( val . constructor ? val . constructor . name : 'Object' ) + ' ' ) +
362367 '{' +
363- printObject ( val , config , indentation , depth , refs ) +
368+ printObjectProperties ( val , config , indentation , depth , refs ) +
364369 '}' ;
365370}
366371
0 commit comments