Skip to content

Commit f7fe38f

Browse files
committed
[Fix] jsx-key: avoid a crash on a non-array node.body
Fixes #3328
1 parent 86f17d2 commit f7fe38f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1313
* [`jsx-key`]: catch key errors inside conditional statements ([#3320][] @TildaDares)
1414
* [`display-name`]: Accept forwardRef and Memo nesting in newer React versions ([#3321][] @TildaDares)
1515
* [`jsx-key`]: avoid a crash from optional chaining from [#3320][] ([#3327][] @ljharb)
16+
* [`jsx-key`]: avoid a crash on a non-array node.body from [#3320][] ([#3328][] @ljharb)
1617

1718
### Changed
1819
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
1920
* [Tests] [`jsx-indent`], [`jsx-one-expression-per-line`]: add passing test cases ([#3314][] @ROSSROSALES)
2021
* [Refactor] `boolean-prop-naming`, `jsx-indent`: avoid assigning to arguments ([#3316][] @caroline223)
2122

23+
[#3328]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3328
2224
[#3327]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3327
2325
[#3321]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3321
2426
[#3320]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3320

lib/rules/jsx-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = {
9595
if (node.alternate) {
9696
getReturnStatements(node.alternate, returnStatements);
9797
}
98-
} else if (node.body) {
98+
} else if (Array.isArray(node.body)) {
9999
node.body.forEach((item) => {
100100
if (item.type === 'IfStatement') {
101101
getReturnStatements(item, returnStatements);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy