Skip to content

Commit

Permalink
[utils] [patch] Fix @babel/eslint-parser 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored and ljharb committed Dec 30, 2021
1 parent e3ca68e commit 210e40a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
7 changes: 6 additions & 1 deletion utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## Unreleased

### Fixed
- [patch] Fix `@babel/eslint-parser` 8 compatibility ([#2343], thanks [@nicolo-ribaudo])

## v2.7.1 - 2021-10-13

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

## v2.7.0 - 2021-10-11

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

[#2343]: https://github.com/import-js/eslint-plugin-import/pull/2343
[#2261]: https://github.com/import-js/eslint-plugin-import/pull/2261
[#2212]: https://github.com/import-js/eslint-plugin-import/pull/2212
[#2160]: https://github.com/import-js/eslint-plugin-import/pull/2160
Expand Down Expand Up @@ -138,6 +142,7 @@ Yanked due to critical issue with cache key resulting from #839.
[@manuth]: https://github.com/manuth
[@maxkomarychev]: https://github.com/maxkomarychev
[@mgwalker]: https://github.com/mgwalker
[@nicolo-ribaudo]: https://github.com/nicolo-ribaudo
[@pmcelhaney]: https://github.com/pmcelhaney
[@sergei-startsev]: https://github.com/sergei-startsev
[@sompylasar]: https://github.com/sompylasar
Expand Down
21 changes: 7 additions & 14 deletions utils/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,27 @@ const fs = require('fs');

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

function getBabelVisitorKeys(parserPath) {
function getBabelEslintVisitorKeys(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) {
// Exposed by @typescript-eslint/parser and @babel/eslint-parser
if (parsedResult && parsedResult.visitorKeys) {
return parsedResult.visitorKeys;
}
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;
}
if (/.*babel-eslint.*/.test(parserPath)) {
return getBabelEslintVisitorKeys(parserPath);
}
return null;
}
Expand Down

0 comments on commit 210e40a

Please sign in to comment.