@@ -492,6 +492,9 @@ function findTypedConstructor(value) {
492
492
493
493
const getBoxedValue = formatPrimitive . bind ( null , stylizeNoColor ) ;
494
494
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.
495
498
function formatValue ( ctx , value , recurseTimes ) {
496
499
// Primitive types cannot have properties
497
500
if ( typeof value !== 'object' && typeof value !== 'function' ) {
@@ -1011,17 +1014,18 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
1011
1014
output [ i ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1012
1015
if ( ctx . showHidden ) {
1013
1016
// .buffer goes last, it's not a primitive like the others.
1014
- const extraKeys = [
1017
+ ctx . indentationLvl += 2 ;
1018
+ for ( const key of [
1015
1019
'BYTES_PER_ELEMENT' ,
1016
1020
'length' ,
1017
1021
'byteLength' ,
1018
1022
'byteOffset' ,
1019
1023
'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 } ` ) ;
1024
1027
}
1028
+ ctx . indentationLvl -= 2 ;
1025
1029
}
1026
1030
// TypedArrays cannot have holes. Therefore it is safe to assume that all
1027
1031
// extra keys are indexed after value.length.
@@ -1034,8 +1038,11 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
1034
1038
function formatSet ( ctx , value , recurseTimes , keys ) {
1035
1039
const output = new Array ( value . size + keys . length + ( ctx . showHidden ? 1 : 0 ) ) ;
1036
1040
let i = 0 ;
1037
- for ( const v of value )
1041
+ ctx . indentationLvl += 2 ;
1042
+ for ( const v of value ) {
1038
1043
output [ i ++ ] = formatValue ( ctx , v , recurseTimes ) ;
1044
+ }
1045
+ ctx . indentationLvl -= 2 ;
1039
1046
// With `showHidden`, `length` will display as a hidden property for
1040
1047
// arrays. For consistency's sake, do the same for `size`, even though this
1041
1048
// property isn't selected by Object.getOwnPropertyNames().
@@ -1050,9 +1057,12 @@ function formatSet(ctx, value, recurseTimes, keys) {
1050
1057
function formatMap ( ctx , value , recurseTimes , keys ) {
1051
1058
const output = new Array ( value . size + keys . length + ( ctx . showHidden ? 1 : 0 ) ) ;
1052
1059
let i = 0 ;
1053
- for ( const [ k , v ] of value )
1060
+ ctx . indentationLvl += 2 ;
1061
+ for ( const [ k , v ] of value ) {
1054
1062
output [ i ++ ] = `${ formatValue ( ctx , k , recurseTimes ) } => ` +
1055
- formatValue ( ctx , v , recurseTimes ) ;
1063
+ formatValue ( ctx , v , recurseTimes ) ;
1064
+ }
1065
+ ctx . indentationLvl -= 2 ;
1056
1066
// See comment in formatSet
1057
1067
if ( ctx . showHidden )
1058
1068
output [ i ++ ] = `[size]: ${ ctx . stylize ( `${ value . size } ` , 'number' ) } ` ;
@@ -1066,8 +1076,11 @@ function formatSetIterInner(ctx, value, recurseTimes, keys, entries, state) {
1066
1076
const maxArrayLength = Math . max ( ctx . maxArrayLength , 0 ) ;
1067
1077
const maxLength = Math . min ( maxArrayLength , entries . length ) ;
1068
1078
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 ++ ) {
1070
1081
output [ i ] = formatValue ( ctx , entries [ i ] , recurseTimes ) ;
1082
+ }
1083
+ ctx . indentationLvl -= 2 ;
1071
1084
if ( state === kWeak ) {
1072
1085
// Sort all entries to have a halfway reliable output (if more entries than
1073
1086
// retrieved ones exist, we can not reliably return the same output).
@@ -1098,11 +1111,13 @@ function formatMapIterInner(ctx, value, recurseTimes, keys, entries, state) {
1098
1111
end = ' ]' ;
1099
1112
middle = ', ' ;
1100
1113
}
1114
+ ctx . indentationLvl += 2 ;
1101
1115
for ( ; i < maxLength ; i ++ ) {
1102
1116
const pos = i * 2 ;
1103
1117
output [ i ] = `${ start } ${ formatValue ( ctx , entries [ pos ] , recurseTimes ) } ` +
1104
1118
`${ middle } ${ formatValue ( ctx , entries [ pos + 1 ] , recurseTimes ) } ${ end } ` ;
1105
1119
}
1120
+ ctx . indentationLvl -= 2 ;
1106
1121
if ( state === kWeak ) {
1107
1122
// Sort all entries to have a halfway reliable output (if more entries
1108
1123
// than retrieved ones exist, we can not reliably return the same output).
@@ -1147,7 +1162,11 @@ function formatPromise(ctx, value, recurseTimes, keys) {
1147
1162
if ( state === kPending ) {
1148
1163
output = [ '<pending>' ] ;
1149
1164
} else {
1165
+ // Using `formatValue` is correct here without the need to fix the
1166
+ // indentation level.
1167
+ ctx . indentationLvl += 2 ;
1150
1168
const str = formatValue ( ctx , result , recurseTimes ) ;
1169
+ ctx . indentationLvl -= 2 ;
1151
1170
output = [ state === kRejected ? `<rejected> ${ str } ` : str ] ;
1152
1171
}
1153
1172
for ( var n = 0 ; n < keys . length ; n ++ ) {
0 commit comments