mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Update 9 validation passes to record errors directly on fn.env instead of returning Result<void, CompilerError>: - validateHooksUsage - validateNoCapitalizedCalls (also changed throwInvalidReact to recordError) - validateUseMemo - dropManualMemoization - validateNoRefAccessInRender - validateNoSetStateInRender - validateNoImpureFunctionsInRender - validateNoFreezingKnownMutableFunctions - validateExhaustiveDependencies Each pass now calls fn.env.recordErrors() instead of returning errors.asResult(). Pipeline.ts call sites updated to remove tryRecord() wrappers and .unwrap(). --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/35875). * #35888 * #35884 * #35883 * #35882 * #35881 * #35880 * #35879 * #35878 * #35877 * #35876 * __->__ #35875
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
import {
|
|
ErrorCategory,
|
|
getRuleForCategory,
|
|
} from 'babel-plugin-react-compiler/src/CompilerError';
|
|
import {normalizeIndent, makeTestCaseError, testRule} from './shared-utils';
|
|
import {allRules} from '../src/rules/ReactCompilerRule';
|
|
|
|
testRule(
|
|
'no-capitalized-calls',
|
|
allRules[getRuleForCategory(ErrorCategory.CapitalizedCalls).name].rule,
|
|
{
|
|
valid: [],
|
|
invalid: [
|
|
{
|
|
name: 'Simple violation',
|
|
code: normalizeIndent`
|
|
import Child from './Child';
|
|
function Component() {
|
|
return <>
|
|
{Child()}
|
|
</>;
|
|
}
|
|
`,
|
|
errors: [
|
|
makeTestCaseError(
|
|
'Capitalized functions are reserved for components',
|
|
),
|
|
],
|
|
},
|
|
{
|
|
name: 'Method call violation',
|
|
code: normalizeIndent`
|
|
import myModule from './MyModule';
|
|
function Component() {
|
|
return <>
|
|
{myModule.Child()}
|
|
</>;
|
|
}
|
|
`,
|
|
errors: [
|
|
makeTestCaseError(
|
|
'Capitalized functions are reserved for components',
|
|
),
|
|
],
|
|
},
|
|
{
|
|
name: 'Multiple diagnostics within the same function are surfaced',
|
|
code: normalizeIndent`
|
|
import Child1 from './Child1';
|
|
import MyModule from './MyModule';
|
|
function Component() {
|
|
return <>
|
|
{Child1()}
|
|
{MyModule.Child2()}
|
|
</>;
|
|
}`,
|
|
errors: [
|
|
makeTestCaseError(
|
|
'Capitalized functions are reserved for components',
|
|
),
|
|
makeTestCaseError(
|
|
'Capitalized functions are reserved for components',
|
|
),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
);
|