diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a7e1d1553..985e31b716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,15 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed * [`function-component-definition`], [`boolean-prop-naming`], [`jsx-first-prop-new-line`], [`jsx-props-no-multi-spaces`], `propTypes`: use type args ([#3629][] @HenryBrown0) +* JSX pragma: fail gracefully ([#3632][] @ljharb) ### Changed * [Tests] add @typescript-eslint/parser v6 ([#3629][] @HenryBrown0) * [Tests] add @typescript-eslint/parser v7 and v8 ([#3629][] @hampustagerud) * [Docs] [`no-danger`]: update broken link ([#3817][] @lucasrmendonca) +[#3632]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3632 + [#3629]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3629 [#3817]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3817 [#3807]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3807 diff --git a/lib/util/pragma.js b/lib/util/pragma.js index 4114442d05..be96c189b6 100644 --- a/lib/util/pragma.js +++ b/lib/util/pragma.js @@ -62,7 +62,8 @@ function getFromContext(context) { } if (!JS_IDENTIFIER_REGEX.test(pragma)) { - throw new Error(`React pragma ${pragma} is not a valid identifier`); + console.warn(`React pragma ${pragma} is not a valid identifier`); + return 'React'; } return pragma; } diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index ac592361cd..84a50c9187 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -505,6 +505,14 @@ ruleTester.run('boolean-prop-naming', rule, { options: [{ rule: '(^(is|has|should|without)[A-Z]([A-Za-z0-9]?)+|disabled|required|checked|defaultChecked)' }], features: ['types'], }, + { + code: ` + // Strip @jsx comments, see https://github.com/microsoft/fluentui/issues/29126 + const resultCode = result.code + .replace('/** @jsxRuntime automatic */', '') + .replace('/** @jsxImportSource @fluentui/react-jsx-runtime */', ''); + `, + }, ]), invalid: parsers.all([ diff --git a/tests/util/pragma.js b/tests/util/pragma.js index 988354a5fc..475f97aaa6 100644 --- a/tests/util/pragma.js +++ b/tests/util/pragma.js @@ -56,9 +56,9 @@ describe('pragma', () => { ); }); - it('throws an error if the pragma is invalid', () => { + it('returns React if the pragma is invalid', () => { const code = '/* @jsx invalid-jsx-pragma */'; - assert.throws(() => getFromContext(fakeContext(code))); + assert.equal(getFromContext(fakeContext(code)), 'React'); }); }); });