Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit d720b5b

Browse files
Switch instanceOf to be named export (graphql#2990)
1 parent 050c508 commit d720b5b

File tree

6 files changed

+26
-33
lines changed

6 files changed

+26
-33
lines changed

src/jsutils/__tests__/instanceOf-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33

4-
import instanceOf from '../instanceOf';
4+
import { instanceOf } from '../instanceOf';
55

66
describe('instanceOf', () => {
77
it('fails with descriptive error message', () => {

src/jsutils/instanceOf.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
/**
22
* A replacement for instanceof which includes an error warning when multi-realm
33
* constructors are detected.
4+
* See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
5+
* See: https://webpack.js.org/guides/production/
46
*/
5-
declare function instanceOf(
6-
value: mixed,
7-
constructor: mixed,
8-
): boolean %checks(value instanceof constructor);
9-
10-
// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
11-
// See: https://webpack.js.org/guides/production/
12-
// eslint-disable-next-line import/no-default-export
13-
export default process.env.NODE_ENV === 'production'
14-
? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
15-
// eslint-disable-next-line no-shadow
16-
function instanceOf(value: mixed, constructor: mixed): boolean {
17-
return value instanceof constructor;
18-
}
19-
: // eslint-disable-next-line no-shadow
20-
function instanceOf(value: any, constructor: any): boolean {
21-
if (value instanceof constructor) {
22-
return true;
7+
export const instanceOf: (mixed, mixed) => boolean =
8+
process.env.NODE_ENV === 'production'
9+
? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
10+
function instanceOf(value: mixed, constructor: mixed): boolean {
11+
return value instanceof constructor;
2312
}
24-
if (value) {
25-
const valueClass = value.constructor;
26-
const className = constructor.name;
27-
if (className && valueClass && valueClass.name === className) {
28-
throw new Error(
29-
`Cannot use ${className} "${value}" from another module or realm.
13+
: function instanceOf(value: any, constructor: any): boolean {
14+
if (value instanceof constructor) {
15+
return true;
16+
}
17+
if (value) {
18+
const valueClass = value.constructor;
19+
const className = constructor.name;
20+
if (className && valueClass && valueClass.name === className) {
21+
throw new Error(
22+
`Cannot use ${className} "${value}" from another module or realm.
3023
3124
Ensure that there is only one instance of "graphql" in the node_modules
3225
directory. If different versions of "graphql" are the dependencies of other
@@ -38,8 +31,8 @@ Duplicate "graphql" modules cannot be used at the same time since different
3831
versions may have different capabilities and behavior. The data from one
3932
version used in the function from another could produce confusing and
4033
spurious results.`,
41-
);
34+
);
35+
}
4236
}
43-
}
44-
return false;
45-
};
37+
return false;
38+
};

src/language/source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inspect } from '../jsutils/inspect';
22
import { devAssert } from '../jsutils/devAssert';
3-
import instanceOf from '../jsutils/instanceOf';
3+
import { instanceOf } from '../jsutils/instanceOf';
44

55
type Location = {|
66
line: number,

src/type/definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { mapValue } from '../jsutils/mapValue';
1111
import { toObjMap } from '../jsutils/toObjMap';
1212
import { devAssert } from '../jsutils/devAssert';
1313
import { keyValMap } from '../jsutils/keyValMap';
14-
import instanceOf from '../jsutils/instanceOf';
14+
import { instanceOf } from '../jsutils/instanceOf';
1515
import { didYouMean } from '../jsutils/didYouMean';
1616
import { isObjectLike } from '../jsutils/isObjectLike';
1717
import { identityFunc } from '../jsutils/identityFunc';

src/type/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ReadOnlyObjMap, ReadOnlyObjMapLike } from '../jsutils/ObjMap';
22
import { inspect } from '../jsutils/inspect';
33
import { toObjMap } from '../jsutils/toObjMap';
44
import { devAssert } from '../jsutils/devAssert';
5-
import instanceOf from '../jsutils/instanceOf';
5+
import { instanceOf } from '../jsutils/instanceOf';
66
import { isObjectLike } from '../jsutils/isObjectLike';
77

88
import type { DirectiveDefinitionNode } from '../language/ast';

src/type/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
import { inspect } from '../jsutils/inspect';
77
import { toObjMap } from '../jsutils/toObjMap';
88
import { devAssert } from '../jsutils/devAssert';
9-
import instanceOf from '../jsutils/instanceOf';
9+
import { instanceOf } from '../jsutils/instanceOf';
1010
import { isObjectLike } from '../jsutils/isObjectLike';
1111

1212
import type { GraphQLError } from '../error/GraphQLError';

0 commit comments

Comments
 (0)