Skip to content

Commit 0da0267

Browse files
committed
Update to latest version of flow
1 parent 3b46751 commit 0da0267

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"coveralls": "2.11.9",
6666
"eslint": "2.7.0",
6767
"eslint-plugin-babel": "3.2.0",
68-
"flow-bin": "0.20.1",
68+
"flow-bin": "0.22.1",
6969
"isparta": "4.0.0",
7070
"mocha": "2.4.5",
7171
"sane": "1.3.4"

src/language/parser.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import type {
3939

4040
Type,
4141
NamedType,
42+
ListType,
43+
NonNullType,
4244

4345
TypeSystemDefinition,
4446

@@ -632,20 +634,20 @@ export function parseType(parser: Parser): Type {
632634
if (skip(parser, TokenKind.BRACKET_L)) {
633635
type = parseType(parser);
634636
expect(parser, TokenKind.BRACKET_R);
635-
type = {
637+
type = ({
636638
kind: LIST_TYPE,
637639
type,
638640
loc: loc(parser, start)
639-
};
641+
}: ListType);
640642
} else {
641643
type = parseNamedType(parser);
642644
}
643645
if (skip(parser, TokenKind.BANG)) {
644-
return {
646+
return ({
645647
kind: NON_NULL_TYPE,
646648
type,
647649
loc: loc(parser, start)
648-
};
650+
}: NonNullType);
649651
}
650652
return type;
651653
}

src/utilities/astFromValue.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010

1111
import invariant from '../jsutils/invariant';
1212
import isNullish from '../jsutils/isNullish';
13-
import type { Value } from '../language/ast';
13+
import type {
14+
Value,
15+
IntValue,
16+
FloatValue,
17+
StringValue,
18+
BooleanValue,
19+
EnumValue,
20+
ListValue,
21+
ObjectValue,
22+
} from '../language/ast';
1423
import {
1524
NAME,
1625
INT,
@@ -68,14 +77,14 @@ export function astFromValue(
6877
// the value is not an array, convert the value using the list's item type.
6978
if (Array.isArray(_value)) {
7079
const itemType = type instanceof GraphQLList ? type.ofType : null;
71-
return {
80+
return ({
7281
kind: LIST,
7382
values: _value.map(item => {
7483
const itemValue = astFromValue(item, itemType);
7584
invariant(itemValue, 'Could not create AST item.');
7685
return itemValue;
7786
})
78-
};
87+
}: ListValue);
7988
} else if (type instanceof GraphQLList) {
8089
// Because GraphQL will accept single values as a "list of one" when
8190
// expecting a list, if there's a non-array value and an expected list type,
@@ -84,7 +93,7 @@ export function astFromValue(
8493
}
8594

8695
if (typeof _value === 'boolean') {
87-
return { kind: BOOLEAN, value: _value };
96+
return ({ kind: BOOLEAN, value: _value }: BooleanValue);
8897
}
8998

9099
// JavaScript numbers can be Float or Int values. Use the GraphQLType to
@@ -95,23 +104,26 @@ export function astFromValue(
95104
const isIntValue = /^[0-9]+$/.test(stringNum);
96105
if (isIntValue) {
97106
if (type === GraphQLFloat) {
98-
return { kind: FLOAT, value: stringNum + '.0' };
107+
return ({ kind: FLOAT, value: stringNum + '.0' }: FloatValue);
99108
}
100-
return { kind: INT, value: stringNum };
109+
return ({ kind: INT, value: stringNum }: IntValue);
101110
}
102-
return { kind: FLOAT, value: stringNum };
111+
return ({ kind: FLOAT, value: stringNum }: FloatValue);
103112
}
104113

105114
// JavaScript strings can be Enum values or String values. Use the
106115
// GraphQLType to differentiate if possible.
107116
if (typeof _value === 'string') {
108117
if (type instanceof GraphQLEnumType &&
109118
/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(_value)) {
110-
return { kind: ENUM, value: _value };
119+
return ({ kind: ENUM, value: _value }: EnumValue);
111120
}
112121
// Use JSON stringify, which uses the same string encoding as GraphQL,
113122
// then remove the quotes.
114-
return { kind: STRING, value: JSON.stringify(_value).slice(1, -1) };
123+
return ({
124+
kind: STRING,
125+
value: JSON.stringify(_value).slice(1, -1)
126+
}: StringValue);
115127
}
116128

117129
// last remaining possible typeof
@@ -135,5 +147,5 @@ export function astFromValue(
135147
});
136148
}
137149
});
138-
return { kind: OBJECT, fields };
150+
return ({ kind: OBJECT, fields }: ObjectValue);
139151
}

0 commit comments

Comments
 (0)