@@ -312,7 +312,8 @@ function strEscape(str) {
312312
313313 let result = '' ;
314314 let last = 0 ;
315- for ( var i = 0 ; i < str . length ; i ++ ) {
315+ const lastIndex = str . length ;
316+ for ( let i = 0 ; i < lastIndex ; i ++ ) {
316317 const point = str . charCodeAt ( i ) ;
317318 if ( point === singleQuote || point === 92 || point < 32 ) {
318319 if ( last === i ) {
@@ -324,7 +325,7 @@ function strEscape(str) {
324325 }
325326 }
326327
327- if ( last !== i ) {
328+ if ( last !== lastIndex ) {
328329 result += str . slice ( last ) ;
329330 }
330331 return addQuotes ( result , singleQuote ) ;
@@ -1059,10 +1060,11 @@ function formatPrimitive(fn, value, ctx) {
10591060 if ( matches . length > 1 ) {
10601061 const indent = ' ' . repeat ( ctx . indentationLvl ) ;
10611062 let res = `${ fn ( strEscape ( matches [ 0 ] ) , 'string' ) } +\n` ;
1062- for ( var i = 1 ; i < matches . length - 1 ; i ++ ) {
1063+ const lastIndex = matches . length - 1 ;
1064+ for ( let i = 1 ; i < lastIndex ; i ++ ) {
10631065 res += `${ indent } ${ fn ( strEscape ( matches [ i ] ) , 'string' ) } +\n` ;
10641066 }
1065- res += `${ indent } ${ fn ( strEscape ( matches [ i ] ) , 'string' ) } ` ;
1067+ res += `${ indent } ${ fn ( strEscape ( matches [ lastIndex ] ) , 'string' ) } ` ;
10661068 return res ;
10671069 }
10681070 }
@@ -1185,10 +1187,10 @@ function formatTypedArray(ctx, value, recurseTimes) {
11851187 const elementFormatter = value . length > 0 && typeof value [ 0 ] === 'number' ?
11861188 formatNumber :
11871189 formatBigInt ;
1188- for ( var i = 0 ; i < maxLength ; ++ i )
1190+ for ( let i = 0 ; i < maxLength ; ++ i )
11891191 output [ i ] = elementFormatter ( ctx . stylize , value [ i ] ) ;
11901192 if ( remaining > 0 ) {
1191- output [ i ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1193+ output [ maxLength ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
11921194 }
11931195 if ( ctx . showHidden ) {
11941196 // .buffer goes last, it's not a primitive like the others.
0 commit comments