mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[be] Change validate functions to not return unnecessary Result
These validations needs to be able to transitively check for violations within function expressions, without immediately erroring. So the inner "-Impl" helpers return a Result. But the outer, exported validate functions don't need to return a Result, especially since TS has no Rust-style enforcement that return values are actually used. Unwrapping within the validation means the caller can't forget to do so and inadvertently silence the errors.
This commit is contained in:
@@ -175,11 +175,11 @@ function* runWithEnvironment(
|
||||
}
|
||||
|
||||
if (env.config.validateRefAccessDuringRender) {
|
||||
validateNoRefAccessInRender(hir).unwrap();
|
||||
validateNoRefAccessInRender(hir);
|
||||
}
|
||||
|
||||
if (env.config.validateNoSetStateInRender) {
|
||||
validateNoSetStateInRender(hir).unwrap();
|
||||
validateNoSetStateInRender(hir);
|
||||
}
|
||||
|
||||
inferReactivePlaces(hir);
|
||||
|
||||
+2
-4
@@ -24,11 +24,9 @@ import { Err, Ok, Result } from "../Utils/Result";
|
||||
* Validates that a function does not access a ref value during render. This includes a partial check
|
||||
* for ref values which are accessed indirectly via function expressions.
|
||||
*/
|
||||
export function validateNoRefAccessInRender(
|
||||
fn: HIRFunction
|
||||
): Result<void, CompilerError> {
|
||||
export function validateNoRefAccessInRender(fn: HIRFunction): void {
|
||||
const refAccessingFunctions: Set<IdentifierId> = new Set();
|
||||
return validateNoRefAccessInRenderImpl(fn, refAccessingFunctions);
|
||||
validateNoRefAccessInRenderImpl(fn, refAccessingFunctions).unwrap();
|
||||
}
|
||||
|
||||
function validateNoRefAccessInRenderImpl(
|
||||
|
||||
+2
-4
@@ -39,11 +39,9 @@ import { Err, Ok, Result } from "../Utils/Result";
|
||||
* y();
|
||||
* ```
|
||||
*/
|
||||
export function validateNoSetStateInRender(
|
||||
fn: HIRFunction
|
||||
): Result<void, CompilerError> {
|
||||
export function validateNoSetStateInRender(fn: HIRFunction): void {
|
||||
const unconditionalSetStateFunctions: Set<IdentifierId> = new Set();
|
||||
return validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions);
|
||||
validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions).unwrap();
|
||||
}
|
||||
|
||||
function validateNoSetStateInRenderImpl(
|
||||
|
||||
Reference in New Issue
Block a user