main
ts 38 lines 947 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 import {
9 ErrorCategory,
10 getRuleForCategory,
11 } from 'babel-plugin-react-compiler/src/CompilerError';
12 import {normalizeIndent, testRule, makeTestCaseError} from './shared-utils';
13 import {allRules} from '../src/rules/ReactCompilerRule';
14
15 testRule(
16 'no ambiguous JSX rule',
17 allRules[getRuleForCategory(ErrorCategory.ErrorBoundaries).name].rule,
18 {
19 valid: [],
20 invalid: [
21 {
22 name: 'JSX in try blocks are warned against',
23 code: normalizeIndent`
24 function Component(props) {
25 let el;
26 try {
27 el = <Child />;
28 } catch {
29 return null;
30 }
31 return el;
32 }
33 `,
34 errors: [makeTestCaseError('Avoid constructing JSX within try/catch')],
35 },
36 ],
37 },
38 );