Skip to content

Commit 091ac3d

Browse files
[babel 8] Bump eslint parser deps (#14872)
* breaking: bump eslint-parser deps * bump eslint dev deps * Use `@nicolo-ribaudo/eslint-scope-5-internals` * Fix tests relying on ESLint 7 API * drop Node.js v10 test * swap eslint with eslint-8 * chore: mark ecmaVersion as latest * add parseForESLint7 * fix: forward the original rule in ESLint 8 * test: remove parseForESLint7 * remove dynamicESLintVersionCheck plugin * Add eslint-7 test workflow * cleanup parseAndAssertSame interface * remove unreachable warning Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
1 parent 580d730 commit 091ac3d

20 files changed

Lines changed: 316 additions & 489 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,15 @@ jobs:
197197
- name: Downgrade Jest for node <= 10
198198
if: matrix.node-version == '6' || matrix.node-version == '8' || matrix.node-version == '10'
199199
run: |
200-
yarn remove jest
201-
yarn add --dev jest@24
200+
yarn up jest@24
202201
# Deduplicate dependencies, because duplicate copies of graceful-fs cause
203202
# problems with the "path" module: https://github.com/facebook/jest/issues/9656
204203
yarn dedupe
205-
- name: Downgrade Jest for node == 12
204+
- name: Downgrade Jest and jest-light-runner for node == 12
206205
if: matrix.node-version == '12'
207206
run: |
208-
yarn remove jest
209-
yarn remove jest-light-runner
210-
yarn add --dev jest@28
211-
yarn add --dev jest-light-runner@0.3.0
207+
yarn up jest@28
208+
yarn up jest-light-runner@0.3.0
212209
# Deduplicate dependencies, because duplicate copies of graceful-fs cause
213210
# problems with the "path" module: https://github.com/facebook/jest/issues/9656
214211
yarn dedupe
@@ -430,3 +427,25 @@ jobs:
430427
node-version: 16.6
431428
- name: Test Node.js 16.6
432429
run: yarn test:runtime:node
430+
431+
eslint7-test:
432+
name: Test @babel/eslint-* with ESLint 7.5.0
433+
needs: build
434+
runs-on: ubuntu-latest
435+
steps:
436+
- name: Checkout code
437+
uses: actions/checkout@v3
438+
- name: Use Node.js latest
439+
uses: actions/setup-node@v3
440+
with:
441+
node-version: "*"
442+
cache: "yarn"
443+
- name: Install
444+
run: yarn install
445+
- uses: actions/download-artifact@v3
446+
with:
447+
name: babel-artifact
448+
- name: Downgrade ESLint to 7.5.0
449+
run: yarn up eslint@7.5.0
450+
- name: Run babel/eslint tests
451+
run: node ./node_modules/.bin/jest eslint

babel.config.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ module.exports = function (api) {
6767
let ignoreLib = true;
6868
let includeRegeneratorRuntime = false;
6969
let needsPolyfillsForOldNode = false;
70-
let dynamicESLintVersionCheck = false;
7170

7271
let transformRuntimeOptions;
7372

@@ -118,7 +117,6 @@ module.exports = function (api) {
118117
needsPolyfillsForOldNode = true;
119118
break;
120119
case "test-legacy": // In test-legacy environment, we build babel on latest node but test on minimum supported legacy versions
121-
dynamicESLintVersionCheck = true;
122120
// fall through
123121
case "production":
124122
// Config during builds before publish.
@@ -128,12 +126,10 @@ module.exports = function (api) {
128126
case "test":
129127
targets = { node: "current" };
130128
needsPolyfillsForOldNode = true;
131-
dynamicESLintVersionCheck = true;
132129
break;
133130
case "development":
134131
envOpts.debug = true;
135132
targets = { node: "current" };
136-
dynamicESLintVersionCheck = true;
137133
break;
138134
}
139135

@@ -291,10 +287,6 @@ module.exports = function (api) {
291287
exclude: /regenerator-runtime/,
292288
plugins: [["@babel/transform-runtime", transformRuntimeOptions]],
293289
},
294-
dynamicESLintVersionCheck && {
295-
test: ["./eslint/*/src"].map(normalize),
296-
plugins: [pluginDynamicESLintVersionCheck],
297-
},
298290
].filter(Boolean),
299291
};
300292

@@ -815,33 +807,6 @@ function pluginBabelParserTokenType({
815807
};
816808
}
817809

818-
// Transforms
819-
// ESLINT_VERSION
820-
// to
821-
// process.env.ESLINT_VERSION_FOR_BABEL
822-
// ? parseInt(process.env.ESLINT_VERSION_FOR_BABEL, 10)
823-
// : ESLINT_VERSION
824-
function pluginDynamicESLintVersionCheck({ template }) {
825-
const transformed = new WeakSet();
826-
827-
return {
828-
visitor: {
829-
ReferencedIdentifier(path) {
830-
if (path.node.name !== "ESLINT_VERSION") return;
831-
832-
if (transformed.has(path.node)) return;
833-
transformed.add(path.node);
834-
835-
path.replaceWith(template.expression.ast`
836-
process.env.ESLINT_VERSION_FOR_BABEL
837-
? parseInt(process.env.ESLINT_VERSION_FOR_BABEL, 10)
838-
: ${path.node}
839-
`);
840-
},
841-
},
842-
};
843-
}
844-
845810
// Inject `0 && exports.foo = 0` hints for the specified exports,
846811
// to help the Node.js CJS-ESM interop. This is only
847812
// needed when compiling ESM re-exports to CJS in `lazy` mode.

eslint/babel-eslint-parser/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
"eslint": "^7.5.0 || ^8.0.0"
3232
},
3333
"dependencies": {
34-
"eslint-scope": "^5.1.1",
35-
"eslint-visitor-keys": "^2.1.0",
34+
"@nicolo-ribaudo/eslint-scope-5-internals": "condition:BABEL_8_BREAKING ? : 5.1.1-v1",
35+
"eslint-scope": "condition:BABEL_8_BREAKING ? ^7.1.1 : ",
36+
"eslint-visitor-keys": "condition:BABEL_8_BREAKING ? ^3.3.0 : ^2.1.0",
3637
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
3738
},
3839
"devDependencies": {
3940
"@babel/core": "workspace:^",
4041
"dedent": "^0.7.0",
41-
"eslint": "^7.27.0",
42-
"eslint-8": "npm:eslint@^8.0.0"
42+
"eslint": "^8.22.0"
4343
}
4444
}

eslint/babel-eslint-parser/src/analyze-scope.cjs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
const escope = require("eslint-scope");
2-
const { Definition } = require("eslint-scope/lib/definition");
3-
const OriginalPatternVisitor = require("eslint-scope/lib/pattern-visitor");
4-
const OriginalReferencer = require("eslint-scope/lib/referencer");
1+
const {
2+
Definition,
3+
PatternVisitor: OriginalPatternVisitor,
4+
Referencer: OriginalReferencer,
5+
Scope,
6+
ScopeManager,
7+
} = process.env.BABEL_8_BREAKING
8+
? require("eslint-scope")
9+
: require("@nicolo-ribaudo/eslint-scope-5-internals");
510
const { getKeys: fallback } = require("eslint-visitor-keys");
611

712
let visitorKeysMap;
@@ -236,7 +241,7 @@ class Referencer extends OriginalReferencer {
236241
}
237242

238243
const parentScope = this.scopeManager.__currentScope;
239-
const scope = new escope.Scope(
244+
const scope = new Scope(
240245
this.scopeManager,
241246
"type-parameters",
242247
parentScope,
@@ -349,7 +354,7 @@ module.exports = function analyzeScope(ast, parserOptions, client) {
349354

350355
options.childVisitorKeys = client.getVisitorKeys();
351356

352-
const scopeManager = new escope.ScopeManager(options);
357+
const scopeManager = new ScopeManager(options);
353358
const referencer = new Referencer(options, scopeManager, client);
354359

355360
referencer.visit(ast);

0 commit comments

Comments
 (0)