@@ -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 ) ;
@@ -1061,10 +1062,11 @@ function formatPrimitive(fn, value, ctx) {
10611062 if ( matches . length > 1 ) {
10621063 const indent = ' ' . repeat ( ctx . indentationLvl ) ;
10631064 let res = `${ fn ( strEscape ( matches [ 0 ] ) , 'string' ) } +\n` ;
1064- for ( var i = 1 ; i < matches . length - 1 ; i ++ ) {
1065+ const lastIndex = matches . length - 1 ;
1066+ for ( let i = 1 ; i < lastIndex ; i ++ ) {
10651067 res += `${ indent } ${ fn ( strEscape ( matches [ i ] ) , 'string' ) } +\n` ;
10661068 }
1067- res += `${ indent } ${ fn ( strEscape ( matches [ i ] ) , 'string' ) } ` ;
1069+ res += `${ indent } ${ fn ( strEscape ( matches [ lastIndex ] ) , 'string' ) } ` ;
10681070 return res ;
10691071 }
10701072 }
@@ -1187,10 +1189,10 @@ function formatTypedArray(ctx, value, recurseTimes) {
11871189 const elementFormatter = value . length > 0 && typeof value [ 0 ] === 'number' ?
11881190 formatNumber :
11891191 formatBigInt ;
1190- for ( var i = 0 ; i < maxLength ; ++ i )
1192+ for ( let i = 0 ; i < maxLength ; ++ i )
11911193 output [ i ] = elementFormatter ( ctx . stylize , value [ i ] ) ;
11921194 if ( remaining > 0 ) {
1193- output [ i ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1195+ output [ maxLength ] = `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
11941196 }
11951197 if ( ctx . showHidden ) {
11961198 // .buffer goes last, it's not a primitive like the others.
0 commit comments