Skip to content

Commit 94bc145

Browse files
tquetano-netflixoliviertassinari
authored andcommitted
safer type checking (#179)
* safer type checking Check for the existence of `node.property` before comparing `node.property.name` * add test for fix case In the scenario where you are importing from another file that has a `createClass` method with no name associated (such as a React abstraction), this can blow up if you have a custom `createReactClassName`. * make test more realistic
1 parent b161c72 commit 94bc145

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ export default function(api) {
224224

225225
return (
226226
currentNode.get('callee').node.name === globalOptions.createReactClassName ||
227-
currentNode.get('callee').node.property.name === 'createClass'
227+
(currentNode.get('callee').node.property &&
228+
currentNode.get('callee').node.property.name === 'createClass')
228229
)
229230
})
230231

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var { createClass } = require('./notReact')
2+
var PropTypes = require('prop-types')
3+
4+
var Class1 = createClass({
5+
displayName: 'Class1',
6+
propTypes: {
7+
foo: PropTypes.string,
8+
},
9+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var {
2+
createClass
3+
} = require('./notReact');
4+
5+
var Class1 = createClass({
6+
displayName: 'Class1'
7+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var createClass = a => a;
2+
3+
module.exports {
4+
createClass
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"createReactClassName": "createClass"
3+
}

0 commit comments

Comments
 (0)