Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler][eslint] Report bailout diagnostics with correct column # #30977

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,33 @@ const rule: Rule.RuleModule = {
detail.loc != null && typeof detail.loc !== 'symbol'
? ` (@:${detail.loc.start.line}:${detail.loc.start.column})`
: '';
/**
* Report bailouts with a smaller span (just the first line).
* Compiler bailout lints only serve to flag that a react function
* has not been optimized by the compiler for codebases which depend
* on compiler memo heavily for perf. These lints are also often not
* actionable.
*/
let endLoc;
if (event.fnLoc.end.line === event.fnLoc.start.line) {
endLoc = event.fnLoc.end;
} else {
endLoc = {
line: event.fnLoc.start.line,
// Babel loc line numbers are 1-indexed
column: sourceCode.split(
/\r?\n|\r|\n/g,
event.fnLoc.start.line,
)[event.fnLoc.start.line - 1].length,
};
}
const firstLineLoc = {
start: event.fnLoc.start,
end: endLoc,
};
context.report({
message: `[ReactCompilerBailout] ${detail.reason}${locStr}`,
loc: event.fnLoc,
loc: firstLineLoc,
suggest,
});
}
Expand Down