@@ -629,6 +629,9 @@ function formatValue(ctx, value, recurseTimes, ln) {
629
629
} else {
630
630
extra = '[items unknown]' ;
631
631
}
632
+ } else if ( types . isModuleNamespaceObject ( value ) ) {
633
+ braces [ 0 ] = `[${ tag } ] {` ;
634
+ formatter = formatNamespaceObject ;
632
635
} else {
633
636
// Check boxed primitives other than string with valueOf()
634
637
// NOTE: `Date` has to be checked first!
@@ -757,6 +760,15 @@ function formatObject(ctx, value, recurseTimes, keys) {
757
760
return output ;
758
761
}
759
762
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
+
760
772
// The array is sparse and/or has extra keys
761
773
function formatSpecialArray ( ctx , value , recurseTimes , keys , maxLength , valLen ) {
762
774
const output = [ ] ;
@@ -980,8 +992,36 @@ function formatPromise(ctx, value, recurseTimes, keys) {
980
992
return output ;
981
993
}
982
994
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
+
983
1023
function formatProperty ( ctx , value , recurseTimes , key , array ) {
984
- let name , str ;
1024
+ let str ;
985
1025
const desc = Object . getOwnPropertyDescriptor ( value , key ) ||
986
1026
{ value : value [ key ] , enumerable : true } ;
987
1027
if ( desc . value !== undefined ) {
@@ -1003,17 +1043,8 @@ function formatProperty(ctx, value, recurseTimes, key, array) {
1003
1043
if ( array === 1 ) {
1004
1044
return str ;
1005
1045
}
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
- }
1015
1046
1016
- return `${ name } : ${ str } ` ;
1047
+ return `${ formatKey ( ctx , key , desc . enumerable ) } : ${ str } ` ;
1017
1048
}
1018
1049
1019
1050
function reduceToSingleString ( ctx , output , base , braces , addLn ) {
0 commit comments