diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e89710802..0cc3999fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`no-unknown-property`]: use a better regex to avoid a crash ([#3666][] @ljharb @SCH227) * [`prop-types`]: handle nested forwardRef + memo ([#3679][] @developer-bandi) * [`no-unknown-property`]: add `fetchPriority` ([#3697][] @SevereCloud) +* [`forbid-elements`]: prevent a crash on `createElement()` ([#3632][] @ljharb) ### Changed * [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0) @@ -56,6 +57,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange [#3638]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3638 [#3634]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3634 [#3633]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3633 +[#3632]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3632 [#3630]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3630 [#3626]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3626 [#3623]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3623 diff --git a/lib/rules/forbid-elements.js b/lib/rules/forbid-elements.js index 7da8f89f42..c7f978a164 100644 --- a/lib/rules/forbid-elements.js +++ b/lib/rules/forbid-elements.js @@ -99,6 +99,10 @@ module.exports = { } const argument = node.arguments[0]; + if (!argument) { + return; + } + const argType = argument.type; if (argType === 'Identifier' && /^[A-Z_]/.test(argument.name)) { diff --git a/tests/lib/rules/forbid-elements.js b/tests/lib/rules/forbid-elements.js index 927f7bd97f..0a80c3f853 100644 --- a/tests/lib/rules/forbid-elements.js +++ b/tests/lib/rules/forbid-elements.js @@ -82,6 +82,9 @@ ruleTester.run('forbid-elements', rule, { code: 'React.createElement(1)', options: [{ forbid: ['button'] }], }, + { + code: 'React.createElement()', + }, ]), invalid: parsers.all([