Skip to content

Commit

Permalink
fix(eslint-plugin-react-compiler): support v9 context api (#32045)
Browse files Browse the repository at this point in the history
## Summary

This change fixes a gap in the plugin's support of eslint v9. In one
place that it's using the `SourceCode` api, it's correctly considering
v9's api. But in the other place where `SourceCode` is used, it's only
using the legacy api, which was removed in v9.
  • Loading branch information
michaelfaith authored Jan 13, 2025
1 parent 6099351 commit b3a95ca
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const rule: Rule.RuleModule = {
},
create(context: Rule.RuleContext) {
// Compat with older versions of eslint
const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text;
const sourceCode = context.sourceCode ?? context.getSourceCode();
const filename = context.filename ?? context.getFilename();
const userOpts = context.options[0] ?? {};
if (
Expand Down Expand Up @@ -180,7 +180,7 @@ const rule: Rule.RuleModule = {
endLoc = {
line: event.fnLoc.start.line,
// Babel loc line numbers are 1-indexed
column: sourceCode.split(
column: sourceCode.text.split(
/\r?\n|\r|\n/g,
event.fnLoc.start.line,
)[event.fnLoc.start.line - 1].length,
Expand Down Expand Up @@ -234,7 +234,6 @@ const rule: Rule.RuleModule = {
nodeLoc: BabelSourceLocation,
suppression: string,
): boolean {
const sourceCode = context.getSourceCode();
const comments = sourceCode.getAllComments();
const flowSuppressionRegex = new RegExp(
'\\$FlowFixMe\\[' + suppression + '\\]',
Expand All @@ -254,7 +253,7 @@ const rule: Rule.RuleModule = {
if (filename.endsWith('.tsx') || filename.endsWith('.ts')) {
try {
const {parse: babelParse} = require('@babel/parser');
babelAST = babelParse(sourceCode, {
babelAST = babelParse(sourceCode.text, {
filename,
sourceType: 'unambiguous',
plugins: ['typescript', 'jsx'],
Expand All @@ -264,7 +263,7 @@ const rule: Rule.RuleModule = {
}
} else {
try {
babelAST = HermesParser.parse(sourceCode, {
babelAST = HermesParser.parse(sourceCode.text, {
babel: true,
enableExperimentalComponentSyntax: true,
sourceFilename: filename,
Expand All @@ -277,7 +276,7 @@ const rule: Rule.RuleModule = {

if (babelAST != null) {
try {
transformFromAstSync(babelAST, sourceCode, {
transformFromAstSync(babelAST, sourceCode.text, {
filename,
highlightCode: false,
retainLines: true,
Expand Down

0 comments on commit b3a95ca

Please sign in to comment.