-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add forwardRef as a valid component definition (#311)
* test: Add failing test case for missing definition on hoc+forwardRef * feat: Add forwardRef as a valid component definition
- Loading branch information
Showing
6 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,22 @@ | ||
|
||
import React from 'react'; | ||
import extendStyles from 'enhancers/extendStyles'; | ||
|
||
type Props = $ReadOnly<{| | ||
color?: ?string, | ||
|}>; | ||
|
||
const ColoredView = React.forwardRef((props: Props, ref) => ( | ||
<div ref={ref} style={{backgroundColor: props.color}} /> | ||
)); | ||
|
||
ColoredView.displayName = 'UncoloredView'; | ||
ColoredView.propTypes = { | ||
color: PropTypes.string.isRequired, | ||
id: PropTypes.string | ||
} | ||
ColoredView.defaultProps = { | ||
id: 'test-forward-ref-default' | ||
} | ||
|
||
module.exports = extendStyles(ColoredView); |
This file contains 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 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 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 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,34 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
import isReactModuleName from './isReactModuleName'; | ||
import match from './match'; | ||
import recast from 'recast'; | ||
import resolveToModule from './resolveToModule'; | ||
|
||
const { | ||
types: { namedTypes: types }, | ||
} = recast; | ||
|
||
/** | ||
* Returns true if the expression is a function call of the form | ||
* `React.forwardRef(...)`. | ||
*/ | ||
export default function isReactForwardRefCall(path: NodePath): boolean { | ||
if (types.ExpressionStatement.check(path.node)) { | ||
path = path.get('expression'); | ||
} | ||
|
||
if (!match(path.node, { callee: { property: { name: 'forwardRef' } } })) { | ||
return false; | ||
} | ||
const module = resolveToModule(path.get('callee', 'object')); | ||
return Boolean(module && isReactModuleName(module)); | ||
} |