diff --git a/src/execution/execute.js b/src/execution/execute.js index aa1e54776c..7e1ea84dea 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -281,8 +281,7 @@ export function buildExecutionContext( let operation: OperationDefinitionNode | void; let hasMultipleAssumedOperations = false; const fragments: ObjMap = Object.create(null); - for (let i = 0; i < document.definitions.length; i++) { - const definition = document.definitions[i]; + for (const definition of document.definitions) { switch (definition.kind) { case Kind.OPERATION_DEFINITION: if (!operationName && operation) { @@ -434,8 +433,7 @@ function executeFields( const results = Object.create(null); let containsPromise = false; - for (let i = 0, keys = Object.keys(fields); i < keys.length; ++i) { - const responseName = keys[i]; + for (const responseName of Object.keys(fields)) { const fieldNodes = fields[responseName]; const fieldPath = addPath(path, responseName); const result = resolveField( @@ -480,8 +478,7 @@ export function collectFields( fields: ObjMap>, visitedFragmentNames: ObjMap, ): ObjMap> { - for (let i = 0; i < selectionSet.selections.length; i++) { - const selection = selectionSet.selections[i]; + for (const selection of selectionSet.selections) { switch (selection.kind) { case Kind.FIELD: { if (!shouldIncludeNode(exeContext, selection)) { @@ -1108,13 +1105,12 @@ function _collectSubfields( ): ObjMap> { let subFieldNodes = Object.create(null); const visitedFragmentNames = Object.create(null); - for (let i = 0; i < fieldNodes.length; i++) { - const selectionSet = fieldNodes[i].selectionSet; - if (selectionSet) { + for (const node of fieldNodes) { + if (node.selectionSet) { subFieldNodes = collectFields( exeContext, returnType, - selectionSet, + node.selectionSet, subFieldNodes, visitedFragmentNames, ); diff --git a/src/jsutils/suggestionList.js b/src/jsutils/suggestionList.js index c42dff8f02..bcbd486057 100644 --- a/src/jsutils/suggestionList.js +++ b/src/jsutils/suggestionList.js @@ -45,8 +45,6 @@ function lexicalDistance(aStr, bStr) { return 0; } - let i; - let j; const d = []; const a = aStr.toLowerCase(); const b = bStr.toLowerCase(); @@ -58,16 +56,16 @@ function lexicalDistance(aStr, bStr) { return 1; } - for (i = 0; i <= aLength; i++) { + for (let i = 0; i <= aLength; i++) { d[i] = [i]; } - for (j = 1; j <= bLength; j++) { + for (let j = 1; j <= bLength; j++) { d[0][j] = j; } - for (i = 1; i <= aLength; i++) { - for (j = 1; j <= bLength; j++) { + for (let i = 1; i <= aLength; i++) { + for (let j = 1; j <= bLength; j++) { const cost = a[i - 1] === b[j - 1] ? 0 : 1; d[i][j] = Math.min( diff --git a/src/polyfills/find.js b/src/polyfills/find.js index feb0fca36d..2243c2a7b9 100644 --- a/src/polyfills/find.js +++ b/src/polyfills/find.js @@ -12,8 +12,7 @@ const find = Array.prototype.find return Array.prototype.find.call(list, predicate); } : function(list, predicate) { - for (let i = 0; i < list.length; i++) { - const value = list[i]; + for (const value of list) { if (predicate(value)) { return value; } diff --git a/src/polyfills/flatMap.js b/src/polyfills/flatMap.js index ba198819d8..b2402dfa59 100644 --- a/src/polyfills/flatMap.js +++ b/src/polyfills/flatMap.js @@ -13,8 +13,8 @@ const flatMap = Array.prototype.flatMap } : function(list, fn) { let result = []; - for (let i = 0; i < list.length; i++) { - const value = fn(list[i]); + for (const item of list) { + const value = fn(item); if (Array.isArray(value)) { result = result.concat(value); } else { diff --git a/src/validation/rules/OverlappingFieldsCanBeMerged.js b/src/validation/rules/OverlappingFieldsCanBeMerged.js index 76aa3f3129..a9db2291da 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMerged.js +++ b/src/validation/rules/OverlappingFieldsCanBeMerged.js @@ -747,8 +747,7 @@ function _collectFieldsAndFragmentNames( nodeAndDefs, fragmentNames, ): void { - for (let i = 0; i < selectionSet.selections.length; i++) { - const selection = selectionSet.selections[i]; + for (const selection of selectionSet.selections) { switch (selection.kind) { case Kind.FIELD: { const fieldName = selection.name.value;