Skip to content

Commit d24e4d0

Browse files
committed
Remove 'isFinite' & 'isInteger' polyfills
1 parent f4f0c72 commit d24e4d0

File tree

4 files changed

+9
-40
lines changed

4 files changed

+9
-40
lines changed

src/polyfills/isFinite.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/polyfills/isInteger.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/type/scalars.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import isFinite from '../polyfills/isFinite';
2-
import isInteger from '../polyfills/isInteger';
3-
41
import inspect from '../jsutils/inspect';
52
import isObjectLike from '../jsutils/isObjectLike';
63

@@ -32,7 +29,7 @@ function serializeInt(outputValue: mixed): number {
3229
num = Number(coercedValue);
3330
}
3431

35-
if (!isInteger(num)) {
32+
if (typeof num !== 'number' || !Number.isInteger(num)) {
3633
throw new GraphQLError(
3734
`Int cannot represent non-integer value: ${inspect(coercedValue)}`,
3835
);
@@ -47,7 +44,7 @@ function serializeInt(outputValue: mixed): number {
4744
}
4845

4946
function coerceInt(inputValue: mixed): number {
50-
if (!isInteger(inputValue)) {
47+
if (typeof inputValue !== 'number' || !Number.isInteger(inputValue)) {
5148
throw new GraphQLError(
5249
`Int cannot represent non-integer value: ${inspect(inputValue)}`,
5350
);
@@ -96,7 +93,7 @@ function serializeFloat(outputValue: mixed): number {
9693
num = Number(coercedValue);
9794
}
9895

99-
if (!isFinite(num)) {
96+
if (typeof num !== 'number' || !Number.isFinite(num)) {
10097
throw new GraphQLError(
10198
`Float cannot represent non numeric value: ${inspect(coercedValue)}`,
10299
);
@@ -105,7 +102,7 @@ function serializeFloat(outputValue: mixed): number {
105102
}
106103

107104
function coerceFloat(inputValue: mixed): number {
108-
if (!isFinite(inputValue)) {
105+
if (typeof inputValue !== 'number' || !Number.isFinite(inputValue)) {
109106
throw new GraphQLError(
110107
`Float cannot represent non numeric value: ${inspect(inputValue)}`,
111108
);
@@ -160,7 +157,7 @@ function serializeString(outputValue: mixed): string {
160157
if (typeof coercedValue === 'boolean') {
161158
return coercedValue ? 'true' : 'false';
162159
}
163-
if (isFinite(coercedValue)) {
160+
if (typeof coercedValue === 'number' && Number.isFinite(coercedValue)) {
164161
return coercedValue.toString();
165162
}
166163
throw new GraphQLError(
@@ -200,7 +197,7 @@ function serializeBoolean(outputValue: mixed): boolean {
200197
if (typeof coercedValue === 'boolean') {
201198
return coercedValue;
202199
}
203-
if (isFinite(coercedValue)) {
200+
if (Number.isFinite(coercedValue)) {
204201
return coercedValue !== 0;
205202
}
206203
throw new GraphQLError(
@@ -239,7 +236,7 @@ function serializeID(outputValue: mixed): string {
239236
if (typeof coercedValue === 'string') {
240237
return coercedValue;
241238
}
242-
if (isInteger(coercedValue)) {
239+
if (Number.isInteger(coercedValue)) {
243240
return String(coercedValue);
244241
}
245242
throw new GraphQLError(`ID cannot represent value: ${inspect(outputValue)}`);
@@ -249,7 +246,7 @@ function coerceID(inputValue: mixed): string {
249246
if (typeof inputValue === 'string') {
250247
return inputValue;
251248
}
252-
if (isInteger(inputValue)) {
249+
if (typeof inputValue === 'number' && Number.isInteger(inputValue)) {
253250
return inputValue.toString();
254251
}
255252
throw new GraphQLError(`ID cannot represent value: ${inspect(inputValue)}`);

src/utilities/astFromValue.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import isFinite from '../polyfills/isFinite';
21
import arrayFrom from '../polyfills/arrayFrom';
32
import objectValues from '../polyfills/objectValues';
43

@@ -114,7 +113,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
114113
}
115114

116115
// JavaScript numbers can be Int or Float values.
117-
if (typeof serialized === 'number' && isFinite(serialized)) {
116+
if (typeof serialized === 'number' && Number.isFinite(serialized)) {
118117
const stringNum = String(serialized);
119118
return integerStringRegExp.test(stringNum)
120119
? { kind: Kind.INT, value: stringNum }

0 commit comments

Comments
 (0)