@@ -638,6 +638,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
638638 } else {
639639 extra = '[items unknown]' ;
640640 }
641+ } else if ( types . isModuleNamespaceObject ( value ) ) {
642+ braces [ 0 ] = `[${ tag } ] {` ;
643+ formatter = formatNamespaceObject ;
641644 } else {
642645 // Check boxed primitives other than string with valueOf()
643646 // NOTE: `Date` has to be checked first!
@@ -766,6 +769,15 @@ function formatObject(ctx, value, recurseTimes, keys) {
766769 return output ;
767770}
768771
772+ function formatNamespaceObject ( ctx , value , recurseTimes , keys ) {
773+ const len = keys . length ;
774+ const output = new Array ( len ) ;
775+ for ( var i = 0 ; i < len ; i ++ ) {
776+ output [ i ] = formatNamespaceProperty ( ctx , value , recurseTimes , keys [ i ] ) ;
777+ }
778+ return output ;
779+ }
780+
769781// The array is sparse and/or has extra keys
770782function formatSpecialArray ( ctx , value , recurseTimes , keys , maxLength , valLen ) {
771783 const output = [ ] ;
@@ -993,8 +1005,36 @@ function formatPromise(ctx, value, recurseTimes, keys) {
9931005 return output ;
9941006}
9951007
1008+ function formatKey ( ctx , key , enumerable ) {
1009+ if ( typeof key === 'symbol' ) {
1010+ return `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
1011+ }
1012+ if ( enumerable === false ) {
1013+ return `[${ key } ]` ;
1014+ }
1015+ if ( keyStrRegExp . test ( key ) ) {
1016+ return ctx . stylize ( key , 'name' ) ;
1017+ }
1018+ return ctx . stylize ( strEscape ( key ) , 'string' ) ;
1019+ }
1020+
1021+ function formatNamespaceProperty ( ctx , ns , recurseTimes , key ) {
1022+ let value ;
1023+ try {
1024+ value = formatValue ( ctx , ns [ key ] , recurseTimes , true ) ;
1025+ } catch ( err ) {
1026+ if ( err instanceof ReferenceError ) {
1027+ value = ctx . stylize ( '<uninitialized>' , 'special' ) ;
1028+ } else {
1029+ throw err ;
1030+ }
1031+ }
1032+
1033+ return `${ formatKey ( ctx , key ) } : ${ value } ` ;
1034+ }
1035+
9961036function formatProperty ( ctx , value , recurseTimes , key , array ) {
997- let name , str ;
1037+ let str ;
9981038 const desc = Object . getOwnPropertyDescriptor ( value , key ) ||
9991039 { value : value [ key ] , enumerable : true } ;
10001040 if ( desc . value !== undefined ) {
@@ -1016,17 +1056,8 @@ function formatProperty(ctx, value, recurseTimes, key, array) {
10161056 if ( array === 1 ) {
10171057 return str ;
10181058 }
1019- if ( typeof key === 'symbol' ) {
1020- name = `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
1021- } else if ( desc . enumerable === false ) {
1022- name = `[${ key } ]` ;
1023- } else if ( keyStrRegExp . test ( key ) ) {
1024- name = ctx . stylize ( key , 'name' ) ;
1025- } else {
1026- name = ctx . stylize ( strEscape ( key ) , 'string' ) ;
1027- }
10281059
1029- return `${ name } : ${ str } ` ;
1060+ return `${ formatKey ( ctx , key , desc . enumerable ) } : ${ str } ` ;
10301061}
10311062
10321063function reduceToSingleString ( ctx , output , base , braces , addLn ) {
0 commit comments