Skip to content

Commit fe5594b

Browse files
author
Yannick Croissant
committed
Fix no-danger-with-children crash with spread on global variables (fixes #921)
1 parent 1df6118 commit fe5594b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/rules/no-danger-with-children.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = {
5656
return attributes.find(function (attribute) {
5757
if (attribute.type === 'JSXSpreadAttribute') {
5858
var variable = findSpreadVariable(attribute.argument.name);
59-
if (variable && variable.defs[0].node.init) {
59+
if (variable && variable.defs.length && variable.defs[0].node.init) {
6060
return findObjectProp(variable.defs[0].node.init, propName);
6161
}
6262
}

tests/lib/rules/no-danger-with-children.js

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ ruleTester.run('no-danger-with-children', rule, {
3030
code: '<div>Children</div>',
3131
parserOptions: parserOptions
3232
},
33+
{
34+
code: '<div {...props} />',
35+
parserOptions: parserOptions,
36+
globals: {
37+
props: true
38+
}
39+
},
3340
{
3441
code: '<div dangerouslySetInnerHTML={{ __html: "HTML" }} />',
3542
parserOptions: parserOptions

0 commit comments

Comments
 (0)