Skip to content

Commit

Permalink
strip %checks annotations (flow)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Oct 27, 2020
1 parent c7af53c commit 5d966bd
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 56 deletions.
5 changes: 2 additions & 3 deletions src/jsutils/instanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
declare function instanceOf(
value: unknown,
constructor: unknown,
): boolean %checks(value instanceof constructor);

): boolean;
// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
// See: https://webpack.js.org/guides/production/
export default process.env.NODE_ENV === 'production'
? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
// eslint-disable-next-line no-shadow
function instanceOf(value: unknown, constructor: unknown): boolean {
function instanceOf(value: unknown, constructor: unknown): boolean { // FIXME: TS_CONVERTION %check
return value instanceof constructor;
}
: // eslint-disable-next-line no-shadow
Expand Down
3 changes: 1 addition & 2 deletions src/jsutils/isAsyncIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Returns true if the provided object implements the AsyncIterator protocol via
* either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method.
*/
declare function isAsyncIterable(value: unknown): boolean %checks(value instanceof
AsyncIterable);
declare function isAsyncIterable(value: unknown): boolean; // FIXME: TS_CONVERTION %check

// eslint-disable-next-line no-redeclare
export default function isAsyncIterable(maybeAsyncIterable) {
Expand Down
3 changes: 1 addition & 2 deletions src/jsutils/isCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* An Object value which might implement the Iterable or Array-like protocols.
* @return {boolean} true if Iterable or Array-like Object.
*/
declare function isCollection(value: unknown): boolean %checks(value instanceof
Iterable);
declare function isCollection(value: unknown): boolean; // FIXME: TS_CONVERTION %check

// eslint-disable-next-line no-redeclare
export default function isCollection(obj) {
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/isObjectLike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* Return true if `value` is object-like. A value is object-like if it's not
* `null` and has a `typeof` result of "object".
*/
export default function isObjectLike(value: unknown): boolean %checks {
export default function isObjectLike(value: unknown): boolean { // FIXME: TS_CONVERTION %check
return typeof value == 'object' && value !== null;
}
3 changes: 1 addition & 2 deletions src/jsutils/isPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Returns true if the value acts like a Promise, i.e. has a "then" function,
* otherwise returns false.
*/
declare function isPromise(value: unknown): boolean %checks(value instanceof
Promise);
declare function isPromise(value: unknown): boolean; // FIXME: TS_CONVERTION %check

// eslint-disable-next-line no-redeclare
export default function isPromise(value) {
Expand Down
2 changes: 1 addition & 1 deletion src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Token {
/**
* @internal
*/
export function isNode(maybeNode: unknown): boolean %checks {
export function isNode(maybeNode: unknown): boolean { // FIXME: TS_CONVERTION %check
return maybeNode != null && typeof maybeNode.kind === 'string';
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Lexer {
/**
* @internal
*/
export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean %checks {
export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean {
return (
kind === TokenKind.BANG ||
kind === TokenKind.DOLLAR ||
Expand Down
18 changes: 9 additions & 9 deletions src/language/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import type { ASTNode } from './ast';
import { Kind } from './kinds';

export function isDefinitionNode(node: ASTNode): boolean %checks {
export function isDefinitionNode(node: ASTNode): boolean {
return (
isExecutableDefinitionNode(node) ||
isTypeSystemDefinitionNode(node) ||
isTypeSystemExtensionNode(node)
);
}

export function isExecutableDefinitionNode(node: ASTNode): boolean %checks {
export function isExecutableDefinitionNode(node: ASTNode): boolean {
return (
node.kind === Kind.OPERATION_DEFINITION ||
node.kind === Kind.FRAGMENT_DEFINITION
);
}

export function isSelectionNode(node: ASTNode): boolean %checks {
export function isSelectionNode(node: ASTNode): boolean {
return (
node.kind === Kind.FIELD ||
node.kind === Kind.FRAGMENT_SPREAD ||
node.kind === Kind.INLINE_FRAGMENT
);
}

export function isValueNode(node: ASTNode): boolean %checks {
export function isValueNode(node: ASTNode): boolean {
return (
node.kind === Kind.VARIABLE ||
node.kind === Kind.INT ||
Expand All @@ -38,23 +38,23 @@ export function isValueNode(node: ASTNode): boolean %checks {
);
}

export function isTypeNode(node: ASTNode): boolean %checks {
export function isTypeNode(node: ASTNode): boolean {
return (
node.kind === Kind.NAMED_TYPE ||
node.kind === Kind.LIST_TYPE ||
node.kind === Kind.NON_NULL_TYPE
);
}

export function isTypeSystemDefinitionNode(node: ASTNode): boolean %checks {
export function isTypeSystemDefinitionNode(node: ASTNode): boolean {
return (
node.kind === Kind.SCHEMA_DEFINITION ||
isTypeDefinitionNode(node) ||
node.kind === Kind.DIRECTIVE_DEFINITION
);
}

export function isTypeDefinitionNode(node: ASTNode): boolean %checks {
export function isTypeDefinitionNode(node: ASTNode): boolean {
return (
node.kind === Kind.SCALAR_TYPE_DEFINITION ||
node.kind === Kind.OBJECT_TYPE_DEFINITION ||
Expand All @@ -65,11 +65,11 @@ export function isTypeDefinitionNode(node: ASTNode): boolean %checks {
);
}

export function isTypeSystemExtensionNode(node: ASTNode): boolean %checks {
export function isTypeSystemExtensionNode(node: ASTNode): boolean {
return node.kind === Kind.SCHEMA_EXTENSION || isTypeExtensionNode(node);
}

export function isTypeExtensionNode(node: ASTNode): boolean %checks {
export function isTypeExtensionNode(node: ASTNode): boolean {
return (
node.kind === Kind.SCALAR_TYPE_EXTENSION ||
node.kind === Kind.OBJECT_TYPE_EXTENSION ||
Expand Down
3 changes: 1 addition & 2 deletions src/language/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export class Source {
*
* @internal
*/
declare function isSource(source: unknown): boolean %checks(source instanceof
Source);
declare function isSource(source: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isSource(source) {
return instanceOf(source, Source);
Expand Down
46 changes: 19 additions & 27 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type GraphQLType =
| GraphQLList<any>
| GraphQLNonNull<any>;

export function isType(type: unknown): boolean %checks {
export function isType(type: unknown): boolean {
return (
isScalarType(type) ||
isObjectType(type) ||
Expand All @@ -89,8 +89,7 @@ export function assertType(type: unknown): GraphQLType {
* There are predicates for each kind of GraphQL type.
*/

declare function isScalarType(type: unknown): boolean %checks(type instanceof
GraphQLScalarType);
declare function isScalarType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isScalarType(type) {
return instanceOf(type, GraphQLScalarType);
Expand All @@ -103,8 +102,7 @@ export function assertScalarType(type: unknown): GraphQLScalarType {
return type;
}

declare function isObjectType(type: unknown): boolean %checks(type instanceof
GraphQLObjectType);
declare function isObjectType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isObjectType(type) {
return instanceOf(type, GraphQLObjectType);
Expand All @@ -117,8 +115,7 @@ export function assertObjectType(type: unknown): GraphQLObjectType {
return type;
}

declare function isInterfaceType(type: unknown): boolean %checks(type instanceof
GraphQLInterfaceType);
declare function isInterfaceType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isInterfaceType(type) {
return instanceOf(type, GraphQLInterfaceType);
Expand All @@ -133,8 +130,7 @@ export function assertInterfaceType(type: unknown): GraphQLInterfaceType {
return type;
}

declare function isUnionType(type: unknown): boolean %checks(type instanceof
GraphQLUnionType);
declare function isUnionType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isUnionType(type) {
return instanceOf(type, GraphQLUnionType);
Expand All @@ -147,8 +143,7 @@ export function assertUnionType(type: unknown): GraphQLUnionType {
return type;
}

declare function isEnumType(type: unknown): boolean %checks(type instanceof
GraphQLEnumType);
declare function isEnumType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isEnumType(type) {
return instanceOf(type, GraphQLEnumType);
Expand All @@ -161,8 +156,7 @@ export function assertEnumType(type: unknown): GraphQLEnumType {
return type;
}

declare function isInputObjectType(type: unknown): boolean %checks(type instanceof
GraphQLInputObjectType);
declare function isInputObjectType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isInputObjectType(type) {
return instanceOf(type, GraphQLInputObjectType);
Expand All @@ -177,8 +171,7 @@ export function assertInputObjectType(type: unknown): GraphQLInputObjectType {
return type;
}

declare function isListType(type: unknown): boolean %checks(type instanceof
GraphQLList);
declare function isListType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isListType(type) {
return instanceOf(type, GraphQLList);
Expand All @@ -191,8 +184,7 @@ export function assertListType(type: unknown): GraphQLList<any> {
return type;
}

declare function isNonNullType(type: unknown): boolean %checks(type instanceof
GraphQLNonNull);
declare function isNonNullType(type: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isNonNullType(type) {
return instanceOf(type, GraphQLNonNull);
Expand Down Expand Up @@ -220,7 +212,7 @@ export type GraphQLInputType =
| GraphQLList<GraphQLInputType>,
>;

export function isInputType(type: unknown): boolean %checks {
export function isInputType(type: unknown): boolean {
return (
isScalarType(type) ||
isEnumType(type) ||
Expand Down Expand Up @@ -255,7 +247,7 @@ export type GraphQLOutputType =
| GraphQLList<GraphQLOutputType>,
>;

export function isOutputType(type: unknown): boolean %checks {
export function isOutputType(type: unknown): boolean {
return (
isScalarType(type) ||
isObjectType(type) ||
Expand All @@ -278,7 +270,7 @@ export function assertOutputType(type: unknown): GraphQLOutputType {
*/
export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType;

export function isLeafType(type: unknown): boolean %checks {
export function isLeafType(type: unknown): boolean {
return isScalarType(type) || isEnumType(type);
}

Expand All @@ -297,7 +289,7 @@ export type GraphQLCompositeType =
| GraphQLInterfaceType
| GraphQLUnionType;

export function isCompositeType(type: unknown): boolean %checks {
export function isCompositeType(type: unknown): boolean {
return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
}

Expand All @@ -315,7 +307,7 @@ export function assertCompositeType(type: unknown): GraphQLCompositeType {
*/
export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType;

export function isAbstractType(type: unknown): boolean %checks {
export function isAbstractType(type: unknown): boolean {
return isInterfaceType(type) || isUnionType(type);
}

Expand Down Expand Up @@ -422,7 +414,7 @@ export class GraphQLNonNull<T extends GraphQLNullableType> {

export type GraphQLWrappingType = GraphQLList<any> | GraphQLNonNull<any>;

export function isWrappingType(type: unknown): boolean %checks {
export function isWrappingType(type: unknown): boolean {
return isListType(type) || isNonNullType(type);
}

Expand All @@ -445,7 +437,7 @@ export type GraphQLNullableType =
| GraphQLInputObjectType
| GraphQLList<any>;

export function isNullableType(type: unknown): boolean %checks {
export function isNullableType(type: unknown): boolean {
return isType(type) && !isNonNullType(type);
}

Expand Down Expand Up @@ -478,7 +470,7 @@ export type GraphQLNamedType =
| GraphQLEnumType
| GraphQLInputObjectType;

export function isNamedType(type: unknown): boolean %checks {
export function isNamedType(type: unknown): boolean {
return (
isScalarType(type) ||
isObjectType(type) ||
Expand Down Expand Up @@ -986,7 +978,7 @@ export type GraphQLArgument = {
astNode: Maybe<InputValueDefinitionNode>,
};

export function isRequiredArgument(arg: GraphQLArgument): boolean %checks {
export function isRequiredArgument(arg: GraphQLArgument): boolean {
return isNonNullType(arg.type) && arg.defaultValue === undefined;
}

Expand Down Expand Up @@ -1573,7 +1565,7 @@ export type GraphQLInputField = {

export function isRequiredInputField(
field: GraphQLInputField,
): boolean %checks {
): boolean {
return isNonNullType(field.type) && field.defaultValue === undefined;
}

Expand Down
4 changes: 2 additions & 2 deletions src/type/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Maybe } from '../jsutils/Maybe';
*/
declare function isDirective(
directive: unknown,
): boolean %checks(directive instanceof GraphQLDirective);
): boolean;
// eslint-disable-next-line no-redeclare
export function isDirective(directive) {
return instanceOf(directive, GraphQLDirective);
Expand Down Expand Up @@ -218,6 +218,6 @@ export const specifiedDirectives = Object.freeze([

export function isSpecifiedDirective(
directive: GraphQLDirective,
): boolean %checks {
): boolean {
return specifiedDirectives.some(({ name }) => name === directive.name);
}
2 changes: 1 addition & 1 deletion src/type/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,6 @@ export const introspectionTypes = Object.freeze([
__TypeKind,
]);

export function isIntrospectionType(type: GraphQLNamedType): boolean %checks {
export function isIntrospectionType(type: GraphQLNamedType): boolean { // FIXME: TS_CONVERTION %check
return introspectionTypes.some(({ name }) => type.name === name);
}
2 changes: 1 addition & 1 deletion src/type/scalars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,6 @@ export const specifiedScalarTypes = Object.freeze([
GraphQLID,
]);

export function isSpecifiedScalarType(type: GraphQLNamedType): boolean %checks {
export function isSpecifiedScalarType(type: GraphQLNamedType): boolean {
return specifiedScalarTypes.some(({ name }) => type.name === name);
}
3 changes: 1 addition & 2 deletions src/type/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import { Maybe } from '../jsutils/Maybe';
/**
* Test if the given value is a GraphQL schema.
*/
declare function isSchema(schema: unknown): boolean %checks(schema instanceof
GraphQLSchema);
declare function isSchema(schema: unknown): boolean;
// eslint-disable-next-line no-redeclare
export function isSchema(schema) {
return instanceOf(schema, GraphQLSchema);
Expand Down

0 comments on commit 5d966bd

Please sign in to comment.