Skip to content

Commit c2bda71

Browse files
author
Keyan Zhang
committed
fixed arrow function return type
1 parent 20aafc3 commit c2bda71

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

transforms/__testfixtures__/class.input.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ var MyComponent = React.createClass({
2323

2424
// Class comment
2525
var MyComponent2 = React.createClass({
26-
getDefaultProps: function() {
26+
getDefaultProps: function(): Object {
2727
return {a: 1};
2828
},
29-
foo: function() { // flow annotations dont work for now
29+
foo: function(): void {
3030
pass(this.foo);
3131
this.forceUpdate();
3232
},
@@ -61,11 +61,12 @@ var MyComponent3 = React.createClass({
6161
};
6262
},
6363

64-
_renderText: function(text: string) { // TODO no return type yet
64+
// comment here
65+
_renderText: function(text: string): ReactElement<any> { // say something
6566
return <Text text={text} />;
6667
},
6768

68-
_renderImageRange: function(text: string, range) { // TODO no return type yet
69+
_renderImageRange: function(text: string, range): ReactElement<any> {
6970
var image = range.image;
7071
if (image) {
7172
return (
@@ -82,7 +83,7 @@ var MyComponent3 = React.createClass({
8283
dontAutobindMe: function(): number { return 12; },
8384

8485
// Function comment
85-
_renderRange: function(text: string, range, bla: Promise<string>) {
86+
_renderRange: function(text: string, range, bla: Promise<string>): ReactElement<any> {
8687
var self = this;
8788

8889
self.dontAutobindMe();

transforms/__testfixtures__/class.output.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MyComponent extends React.Component {
2727
class MyComponent2 extends React.Component {
2828
static defaultProps = {a: 1};
2929

30-
foo = () => { // flow annotations dont work for now
30+
foo = (): void => {
3131
pass(this.foo);
3232
this.forceUpdate();
3333
};
@@ -63,14 +63,15 @@ class MyComponent3 extends React.Component {
6363
};
6464
}
6565

66-
_renderText = (text: string) => { // TODO no return type yet
66+
// comment here
67+
_renderText = (text: string): ReactElement<any> => { // say something
6768
return <Text text={text} />;
6869
};
6970

7071
autobindMe = () => {};
7172

7273
// Function comment
73-
_renderRange = (text: string, range, bla: Promise<string>) => {
74+
_renderRange = (text: string, range, bla: Promise<string>): ReactElement<any> => {
7475
var self = this;
7576

7677
self.dontAutobindMe();
@@ -95,7 +96,7 @@ class MyComponent3 extends React.Component {
9596
return text;
9697
};
9798

98-
_renderImageRange(text: string, range) { // TODO no return type yet
99+
_renderImageRange(text: string, range): ReactElement<any> {
99100
var image = range.image;
100101
if (image) {
101102
return (

transforms/class.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,19 @@ module.exports = (file, api, options) => {
352352
];
353353
};
354354

355+
const copyReturnType = (to, from) => {
356+
to.returnType = from.returnType;
357+
return to;
358+
};
359+
355360
const createArrowFunctionExpression = fn =>
356-
j.arrowFunctionExpression(
361+
copyReturnType(j.arrowFunctionExpression(
357362
fn.params,
358363
fn.body,
359364
false
360-
);
365+
), fn);
361366

362-
const createArrowPropertyFromMethod = method => // TODO fix flow annotations
367+
const createArrowPropertyFromMethod = method =>
363368
withComments(j.classProperty(
364369
j.identifier(method.key.name),
365370
createArrowFunctionExpression(method.value),

0 commit comments

Comments
 (0)