Skip to content

Commit

Permalink
Fix no-danger-with-children crash with undefined (fixes #1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jul 5, 2017
1 parent 65b746e commit bef5897
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = {
const variable = variableUtil.variablesInScope(context).find(function (item) {
return item.name === props.name;
});
if (variable && variable.defs[0].node.init) {
if (variable && variable.defs.length && variable.defs[0].node.init) {

This comment has been minimized.

Copy link
@jseminck

jseminck Jul 5, 2017

Contributor

@yannickcr what about the same condition on line 41?

                    if (variable && variable.defs[0].node.init) {

Not sure when this could fail, but doesn't hurt to add the same check there?

This comment has been minimized.

Copy link
@yannickcr

yannickcr Jul 5, 2017

Author Member

You're right, I will add a check there too.

props = variable.defs[0].node.init;
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ ruleTester.run('no-danger-with-children', rule, {
},
{
code: 'React.createElement("Hello", {}, "Children");'
},
{
code: '<Hello {...undefined}>Children</Hello>'
},
{
code: 'React.createElement("Hello", undefined, "Children")'
}
],
invalid: [
Expand Down

0 comments on commit bef5897

Please sign in to comment.