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

Drop 'Array.from' polyfill #2912

Merged
merged 1 commit into from Feb 10, 2021
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
4 changes: 1 addition & 3 deletions src/execution/execute.js
@@ -1,5 +1,3 @@
import arrayFrom from '../polyfills/arrayFrom';

import type { Path } from '../jsutils/Path';
import type { ObjMap } from '../jsutils/ObjMap';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
Expand Down Expand Up @@ -833,7 +831,7 @@ function completeListValue(
// where the list contains no Promises by avoiding creating another Promise.
const itemType = returnType.ofType;
let containsPromise = false;
const completedResults = arrayFrom(result, (item, index) => {
const completedResults = Array.from(result, (item, index) => {
// No need to modify the info object containing the path,
// since from here on it is not ever accessed by resolver functions.
const itemPath = addPath(path, index, undefined);
Expand Down
6 changes: 5 additions & 1 deletion src/jsutils/isCollection.js
Expand Up @@ -21,7 +21,11 @@ import { SYMBOL_ITERATOR } from '../polyfills/symbols';
* An Object value which might implement the Iterable or Array-like protocols.
* @return {boolean} true if Iterable or Array-like Object.
*/
export default function isCollection(obj: mixed): boolean {
declare function isCollection(value: mixed): boolean %checks(value instanceof
Iterable);

// eslint-disable-next-line no-redeclare
export default function isCollection(obj) {
if (obj == null || typeof obj !== 'object') {
return false;
}
Expand Down
57 changes: 0 additions & 57 deletions src/polyfills/arrayFrom.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/type/schema.js
@@ -1,4 +1,3 @@
import arrayFrom from '../polyfills/arrayFrom';
import objectValues from '../polyfills/objectValues';
import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols';

Expand Down Expand Up @@ -207,7 +206,7 @@ export class GraphQLSchema {
// Keep track of all implementations by interface name.
this._implementationsMap = Object.create(null);

for (const namedType of arrayFrom(allReferencedTypes)) {
for (const namedType of Array.from(allReferencedTypes)) {
if (namedType == null) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/astFromValue.js
@@ -1,4 +1,3 @@
import arrayFrom from '../polyfills/arrayFrom';
import objectValues from '../polyfills/objectValues';

import inspect from '../jsutils/inspect';
Expand Down Expand Up @@ -67,7 +66,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
const valuesNodes = [];
// Since we transpile for-of in loose mode it doesn't support iterators
// and it's required to first convert iteratable into array
for (const item of arrayFrom(value)) {
for (const item of Array.from(value)) {
const itemNode = astFromValue(item, itemType);
if (itemNode != null) {
valuesNodes.push(itemNode);
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/coerceInputValue.js
@@ -1,4 +1,3 @@
import arrayFrom from '../polyfills/arrayFrom';
import objectValues from '../polyfills/objectValues';

import type { Path } from '../jsutils/Path';
Expand Down Expand Up @@ -79,7 +78,7 @@ function coerceInputValueImpl(
if (isListType(type)) {
const itemType = type.ofType;
if (isCollection(inputValue)) {
return arrayFrom(inputValue, (itemValue, index) => {
return Array.from(inputValue, (itemValue, index) => {
const itemPath = addPath(path, index, undefined);
return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
});
Expand Down
4 changes: 1 addition & 3 deletions src/validation/rules/FieldsOnCorrectTypeRule.js
@@ -1,5 +1,3 @@
import arrayFrom from '../../polyfills/arrayFrom';

import didYouMean from '../../jsutils/didYouMean';
import suggestionList from '../../jsutils/suggestionList';
import naturalCompare from '../../jsutils/naturalCompare';
Expand Down Expand Up @@ -107,7 +105,7 @@ function getSuggestedTypeNames(
}
}

return arrayFrom(suggestedTypes)
return Array.from(suggestedTypes)
.sort((typeA, typeB) => {
// Suggest both interface and object types based on how common they are.
const usageCountDiff = usageCount[typeB.name] - usageCount[typeA.name];
Expand Down