Skip to content

Commit 1f60a41

Browse files
committed
[compiler][eslint] Add donotuse flag for bailouts
--- Adding an experimental / donotuse flag for small Meta internal usecase ghstack-source-id: 908ef1e150c9fef1347616c9c4dc6bf3316900b0 Pull Request resolved: #30342
1 parent 735d3d2 commit 1f60a41

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ const tests: CompilerTestCases = {
179179
},
180180
],
181181
},
182+
{
183+
name: "Test experimental/unstable report all bailouts mode",
184+
options: [
185+
{
186+
reportableLevels: new Set([ErrorSeverity.InvalidReact]),
187+
__unstable_donotuse_reportAllBailouts: true,
188+
},
189+
],
190+
code: normalizeIndent`
191+
function Foo(x) {
192+
var y = 1;
193+
return <div>{y * x}</div>;
194+
}`,
195+
errors: [
196+
{
197+
message:
198+
"[ReactCompilerBailout] (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (@:3:2)",
199+
},
200+
],
201+
},
182202
],
183203
};
184204

compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ const rule: Rule.RuleModule = {
129129
} else {
130130
reportableLevels = DEFAULT_REPORTABLE_LEVELS;
131131
}
132+
/**
133+
* Experimental setting to report all compilation bailouts on the compilation
134+
* unit (e.g. function or hook) instead of the offensive line.
135+
* Intended to be used when a codebase is 100% reliant on the compiler for
136+
* memoization (i.e. deleted all manual memo) and needs compilation success
137+
* signals for perf debugging.
138+
*/
139+
let __unstable_donotuse_reportAllBailouts: boolean = false;
140+
if (
141+
userOpts["__unstable_donotuse_reportAllBailouts"] != null &&
142+
typeof userOpts["__unstable_donotuse_reportAllBailouts"] === "boolean"
143+
) {
144+
__unstable_donotuse_reportAllBailouts =
145+
userOpts["__unstable_donotuse_reportAllBailouts"];
146+
}
147+
132148
const options: PluginOptions = {
133149
...parsePluginOptions(userOpts),
134150
...COMPILER_OPTIONS,
@@ -139,6 +155,19 @@ const rule: Rule.RuleModule = {
139155
userLogger?.logEvent(filename, event);
140156
if (event.kind === "CompileError") {
141157
const detail = event.detail;
158+
const suggest = makeSuggestions(detail);
159+
if (__unstable_donotuse_reportAllBailouts && event.fnLoc != null) {
160+
const locStr =
161+
detail.loc != null && typeof detail.loc !== "symbol"
162+
? ` (@:${detail.loc.start.line}:${detail.loc.start.column})`
163+
: "";
164+
context.report({
165+
message: `[ReactCompilerBailout] ${detail.reason}${locStr}`,
166+
loc: event.fnLoc,
167+
suggest,
168+
});
169+
}
170+
142171
if (!isReportableDiagnostic(detail)) {
143172
return;
144173
}
@@ -154,7 +183,7 @@ const rule: Rule.RuleModule = {
154183
context.report({
155184
message: detail.reason,
156185
loc,
157-
suggest: makeSuggestions(detail),
186+
suggest,
158187
});
159188
}
160189
}

0 commit comments

Comments
 (0)