@@ -543,6 +543,9 @@ function findTypedConstructor(value) {
543
543
544
544
const getBoxedValue = formatPrimitive . bind ( null , stylizeNoColor ) ;
545
545
546
+ // Note: using `formatValue` directly requires the indentation level to be
547
+ // corrected by setting `ctx.indentationLvL += diff` and then to decrease the
548
+ // value afterwards again.
546
549
function formatValue ( ctx , value , recurseTimes ) {
547
550
// Primitive types cannot have properties
548
551
if ( typeof value !== 'object' && typeof value !== 'function' ) {
@@ -1063,17 +1066,18 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
1063
1066
output [ i ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1064
1067
if ( ctx . showHidden ) {
1065
1068
// .buffer goes last, it's not a primitive like the others.
1066
- const extraKeys = [
1069
+ ctx . indentationLvl += 2 ;
1070
+ for ( const key of [
1067
1071
'BYTES_PER_ELEMENT' ,
1068
1072
'length' ,
1069
1073
'byteLength' ,
1070
1074
'byteOffset' ,
1071
1075
'buffer'
1072
- ] ;
1073
- for ( i = 0 ; i < extraKeys . length ; i ++ ) {
1074
- const str = formatValue ( ctx , value [ extraKeys [ i ] ] , recurseTimes ) ;
1075
- output . push ( `[${ extraKeys [ i ] } ]: ${ str } ` ) ;
1076
+ ] ) {
1077
+ const str = formatValue ( ctx , value [ key ] , recurseTimes ) ;
1078
+ output . push ( `[${ key } ]: ${ str } ` ) ;
1076
1079
}
1080
+ ctx . indentationLvl -= 2 ;
1077
1081
}
1078
1082
// TypedArrays cannot have holes. Therefore it is safe to assume that all
1079
1083
// extra keys are indexed after value.length.
@@ -1086,8 +1090,11 @@ function formatTypedArray(ctx, value, recurseTimes, keys) {
1086
1090
function formatSet ( ctx , value , recurseTimes , keys ) {
1087
1091
const output = new Array ( value . size + keys . length + ( ctx . showHidden ? 1 : 0 ) ) ;
1088
1092
let i = 0 ;
1089
- for ( const v of value )
1093
+ ctx . indentationLvl += 2 ;
1094
+ for ( const v of value ) {
1090
1095
output [ i ++ ] = formatValue ( ctx , v , recurseTimes ) ;
1096
+ }
1097
+ ctx . indentationLvl -= 2 ;
1091
1098
// With `showHidden`, `length` will display as a hidden property for
1092
1099
// arrays. For consistency's sake, do the same for `size`, even though this
1093
1100
// property isn't selected by Object.getOwnPropertyNames().
@@ -1102,9 +1109,12 @@ function formatSet(ctx, value, recurseTimes, keys) {
1102
1109
function formatMap ( ctx , value , recurseTimes , keys ) {
1103
1110
const output = new Array ( value . size + keys . length + ( ctx . showHidden ? 1 : 0 ) ) ;
1104
1111
let i = 0 ;
1105
- for ( const [ k , v ] of value )
1112
+ ctx . indentationLvl += 2 ;
1113
+ for ( const [ k , v ] of value ) {
1106
1114
output [ i ++ ] = `${ formatValue ( ctx , k , recurseTimes ) } => ` +
1107
- formatValue ( ctx , v , recurseTimes ) ;
1115
+ formatValue ( ctx , v , recurseTimes ) ;
1116
+ }
1117
+ ctx . indentationLvl -= 2 ;
1108
1118
// See comment in formatSet
1109
1119
if ( ctx . showHidden )
1110
1120
output [ i ++ ] = `[size]: ${ ctx . stylize ( `${ value . size } ` , 'number' ) } ` ;
@@ -1118,8 +1128,11 @@ function formatSetIterInner(ctx, value, recurseTimes, keys, entries, state) {
1118
1128
const maxArrayLength = Math . max ( ctx . maxArrayLength , 0 ) ;
1119
1129
const maxLength = Math . min ( maxArrayLength , entries . length ) ;
1120
1130
let output = new Array ( maxLength ) ;
1121
- for ( var i = 0 ; i < maxLength ; ++ i )
1131
+ ctx . indentationLvl += 2 ;
1132
+ for ( var i = 0 ; i < maxLength ; i ++ ) {
1122
1133
output [ i ] = formatValue ( ctx , entries [ i ] , recurseTimes ) ;
1134
+ }
1135
+ ctx . indentationLvl -= 2 ;
1123
1136
if ( state === kWeak ) {
1124
1137
// Sort all entries to have a halfway reliable output (if more entries than
1125
1138
// retrieved ones exist, we can not reliably return the same output).
@@ -1150,11 +1163,13 @@ function formatMapIterInner(ctx, value, recurseTimes, keys, entries, state) {
1150
1163
end = ' ]' ;
1151
1164
middle = ', ' ;
1152
1165
}
1166
+ ctx . indentationLvl += 2 ;
1153
1167
for ( ; i < maxLength ; i ++ ) {
1154
1168
const pos = i * 2 ;
1155
1169
output [ i ] = `${ start } ${ formatValue ( ctx , entries [ pos ] , recurseTimes ) } ` +
1156
1170
`${ middle } ${ formatValue ( ctx , entries [ pos + 1 ] , recurseTimes ) } ${ end } ` ;
1157
1171
}
1172
+ ctx . indentationLvl -= 2 ;
1158
1173
if ( state === kWeak ) {
1159
1174
// Sort all entries to have a halfway reliable output (if more entries
1160
1175
// than retrieved ones exist, we can not reliably return the same output).
@@ -1199,7 +1214,11 @@ function formatPromise(ctx, value, recurseTimes, keys) {
1199
1214
if ( state === kPending ) {
1200
1215
output = [ '<pending>' ] ;
1201
1216
} else {
1217
+ // Using `formatValue` is correct here without the need to fix the
1218
+ // indentation level.
1219
+ ctx . indentationLvl += 2 ;
1202
1220
const str = formatValue ( ctx , result , recurseTimes ) ;
1221
+ ctx . indentationLvl -= 2 ;
1203
1222
output = [ state === kRejected ? `<rejected> ${ str } ` : str ] ;
1204
1223
}
1205
1224
for ( var n = 0 ; n < keys . length ; n ++ ) {
0 commit comments