mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[pipeline] Recognize "use no forget" directive
---
Add "use no forget", not gated behind a feature flag for simplicity ("use no
forget" should always tell Forget to not compile a component, right?)
This commit is contained in:
@@ -45,6 +45,15 @@ function hasAnyUseForgetDirectives(directives: t.Directive[]): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasAnyUseNoForgetDirectives(directives: t.Directive[]): boolean {
|
||||
for (const directive of directives) {
|
||||
if (directive.value.value === "use no forget") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the Compiler pipeline and mutates the source AST to include the newly compiled function.
|
||||
* Returns a boolean denoting if the AST was mutated or not.
|
||||
@@ -305,6 +314,13 @@ function shouldVisitNode(
|
||||
fn: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression>,
|
||||
pass: CompilerPass
|
||||
): boolean {
|
||||
if (fn.node.body.type === "BlockStatement") {
|
||||
const shouldSkip = hasAnyUseNoForgetDirectives(fn.node.body.directives);
|
||||
if (shouldSkip) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (pass.opts.enableOnlyOnReactScript && fn.isFunctionDeclaration()) {
|
||||
return isComponentDeclaration(fn.node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user