Skip to content

Commit a5dc2a2

Browse files
committed
[Fix] jsx-key: avoid a crash
Fixes #3220
1 parent c605fd8 commit a5dc2a2

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Fixed
99
* [`jsx-key`]: prevent false "missing array key" warning ([#3215][] @ljharb)
1010
* [`jsx-indent`]: avoid checking returns sans jsx ([#3218][] @ljharb)
11+
* [`jsx-key`]: avoid a crash ([#3220][] @ljharb)
1112

13+
[#3220]: https://github.com/yannickcr/eslint-plugin-react/issues/3220
1214
[#3218]: https://github.com/yannickcr/eslint-plugin-react/issues/3218
1315
[#3215]: https://github.com/yannickcr/eslint-plugin-react/issues/3215
1416

lib/rules/jsx-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module.exports = {
108108

109109
return {
110110
'ArrayExpression, JSXElement > JSXElement'(node) {
111-
const jsx = (node.type === 'ArrayExpression' ? node.elements : node.parent.children).filter((x) => x.type === 'JSXElement');
111+
const jsx = (node.type === 'ArrayExpression' ? node.elements : node.parent.children).filter((x) => x && x.type === 'JSXElement');
112112
if (jsx.length === 0) {
113113
return;
114114
}

tests/lib/rules/jsx-key.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ ruleTester.run('jsx-key', rule, {
115115
`,
116116
features: ['types'],
117117
},
118+
{
119+
code: `
120+
// testrule.jsx
121+
const trackLink = () => {};
122+
const getAnalyticsUiElement = () => {};
123+
124+
const onTextButtonClick = (e, item) => trackLink([, getAnalyticsUiElement(item), item.name], e);
125+
`,
126+
},
118127
]),
119128
invalid: parsers.all([
120129
{

0 commit comments

Comments
 (0)