@@ -629,6 +629,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
629629 } else {
630630 extra = '[items unknown]' ;
631631 }
632+ } else if ( types . isModuleNamespaceObject ( value ) ) {
633+ braces [ 0 ] = `[${ tag } ] {` ;
634+ formatter = formatNamespaceObject ;
632635 } else {
633636 // Check boxed primitives other than string with valueOf()
634637 // NOTE: `Date` has to be checked first!
@@ -757,6 +760,15 @@ function formatObject(ctx, value, recurseTimes, keys) {
757760 return output ;
758761}
759762
763+ function formatNamespaceObject ( ctx , value , recurseTimes , keys ) {
764+ const len = keys . length ;
765+ const output = new Array ( len ) ;
766+ for ( var i = 0 ; i < len ; i ++ ) {
767+ output [ i ] = formatNamespaceProperty ( ctx , value , recurseTimes , keys [ i ] ) ;
768+ }
769+ return output ;
770+ }
771+
760772// The array is sparse and/or has extra keys
761773function formatSpecialArray ( ctx , value , recurseTimes , keys , maxLength , valLen ) {
762774 const output = [ ] ;
@@ -980,8 +992,36 @@ function formatPromise(ctx, value, recurseTimes, keys) {
980992 return output ;
981993}
982994
995+ function formatKey ( ctx , key , enumerable ) {
996+ if ( typeof key === 'symbol' ) {
997+ return `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
998+ }
999+ if ( enumerable === false ) {
1000+ return `[${ key } ]` ;
1001+ }
1002+ if ( keyStrRegExp . test ( key ) ) {
1003+ return ctx . stylize ( key , 'name' ) ;
1004+ }
1005+ return ctx . stylize ( strEscape ( key ) , 'string' ) ;
1006+ }
1007+
1008+ function formatNamespaceProperty ( ctx , ns , recurseTimes , key ) {
1009+ let value ;
1010+ try {
1011+ value = formatValue ( ctx , ns [ key ] , recurseTimes , true ) ;
1012+ } catch ( err ) {
1013+ if ( err instanceof ReferenceError ) {
1014+ value = ctx . stylize ( '<uninitialized>' , 'special' ) ;
1015+ } else {
1016+ throw err ;
1017+ }
1018+ }
1019+
1020+ return `${ formatKey ( ctx , key ) } : ${ value } ` ;
1021+ }
1022+
9831023function formatProperty ( ctx , value , recurseTimes , key , array ) {
984- let name , str ;
1024+ let str ;
9851025 const desc = Object . getOwnPropertyDescriptor ( value , key ) ||
9861026 { value : value [ key ] , enumerable : true } ;
9871027 if ( desc . value !== undefined ) {
@@ -1003,17 +1043,8 @@ function formatProperty(ctx, value, recurseTimes, key, array) {
10031043 if ( array === 1 ) {
10041044 return str ;
10051045 }
1006- if ( typeof key === 'symbol' ) {
1007- name = `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
1008- } else if ( desc . enumerable === false ) {
1009- name = `[${ key } ]` ;
1010- } else if ( keyStrRegExp . test ( key ) ) {
1011- name = ctx . stylize ( key , 'name' ) ;
1012- } else {
1013- name = ctx . stylize ( strEscape ( key ) , 'string' ) ;
1014- }
10151046
1016- return `${ name } : ${ str } ` ;
1047+ return `${ formatKey ( ctx , key , desc . enumerable ) } : ${ str } ` ;
10171048}
10181049
10191050function reduceToSingleString ( ctx , output , base , braces , addLn ) {
0 commit comments