@@ -193,7 +193,7 @@ function inspect(value, opts) {
193
193
}
194
194
if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
195
195
if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
196
- return formatValue ( ctx , value , ctx . depth ) ;
196
+ return formatValue ( ctx , value , 0 ) ;
197
197
}
198
198
inspect . custom = customInspectSymbol ;
199
199
@@ -407,11 +407,10 @@ function getCtxStyle(constructor, tag) {
407
407
}
408
408
409
409
function formatProxy ( ctx , proxy , recurseTimes ) {
410
- if ( recurseTimes != null ) {
411
- if ( recurseTimes < 0 )
412
- return ctx . stylize ( 'Proxy [Array]' , 'special' ) ;
413
- recurseTimes -= 1 ;
410
+ if ( recurseTimes > ctx . depth && ctx . depth !== null ) {
411
+ return ctx . stylize ( 'Proxy [Array]' , 'special' ) ;
414
412
}
413
+ recurseTimes += 1 ;
415
414
ctx . indentationLvl += 2 ;
416
415
const res = [
417
416
formatValue ( ctx , proxy [ 0 ] , recurseTimes ) ,
@@ -526,7 +525,10 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
526
525
maybeCustom !== inspect &&
527
526
// Also filter out any prototype objects using the circular check.
528
527
! ( value . constructor && value . constructor . prototype === value ) ) {
529
- const ret = maybeCustom . call ( value , recurseTimes , ctx ) ;
528
+ // This makes sure the recurseTimes are reported as before while using
529
+ // a counter internally.
530
+ const depth = ctx . depth === null ? null : ctx . depth - recurseTimes ;
531
+ const ret = maybeCustom . call ( value , depth , ctx ) ;
530
532
531
533
// If the custom inspection method returned `this`, don't go into
532
534
// infinite recursion.
@@ -643,7 +645,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
643
645
const prefix = getPrefix ( constructor , tag , 'RegExp' ) ;
644
646
if ( prefix !== 'RegExp ' )
645
647
base = `${ prefix } ${ base } ` ;
646
- if ( keys . length === 0 || recurseTimes < 0 )
648
+ if ( keys . length === 0 || recurseTimes > ctx . depth && ctx . depth !== null )
647
649
return ctx . stylize ( base , 'regexp' ) ;
648
650
} else if ( isDate ( value ) ) {
649
651
// Make dates with properties first say the date
@@ -757,11 +759,10 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
757
759
}
758
760
}
759
761
760
- if ( recurseTimes != null ) {
761
- if ( recurseTimes < 0 )
762
- return ctx . stylize ( `[${ getCtxStyle ( constructor , tag ) } ]` , 'special' ) ;
763
- recurseTimes -= 1 ;
762
+ if ( recurseTimes > ctx . depth && ctx . depth !== null ) {
763
+ return ctx . stylize ( `[${ getCtxStyle ( constructor , tag ) } ]` , 'special' ) ;
764
764
}
765
+ recurseTimes += 1 ;
765
766
766
767
ctx . seen . push ( value ) ;
767
768
let output ;
0 commit comments