@@ -822,12 +822,11 @@ function formatPrimitive(fn, value, ctx) {
822822 if ( ctx . compact === false &&
823823 ctx . indentationLvl + value . length > ctx . breakLength &&
824824 value . length > kMinLineLength ) {
825- // eslint-disable-next-line max-len
826- const minLineLength = Math . max ( ctx . breakLength - ctx . indentationLvl , kMinLineLength ) ;
827- // eslint-disable-next-line max-len
828- const averageLineLength = Math . ceil ( value . length / Math . ceil ( value . length / minLineLength ) ) ;
825+ const rawMaxLineLength = ctx . breakLength - ctx . indentationLvl ;
826+ const maxLineLength = Math . max ( rawMaxLineLength , kMinLineLength ) ;
827+ const lines = Math . ceil ( value . length / maxLineLength ) ;
828+ const averageLineLength = Math . ceil ( value . length / lines ) ;
829829 const divisor = Math . max ( averageLineLength , kMinLineLength ) ;
830- let res = '' ;
831830 if ( readableRegExps [ divisor ] === undefined ) {
832831 // Build a new RegExp that naturally breaks text into multiple lines.
833832 //
@@ -843,7 +842,7 @@ function formatPrimitive(fn, value, ctx) {
843842 const matches = value . match ( readableRegExps [ divisor ] ) ;
844843 if ( matches . length > 1 ) {
845844 const indent = ' ' . repeat ( ctx . indentationLvl ) ;
846- res + = `${ fn ( strEscape ( matches [ 0 ] ) , 'string' ) } +\n` ;
845+ let res = `${ fn ( strEscape ( matches [ 0 ] ) , 'string' ) } +\n` ;
847846 for ( var i = 1 ; i < matches . length - 1 ; i ++ ) {
848847 res += `${ indent } ${ fn ( strEscape ( matches [ i ] ) , 'string' ) } +\n` ;
849848 }
0 commit comments