@@ -46,6 +46,7 @@ const {
4646 ArrayPrototypeConcat,
4747 ArrayPrototypeFilter,
4848 ArrayPrototypeFindIndex,
49+ ArrayPrototypeForEach,
4950 ArrayPrototypeIncludes,
5051 ArrayPrototypeJoin,
5152 ArrayPrototypeMap,
@@ -663,7 +664,7 @@ function REPLServer(prompt,
663664let matched = false ;
664665
665666errStack = '' ;
666- for ( const line of lines ) {
667+ ArrayPrototypeForEach ( lines , ( line ) => {
667668if ( ! matched &&
668669RegExpPrototypeTest ( / ^ \[ ? ( [ A - Z ] [ a - z 0 - 9 _ ] * ) * E r r o r / , line ) ) {
669670errStack += writer . options . breakLength >= line . length ?
@@ -673,7 +674,7 @@ function REPLServer(prompt,
673674} else {
674675errStack += line ;
675676}
676- }
677+ } ) ;
677678if ( ! matched ) {
678679const ln = lines . length === 1 ? ' ' : ':\n' ;
679680errStack = `Uncaught${ ln } ${ errStack } ` ;
@@ -754,9 +755,7 @@ function REPLServer(prompt,
754755const prioritizedSigintQueue = new SafeSet ( ) ;
755756self . on ( 'SIGINT' , function onSigInt ( ) {
756757if ( prioritizedSigintQueue . size > 0 ) {
757- for ( const task of prioritizedSigintQueue ) {
758- task ( ) ;
759- }
758+ ArrayPrototypeForEach ( prioritizedSigintQueue , ( task ) => task ( ) ) ;
760759return ;
761760}
762761
@@ -1010,13 +1009,13 @@ REPLServer.prototype.createContext = function() {
10101009} , ( ) => {
10111010context = vm . createContext ( ) ;
10121011} ) ;
1013- for ( const name of ObjectGetOwnPropertyNames ( global ) ) {
1012+ ArrayPrototypeForEach ( ObjectGetOwnPropertyNames ( global ) , ( name ) => {
10141013// Only set properties that do not already exist as a global builtin.
10151014if ( ! globalBuiltins . has ( name ) ) {
10161015ObjectDefineProperty ( context , name ,
10171016ObjectGetOwnPropertyDescriptor ( global , name ) ) ;
10181017}
1019- }
1018+ } ) ;
10201019context . global = context ;
10211020const _console = new Console ( this . output ) ;
10221021ObjectDefineProperty ( context , 'console' , {
@@ -1231,7 +1230,7 @@ function complete(line, callback) {
12311230paths = ArrayPrototypeConcat ( module . paths , CJSModule . globalPaths ) ;
12321231}
12331232
1234- for ( let dir of paths ) {
1233+ ArrayPrototypeForEach ( paths , ( dir ) => {
12351234dir = path . resolve ( dir , subdir ) ;
12361235const dirents = gracefulReaddir ( dir , { withFileTypes : true } ) || [ ] ;
12371236for ( const dirent of dirents ) {
@@ -1259,7 +1258,7 @@ function complete(line, callback) {
12591258}
12601259}
12611260}
1262- }
1261+ } ) ;
12631262if ( group . length ) {
12641263ArrayPrototypePush ( completionGroups , group ) ;
12651264}
@@ -1269,7 +1268,7 @@ function complete(line, callback) {
12691268}
12701269} else if ( RegExpPrototypeTest ( fsAutoCompleteRE , line ) &&
12711270this . allowBlockingCompletions ) {
1272- [ completionGroups , completeOn ] = completeFSFunctions ( line ) ;
1271+ ( { 0 : completionGroups , 1 : completeOn } = completeFSFunctions ( line ) ) ;
12731272// Handle variable member lookup.
12741273// We support simple chained expressions like the following (no function
12751274// calls, etc.). That is for simplicity and also because we *eval* that
@@ -1282,7 +1281,7 @@ function complete(line, callback) {
12821281// foo.<|> # completions for 'foo' with filter ''
12831282} else if ( line . length === 0 ||
12841283RegExpPrototypeTest ( / \w | \. | \$ / , line [ line . length - 1 ] ) ) {
1285- const [ match ] = RegExpPrototypeExec ( simpleExpressionRE , line ) || [ '' ] ;
1284+ const { 0 : match } = RegExpPrototypeExec ( simpleExpressionRE , line ) || [ '' ] ;
12861285if ( line . length !== 0 && ! match ) {
12871286completionGroupsLoaded ( ) ;
12881287return ;
@@ -1352,11 +1351,11 @@ function complete(line, callback) {
13521351
13531352if ( memberGroups . length ) {
13541353expr += chaining ;
1355- for ( const group of memberGroups ) {
1354+ ArrayPrototypeForEach ( memberGroups , ( group ) => {
13561355ArrayPrototypePush ( completionGroups ,
13571356ArrayPrototypeMap ( group ,
13581357( member ) => `${ expr } ${ member } ` ) ) ;
1359- }
1358+ } ) ;
13601359if ( filter ) {
13611360filter = `${ expr } ${ filter } ` ;
13621361}
@@ -1375,37 +1374,38 @@ function complete(line, callback) {
13751374// Filter, sort (within each group), uniq and merge the completion groups.
13761375if ( completionGroups . length && filter ) {
13771376const newCompletionGroups = [ ] ;
1378- for ( const group of completionGroups ) {
1377+ ArrayPrototypeForEach ( completionGroups , ( group ) => {
13791378const filteredGroup = ArrayPrototypeFilter (
13801379group ,
13811380( str ) => StringPrototypeStartsWith ( str , filter )
13821381) ;
13831382if ( filteredGroup . length ) {
13841383ArrayPrototypePush ( newCompletionGroups , filteredGroup ) ;
13851384}
1386- }
1385+ } ) ;
13871386completionGroups = newCompletionGroups ;
13881387}
13891388
13901389const completions = [ ] ;
13911390// Unique completions across all groups.
1392- const uniqueSet = new SafeSet ( [ '' ] ) ;
1391+ const uniqueSet = new SafeSet ( ) ;
1392+ uniqueSet . add ( '' ) ;
13931393// Completion group 0 is the "closest" (least far up the inheritance
13941394// chain) so we put its completions last: to be closest in the REPL.
1395- for ( const group of completionGroups ) {
1395+ ArrayPrototypeForEach ( completionGroups , ( group ) => {
13961396ArrayPrototypeSort ( group , ( a , b ) => ( b > a ? 1 : - 1 ) ) ;
13971397const setSize = uniqueSet . size ;
1398- for ( const entry of group ) {
1398+ ArrayPrototypeForEach ( group , ( entry ) => {
13991399if ( ! uniqueSet . has ( entry ) ) {
14001400ArrayPrototypeUnshift ( completions , entry ) ;
14011401uniqueSet . add ( entry ) ;
14021402}
1403- }
1403+ } ) ;
14041404// Add a separator between groups.
14051405if ( uniqueSet . size !== setSize ) {
14061406ArrayPrototypeUnshift ( completions , '' ) ;
14071407}
1408- }
1408+ } ) ;
14091409
14101410// Remove obsolete group entry, if present.
14111411if ( completions [ 0 ] === '' ) {
@@ -1569,14 +1569,13 @@ function defineDefaultCommands(repl) {
15691569const longestNameLength = MathMax (
15701570 ...ArrayPrototypeMap ( names , ( name ) => name . length )
15711571) ;
1572- for ( let n = 0 ; n < names . length ; n ++ ) {
1573- const name = names [ n ] ;
1572+ ArrayPrototypeForEach ( names , ( name ) => {
15741573const cmd = this . commands [ name ] ;
15751574const spaces =
15761575StringPrototypeRepeat ( ' ' , longestNameLength - name . length + 3 ) ;
15771576const line = `.${ name } ${ cmd . help ? spaces + cmd . help : '' } \n` ;
15781577this . output . write ( line ) ;
1579- }
1578+ } ) ;
15801579this . output . write ( '\nPress Ctrl+C to abort current expression, ' +
15811580'Ctrl+D to exit the REPL\n' ) ;
15821581this . displayPrompt ( ) ;
0 commit comments