Skip to content

Commit fbc62b1

Browse files
authored
feat(react): Support new flow 0.53 annotations (#209)
1 parent abd2a96 commit fbc62b1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/handlers/__tests__/flowTypeHandler-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,24 @@ describe('flowTypeHandler', () => {
134134
}
135135

136136
describe('TypeAlias', () => {
137-
describe('class definition', () => {
137+
describe('class definition for flow <0.53', () => {
138138
test(
139139
propTypesSrc => statement(template('class Foo extends Component<void, Props, void> {}', propTypesSrc))
140140
);
141141
});
142142

143+
describe('class definition for flow >=0.53 without State', () => {
144+
test(
145+
propTypesSrc => statement(template('class Foo extends Component<Props> {}', propTypesSrc))
146+
);
147+
});
148+
149+
describe('class definition for flow >=0.53 with State', () => {
150+
test(
151+
propTypesSrc => statement(template('class Foo extends Component<Props, State> {}', propTypesSrc))
152+
);
153+
});
154+
143155
describe('class definition with inline props', () => {
144156
test(
145157
propTypesSrc => statement(template('class Foo extends Component { props: Props; }', propTypesSrc))

src/utils/getFlowTypeFromReactComponent.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ export default (path: NodePath): ?NodePath => {
3232
const superTypes = path.get('superTypeParameters');
3333

3434
if (superTypes.value) {
35-
typePath = superTypes.get('params').get(1);
35+
const params = superTypes.get('params');
36+
if (params.value.length === 3) {
37+
typePath = params.get(1);
38+
} else {
39+
typePath = params.get(0);
40+
}
3641
} else {
3742
const propsMemberPath = getMemberValuePath(path, 'props');
3843
if (!propsMemberPath) {

0 commit comments

Comments
 (0)