mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[eslint-plugin] Fall back to context.getSourceCode()
Older versions of eslint use the deprecated method, so add a fallback in the event a modern version of eslint isn't available
This commit is contained in:
+3
-1
@@ -23,7 +23,9 @@ const rule: Rule.RuleModule = {
|
||||
},
|
||||
},
|
||||
create(context: Rule.RuleContext) {
|
||||
const babelAST = parser.parse(context.sourceCode.text);
|
||||
// Compat with older versions of eslint
|
||||
const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text;
|
||||
const babelAST = parser.parse(sourceCode);
|
||||
if (babelAST != null) {
|
||||
traverse(babelAST, {
|
||||
Program(prog) {
|
||||
|
||||
Reference in New Issue
Block a user