Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert more cycles to 'for..of' #2100

Merged
merged 1 commit into from Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/execution/execute.js
Expand Up @@ -281,8 +281,7 @@ export function buildExecutionContext(
let operation: OperationDefinitionNode | void;
let hasMultipleAssumedOperations = false;
const fragments: ObjMap<FragmentDefinitionNode> = 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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -480,8 +478,7 @@ export function collectFields(
fields: ObjMap<Array<FieldNode>>,
visitedFragmentNames: ObjMap<boolean>,
): ObjMap<Array<FieldNode>> {
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)) {
Expand Down Expand Up @@ -1108,13 +1105,12 @@ function _collectSubfields(
): ObjMap<Array<FieldNode>> {
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,
);
Expand Down
10 changes: 4 additions & 6 deletions src/jsutils/suggestionList.js
Expand Up @@ -45,8 +45,6 @@ function lexicalDistance(aStr, bStr) {
return 0;
}

let i;
let j;
const d = [];
const a = aStr.toLowerCase();
const b = bStr.toLowerCase();
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/polyfills/find.js
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/polyfills/flatMap.js
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/validation/rules/OverlappingFieldsCanBeMerged.js
Expand Up @@ -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;
Expand Down