Skip to content

Commit 2eb159e

Browse files
author
Andy Hanson
committed
Rename 'find' functions
1 parent 3de8c22 commit 2eb159e

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ namespace ts {
10321032
}
10331033

10341034
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
1035-
return find(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
1035+
return findMap(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
10361036
}
10371037

10381038
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {

src/compiler/core.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ namespace ts {
110110
}
111111

112112
/** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
113-
export function tryFind<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
113+
export function find<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
114114
for (let i = 0, len = array.length; i < len; i++) {
115115
const value = array[i];
116116
if (predicate(value, i)) {
@@ -120,8 +120,11 @@ namespace ts {
120120
return undefined;
121121
}
122122

123-
/** Like `forEach`, but assumes existence of array and fails if no truthy value is found. */
124-
export function find<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
123+
/**
124+
* Returns the first truthy result of `callback`, or else fails.
125+
* This is like `forEach`, but never returns undefined.
126+
*/
127+
export function findMap<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
125128
for (let i = 0, len = array.length; i < len; i++) {
126129
const result = callback(array[i], i);
127130
if (result) {

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@ namespace ts {
27152715

27162716
/** Return ".ts" or ".tsx" if that is the extension. */
27172717
export function tryExtractTypeScriptExtension(fileName: string): string | undefined {
2718-
return tryFind(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension));
2718+
return find(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension));
27192719
}
27202720
// Must have '.d.ts' first because if '.ts' goes first, that will be detected as the extension instead of '.d.ts'.
27212721
const supportedTypescriptExtensionsWithDtsFirst = supportedTypeScriptExtensions.slice().reverse();

0 commit comments

Comments
 (0)