@@ -492,6 +492,9 @@ function findTypedConstructor(value) {
492492
493493const getBoxedValue = formatPrimitive . bind ( null , stylizeNoColor ) ;
494494
495+ // Note: using `formatValue` directly requires the indentation level to be
496+ // corrected by setting `ctx.indentationLvL += diff` and then to decrease the
497+ // value afterwards again.
495498function formatValue ( ctx , value , recurseTimes ) {
496499 // Primitive types cannot have properties
497500 if ( typeof value !== 'object' && typeof value !== 'function' ) {
@@ -1011,17 +1014,18 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
10111014 output [ i ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
10121015 if ( ctx . showHidden ) {
10131016 // .buffer goes last, it's not a primitive like the others.
1014- const extraKeys = [
1017+ ctx . indentationLvl += 2 ;
1018+ for ( const key of [
10151019 'BYTES_PER_ELEMENT' ,
10161020 'length' ,
10171021 'byteLength' ,
10181022 'byteOffset' ,
10191023 'buffer'
1020- ] ;
1021- for ( i = 0 ; i < extraKeys . length ; i ++ ) {
1022- const str = formatValue ( ctx , value [ extraKeys [ i ] ] , recurseTimes ) ;
1023- output . push ( `[${ extraKeys [ i ] } ]: ${ str } ` ) ;
1024+ ] ) {
1025+ const str = formatValue ( ctx , value [ key ] , recurseTimes ) ;
1026+ output . push ( `[${ key } ]: ${ str } ` ) ;
10241027 }
1028+ ctx . indentationLvl -= 2 ;
10251029 }
10261030 // TypedArrays cannot have holes. Therefore it is safe to assume that all
10271031 // extra keys are indexed after value.length.
@@ -1034,8 +1038,11 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
10341038function formatSet ( ctx , value , recurseTimes , keys ) {
10351039 const output = new Array ( value . size + keys . length + ( ctx . showHidden ? 1 : 0 ) ) ;
10361040 let i = 0 ;
1037- for ( const v of value )
1041+ ctx . indentationLvl += 2 ;
1042+ for ( const v of value ) {
10381043 output [ i ++ ] = formatValue ( ctx , v , recurseTimes ) ;
1044+ }
1045+ ctx . indentationLvl -= 2 ;
10391046 // With `showHidden`, `length` will display as a hidden property for
10401047 // arrays. For consistency's sake, do the same for `size`, even though this
10411048 // property isn't selected by Object.getOwnPropertyNames().
@@ -1050,9 +1057,12 @@ function formatSet(ctx, value, recurseTimes, keys) {
10501057function formatMap ( ctx , value , recurseTimes , keys ) {
10511058 const output = new Array ( value . size + keys . length + ( ctx . showHidden ? 1 : 0 ) ) ;
10521059 let i = 0 ;
1053- for ( const [ k , v ] of value )
1060+ ctx . indentationLvl += 2 ;
1061+ for ( const [ k , v ] of value ) {
10541062 output [ i ++ ] = `${ formatValue ( ctx , k , recurseTimes ) } => ` +
1055- formatValue ( ctx , v , recurseTimes ) ;
1063+ formatValue ( ctx , v , recurseTimes ) ;
1064+ }
1065+ ctx . indentationLvl -= 2 ;
10561066 // See comment in formatSet
10571067 if ( ctx . showHidden )
10581068 output [ i ++ ] = `[size]: ${ ctx . stylize ( `${ value . size } ` , 'number' ) } ` ;
@@ -1066,8 +1076,11 @@ function formatSetIterInner(ctx, value, recurseTimes, keys, entries, state) {
10661076 const maxArrayLength = Math . max ( ctx . maxArrayLength , 0 ) ;
10671077 const maxLength = Math . min ( maxArrayLength , entries . length ) ;
10681078 let output = new Array ( maxLength ) ;
1069- for ( var i = 0 ; i < maxLength ; ++ i )
1079+ ctx . indentationLvl += 2 ;
1080+ for ( var i = 0 ; i < maxLength ; i ++ ) {
10701081 output [ i ] = formatValue ( ctx , entries [ i ] , recurseTimes ) ;
1082+ }
1083+ ctx . indentationLvl -= 2 ;
10711084 if ( state === kWeak ) {
10721085 // Sort all entries to have a halfway reliable output (if more entries than
10731086 // retrieved ones exist, we can not reliably return the same output).
@@ -1098,11 +1111,13 @@ function formatMapIterInner(ctx, value, recurseTimes, keys, entries, state) {
10981111 end = ' ]' ;
10991112 middle = ', ' ;
11001113 }
1114+ ctx . indentationLvl += 2 ;
11011115 for ( ; i < maxLength ; i ++ ) {
11021116 const pos = i * 2 ;
11031117 output [ i ] = `${ start } ${ formatValue ( ctx , entries [ pos ] , recurseTimes ) } ` +
11041118 `${ middle } ${ formatValue ( ctx , entries [ pos + 1 ] , recurseTimes ) } ${ end } ` ;
11051119 }
1120+ ctx . indentationLvl -= 2 ;
11061121 if ( state === kWeak ) {
11071122 // Sort all entries to have a halfway reliable output (if more entries
11081123 // than retrieved ones exist, we can not reliably return the same output).
@@ -1147,7 +1162,11 @@ function formatPromise(ctx, value, recurseTimes, keys) {
11471162 if ( state === kPending ) {
11481163 output = [ '<pending>' ] ;
11491164 } else {
1165+ // Using `formatValue` is correct here without the need to fix the
1166+ // indentation level.
1167+ ctx . indentationLvl += 2 ;
11501168 const str = formatValue ( ctx , result , recurseTimes ) ;
1169+ ctx . indentationLvl -= 2 ;
11511170 output = [ state === kRejected ? `<rejected> ${ str } ` : str ] ;
11521171 }
11531172 for ( var n = 0 ; n < keys . length ; n ++ ) {
0 commit comments