mirror of
https://github.com/facebook/react.git
synced 2026-02-22 03:42:05 +00:00
[compiler][eslint] Add donotuse flag for bailouts
---
Adding an experimental / donotuse flag for small Meta internal usecase
ghstack-source-id: 908ef1e150
Pull Request resolved: https://github.com/facebook/react/pull/30342
This commit is contained in:
@@ -179,6 +179,26 @@ const tests: CompilerTestCases = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Test experimental/unstable report all bailouts mode",
|
||||
options: [
|
||||
{
|
||||
reportableLevels: new Set([ErrorSeverity.InvalidReact]),
|
||||
__unstable_donotuse_reportAllBailouts: true,
|
||||
},
|
||||
],
|
||||
code: normalizeIndent`
|
||||
function Foo(x) {
|
||||
var y = 1;
|
||||
return <div>{y * x}</div>;
|
||||
}`,
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
"[ReactCompilerBailout] (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (@:3:2)",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -129,6 +129,22 @@ const rule: Rule.RuleModule = {
|
||||
} else {
|
||||
reportableLevels = DEFAULT_REPORTABLE_LEVELS;
|
||||
}
|
||||
/**
|
||||
* Experimental setting to report all compilation bailouts on the compilation
|
||||
* unit (e.g. function or hook) instead of the offensive line.
|
||||
* Intended to be used when a codebase is 100% reliant on the compiler for
|
||||
* memoization (i.e. deleted all manual memo) and needs compilation success
|
||||
* signals for perf debugging.
|
||||
*/
|
||||
let __unstable_donotuse_reportAllBailouts: boolean = false;
|
||||
if (
|
||||
userOpts["__unstable_donotuse_reportAllBailouts"] != null &&
|
||||
typeof userOpts["__unstable_donotuse_reportAllBailouts"] === "boolean"
|
||||
) {
|
||||
__unstable_donotuse_reportAllBailouts =
|
||||
userOpts["__unstable_donotuse_reportAllBailouts"];
|
||||
}
|
||||
|
||||
const options: PluginOptions = {
|
||||
...parsePluginOptions(userOpts),
|
||||
...COMPILER_OPTIONS,
|
||||
@@ -139,6 +155,19 @@ const rule: Rule.RuleModule = {
|
||||
userLogger?.logEvent(filename, event);
|
||||
if (event.kind === "CompileError") {
|
||||
const detail = event.detail;
|
||||
const suggest = makeSuggestions(detail);
|
||||
if (__unstable_donotuse_reportAllBailouts && event.fnLoc != null) {
|
||||
const locStr =
|
||||
detail.loc != null && typeof detail.loc !== "symbol"
|
||||
? ` (@:${detail.loc.start.line}:${detail.loc.start.column})`
|
||||
: "";
|
||||
context.report({
|
||||
message: `[ReactCompilerBailout] ${detail.reason}${locStr}`,
|
||||
loc: event.fnLoc,
|
||||
suggest,
|
||||
});
|
||||
}
|
||||
|
||||
if (!isReportableDiagnostic(detail)) {
|
||||
return;
|
||||
}
|
||||
@@ -154,7 +183,7 @@ const rule: Rule.RuleModule = {
|
||||
context.report({
|
||||
message: detail.reason,
|
||||
loc,
|
||||
suggest: makeSuggestions(detail),
|
||||
suggest,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user