Skip to content

Commit

Permalink
Remove polyfills for Symbol (graphql#2913)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 20, 2021
1 parent 93b2c67 commit b027b07
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/error/GraphQLError.js
Expand Up @@ -2,7 +2,6 @@
// flowlint uninitialized-instance-property:off

import isObjectLike from '../jsutils/isObjectLike';
import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols';

import type { ASTNode } from '../language/ast';
import type { Source } from '../language/source';
Expand Down Expand Up @@ -213,7 +212,7 @@ export class GraphQLError extends Error {

// FIXME: workaround to not break chai comparisons, should be remove in v16
// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG](): string {
get [Symbol.toStringTag](): string {
return 'Object';
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/jsutils/isAsyncIterable.js
@@ -1,5 +1,3 @@
import { SYMBOL_ASYNC_ITERATOR } from '../polyfills/symbols';

/**
* Returns true if the provided object implements the AsyncIterator protocol via
* either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method.
Expand All @@ -9,5 +7,5 @@ declare function isAsyncIterable(value: mixed): boolean %checks(value instanceof

// eslint-disable-next-line no-redeclare
export default function isAsyncIterable(maybeAsyncIterable) {
return typeof maybeAsyncIterable?.[SYMBOL_ASYNC_ITERATOR] === 'function';
return typeof maybeAsyncIterable?.[Symbol.asyncIterator] === 'function';
}
4 changes: 1 addition & 3 deletions src/jsutils/isCollection.js
@@ -1,5 +1,3 @@
import { SYMBOL_ITERATOR } from '../polyfills/symbols';

/**
* Returns true if the provided object is an Object (i.e. not a string literal)
* and is either Iterable or Array-like.
Expand Down Expand Up @@ -37,5 +35,5 @@ export default function isCollection(obj) {
}

// Is Iterable?
return typeof obj[SYMBOL_ITERATOR] === 'function';
return typeof obj[Symbol.iterator] === 'function';
}
4 changes: 1 addition & 3 deletions src/language/source.js
@@ -1,5 +1,3 @@
import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols';

import inspect from '../jsutils/inspect';
import devAssert from '../jsutils/devAssert';
import instanceOf from '../jsutils/instanceOf';
Expand Down Expand Up @@ -45,7 +43,7 @@ export class Source {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'Source';
}
}
Expand Down
19 changes: 0 additions & 19 deletions src/polyfills/symbols.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/subscription/mapAsyncIterator.js
@@ -1,5 +1,3 @@
import { SYMBOL_ASYNC_ITERATOR } from '../polyfills/symbols';

import type { PromiseOrValue } from '../jsutils/PromiseOrValue';

/**
Expand All @@ -12,7 +10,7 @@ export default function mapAsyncIterator<T, U>(
rejectCallback?: (any) => PromiseOrValue<U>,
): AsyncGenerator<U, void, void> {
// $FlowFixMe[prop-missing]
const iteratorMethod = iterable[SYMBOL_ASYNC_ITERATOR];
const iteratorMethod = iterable[Symbol.asyncIterator];
const iterator: any = iteratorMethod.call(iterable);
let $return: any;
let abruptClose;
Expand Down Expand Up @@ -55,7 +53,7 @@ export default function mapAsyncIterator<T, U>(
}
return Promise.reject(error).catch(abruptClose);
},
[SYMBOL_ASYNC_ITERATOR]() {
[Symbol.asyncIterator]() {
return this;
},
}: $FlowFixMe);
Expand Down
17 changes: 8 additions & 9 deletions src/type/definition.js
@@ -1,5 +1,4 @@
import objectEntries from '../polyfills/objectEntries';
import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols';

import type { Path } from '../jsutils/Path';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
Expand Down Expand Up @@ -366,7 +365,7 @@ export class GraphQLList<+T: GraphQLType> {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLList';
}
}
Expand Down Expand Up @@ -415,7 +414,7 @@ export class GraphQLNonNull<+T: GraphQLNullableType> {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLNonNull';
}
}
Expand Down Expand Up @@ -627,7 +626,7 @@ export class GraphQLScalarType {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLScalarType';
}
}
Expand Down Expand Up @@ -774,7 +773,7 @@ export class GraphQLObjectType {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}
Expand Down Expand Up @@ -1094,7 +1093,7 @@ export class GraphQLInterfaceType {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLInterfaceType';
}
}
Expand Down Expand Up @@ -1204,7 +1203,7 @@ export class GraphQLUnionType {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLUnionType';
}
}
Expand Down Expand Up @@ -1385,7 +1384,7 @@ export class GraphQLEnumType /* <T> */ {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLEnumType';
}
}
Expand Down Expand Up @@ -1537,7 +1536,7 @@ export class GraphQLInputObjectType {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLInputObjectType';
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/type/directives.js
@@ -1,5 +1,4 @@
import objectEntries from '../polyfills/objectEntries';
import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols';

import type { ReadOnlyObjMap, ReadOnlyObjMapLike } from '../jsutils/ObjMap';
import inspect from '../jsutils/inspect';
Expand Down Expand Up @@ -105,7 +104,7 @@ export class GraphQLDirective {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLDirective';
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/type/schema.js
@@ -1,5 +1,4 @@
import objectValues from '../polyfills/objectValues';
import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols';

import type {
ObjMap,
Expand Down Expand Up @@ -346,7 +345,7 @@ export class GraphQLSchema {
}

// $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
get [SYMBOL_TO_STRING_TAG]() {
get [Symbol.toStringTag]() {
return 'GraphQLSchema';
}
}
Expand Down

0 comments on commit b027b07

Please sign in to comment.