Upgrade eslint-plugin-import

R=jacktfranklin@chromium.org

Bug: none
Change-Id: I0ad7ba9133af3db19c448a284d79bdfc08101dea
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3268294
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
diff --git a/node_modules/eslint-module-utils/parse.js b/node_modules/eslint-module-utils/parse.js
index 3b2ac02..a771544 100644
--- a/node_modules/eslint-module-utils/parse.js
+++ b/node_modules/eslint-module-utils/parse.js
@@ -3,9 +3,42 @@
 
 const moduleRequire = require('./module-require').default;
 const extname = require('path').extname;
+const fs = require('fs');
 
 const log = require('debug')('eslint-plugin-import:parse');
 
+function getBabelVisitorKeys(parserPath) {
+  if (parserPath.endsWith('index.js')) {
+    const hypotheticalLocation = parserPath.replace('index.js', 'visitor-keys.js');
+    if (fs.existsSync(hypotheticalLocation)) {
+      const keys = moduleRequire(hypotheticalLocation);
+      return keys.default || keys;
+    }
+  } else if (parserPath.endsWith('index.cjs')) {
+    const hypotheticalLocation = parserPath.replace('index.cjs', 'worker/ast-info.cjs');
+    if (fs.existsSync(hypotheticalLocation)) {
+      const astInfo = moduleRequire(hypotheticalLocation);
+      return astInfo.getVisitorKeys();
+    }
+  }
+  return null;
+}
+
+function keysFromParser(parserPath, parserInstance, parsedResult) {
+  if (/.*espree.*/.test(parserPath)) {
+    return parserInstance.VisitorKeys;
+  }
+  if (/.*(babel-eslint|@babel\/eslint-parser).*/.test(parserPath)) {
+    return getBabelVisitorKeys(parserPath);
+  }
+  if (/.*@typescript-eslint\/parser/.test(parserPath)) {
+    if (parsedResult) {
+      return parsedResult.visitorKeys;
+    }
+  }
+  return null;
+}
+
 exports.default = function parse(path, content, context) {
 
   if (context == null) throw new Error('need context to parse properly');
@@ -45,20 +78,36 @@
   if (typeof parser.parseForESLint === 'function') {
     let ast;
     try {
-      ast = parser.parseForESLint(content, parserOptions).ast;
+      const parserRaw = parser.parseForESLint(content, parserOptions);
+      ast = parserRaw.ast;
+      return {
+        ast,
+        visitorKeys: keysFromParser(parserPath, parser, parserRaw),
+      };
     } catch (e) {
       console.warn();
       console.warn('Error while parsing ' + parserOptions.filePath);
       console.warn('Line ' + e.lineNumber + ', column ' + e.column + ': ' + e.message);
     }
     if (!ast || typeof ast !== 'object') {
-      console.warn('`parseForESLint` from parser `' + parserPath + '` is invalid and will just be ignored');
+      console.warn(
+        '`parseForESLint` from parser `' +
+          parserPath +
+          '` is invalid and will just be ignored'
+      );
     } else {
-      return ast;
+      return {
+        ast,
+        visitorKeys: keysFromParser(parserPath, parser, undefined),
+      };
     }
   }
 
-  return parser.parse(content, parserOptions);
+  const keys = keysFromParser(parserPath, parser, undefined);
+  return {
+    ast: parser.parse(content, parserOptions),
+    visitorKeys: keys,
+  };
 };
 
 function getParserPath(path, context) {