Skip to content

Commit b3a95ca

Browse files
authored
fix(eslint-plugin-react-compiler): support v9 context api (facebook#32045)
## 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.
1 parent 6099351 commit b3a95ca

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const rule: Rule.RuleModule = {
121121
},
122122
create(context: Rule.RuleContext) {
123123
// Compat with older versions of eslint
124-
const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text;
124+
const sourceCode = context.sourceCode ?? context.getSourceCode();
125125
const filename = context.filename ?? context.getFilename();
126126
const userOpts = context.options[0] ?? {};
127127
if (
@@ -180,7 +180,7 @@ const rule: Rule.RuleModule = {
180180
endLoc = {
181181
line: event.fnLoc.start.line,
182182
// Babel loc line numbers are 1-indexed
183-
column: sourceCode.split(
183+
column: sourceCode.text.split(
184184
/\r?\n|\r|\n/g,
185185
event.fnLoc.start.line,
186186
)[event.fnLoc.start.line - 1].length,
@@ -234,7 +234,6 @@ const rule: Rule.RuleModule = {
234234
nodeLoc: BabelSourceLocation,
235235
suppression: string,
236236
): boolean {
237-
const sourceCode = context.getSourceCode();
238237
const comments = sourceCode.getAllComments();
239238
const flowSuppressionRegex = new RegExp(
240239
'\\$FlowFixMe\\[' + suppression + '\\]',
@@ -254,7 +253,7 @@ const rule: Rule.RuleModule = {
254253
if (filename.endsWith('.tsx') || filename.endsWith('.ts')) {
255254
try {
256255
const {parse: babelParse} = require('@babel/parser');
257-
babelAST = babelParse(sourceCode, {
256+
babelAST = babelParse(sourceCode.text, {
258257
filename,
259258
sourceType: 'unambiguous',
260259
plugins: ['typescript', 'jsx'],
@@ -264,7 +263,7 @@ const rule: Rule.RuleModule = {
264263
}
265264
} else {
266265
try {
267-
babelAST = HermesParser.parse(sourceCode, {
266+
babelAST = HermesParser.parse(sourceCode.text, {
268267
babel: true,
269268
enableExperimentalComponentSyntax: true,
270269
sourceFilename: filename,
@@ -277,7 +276,7 @@ const rule: Rule.RuleModule = {
277276

278277
if (babelAST != null) {
279278
try {
280-
transformFromAstSync(babelAST, sourceCode, {
279+
transformFromAstSync(babelAST, sourceCode.text, {
281280
filename,
282281
highlightCode: false,
283282
retainLines: true,

0 commit comments

Comments
 (0)