-
-
Notifications
You must be signed in to change notification settings - Fork 301
Stateless Components #28
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
Changes from 7 commits
fade574
46fe2e7
f1ff543
90fd1ef
2b944a3
fdabdfd
e4c867c
421506e
a0e3623
0a55372
5cf5c17
6698e23
336890a
65373f5
2d821cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
import isReactComponentClass from '../utils/isReactComponentClass'; | ||
import isReactCreateClassCall from '../utils/isReactCreateClassCall'; | ||
import isStatelessComponent from '../utils/isStatelessComponent'; | ||
import normalizeClassDefinition from '../utils/normalizeClassDefinition'; | ||
import resolveToValue from '../utils/resolveToValue'; | ||
|
||
|
@@ -34,7 +35,19 @@ export default function findAllReactCreateClassCalls( | |
return false; | ||
} | ||
|
||
function statelessVisitor(path) { | ||
if (isStatelessComponent(path)) { | ||
// TODO: normalizeStatelessDefinition to pick up propTypes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done right? (because we use a different way to resolve this information) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why yes I do believe it is! |
||
definitions.push(path); | ||
} | ||
return false; | ||
} | ||
|
||
recast.visit(ast, { | ||
visitFunctionDeclaration: statelessVisitor, | ||
visitFunctionExpression: statelessVisitor, | ||
visitProperty: statelessVisitor, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this, do we? What case does this capture which isn't captured otherwise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this as part of supporting some of the permutations also being added to gaearon/babel-plugin-react-transform; namely this format: https://github.com/gaearon/babel-plugin-react-transform/pull/34/files#diff-9d6f6ff3fa6b5b63c09190bd7a2efb95R15 Honestly I’m not sure if that is captured or handled correctly yet. 😇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be handled by the other visitors since methods are just represented as function expressions in the AST. On Oct 7, 2015, at 12:51 PM, Dustan Kasten <[email protected]mailto:[email protected]> wrote: In src/resolver/findAllComponentDefinitions.jshttps://github.com//pull/28#discussion_r41437429:
I added this as part of supporting some of the permutations also being added to gaearon/babel-plugin-react-transform; namely this format: https://github.com/gaearon/babel-plugin-react-transform/pull/34/files#diff-9d6f6ff3fa6b5b63c09190bd7a2efb95R15 Honestly I’m not sure if that is captured or handled correctly yet. [:innocent:] — |
||
visitArrowFunctionExpression: statelessVisitor, | ||
visitClassExpression: classVisitor, | ||
visitClassDeclaration: classVisitor, | ||
visitCallExpression: function(path) { | ||
|
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.
This function for this isn’t quite recursive enough. While all of these resolve as expected, the following two cases do not resolve correctly yet:
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.
This works like a champ.