Rename 'find' functions
This commit is contained in:
parent
3de8c22196
commit
2eb159e269
3 changed files with 8 additions and 5 deletions
|
@ -1032,7 +1032,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
|
||||
return find(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
|
||||
return findMap(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
|
||||
}
|
||||
|
||||
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
/** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
|
||||
export function tryFind<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
|
||||
export function find<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
const value = array[i];
|
||||
if (predicate(value, i)) {
|
||||
|
@ -120,8 +120,11 @@ namespace ts {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
/** Like `forEach`, but assumes existence of array and fails if no truthy value is found. */
|
||||
export function find<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
|
||||
/**
|
||||
* Returns the first truthy result of `callback`, or else fails.
|
||||
* This is like `forEach`, but never returns undefined.
|
||||
*/
|
||||
export function findMap<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
const result = callback(array[i], i);
|
||||
if (result) {
|
||||
|
|
|
@ -2715,7 +2715,7 @@ namespace ts {
|
|||
|
||||
/** Return ".ts" or ".tsx" if that is the extension. */
|
||||
export function tryExtractTypeScriptExtension(fileName: string): string | undefined {
|
||||
return tryFind(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension));
|
||||
return find(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension));
|
||||
}
|
||||
// Must have '.d.ts' first because if '.ts' goes first, that will be detected as the extension instead of '.d.ts'.
|
||||
const supportedTypescriptExtensionsWithDtsFirst = supportedTypeScriptExtensions.slice().reverse();
|
||||
|
|
Loading…
Reference in a new issue