[compiler] Emit CompileSkip before CompileSuccess event (#33012)
Previously the CompileSuccess event would emit first before CompileSkip, so the lsp's codelens would incorrectly flag skipped components/hooks (via 'use no memo') as being optimized. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33012). * __->__ #33012 * #33011 * #33010
lauren committed
Apr 24, 2025 at 13:30 UTC
9938f83ca21f6e01e31b41ce8335a4516de276d1
1 file changed
+17
-17
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts
+17
-17
@@ -469,6 +469,23 @@ export function compileProgram(
469
}
470
}
471
472
+ /**
473
+ * Otherwise if 'use no forget/memo' is present, we still run the code through the compiler
474
+ * for validation but we don't mutate the babel AST. This allows us to flag if there is an
475
+ * unused 'use no forget/memo' directive.
476
+ */
477
+ if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) {
478
+ for (const directive of optOutDirectives) {
479
+ pass.opts.logger?.logEvent(pass.filename, {
480
+ kind: 'CompileSkip',
481
+ fnLoc: fn.node.body.loc ?? null,
482
+ reason: `Skipped due to '${directive.value.value}' directive.`,
483
+ loc: directive.loc ?? null,
484
+ });
485
+ }
486
+ return null;
487
+ }
488
+
489
pass.opts.logger?.logEvent(pass.filename, {
490
kind: 'CompileSuccess',
491
fnLoc: fn.node.loc ?? null,
@@ -492,23 +509,6 @@ export function compileProgram(
509
return null;
510
}
511
495
- /**
496
- * Otherwise if 'use no forget/memo' is present, we still run the code through the compiler
497
- * for validation but we don't mutate the babel AST. This allows us to flag if there is an
498
- * unused 'use no forget/memo' directive.
499
- */
500
- if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) {
501
- for (const directive of optOutDirectives) {
502
- pass.opts.logger?.logEvent(pass.filename, {
503
- kind: 'CompileSkip',
504
- fnLoc: fn.node.body.loc ?? null,
505
- reason: `Skipped due to '${directive.value.value}' directive.`,
506
- loc: directive.loc ?? null,
507
- });
508
- }
509
- return null;
510
- }
511
-
512
if (!pass.opts.noEmit) {
513
return compileResult.compiledFn;
514
}