@@ -416,7 +416,7 @@ function getPrefix(constructor, tag) {
416416 return '' ;
417417}
418418
419- function formatValue ( ctx , value , recurseTimes , ln ) {
419+ function formatValue ( ctx , value , recurseTimes ) {
420420 // Primitive types cannot have properties
421421 if ( typeof value !== 'object' && typeof value !== 'function' ) {
422422 return formatPrimitive ( ctx . stylize , value , ctx ) ;
@@ -582,7 +582,7 @@ function formatValue(ctx, value, recurseTimes, ln) {
582582 return ctx . stylize ( dateToISOString . call ( value ) , 'date' ) ;
583583 }
584584 // Make dates with properties first say the date
585- base = ` ${ dateToISOString . call ( value ) } ` ;
585+ base = dateToISOString . call ( value ) ;
586586 } else if ( isError ( value ) ) {
587587 // Make error with message first say the error
588588 base = formatError ( value ) ;
@@ -683,7 +683,7 @@ function formatValue(ctx, value, recurseTimes, ln) {
683683 }
684684 ctx . seen . pop ( ) ;
685685
686- return reduceToSingleString ( ctx , output , base , braces , ln ) ;
686+ return reduceToSingleString ( ctx , output , base , braces ) ;
687687}
688688
689689function formatNumber ( fn , value ) {
@@ -758,7 +758,23 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
758758 const len = keys . length ;
759759 const output = new Array ( len ) ;
760760 for ( var i = 0 ; i < len ; i ++ ) {
761- output [ i ] = formatNamespaceProperty ( ctx , value , recurseTimes , keys [ i ] ) ;
761+ try {
762+ output [ i ] = formatProperty ( ctx , value , recurseTimes , keys [ i ] , 0 ) ;
763+ } catch ( err ) {
764+ if ( ! ( err instanceof ReferenceError ) ) {
765+ throw err ;
766+ }
767+ // Use the existing functionality. This makes sure the indentation and
768+ // line breaks are always correct. Otherwise it is very difficult to keep
769+ // this aligned, even though this is a hacky way of dealing with this.
770+ const tmp = { [ keys [ i ] ] : '' } ;
771+ output [ i ] = formatProperty ( ctx , tmp , recurseTimes , keys [ i ] , 0 ) ;
772+ const pos = output [ i ] . lastIndexOf ( ' ' ) ;
773+ // We have to find the last whitespace and have to replace that value as
774+ // it will be visualized as a regular string.
775+ output [ i ] = output [ i ] . slice ( 0 , pos + 1 ) +
776+ ctx . stylize ( '<uninitialized>' , 'special' ) ;
777+ }
762778 }
763779 return output ;
764780}
@@ -986,42 +1002,21 @@ function formatPromise(ctx, value, recurseTimes, keys) {
9861002 return output ;
9871003}
9881004
989- function formatKey ( ctx , key , enumerable ) {
990- if ( typeof key === 'symbol' ) {
991- return `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
992- }
993- if ( enumerable === false ) {
994- return `[${ key } ]` ;
995- }
996- if ( keyStrRegExp . test ( key ) ) {
997- return ctx . stylize ( key , 'name' ) ;
998- }
999- return ctx . stylize ( strEscape ( key ) , 'string' ) ;
1000- }
1001-
1002- function formatNamespaceProperty ( ctx , ns , recurseTimes , key ) {
1003- let value ;
1004- try {
1005- value = formatValue ( ctx , ns [ key ] , recurseTimes , true ) ;
1006- } catch ( err ) {
1007- if ( err instanceof ReferenceError ) {
1008- value = ctx . stylize ( '<uninitialized>' , 'special' ) ;
1009- } else {
1010- throw err ;
1011- }
1012- }
1013-
1014- return `${ formatKey ( ctx , key ) } : ${ value } ` ;
1015- }
1016-
10171005function formatProperty ( ctx , value , recurseTimes , key , array ) {
1018- let str ;
1006+ let name , str ;
1007+ let extra = ' ' ;
10191008 const desc = Object . getOwnPropertyDescriptor ( value , key ) ||
10201009 { value : value [ key ] , enumerable : true } ;
10211010 if ( desc . value !== undefined ) {
10221011 const diff = array !== 0 || ctx . compact === false ? 2 : 3 ;
10231012 ctx . indentationLvl += diff ;
1024- str = formatValue ( ctx , desc . value , recurseTimes , array === 0 ) ;
1013+ str = formatValue ( ctx , desc . value , recurseTimes ) ;
1014+ if ( diff === 3 ) {
1015+ const len = ctx . colors ? removeColors ( str ) . length : str . length ;
1016+ if ( ctx . breakLength < len ) {
1017+ extra = `\n${ ' ' . repeat ( ctx . indentationLvl ) } ` ;
1018+ }
1019+ }
10251020 ctx . indentationLvl -= diff ;
10261021 } else if ( desc . get !== undefined ) {
10271022 if ( desc . set !== undefined ) {
@@ -1037,11 +1032,19 @@ function formatProperty(ctx, value, recurseTimes, key, array) {
10371032 if ( array === 1 ) {
10381033 return str ;
10391034 }
1040-
1041- return `${ formatKey ( ctx , key , desc . enumerable ) } : ${ str } ` ;
1035+ if ( typeof key === 'symbol' ) {
1036+ name = `[${ ctx . stylize ( key . toString ( ) , 'symbol' ) } ]` ;
1037+ } else if ( desc . enumerable === false ) {
1038+ name = `[${ key } ]` ;
1039+ } else if ( keyStrRegExp . test ( key ) ) {
1040+ name = ctx . stylize ( key , 'name' ) ;
1041+ } else {
1042+ name = ctx . stylize ( strEscape ( key ) , 'string' ) ;
1043+ }
1044+ return `${ name } :${ extra } ${ str } ` ;
10421045}
10431046
1044- function reduceToSingleString ( ctx , output , base , braces , addLn ) {
1047+ function reduceToSingleString ( ctx , output , base , braces ) {
10451048 const breakLength = ctx . breakLength ;
10461049 let i = 0 ;
10471050 if ( ctx . compact === false ) {
@@ -1070,11 +1073,10 @@ function reduceToSingleString(ctx, output, base, braces, addLn) {
10701073 // we need to force the first item to be on the next line or the
10711074 // items will not line up correctly.
10721075 const indentation = ' ' . repeat ( ctx . indentationLvl ) ;
1073- const extraLn = addLn === true ? `\n${ indentation } ` : '' ;
10741076 const ln = base === '' && braces [ 0 ] . length === 1 ?
1075- ' ' : `${ base ? ` ${ base } ` : base } \n${ indentation } ` ;
1077+ ' ' : `${ base ? ` ${ base } ` : '' } \n${ indentation } ` ;
10761078 const str = join ( output , `,\n${ indentation } ` ) ;
1077- return `${ extraLn } ${ braces [ 0 ] } ${ ln } ${ str } ${ braces [ 1 ] } ` ;
1079+ return `${ braces [ 0 ] } ${ ln } ${ str } ${ braces [ 1 ] } ` ;
10781080}
10791081
10801082function isBoolean ( arg ) {
0 commit comments