Skip to content

Commit

Permalink
[Fix] jsx-key: avoid a crash
Browse files Browse the repository at this point in the history
Fixes #3220
  • Loading branch information
ljharb committed Feb 25, 2022
1 parent c605fd8 commit a5dc2a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-key.js
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/jsx-key.js
Expand Up @@ -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([
{
Expand Down

0 comments on commit a5dc2a2

Please sign in to comment.