Skip to content

Commit 011371d

Browse files
author
Keyan Zhang
committed
added support for static methods
1 parent cb88509 commit 011371d

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

transforms/__testfixtures__/class-test2.input.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ var ComponentWithNonSimpleInitialState = React.createClass({
88
statics: {
99
iDontKnowWhyYouNeedThis: true, // but comment it
1010
foo: 'bar',
11+
dontBindMe: function(count: number): any {
12+
return this;
13+
},
1114
},
1215

1316
getInitialState: function() {

transforms/__testfixtures__/class-test2.output.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class ComponentWithNonSimpleInitialState extends React.Component {
88
static iDontKnowWhyYouNeedThis = true; // but comment it
99
static foo = 'bar';
1010

11+
static dontBindMe(count: number): any {
12+
return this;
13+
}
14+
1115
constructor(props) {
1216
super(props);
1317

transforms/__testfixtures__/class.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MyComponent2 extends React.Component {
3535

3636
class MyComponent3 extends React.Component {
3737
static someThing = 10;
38-
static funcThatDoesNothing = function(): void {};
38+
static funcThatDoesNothing(): void {}
3939

4040
static propTypes = {
4141
highlightEntities: React.PropTypes.bool,

transforms/class.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,23 @@ module.exports = (file, api, options) => {
432432
), {comments});
433433
};
434434

435-
const createStaticClassProperty = staticProperty =>
436-
withComments(j.classProperty(
435+
const createStaticClassProperty = staticProperty => {
436+
if (staticProperty.value.type === 'FunctionExpression') {
437+
return withComments(j.methodDefinition(
438+
'method',
439+
j.identifier(staticProperty.key.name),
440+
staticProperty.value,
441+
true
442+
), staticProperty);
443+
}
444+
445+
return withComments(j.classProperty(
437446
j.identifier(staticProperty.key.name),
438447
staticProperty.value,
439448
null,
440449
true
441450
), staticProperty);
451+
};
442452

443453
const createStaticClassProperties = statics =>
444454
statics.map(createStaticClassProperty);

0 commit comments

Comments
 (0)