Skip to content

Commit a7f71a3

Browse files
author
Keyan Zhang
committed
flow works now
1 parent 5f7b1b2 commit a7f71a3

11 files changed

+395
-35
lines changed

npm-shrinkwrap.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

transforms/__testfixtures__/class-proptypes.output.js renamed to transforms/__testfixtures__/class-flow1.output.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ class Component extends React.Component {
1616
optionalEnum?: 'News' | 'Photos' | 1 | true | null,
1717
optionalUnion?: string | number | Message,
1818
optionalArrayOf?: Array<number>,
19-
optionalObjectOf?: {[key: string]: number},
20-
optionalObjectWithShape?: {color: string, fontSize: number},
19+
optionalObjectOf?: {[key: string]: number,},
20+
optionalObjectWithShape?: {
21+
color?: string,
22+
fontSize?: number,
23+
},
2124
requiredFunc: Function,
2225
requiredAny: any,
2326
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* code taken from https://github.com/reactjs/react-router/blob/master/modules/IndexRoute.js */
2+
/* @flow */
3+
4+
import React from 'react'
5+
import warning from './routerWarning'
6+
import invariant from 'invariant'
7+
import { createRouteFromReactElement } from './RouteUtils'
8+
import { component, components, falsy } from './InternalPropTypes'
9+
10+
const { func } = React.PropTypes
11+
12+
/**
13+
* An <IndexRoute> is used to specify its parent's <Route indexRoute> in
14+
* a JSX route config.
15+
*/
16+
const IndexRoute = React.createClass({
17+
18+
statics: {
19+
20+
createRouteFromReactElement(element, parentRoute) {
21+
/* istanbul ignore else: sanity check */
22+
if (parentRoute) {
23+
parentRoute.indexRoute = createRouteFromReactElement(element)
24+
} else {
25+
warning(
26+
false,
27+
'An <IndexRoute> does not make sense at the root of your route config'
28+
)
29+
}
30+
}
31+
32+
},
33+
34+
propTypes: {
35+
path: falsy,
36+
component,
37+
components,
38+
getComponent: func,
39+
getComponents: func
40+
},
41+
42+
/* istanbul ignore next: sanity check */
43+
render() {
44+
invariant(
45+
false,
46+
'<IndexRoute> elements are for router configuration only and should not be rendered'
47+
)
48+
}
49+
50+
})
51+
52+
export default IndexRoute
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* code taken from https://github.com/reactjs/react-router/blob/master/modules/IndexRoute.js */
2+
/* @flow */
3+
4+
import React from 'react'
5+
import warning from './routerWarning'
6+
import invariant from 'invariant'
7+
import { createRouteFromReactElement } from './RouteUtils'
8+
import { component, components, falsy } from './InternalPropTypes'
9+
10+
const { func } = React.PropTypes
11+
12+
/**
13+
* An <IndexRoute> is used to specify its parent's <Route indexRoute> in
14+
* a JSX route config.
15+
*/
16+
class IndexRoute extends React.Component {
17+
props: {
18+
path?: any,
19+
component?: any,
20+
components?: any,
21+
getComponent?: any,
22+
getComponents?: any,
23+
};
24+
25+
static createRouteFromReactElement(element, parentRoute) {
26+
/* istanbul ignore else: sanity check */
27+
if (parentRoute) {
28+
parentRoute.indexRoute = createRouteFromReactElement(element)
29+
} else {
30+
warning(
31+
false,
32+
'An <IndexRoute> does not make sense at the root of your route config'
33+
)
34+
}
35+
}
36+
37+
static propTypes = {
38+
path: falsy,
39+
component,
40+
components,
41+
getComponent: func,
42+
getComponents: func
43+
};
44+
45+
/* istanbul ignore next: sanity check */
46+
render() {
47+
invariant(
48+
false,
49+
'<IndexRoute> elements are for router configuration only and should not be rendered'
50+
)
51+
}
52+
}
53+
54+
export default IndexRoute
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* @flow */
2+
3+
var React = require('react');
4+
var {PropTypes} = React;
5+
6+
var getPropTypes = () => PropTypes.string;
7+
8+
var myUnionPropType = PropTypes.oneOfType([
9+
PropTypes.string,
10+
PropTypes.number,
11+
PropTypes.instanceOf(Message),
12+
]);
13+
14+
var spreadMe = {
15+
optionalArray: PropTypes.array,
16+
optionalBool: PropTypes.bool,
17+
};
18+
19+
var optionalFuncShortHand = PropTypes.func;
20+
21+
var Component = React.createClass({
22+
propTypes: {
23+
...spreadMe,
24+
optionalFuncShortHand,
25+
optionalNumber: 1 + 1 === 2 ? PropTypes.number : PropTypes.string,
26+
optionalObject: PropTypes.object,
27+
optionalString: getPropTypes(),
28+
optionalNode: PropTypes.node,
29+
optionalElement: PropTypes.element,
30+
optionalMessage: PropTypes.instanceOf(Message),
31+
optionalEnum: PropTypes.oneOf(['News', 'Photos', 1, true, null]),
32+
optionalUnion: myUnionPropType,
33+
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
34+
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
35+
optionalObjectWithShape: PropTypes.shape({
36+
color: PropTypes.string,
37+
fontSize: PropTypes.number,
38+
}),
39+
requiredFunc: PropTypes.func.isRequired,
40+
requiredAny: PropTypes.any.isRequired,
41+
},
42+
43+
render: function() {
44+
return (
45+
<div>type safety</div>
46+
);
47+
},
48+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* @flow */
2+
3+
var React = require('react');
4+
var {PropTypes} = React;
5+
6+
var getPropTypes = () => PropTypes.string;
7+
8+
var myUnionPropType = PropTypes.oneOfType([
9+
PropTypes.string,
10+
PropTypes.number,
11+
PropTypes.instanceOf(Message),
12+
]);
13+
14+
var spreadMe = {
15+
optionalArray: PropTypes.array,
16+
optionalBool: PropTypes.bool,
17+
};
18+
19+
var optionalFuncShortHand = PropTypes.func;
20+
21+
class Component extends React.Component {
22+
props: {
23+
optionalFuncShortHand?: any,
24+
optionalNumber?: any,
25+
optionalObject?: Object,
26+
optionalString?: any,
27+
optionalNode?: any,
28+
optionalElement?: any,
29+
optionalMessage?: Message,
30+
optionalEnum?: 'News' | 'Photos' | 1 | true | null,
31+
optionalUnion?: any,
32+
optionalArrayOf?: Array<number>,
33+
optionalObjectOf?: {[key: string]: number,},
34+
optionalObjectWithShape?: {
35+
color?: string,
36+
fontSize?: number,
37+
},
38+
requiredFunc: Function,
39+
requiredAny: any,
40+
};
41+
42+
static propTypes = {
43+
...spreadMe,
44+
optionalFuncShortHand,
45+
optionalNumber: 1 + 1 === 2 ? PropTypes.number : PropTypes.string,
46+
optionalObject: PropTypes.object,
47+
optionalString: getPropTypes(),
48+
optionalNode: PropTypes.node,
49+
optionalElement: PropTypes.element,
50+
optionalMessage: PropTypes.instanceOf(Message),
51+
optionalEnum: PropTypes.oneOf(['News', 'Photos', 1, true, null]),
52+
optionalUnion: myUnionPropType,
53+
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
54+
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
55+
optionalObjectWithShape: PropTypes.shape({
56+
color: PropTypes.string,
57+
fontSize: PropTypes.number,
58+
}),
59+
requiredFunc: PropTypes.func.isRequired,
60+
requiredAny: PropTypes.any.isRequired,
61+
};
62+
63+
render() {
64+
return (
65+
<div>type safety</div>
66+
);
67+
}
68+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* @flow */
2+
3+
var React = require('react');
4+
var {PropTypes} = React;
5+
6+
var myUnionPropType = PropTypes.oneOfType([
7+
PropTypes.string,
8+
PropTypes.number,
9+
PropTypes.instanceOf(Message),
10+
]);
11+
12+
var spreadMe = {
13+
optionalArray: PropTypes.array,
14+
optionalBool: PropTypes.bool,
15+
};
16+
17+
var optionalFuncShortHand = PropTypes.func;
18+
19+
var Component = React.createClass({
20+
propTypes: Object.assign({}, {
21+
...spreadMe,
22+
optionalFuncShortHand,
23+
optionalNumber: PropTypes.number,
24+
optionalObject: PropTypes.object,
25+
}),
26+
27+
render: function() {
28+
return (
29+
<div>type safety</div>
30+
);
31+
},
32+
});
33+
34+
var thatPropTypes = {};
35+
36+
var Component2 = React.createClass({
37+
propTypes: thatPropTypes,
38+
39+
render: function() {
40+
return (
41+
<div>type safety</div>
42+
);
43+
},
44+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* @flow */
2+
3+
var React = require('react');
4+
var {PropTypes} = React;
5+
6+
var myUnionPropType = PropTypes.oneOfType([
7+
PropTypes.string,
8+
PropTypes.number,
9+
PropTypes.instanceOf(Message),
10+
]);
11+
12+
var spreadMe = {
13+
optionalArray: PropTypes.array,
14+
optionalBool: PropTypes.bool,
15+
};
16+
17+
var optionalFuncShortHand = PropTypes.func;
18+
19+
class Component extends React.Component {
20+
static propTypes = Object.assign({}, {
21+
...spreadMe,
22+
optionalFuncShortHand,
23+
optionalNumber: PropTypes.number,
24+
optionalObject: PropTypes.object,
25+
});
26+
27+
render() {
28+
return (
29+
<div>type safety</div>
30+
);
31+
}
32+
}
33+
34+
var thatPropTypes = {};
35+
36+
class Component2 extends React.Component {
37+
static propTypes = thatPropTypes;
38+
39+
render() {
40+
return (
41+
<div>type safety</div>
42+
);
43+
}
44+
}

transforms/__tests__/class-test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ const pureMixinAlternativeOption = {
1818

1919
defineTest(__dirname, 'class');
2020
defineTest(__dirname, 'class', pureMixinAlternativeOption, 'class-test2');
21-
defineTest(__dirname, 'class', null, 'export-default-class');
21+
defineTest(__dirname, 'class', { flow: true }, 'export-default-class');
2222
defineTest(__dirname, 'class', pureMixinAlternativeOption, 'class-pure-mixin1');
23-
defineTest(__dirname, 'class', null, 'class-pure-mixin2');
24-
defineTest(__dirname, 'class', null, 'class-initial-state');
25-
defineTest(__dirname, 'class', null, 'class-property-field');
26-
defineTest(__dirname, 'class', { flow: true }, 'class-proptypes');
23+
defineTest(__dirname, 'class', { flow: true }, 'class-pure-mixin2');
24+
defineTest(__dirname, 'class', { flow: true }, 'class-initial-state');
25+
defineTest(__dirname, 'class', { flow: true }, 'class-property-field');
26+
defineTest(__dirname, 'class', { flow: true }, 'class-flow1');
27+
defineTest(__dirname, 'class', { flow: true }, 'class-flow2');
28+
defineTest(__dirname, 'class', { flow: true }, 'class-flow3');
29+
defineTest(__dirname, 'class', { flow: true }, 'class-flow4');

0 commit comments

Comments
 (0)