Skip to content

Commit 9938f83

Browse files
authored
[compiler] Emit CompileSkip before CompileSuccess event (facebook#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). * __->__ facebook#33012 * facebook#33011 * facebook#33010
1 parent 2af218a commit 9938f83

File tree

1 file changed

+17
-17
lines changed
  • compiler/packages/babel-plugin-react-compiler/src/Entrypoint

1 file changed

+17
-17
lines changed

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,23 @@ export function compileProgram(
469469
}
470470
}
471471

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+
472489
pass.opts.logger?.logEvent(pass.filename, {
473490
kind: 'CompileSuccess',
474491
fnLoc: fn.node.loc ?? null,
@@ -492,23 +509,6 @@ export function compileProgram(
492509
return null;
493510
}
494511

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-
512512
if (!pass.opts.noEmit) {
513513
return compileResult.compiledFn;
514514
}

0 commit comments

Comments
 (0)