Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07503b7

Browse filesBrowse files
committed
[Fix] JSX pragma: fail gracefully
Fixes #3632
1 parent bdc5791 commit 07503b7
Copy full SHA for 07503b7

File tree

Expand file treeCollapse file tree

4 files changed

+15
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+15
-3
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1111

1212
### Fixed
1313
* [`function-component-definition`], [`boolean-prop-naming`], [`jsx-first-prop-new-line`], [`jsx-props-no-multi-spaces`], `propTypes`: use type args ([#3629][] @HenryBrown0)
14+
* JSX pragma: fail gracefully ([#3632][] @ljharb)
1415

1516
### Changed
1617
* [Tests] add @typescript-eslint/parser v6 ([#3629][] @HenryBrown0)
1718
* [Tests] add @typescript-eslint/parser v7 and v8 ([#3629][] @hampustagerud)
1819
* [Docs] [`no-danger`]: update broken link ([#3817][] @lucasrmendonca)
1920

21+
[#3632]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3632
22+
2023
[#3629]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3629
2124
[#3817]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3817
2225
[#3807]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3807

‎lib/util/pragma.js

Copy file name to clipboardExpand all lines: lib/util/pragma.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ function getFromContext(context) {
6262
}
6363

6464
if (!JS_IDENTIFIER_REGEX.test(pragma)) {
65-
throw new Error(`React pragma ${pragma} is not a valid identifier`);
65+
console.warn(`React pragma ${pragma} is not a valid identifier`);
66+
return 'React';
6667
}
6768
return pragma;
6869
}

‎tests/lib/rules/boolean-prop-naming.js

Copy file name to clipboardExpand all lines: tests/lib/rules/boolean-prop-naming.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,14 @@ ruleTester.run('boolean-prop-naming', rule, {
505505
options: [{ rule: '(^(is|has|should|without)[A-Z]([A-Za-z0-9]?)+|disabled|required|checked|defaultChecked)' }],
506506
features: ['types'],
507507
},
508+
{
509+
code: `
510+
// Strip @jsx comments, see https://github.com/microsoft/fluentui/issues/29126
511+
const resultCode = result.code
512+
.replace('/** @jsxRuntime automatic */', '')
513+
.replace('/** @jsxImportSource @fluentui/react-jsx-runtime */', '');
514+
`,
515+
},
508516
]),
509517

510518
invalid: parsers.all([

‎tests/util/pragma.js

Copy file name to clipboardExpand all lines: tests/util/pragma.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ describe('pragma', () => {
5656
);
5757
});
5858

59-
it('throws an error if the pragma is invalid', () => {
59+
it('returns React if the pragma is invalid', () => {
6060
const code = '/* @jsx invalid-jsx-pragma */';
61-
assert.throws(() => getFromContext(fakeContext(code)));
61+
assert.equal(getFromContext(fakeContext(code)), 'React');
6262
});
6363
});
6464
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.