mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[be] Access all features flags through Environment
Most of our feature flags are accessed via the `Environment`, but a few cases have slipped in where we look at the `config` object directly. The problem is that the config object doesn't set defaults, so the check is effectively encoding what the default is. This PR moves to always accessing flags off of the environment, and adds a few flags that weren't yet defined there.
This commit is contained in:
@@ -86,13 +86,27 @@ export function* run(
|
||||
): Generator<CompilerPipelineValue, CodegenFunction> {
|
||||
const contextIdentifiers = findContextIdentifiers(func);
|
||||
const env = new Environment(config ?? null, contextIdentifiers);
|
||||
const ast = yield* runWithEnvironment(func, env);
|
||||
return ast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this is split from run() to make `config` out of scope, so that all
|
||||
* access to feature flags has to be through the Environment for consistency.
|
||||
*/
|
||||
function* runWithEnvironment(
|
||||
func: NodePath<
|
||||
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
|
||||
>,
|
||||
env: Environment
|
||||
): Generator<CompilerPipelineValue, CodegenFunction> {
|
||||
const hir = lower(func, env).unwrap();
|
||||
yield log({ kind: "hir", name: "HIR", value: hir });
|
||||
|
||||
pruneMaybeThrows(hir);
|
||||
yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
|
||||
|
||||
if (config?.inlineUseMemo) {
|
||||
if (env.inlineUseMemo) {
|
||||
inlineUseMemo(hir);
|
||||
yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
|
||||
}
|
||||
@@ -245,8 +259,8 @@ export function* run(
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
let memoizeJsxElements = config?.memoizeJsxElements ?? true;
|
||||
if (config?.enableForest) {
|
||||
let memoizeJsxElements = env.memoizeJsxElements;
|
||||
if (env.enableForest) {
|
||||
memoizeJsxElements = false;
|
||||
}
|
||||
pruneNonEscapingScopes(reactiveFunction, { memoizeJsxElements });
|
||||
@@ -279,7 +293,7 @@ export function* run(
|
||||
});
|
||||
}
|
||||
|
||||
if (config?.enableForest) {
|
||||
if (env.enableForest) {
|
||||
yield* lowerToForest(reactiveFunction);
|
||||
}
|
||||
|
||||
|
||||
@@ -258,6 +258,8 @@ export class Environment {
|
||||
enableAssumeHooksFollowRulesOfReact: boolean;
|
||||
enableTreatHooksAsFunctions: boolean;
|
||||
enableNoAliasOptimizations: boolean;
|
||||
inlineUseMemo: boolean;
|
||||
memoizeJsxElements: boolean;
|
||||
disableAllMemoization: boolean;
|
||||
enableEmitFreeze: ExternalFunction | null;
|
||||
enableMergeConsecutiveScopes: boolean;
|
||||
@@ -320,6 +322,8 @@ export class Environment {
|
||||
this.assertValidMutableRanges = config?.assertValidMutableRanges ?? false;
|
||||
this.validateNoSetStateInRender =
|
||||
config?.validateNoSetStateInRender ?? false;
|
||||
this.inlineUseMemo = config?.inlineUseMemo ?? false;
|
||||
this.memoizeJsxElements = config?.memoizeJsxElements ?? true;
|
||||
this.bailoutOnHoleyArrays = config?.bailoutOnHoleyArrays ?? false;
|
||||
this.enableForest = config?.enableForest ?? false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user