@@ -4559,12 +4559,12 @@ namespace ts {
4559
4559
4560
4560
// Determine the path to the directory containing the script relative to the root directory it is contained within
4561
4561
let relativeDirectory : string ;
4562
- forEach ( rootDirs , rootDirectory => {
4562
+ for ( const rootDirectory of rootDirs ) {
4563
4563
if ( containsPath ( rootDirectory , scriptPath , basePath , ignoreCase ) ) {
4564
4564
relativeDirectory = scriptPath . substr ( rootDirectory . length ) ;
4565
- return true ;
4565
+ break ;
4566
4566
}
4567
- } ) ;
4567
+ }
4568
4568
4569
4569
// Now find a path for each potential directory that is to be merged with the one containing the script
4570
4570
return deduplicate ( map ( rootDirs , rootDirectory => combinePaths ( rootDirectory , relativeDirectory ) ) ) ;
@@ -4600,10 +4600,10 @@ namespace ts {
4600
4600
if ( directoryProbablyExists ( baseDirectory , host ) ) {
4601
4601
// Enumerate the available files
4602
4602
const files = host . readDirectory ( baseDirectory , extensions , /*exclude*/ undefined , /*include*/ [ "./*" ] ) ;
4603
- forEach ( files , filePath => {
4603
+ for ( let filePath of files ) {
4604
4604
filePath = normalizePath ( filePath ) ;
4605
4605
if ( exclude && comparePaths ( filePath , exclude , scriptPath , ignoreCase ) === Comparison . EqualTo ) {
4606
- return false ;
4606
+ continue ;
4607
4607
}
4608
4608
4609
4609
const fileName = includeExtensions ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
@@ -4616,20 +4616,20 @@ namespace ts {
4616
4616
sortText : fileName
4617
4617
} ) ;
4618
4618
}
4619
- } ) ;
4619
+ }
4620
4620
4621
4621
// If possible, get folder completion as well
4622
4622
if ( host . getDirectories ) {
4623
4623
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 ) ) ;
4626
4626
4627
4627
result . push ( {
4628
4628
name : directoryName ,
4629
4629
kind : ScriptElementKind . directory ,
4630
4630
sortText : directoryName
4631
4631
} ) ;
4632
- } ) ;
4632
+ }
4633
4633
}
4634
4634
}
4635
4635
@@ -4660,11 +4660,11 @@ namespace ts {
4660
4660
if ( paths . hasOwnProperty ( path ) ) {
4661
4661
if ( path === "*" ) {
4662
4662
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 ) ) {
4665
4665
result . push ( createCompletionEntryForModule ( match , ScriptElementKind . externalModuleName ) ) ;
4666
- } ) ;
4667
- } ) ;
4666
+ }
4667
+ }
4668
4668
}
4669
4669
}
4670
4670
else if ( startsWith ( path , fragment ) ) {
@@ -4683,9 +4683,9 @@ namespace ts {
4683
4683
4684
4684
getCompletionEntriesFromTypings ( host , options , scriptPath , result ) ;
4685
4685
4686
- forEach ( enumeratePotentialNonRelativeModules ( fragment , scriptPath , options ) , moduleName => {
4686
+ for ( const moduleName of enumeratePotentialNonRelativeModules ( fragment , scriptPath , options ) ) {
4687
4687
result . push ( createCompletionEntryForModule ( moduleName , ScriptElementKind . externalModuleName ) ) ;
4688
- } ) ;
4688
+ }
4689
4689
4690
4690
return result ;
4691
4691
}
@@ -4717,17 +4717,17 @@ namespace ts {
4717
4717
const result : string [ ] = [ ] ;
4718
4718
4719
4719
// Trim away prefix and suffix
4720
- forEach ( matches , match => {
4720
+ for ( const match of matches ) {
4721
4721
const normalizedMatch = normalizePath ( match ) ;
4722
4722
if ( ! endsWith ( normalizedMatch , normalizedSuffix ) || ! startsWith ( normalizedMatch , completePrefix ) ) {
4723
- return ;
4723
+ continue ;
4724
4724
}
4725
4725
4726
4726
const start = completePrefix . length ;
4727
4727
const length = normalizedMatch . length - start - normalizedSuffix . length ;
4728
4728
4729
4729
result . push ( removeFileExtension ( normalizedMatch . substr ( start , length ) ) ) ;
4730
- } ) ;
4730
+ }
4731
4731
return result ;
4732
4732
}
4733
4733
@@ -4740,15 +4740,15 @@ namespace ts {
4740
4740
const moduleNameFragment = isNestedModule ? fragment . substr ( 0 , fragment . lastIndexOf ( directorySeparator ) ) : undefined ;
4741
4741
4742
4742
// 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 ) ) ;
4745
4745
4746
4746
// Nested modules of the form "module-name/sub" need to be adjusted to only return the string
4747
4747
// after the last '/' that appears in the fragment because that's where the replacement span
4748
4748
// starts
4749
4749
if ( isNestedModule ) {
4750
4750
const moduleNameWithSeperator = ensureTrailingDirectorySeparator ( moduleNameFragment ) ;
4751
- nonRelativeModules = ts . map ( nonRelativeModules , moduleName => {
4751
+ nonRelativeModules = map ( nonRelativeModules , moduleName => {
4752
4752
if ( startsWith ( fragment , moduleNameWithSeperator ) ) {
4753
4753
return moduleName . substr ( moduleNameWithSeperator . length ) ;
4754
4754
}
@@ -4758,20 +4758,20 @@ namespace ts {
4758
4758
4759
4759
4760
4760
if ( ! options . moduleResolution || options . moduleResolution === ModuleResolutionKind . NodeJs ) {
4761
- forEach ( enumerateNodeModulesVisibleToScript ( host , scriptPath ) , visibleModule => {
4761
+ for ( const visibleModule of enumerateNodeModulesVisibleToScript ( host , scriptPath ) ) {
4762
4762
if ( ! isNestedModule ) {
4763
4763
nonRelativeModules . push ( visibleModule . moduleName ) ;
4764
4764
}
4765
4765
else if ( startsWith ( visibleModule . moduleName , moduleNameFragment ) ) {
4766
4766
const nestedFiles = host . readDirectory ( visibleModule . moduleDir , supportedTypeScriptExtensions , /*exclude*/ undefined , /*include*/ [ "./*" ] ) ;
4767
4767
4768
- forEach ( nestedFiles , ( f ) => {
4768
+ for ( let f of nestedFiles ) {
4769
4769
f = normalizePath ( f ) ;
4770
4770
const nestedModule = removeFileExtension ( getBaseFileName ( f ) ) ;
4771
4771
nonRelativeModules . push ( nestedModule ) ;
4772
- } ) ;
4772
+ }
4773
4773
}
4774
- } ) ;
4774
+ }
4775
4775
}
4776
4776
4777
4777
return deduplicate ( nonRelativeModules ) ;
@@ -4827,9 +4827,9 @@ namespace ts {
4827
4827
function getCompletionEntriesFromTypings ( host : LanguageServiceHost , options : CompilerOptions , scriptPath : string , result : ImportCompletionEntry [ ] = [ ] ) : ImportCompletionEntry [ ] {
4828
4828
// Check for typings specified in compiler options
4829
4829
if ( options . types ) {
4830
- forEach ( options . types , moduleName => {
4830
+ for ( const moduleName of options . types ) {
4831
4831
result . push ( createCompletionEntryForModule ( moduleName , ScriptElementKind . externalModuleName ) ) ;
4832
- } ) ;
4832
+ }
4833
4833
}
4834
4834
else if ( host . getDirectories && options . typeRoots ) {
4835
4835
const absoluteRoots = map ( options . typeRoots , rootDirectory => {
@@ -4840,26 +4840,28 @@ namespace ts {
4840
4840
const basePath = options . project || host . getCurrentDirectory ( ) ;
4841
4841
return normalizePath ( combinePaths ( basePath , rootDirectory ) ) ;
4842
4842
} ) ;
4843
- forEach ( absoluteRoots , absoluteRoot => getCompletionEntriesFromDirectories ( host , options , absoluteRoot , result ) ) ;
4843
+ for ( const absoluteRoot of absoluteRoots ) {
4844
+ getCompletionEntriesFromDirectories ( host , options , absoluteRoot , result ) ;
4845
+ }
4844
4846
}
4845
4847
4846
4848
if ( host . getDirectories ) {
4847
4849
// Also get all @types typings installed in visible node_modules directories
4848
- forEach ( findPackageJsons ( scriptPath ) , package => {
4850
+ for ( const package of findPackageJsons ( scriptPath ) ) {
4849
4851
const typesDir = combinePaths ( getDirectoryPath ( package ) , "node_modules/@types" ) ;
4850
4852
getCompletionEntriesFromDirectories ( host , options , typesDir , result ) ;
4851
- } ) ;
4853
+ }
4852
4854
}
4853
4855
4854
4856
return result ;
4855
4857
}
4856
4858
4857
4859
function getCompletionEntriesFromDirectories ( host : LanguageServiceHost , options : CompilerOptions , directory : string , result : ImportCompletionEntry [ ] ) {
4858
4860
if ( host . getDirectories && directoryProbablyExists ( directory , host ) ) {
4859
- forEach ( host . getDirectories ( directory ) , typeDirectory => {
4861
+ for ( let typeDirectory of host . getDirectories ( directory ) ) {
4860
4862
typeDirectory = normalizePath ( typeDirectory ) ;
4861
4863
result . push ( createCompletionEntryForModule ( getBaseFileName ( typeDirectory ) , ScriptElementKind . externalModuleName ) ) ;
4862
- } ) ;
4864
+ }
4863
4865
}
4864
4866
}
4865
4867
@@ -4889,7 +4891,7 @@ namespace ts {
4889
4891
4890
4892
function enumerateNodeModulesVisibleToScript ( host : LanguageServiceHost , scriptPath : string ) {
4891
4893
const result : VisibleModuleInfo [ ] = [ ] ;
4892
- findPackageJsons ( scriptPath ) . forEach ( ( packageJson ) => {
4894
+ for ( const packageJson of findPackageJsons ( scriptPath ) ) {
4893
4895
const package = tryReadingPackageJson ( packageJson ) ;
4894
4896
if ( ! package ) {
4895
4897
return ;
@@ -4905,14 +4907,14 @@ namespace ts {
4905
4907
addPotentialPackageNames ( package . devDependencies , foundModuleNames ) ;
4906
4908
}
4907
4909
4908
- forEach ( foundModuleNames , ( moduleName ) => {
4910
+ for ( const moduleName of foundModuleNames ) {
4909
4911
const moduleDir = combinePaths ( nodeModulesDir , moduleName ) ;
4910
4912
result . push ( {
4911
4913
moduleName,
4912
4914
moduleDir
4913
4915
} ) ;
4914
- } ) ;
4915
- } ) ;
4916
+ }
4917
+ }
4916
4918
4917
4919
return result ;
4918
4920
0 commit comments