@@ -4559,12 +4559,12 @@ namespace ts {
45594559
45604560 // Determine the path to the directory containing the script relative to the root directory it is contained within
45614561 let relativeDirectory : string ;
4562- forEach ( rootDirs , rootDirectory => {
4562+ for ( const rootDirectory of rootDirs ) {
45634563 if ( containsPath ( rootDirectory , scriptPath , basePath , ignoreCase ) ) {
45644564 relativeDirectory = scriptPath . substr ( rootDirectory . length ) ;
4565- return true ;
4565+ break ;
45664566 }
4567- } ) ;
4567+ }
45684568
45694569 // Now find a path for each potential directory that is to be merged with the one containing the script
45704570 return deduplicate ( map ( rootDirs , rootDirectory => combinePaths ( rootDirectory , relativeDirectory ) ) ) ;
@@ -4600,10 +4600,10 @@ namespace ts {
46004600 if ( directoryProbablyExists ( baseDirectory , host ) ) {
46014601 // Enumerate the available files
46024602 const files = host . readDirectory ( baseDirectory , extensions , /*exclude*/ undefined , /*include*/ [ "./*" ] ) ;
4603- forEach ( files , filePath => {
4603+ for ( let filePath of files ) {
46044604 filePath = normalizePath ( filePath ) ;
46054605 if ( exclude && comparePaths ( filePath , exclude , scriptPath , ignoreCase ) === Comparison . EqualTo ) {
4606- return false ;
4606+ continue ;
46074607 }
46084608
46094609 const fileName = includeExtensions ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
@@ -4616,20 +4616,20 @@ namespace ts {
46164616 sortText : fileName
46174617 } ) ;
46184618 }
4619- } ) ;
4619+ }
46204620
46214621 // If possible, get folder completion as well
46224622 if ( host . getDirectories ) {
46234623 const directories = host . getDirectories ( baseDirectory ) ;
4624- forEach ( directories , d => {
4625- const directoryName = getBaseFileName ( normalizePath ( d ) ) ;
4624+ for ( const directory of directories ) {
4625+ const directoryName = getBaseFileName ( normalizePath ( directory ) ) ;
46264626
46274627 result . push ( {
46284628 name : directoryName ,
46294629 kind : ScriptElementKind . directory ,
46304630 sortText : directoryName
46314631 } ) ;
4632- } ) ;
4632+ }
46334633 }
46344634 }
46354635
@@ -4660,11 +4660,11 @@ namespace ts {
46604660 if ( paths . hasOwnProperty ( path ) ) {
46614661 if ( path === "*" ) {
46624662 if ( paths [ path ] ) {
4663- forEach ( paths [ path ] , pattern => {
4664- forEach ( getModulesForPathsPattern ( fragment , baseUrl , pattern , fileExtensions ) , match => {
4663+ for ( const pattern of paths [ path ] ) {
4664+ for ( const match of getModulesForPathsPattern ( fragment , baseUrl , pattern , fileExtensions ) ) {
46654665 result . push ( createCompletionEntryForModule ( match , ScriptElementKind . externalModuleName ) ) ;
4666- } ) ;
4667- } ) ;
4666+ }
4667+ }
46684668 }
46694669 }
46704670 else if ( startsWith ( path , fragment ) ) {
@@ -4683,9 +4683,9 @@ namespace ts {
46834683
46844684 getCompletionEntriesFromTypings ( host , options , scriptPath , result ) ;
46854685
4686- forEach ( enumeratePotentialNonRelativeModules ( fragment , scriptPath , options ) , moduleName => {
4686+ for ( const moduleName of enumeratePotentialNonRelativeModules ( fragment , scriptPath , options ) ) {
46874687 result . push ( createCompletionEntryForModule ( moduleName , ScriptElementKind . externalModuleName ) ) ;
4688- } ) ;
4688+ }
46894689
46904690 return result ;
46914691 }
@@ -4717,17 +4717,17 @@ namespace ts {
47174717 const result : string [ ] = [ ] ;
47184718
47194719 // Trim away prefix and suffix
4720- forEach ( matches , match => {
4720+ for ( const match of matches ) {
47214721 const normalizedMatch = normalizePath ( match ) ;
47224722 if ( ! endsWith ( normalizedMatch , normalizedSuffix ) || ! startsWith ( normalizedMatch , completePrefix ) ) {
4723- return ;
4723+ continue ;
47244724 }
47254725
47264726 const start = completePrefix . length ;
47274727 const length = normalizedMatch . length - start - normalizedSuffix . length ;
47284728
47294729 result . push ( removeFileExtension ( normalizedMatch . substr ( start , length ) ) ) ;
4730- } ) ;
4730+ }
47314731 return result ;
47324732 }
47334733
@@ -4740,15 +4740,15 @@ namespace ts {
47404740 const moduleNameFragment = isNestedModule ? fragment . substr ( 0 , fragment . lastIndexOf ( directorySeparator ) ) : undefined ;
47414741
47424742 // Get modules that the type checker picked up
4743- const ambientModules = ts . map ( program . getTypeChecker ( ) . getAmbientModules ( ) , sym => stripQuotes ( sym . name ) ) ;
4744- let nonRelativeModules = ts . filter ( ambientModules , moduleName => startsWith ( moduleName , fragment ) ) ;
4743+ const ambientModules = map ( program . getTypeChecker ( ) . getAmbientModules ( ) , sym => stripQuotes ( sym . name ) ) ;
4744+ let nonRelativeModules = filter ( ambientModules , moduleName => startsWith ( moduleName , fragment ) ) ;
47454745
47464746 // Nested modules of the form "module-name/sub" need to be adjusted to only return the string
47474747 // after the last '/' that appears in the fragment because that's where the replacement span
47484748 // starts
47494749 if ( isNestedModule ) {
47504750 const moduleNameWithSeperator = ensureTrailingDirectorySeparator ( moduleNameFragment ) ;
4751- nonRelativeModules = ts . map ( nonRelativeModules , moduleName => {
4751+ nonRelativeModules = map ( nonRelativeModules , moduleName => {
47524752 if ( startsWith ( fragment , moduleNameWithSeperator ) ) {
47534753 return moduleName . substr ( moduleNameWithSeperator . length ) ;
47544754 }
@@ -4758,20 +4758,20 @@ namespace ts {
47584758
47594759
47604760 if ( ! options . moduleResolution || options . moduleResolution === ModuleResolutionKind . NodeJs ) {
4761- forEach ( enumerateNodeModulesVisibleToScript ( host , scriptPath ) , visibleModule => {
4761+ for ( const visibleModule of enumerateNodeModulesVisibleToScript ( host , scriptPath ) ) {
47624762 if ( ! isNestedModule ) {
47634763 nonRelativeModules . push ( visibleModule . moduleName ) ;
47644764 }
47654765 else if ( startsWith ( visibleModule . moduleName , moduleNameFragment ) ) {
47664766 const nestedFiles = host . readDirectory ( visibleModule . moduleDir , supportedTypeScriptExtensions , /*exclude*/ undefined , /*include*/ [ "./*" ] ) ;
47674767
4768- forEach ( nestedFiles , ( f ) => {
4768+ for ( let f of nestedFiles ) {
47694769 f = normalizePath ( f ) ;
47704770 const nestedModule = removeFileExtension ( getBaseFileName ( f ) ) ;
47714771 nonRelativeModules . push ( nestedModule ) ;
4772- } ) ;
4772+ }
47734773 }
4774- } ) ;
4774+ }
47754775 }
47764776
47774777 return deduplicate ( nonRelativeModules ) ;
@@ -4827,9 +4827,9 @@ namespace ts {
48274827 function getCompletionEntriesFromTypings ( host : LanguageServiceHost , options : CompilerOptions , scriptPath : string , result : ImportCompletionEntry [ ] = [ ] ) : ImportCompletionEntry [ ] {
48284828 // Check for typings specified in compiler options
48294829 if ( options . types ) {
4830- forEach ( options . types , moduleName => {
4830+ for ( const moduleName of options . types ) {
48314831 result . push ( createCompletionEntryForModule ( moduleName , ScriptElementKind . externalModuleName ) ) ;
4832- } ) ;
4832+ }
48334833 }
48344834 else if ( host . getDirectories && options . typeRoots ) {
48354835 const absoluteRoots = map ( options . typeRoots , rootDirectory => {
@@ -4840,26 +4840,28 @@ namespace ts {
48404840 const basePath = options . project || host . getCurrentDirectory ( ) ;
48414841 return normalizePath ( combinePaths ( basePath , rootDirectory ) ) ;
48424842 } ) ;
4843- forEach ( absoluteRoots , absoluteRoot => getCompletionEntriesFromDirectories ( host , options , absoluteRoot , result ) ) ;
4843+ for ( const absoluteRoot of absoluteRoots ) {
4844+ getCompletionEntriesFromDirectories ( host , options , absoluteRoot , result ) ;
4845+ }
48444846 }
48454847
48464848 if ( host . getDirectories ) {
48474849 // Also get all @types typings installed in visible node_modules directories
4848- forEach ( findPackageJsons ( scriptPath ) , package => {
4850+ for ( const package of findPackageJsons ( scriptPath ) ) {
48494851 const typesDir = combinePaths ( getDirectoryPath ( package ) , "node_modules/@types" ) ;
48504852 getCompletionEntriesFromDirectories ( host , options , typesDir , result ) ;
4851- } ) ;
4853+ }
48524854 }
48534855
48544856 return result ;
48554857 }
48564858
48574859 function getCompletionEntriesFromDirectories ( host : LanguageServiceHost , options : CompilerOptions , directory : string , result : ImportCompletionEntry [ ] ) {
48584860 if ( host . getDirectories && directoryProbablyExists ( directory , host ) ) {
4859- forEach ( host . getDirectories ( directory ) , typeDirectory => {
4861+ for ( let typeDirectory of host . getDirectories ( directory ) ) {
48604862 typeDirectory = normalizePath ( typeDirectory ) ;
48614863 result . push ( createCompletionEntryForModule ( getBaseFileName ( typeDirectory ) , ScriptElementKind . externalModuleName ) ) ;
4862- } ) ;
4864+ }
48634865 }
48644866 }
48654867
@@ -4889,7 +4891,7 @@ namespace ts {
48894891
48904892 function enumerateNodeModulesVisibleToScript ( host : LanguageServiceHost , scriptPath : string ) {
48914893 const result : VisibleModuleInfo [ ] = [ ] ;
4892- findPackageJsons ( scriptPath ) . forEach ( ( packageJson ) => {
4894+ for ( const packageJson of findPackageJsons ( scriptPath ) ) {
48934895 const package = tryReadingPackageJson ( packageJson ) ;
48944896 if ( ! package ) {
48954897 return ;
@@ -4905,14 +4907,14 @@ namespace ts {
49054907 addPotentialPackageNames ( package . devDependencies , foundModuleNames ) ;
49064908 }
49074909
4908- forEach ( foundModuleNames , ( moduleName ) => {
4910+ for ( const moduleName of foundModuleNames ) {
49094911 const moduleDir = combinePaths ( nodeModulesDir , moduleName ) ;
49104912 result . push ( {
49114913 moduleName,
49124914 moduleDir
49134915 } ) ;
4914- } ) ;
4915- } ) ;
4916+ }
4917+ }
49164918
49174919 return result ;
49184920
0 commit comments