Invert shouldVisitNode logic
Lauren Tan committed
Aug 10, 2023 at 17:24 UTC
c3ec002d69e94b4b48ba2da41ab6cf4d2c3ff06d
1 file changed
+4
-13
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+4
-13
@@ -331,26 +331,17 @@ function shouldVisitNode(
331
pass: CompilerPass
332
): boolean {
333
if (pass.opts.enableOnlyOnReactScript) {
334
- if (!isComponentDeclaration(fn.node)) {
335
- return false;
336
- }
334
+ return isComponentDeclaration(fn.node);
335
}
336
337
if (pass.opts.enableOnlyOnUseForgetDirective) {
338
const body = fn.get("body");
341
- if (!body.isBlockStatement()) {
342
- return false;
343
- }
344
- if (!hasAnyUseForgetDirectives(body.node.directives)) {
345
- return false;
339
+ if (body.isBlockStatement()) {
340
+ return hasAnyUseForgetDirectives(body.node.directives);
341
}
342
}
343
349
- if (fn.scope.getProgramParent() !== fn.scope.parent) {
350
- return false;
351
- }
352
-
353
- return true;
344
+ return fn.scope.getProgramParent() === fn.scope.parent;
345
}
346
347
function log(error: CompilerError, filename: string | null): void {