-
Notifications
You must be signed in to change notification settings - Fork 294
Class transform with property initializer #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
2a509a6
added boilerplates
eacb1e1
renamed to avoid conflict
2c5b461
added a failing test
6d9e3cb
added initial working version
00790d4
added support for mixins
93e5931
added a test for ES6 export
a151336
renamed liftGetInitialState
20aafc3
changed to update the existing one instead
c2bda71
fixed arrow function return type
f5f6da0
temporally added npm shrinkwrap
f70dad2
changed initial state transformation
c136e9c
added react-addons-pure-render-mixin support
311f472
Revert "temporally added npm shrinkwrap"
747dc5b
dont sort and bind everything
c7136e2
prune unused requires safely and add support for primitives as class …
d4faea4
updated README
cb88509
updated constructor args (only use props/context when needed)
011371d
added support for static methods
c4c3c1a
dont bind getChildContext
3936f55
handle constructor arguments properly
ada3fb8
fixed incorrect behavior when mixins is a non-array value
0cfad0a
fix early returns in getInitialState
84f8b71
merged master and upgraded deps
5f7b1b2
WIP flow transformation; switched parser to Flow
a7f71a3
flow works now
231f629
added support for flow property initializers
b8bb77a
better way to detect early returns in getInitialState
e00677f
bail out if user uses getInitialState or getDefaultProps elsewhere
59e3671
bail out if arguments is found
4f64cc2
defer state property initializer evaluation when necessary
d67b6a8
no shadowing in constructor
3cc6d71
handle inner function declarations in getInitialState correctly
f06bcd6
fix lint errors
53730d9
displayName shouldn't show up twice
19b611a
fixed anonymous createClass
b86a89d
covered more flow edge cases
595bb97
handle nullable prop types correctly
5b058f8
always print parens for single arg arrow functions
b532b52
fixed edge case when class spec is not an object expression
da84faf
support literal keys in prop types
7214e92
added TypeParameter and NullTypeAnnotation to ast-types
bb15c72
renamed recast option to flowObjectCommas
9f1702b
no trailing comma for single-line flow object types
d7083fe
catch edge case where React.createClass() is called with nothing
ef23055
improved the logic of repositioning `state` property
46d13c0
added `pure-component` option
82d4a52
updated npm-shrinkwrap
f00fbb0
rename this.context to context in constructor
667e592
fixed how we identify shadowing issues
8b15535
updated README.md
953386a
use FlowFixMe for unrecognizable types
3e62530
retain getInitialState()'s return type when possible
3f700c1
stricter checking of referencing APIs that will be removed
51494ac
optional !== nullable
ab1e1a7
support void (undefined) in PropTypes.oneOf()
62978f4
annotate state type when it's inlined in the constructor
ee36b61
added 'remove-runtime-proptypes' option
1011552
changed inexplicit any to FlowFixMe
847de6d
Redesigned the way we start modding components.
b65424c
fixed default and rest params
738558c
retain top comments when pure-render-mixin is the first node of the body
3956765
fixed trailing comma for func rest params; updated recast
c39d3f7
handle top comments better
c02901c
OtherClass.getDefaultProps() -> OtherClass.defaultProps
1e9204b
updated README
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
|
||
var React = require('React'); | ||
var ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin'); | ||
var FooBarMixin = require('FooBarMixin'); | ||
|
||
var ComponentWithNonSimpleInitialState = React.createClass({ | ||
statics: { | ||
iDontKnowWhyYouNeedThis: true, // but comment it | ||
foo: 'bar', | ||
}, | ||
|
||
getInitialState: function() { | ||
return { | ||
counter: this.props.initialNumber + 1, | ||
}; | ||
}, | ||
|
||
render: function() { | ||
return ( | ||
<div>{this.state.counter}</div> | ||
); | ||
}, | ||
}); | ||
|
||
// Comment | ||
module.exports = React.createClass({ | ||
propTypes: { | ||
foo: React.PropTypes.bool, | ||
}, | ||
|
||
getDefaultProps: function() { | ||
return { | ||
foo: 12, | ||
}; | ||
}, | ||
|
||
getInitialState: function() { // non-simple getInitialState | ||
var data = 'bar'; | ||
return { | ||
bar: data, | ||
}; | ||
}, | ||
|
||
render: function() { | ||
return <div />; | ||
}, | ||
}); | ||
|
||
var ComponentWithOnlyPureRenderMixin = React.createClass({ | ||
mixins: [ReactComponentWithPureRenderMixin], | ||
|
||
getInitialState: function() { | ||
return { | ||
counter: this.props.initialNumber + 1, | ||
}; | ||
}, | ||
|
||
render: function() { | ||
return ( | ||
<div>{this.state.counter}</div> | ||
); | ||
}, | ||
}); | ||
|
||
var ComponentWithInconvertibleMixins = React.createClass({ | ||
mixins: [ReactComponentWithPureRenderMixin, FooBarMixin], | ||
|
||
getInitialState: function() { | ||
return { | ||
counter: this.props.initialNumber + 1, | ||
}; | ||
}, | ||
|
||
render: function() { | ||
return ( | ||
<div>{this.state.counter}</div> | ||
); | ||
}, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t forget to remove this TODO 😉