@@ -638,6 +638,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
638
638
} else {
639
639
extra = '[items unknown]' ;
640
640
}
641
+ } else if ( types . isModuleNamespaceObject ( value ) ) {
642
+ braces [ 0 ] = `[${ tag } ] {` ;
643
+ formatter = formatNamespaceObject ;
641
644
} else {
642
645
// Check boxed primitives other than string with valueOf()
643
646
// NOTE: `Date` has to be checked first!
@@ -766,6 +769,15 @@ function formatObject(ctx, value, recurseTimes, keys) {
766
769
return output ;
767
770
}
768
771
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
+
769
781
// The array is sparse and/or has extra keys
770
782
function formatSpecialArray ( ctx , value , recurseTimes , keys , maxLength , valLen ) {
771
783
const output = [ ] ;
@@ -993,8 +1005,36 @@ function formatPromise(ctx, value, recurseTimes, keys) {
993
1005
return output ;
994
1006
}
995
1007
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
+
996
1036
function formatProperty ( ctx , value , recurseTimes , key , array ) {
997
- let name , str ;
1037
+ let str ;
998
1038
const desc = Object . getOwnPropertyDescriptor ( value , key ) ||
999
1039
{ value : value [ key ] , enumerable : true } ;
1000
1040
if ( desc . value !== undefined ) {
@@ -1016,17 +1056,8 @@ function formatProperty(ctx, value, recurseTimes, key, array) {
1016
1056
if ( array === 1 ) {
1017
1057
return str ;
1018
1058
}
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
- }
1028
1059
1029
- return `${ name } : ${ str } ` ;
1060
+ return `${ formatKey ( ctx , key , desc . enumerable ) } : ${ str } ` ;
1030
1061
}
1031
1062
1032
1063
function reduceToSingleString ( ctx , output , base , braces , addLn ) {
0 commit comments