@@ -192,7 +192,7 @@ function inspect(value, opts) {
192192 }
193193 if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
194194 if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
195- return formatValue ( ctx , value , ctx . depth ) ;
195+ return formatValue ( ctx , value , 0 ) ;
196196}
197197inspect . custom = customInspectSymbol ;
198198
@@ -406,11 +406,10 @@ function getCtxStyle(constructor, tag) {
406406}
407407
408408function formatProxy ( ctx , proxy , recurseTimes ) {
409- if ( recurseTimes != null ) {
410- if ( recurseTimes < 0 )
411- return ctx . stylize ( 'Proxy [Array]' , 'special' ) ;
412- recurseTimes -= 1 ;
409+ if ( recurseTimes > ctx . depth && ctx . depth !== null ) {
410+ return ctx . stylize ( 'Proxy [Array]' , 'special' ) ;
413411 }
412+ recurseTimes += 1 ;
414413 ctx . indentationLvl += 2 ;
415414 const res = [
416415 formatValue ( ctx , proxy [ 0 ] , recurseTimes ) ,
@@ -525,7 +524,10 @@ function formatValue(ctx, value, recurseTimes) {
525524 maybeCustom !== inspect &&
526525 // Also filter out any prototype objects using the circular check.
527526 ! ( value . constructor && value . constructor . prototype === value ) ) {
528- const ret = maybeCustom . call ( value , recurseTimes , ctx ) ;
527+ // This makes sure the recurseTimes are reported as before while using
528+ // a counter internally.
529+ const depth = ctx . depth === null ? null : ctx . depth - recurseTimes ;
530+ const ret = maybeCustom . call ( value , depth , ctx ) ;
529531
530532 // If the custom inspection method returned `this`, don't go into
531533 // infinite recursion.
@@ -642,7 +644,7 @@ function formatRaw(ctx, value, recurseTimes) {
642644 const prefix = getPrefix ( constructor , tag , 'RegExp' ) ;
643645 if ( prefix !== 'RegExp ' )
644646 base = `${ prefix } ${ base } ` ;
645- if ( keys . length === 0 || recurseTimes < 0 )
647+ if ( keys . length === 0 || recurseTimes > ctx . depth && ctx . depth !== null )
646648 return ctx . stylize ( base , 'regexp' ) ;
647649 } else if ( isDate ( value ) ) {
648650 // Make dates with properties first say the date
@@ -753,11 +755,10 @@ function formatRaw(ctx, value, recurseTimes) {
753755 }
754756 }
755757
756- if ( recurseTimes != null ) {
757- if ( recurseTimes < 0 )
758- return ctx . stylize ( `[${ getCtxStyle ( constructor , tag ) } ]` , 'special' ) ;
759- recurseTimes -= 1 ;
758+ if ( recurseTimes > ctx . depth && ctx . depth !== null ) {
759+ return ctx . stylize ( `[${ getCtxStyle ( constructor , tag ) } ]` , 'special' ) ;
760760 }
761+ recurseTimes += 1 ;
761762
762763 ctx . seen . push ( value ) ;
763764 let output ;
0 commit comments