diff --git a/CHANGELOG.md b/CHANGELOG.md index 67bfeae71c..7891e9d2ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed * [`jsx-key`]: prevent false "missing array key" warning ([#3215][] @ljharb) * [`jsx-indent`]: avoid checking returns sans jsx ([#3218][] @ljharb) +* [`jsx-key`]: avoid a crash ([#3220][] @ljharb) +[#3220]: https://github.com/yannickcr/eslint-plugin-react/issues/3220 [#3218]: https://github.com/yannickcr/eslint-plugin-react/issues/3218 [#3215]: https://github.com/yannickcr/eslint-plugin-react/issues/3215 diff --git a/lib/rules/jsx-key.js b/lib/rules/jsx-key.js index 7216f4c413..65f9e37ea0 100644 --- a/lib/rules/jsx-key.js +++ b/lib/rules/jsx-key.js @@ -108,7 +108,7 @@ module.exports = { return { 'ArrayExpression, JSXElement > JSXElement'(node) { - const jsx = (node.type === 'ArrayExpression' ? node.elements : node.parent.children).filter((x) => x.type === 'JSXElement'); + const jsx = (node.type === 'ArrayExpression' ? node.elements : node.parent.children).filter((x) => x && x.type === 'JSXElement'); if (jsx.length === 0) { return; } diff --git a/tests/lib/rules/jsx-key.js b/tests/lib/rules/jsx-key.js index ab821418b9..04103f45df 100644 --- a/tests/lib/rules/jsx-key.js +++ b/tests/lib/rules/jsx-key.js @@ -115,6 +115,15 @@ ruleTester.run('jsx-key', rule, { `, features: ['types'], }, + { + code: ` + // testrule.jsx + const trackLink = () => {}; + const getAnalyticsUiElement = () => {}; + + const onTextButtonClick = (e, item) => trackLink([, getAnalyticsUiElement(item), item.name], e); + `, + }, ]), invalid: parsers.all([ {