From f7fe38f7ac8e3dfde4d0befe17b5c28ff5fed55a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 11 Jul 2022 08:02:21 -0700 Subject: [PATCH] [Fix] `jsx-key`: avoid a crash on a non-array node.body Fixes #3328 --- CHANGELOG.md | 2 ++ lib/rules/jsx-key.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 300aabda17..6fa165d487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,14 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`jsx-key`]: catch key errors inside conditional statements ([#3320][] @TildaDares) * [`display-name`]: Accept forwardRef and Memo nesting in newer React versions ([#3321][] @TildaDares) * [`jsx-key`]: avoid a crash from optional chaining from [#3320][] ([#3327][] @ljharb) +* [`jsx-key`]: avoid a crash on a non-array node.body from [#3320][] ([#3328][] @ljharb) ### Changed * [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223) * [Tests] [`jsx-indent`], [`jsx-one-expression-per-line`]: add passing test cases ([#3314][] @ROSSROSALES) * [Refactor] `boolean-prop-naming`, `jsx-indent`: avoid assigning to arguments ([#3316][] @caroline223) +[#3328]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3328 [#3327]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3327 [#3321]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3321 [#3320]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3320 diff --git a/lib/rules/jsx-key.js b/lib/rules/jsx-key.js index e2aa757d3d..e3731945a8 100644 --- a/lib/rules/jsx-key.js +++ b/lib/rules/jsx-key.js @@ -95,7 +95,7 @@ module.exports = { if (node.alternate) { getReturnStatements(node.alternate, returnStatements); } - } else if (node.body) { + } else if (Array.isArray(node.body)) { node.body.forEach((item) => { if (item.type === 'IfStatement') { getReturnStatements(item, returnStatements);