Files
test-repo/tests/flow/new_react/classes.js
T
Simon Lydell dc93bdc983 Sync the Flow tests (#1163)
* Extract custom tests from tests/flow/

Approach:

1. Remove all .js files in tests/flow except .snap.js files.
2. Copy over all .js files from tests/ in the flow repo.
3. Go through the diff looking for deletions.
   - It was easy to see which deletions were due to changes in the tests
     due to updates in the flow repo.
   - For the rest of the deletions, I used `git blame` to verify that
     they had been added by us since the flow tests were copied over.

This makes tests/flow/ simply a copy of the tests from the flow repo,
making it easier to sync with the upstream flow tests in the future.

* Add a script for syncing the flow tests

* Sync the flow tests
2017-04-08 07:52:38 -07:00

84 lines
1.3 KiB
JavaScript

var React = require('React');
type DefaultProps = { };
type Props = { x: number };
type State = { y: number };
class Foo extends React.Component {
props: Props;
state: State;
static defaultProps: DefaultProps;
is_mounted: boolean;
static bar(): void {}
qux(): void {
var _: string = this.props.x;
}
constructor(props) {
super(props);
this.state = { y: "" };
}
setState(o: { y_: string }): void { }
componentDidMount(): void {
this.is_mounted = true;
}
componentWillReceiveProps(
nextProps: Object,
nextContext: any
): void {
this.qux();
}
}
Foo.defaultProps = 0;
var foo: $jsx<number> = <Foo/>;
Foo.bar();
var FooLegacy = React.createClass({
is_mounted: (undefined: ?boolean),
propTypes: {
x: React.PropTypes.number.isRequired
},
getDefaultProps(): DefaultProps { return {} },
statics: {
bar(): void {}
},
qux(): void {
var _: string = this.props.x;
},
getInitialState(): { y: string } {
return { y: "" };
},
setState(o: { y_: string }): void { },
componentDidMount(): void {
this.is_mounted = true;
},
componentWillReceiveProps(
nextProps: Object,
nextContext: any
): void {
this.qux();
},
});
FooLegacy.defaultProps = 0;
var foo_legacy: $jsx<number> = <FooLegacy/>;
FooLegacy.bar();