Skip to content

Commit 210e40a

Browse files
nicolo-ribaudoljharb
authored andcommitted
[utils] [patch] Fix @babel/eslint-parser 8 compatibility
1 parent e3ca68e commit 210e40a

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

utils/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
- [patch] Fix `@babel/eslint-parser` 8 compatibility ([#2343], thanks [@nicolo-ribaudo])
10+
811
## v2.7.1 - 2021-10-13
912

1013
### Fixed
11-
- fixed SyntaxError in node <= 6: Unexpected token ) in parse.js ([#2261], thanks [@VitusFW])
14+
- fixed SyntaxError in node <= 6: Unexpected token ) in parse.js ([#2261], thanks [@VitusFW])
1215

1316
## v2.7.0 - 2021-10-11
1417

@@ -102,6 +105,7 @@ Yanked due to critical issue with cache key resulting from #839.
102105
### Fixed
103106
- `unambiguous.test()` regex is now properly in multiline mode
104107

108+
[#2343]: https://github.com/import-js/eslint-plugin-import/pull/2343
105109
[#2261]: https://github.com/import-js/eslint-plugin-import/pull/2261
106110
[#2212]: https://github.com/import-js/eslint-plugin-import/pull/2212
107111
[#2160]: https://github.com/import-js/eslint-plugin-import/pull/2160
@@ -138,6 +142,7 @@ Yanked due to critical issue with cache key resulting from #839.
138142
[@manuth]: https://github.com/manuth
139143
[@maxkomarychev]: https://github.com/maxkomarychev
140144
[@mgwalker]: https://github.com/mgwalker
145+
[@nicolo-ribaudo]: https://github.com/nicolo-ribaudo
141146
[@pmcelhaney]: https://github.com/pmcelhaney
142147
[@sergei-startsev]: https://github.com/sergei-startsev
143148
[@sompylasar]: https://github.com/sompylasar

utils/parse.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,27 @@ const fs = require('fs');
77

88
const log = require('debug')('eslint-plugin-import:parse');
99

10-
function getBabelVisitorKeys(parserPath) {
10+
function getBabelEslintVisitorKeys(parserPath) {
1111
if (parserPath.endsWith('index.js')) {
1212
const hypotheticalLocation = parserPath.replace('index.js', 'visitor-keys.js');
1313
if (fs.existsSync(hypotheticalLocation)) {
1414
const keys = moduleRequire(hypotheticalLocation);
1515
return keys.default || keys;
1616
}
17-
} else if (parserPath.endsWith('index.cjs')) {
18-
const hypotheticalLocation = parserPath.replace('index.cjs', 'worker/ast-info.cjs');
19-
if (fs.existsSync(hypotheticalLocation)) {
20-
const astInfo = moduleRequire(hypotheticalLocation);
21-
return astInfo.getVisitorKeys();
22-
}
2317
}
2418
return null;
2519
}
2620

2721
function keysFromParser(parserPath, parserInstance, parsedResult) {
22+
// Exposed by @typescript-eslint/parser and @babel/eslint-parser
23+
if (parsedResult && parsedResult.visitorKeys) {
24+
return parsedResult.visitorKeys;
25+
}
2826
if (/.*espree.*/.test(parserPath)) {
2927
return parserInstance.VisitorKeys;
3028
}
31-
if (/.*(babel-eslint|@babel\/eslint-parser).*/.test(parserPath)) {
32-
return getBabelVisitorKeys(parserPath);
33-
}
34-
if (/.*@typescript-eslint\/parser/.test(parserPath)) {
35-
if (parsedResult) {
36-
return parsedResult.visitorKeys;
37-
}
29+
if (/.*babel-eslint.*/.test(parserPath)) {
30+
return getBabelEslintVisitorKeys(parserPath);
3831
}
3932
return null;
4033
}

0 commit comments

Comments
 (0)