Remove 'indexOf' helper, use 'arr.indexOf()' (#20194)

This commit is contained in:
Andy
2018-01-08 10:39:52 -08:00
committed by GitHub
parent f83283c068
commit fc18f08e63
8 changed files with 29 additions and 38 deletions

View File

@@ -427,8 +427,9 @@ namespace ts.BreakpointResolver {
}
else {
const functionDeclaration = <FunctionLikeDeclaration>parameter.parent;
const indexOfParameter = indexOf(functionDeclaration.parameters, parameter);
if (indexOfParameter) {
const indexOfParameter = functionDeclaration.parameters.indexOf(parameter);
Debug.assert(indexOfParameter !== -1);
if (indexOfParameter !== 0) {
// Not a first parameter, go to previous parameter
return spanInParameterDeclaration(functionDeclaration.parameters[indexOfParameter - 1]);
}

View File

@@ -367,12 +367,13 @@ namespace ts.formatting {
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorSettings): number {
const containingList = getContainingList(node, sourceFile);
return containingList ? getActualIndentationFromList(containingList) : Value.Unknown;
function getActualIndentationFromList(list: ReadonlyArray<Node>): number {
const index = indexOf(list, node);
return index !== -1 ? deriveActualIndentationFromList(list, index, sourceFile, options) : Value.Unknown;
if (containingList) {
const index = containingList.indexOf(node);
if (index !== -1) {
return deriveActualIndentationFromList(containingList, index, sourceFile, options);
}
}
return Value.Unknown;
}
function getLineIndentationWhenExpressionIsInMultiLine(node: Node, sourceFile: SourceFile, options: EditorSettings): number {

View File

@@ -112,7 +112,7 @@ namespace ts.JsDoc {
function forEachUnique<T, U>(array: T[], callback: (element: T, index: number) => U): U {
if (array) {
for (let i = 0; i < array.length; i++) {
if (indexOf(array, array[i]) === i) {
if (array.indexOf(array[i]) === i) {
const result = callback(array[i], i);
if (result) {
return result;