mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add config option to ignore 'use no forget' directives
This will let us test without taking into account the existing 'use no forget' directives to better understand what validations we may need to build. There are two other files that look for this directive that do not seem to take compiler options: 1. https://github.com/facebook/react-forget/blob/408617ec8a5caa815f61d4204cb3fec0775593ca/react/scripts/babel/transform-forget.js#L25 2. https://github.com/facebook/react-forget/blob/408617ec8a5caa815f61d4204cb3fec0775593ca/packages/babel-plugin-react-forget/scripts/jest/makeTransform.ts#L119 Do I need to do anything for those?
This commit is contained in:
@@ -51,13 +51,15 @@ function findDirectiveEnablingMemoization(
|
||||
}
|
||||
|
||||
function findDirectiveDisablingMemoization(
|
||||
directives: t.Directive[]
|
||||
directives: t.Directive[],
|
||||
options: PluginOptions
|
||||
): t.Directive | null {
|
||||
for (const directive of directives) {
|
||||
const directiveValue = directive.value.value;
|
||||
if (
|
||||
directiveValue === "use no forget" ||
|
||||
directiveValue === "use no memo"
|
||||
(directiveValue === "use no forget" ||
|
||||
directiveValue === "use no memo") &&
|
||||
!options.ignoreUseNoForget
|
||||
) {
|
||||
return directive;
|
||||
}
|
||||
@@ -197,12 +199,15 @@ export function compileProgram(
|
||||
program: NodePath<t.Program>,
|
||||
pass: CompilerPass
|
||||
): void {
|
||||
const options = parsePluginOptions(pass.opts);
|
||||
|
||||
// Top level "use no forget", skip this file entirely
|
||||
if (findDirectiveDisablingMemoization(program.node.directives) != null) {
|
||||
if (
|
||||
findDirectiveDisablingMemoization(program.node.directives, options) != null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const options = parsePluginOptions(pass.opts);
|
||||
const environment = parseEnvironmentConfig(pass.opts.environment ?? {});
|
||||
|
||||
/*
|
||||
@@ -400,7 +405,8 @@ function getReactFunctionType(
|
||||
if (fn.node.body.type === "BlockStatement") {
|
||||
// Opt-outs disable compilation regardless of mode
|
||||
const useNoForget = findDirectiveDisablingMemoization(
|
||||
fn.node.body.directives
|
||||
fn.node.body.directives,
|
||||
pass.opts
|
||||
);
|
||||
if (useNoForget != null) {
|
||||
pass.opts.logger?.logEvent(pass.filename, {
|
||||
|
||||
Reference in New Issue
Block a user