[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:
Mofei Zhang
2023-08-17 11:03:20 -04:00
parent 28688ade9f
commit 2b4a1d86ff
@@ -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);
}