@@ -219,17 +219,33 @@ class ObjectPreview {
219
219
[ customInspectSymbol ] ( depth , opts ) {
220
220
switch ( this . type ) {
221
221
case 'object' : {
222
- const props = ArrayPrototypeMap ( this . properties , ( prop , idx ) => {
223
- const value = utilInspect ( new PropertyPreview ( prop ) ) ;
224
- if ( prop . name === `${ idx } ` ) return value ;
225
- return `${ prop . name } : ${ value } ` ;
226
- } ) ;
227
- if ( this . overflow ) {
228
- ArrayPrototypePush ( props , '...' ) ;
222
+ switch ( this . subtype ) {
223
+ case 'date' :
224
+ return utilInspect ( new Date ( this . description ) , opts ) ;
225
+ case 'null' :
226
+ return utilInspect ( null , opts ) ;
227
+ case 'regexp' :
228
+ return opts . stylize ( this . description , 'regexp' ) ;
229
+ case 'array' :
230
+ case undefined : {
231
+ if ( this . properties . length === 0 ) {
232
+ return this . subtype === 'array' ? '[]' : '{}' ;
233
+ }
234
+ const props = ArrayPrototypeMap ( this . properties , ( prop , idx ) => {
235
+ const value = utilInspect ( new PropertyPreview ( prop ) ) ;
236
+ if ( prop . name === `${ idx } ` ) return value ;
237
+ return `${ prop . name } : ${ value } ` ;
238
+ } ) ;
239
+ if ( this . overflow ) {
240
+ ArrayPrototypePush ( props , '...' ) ;
241
+ }
242
+ const singleLine = ArrayPrototypeJoin ( props , ', ' ) ;
243
+ const propString = singleLine . length > 60 ? ArrayPrototypeJoin ( props , ',\n ' ) : singleLine ;
244
+ return this . subtype === 'array' ? `[ ${ propString } ]` : `{ ${ propString } }` ;
245
+ }
246
+ default :
247
+ return this . description ;
229
248
}
230
- const singleLine = ArrayPrototypeJoin ( props , ', ' ) ;
231
- const propString = singleLine . length > 60 ? ArrayPrototypeJoin ( props , ',\n ' ) : singleLine ;
232
- return this . subtype === 'array' ? `[ ${ propString } ]` : `{ ${ propString } }` ;
233
249
}
234
250
default :
235
251
return this . description ;
@@ -268,6 +284,25 @@ class RemoteObject {
268
284
return utilInspect ( null , opts ) ;
269
285
case 'regexp' :
270
286
return opts . stylize ( this . description , 'regexp' ) ;
287
+ case 'set' : {
288
+ if ( ! this . preview . entries ) {
289
+ return `${ this . description } {}` ;
290
+ }
291
+ const values = ArrayPrototypeMap ( this . preview . entries , ( entry ) =>
292
+ utilInspect ( new ObjectPreview ( entry . value ) , opts ) ) ;
293
+ return `${ this . description } { ${ ArrayPrototypeJoin ( values , ', ' ) } }` ;
294
+ }
295
+ case 'map' : {
296
+ if ( ! this . preview . entries ) {
297
+ return `${ this . description } {}` ;
298
+ }
299
+ const mappings = ArrayPrototypeMap ( this . preview . entries , ( entry ) => {
300
+ const key = utilInspect ( new ObjectPreview ( entry . key ) , opts ) ;
301
+ const value = utilInspect ( new ObjectPreview ( entry . value ) , opts ) ;
302
+ return `${ key } => ${ value } ` ;
303
+ } ) ;
304
+ return `${ this . description } { ${ ArrayPrototypeJoin ( mappings , ', ' ) } }` ;
305
+ }
271
306
default :
272
307
break ;
273
308
}
0 commit comments