Remove monkeypatching dead code (babel/babel-eslint#737)

This commit is contained in:
Kai Cataldo 2019-01-10 18:28:40 -05:00
parent 47de99e1b8
commit 2b9ee42ded
5 changed files with 12 additions and 57 deletions

View File

@ -327,11 +327,6 @@ module.exports = function(ast, parserOptions) {
fallback, fallback,
}; };
if (OriginalReferencer._babelEslintPatched) {
require("./patch-eslint-scope")(parserOptions);
return escope.analyze(ast, options);
}
options.childVisitorKeys = childVisitorKeys; options.childVisitorKeys = childVisitorKeys;
const scopeManager = new escope.ScopeManager(options); const scopeManager = new escope.ScopeManager(options);

View File

@ -14,7 +14,7 @@
"homepage": "https://github.com/babel/babel-eslint", "homepage": "https://github.com/babel/babel-eslint",
"scripts": { "scripts": {
"test": "npm run lint && npm run test-only", "test": "npm run lint && npm run test-only",
"test-only": "cd test && mocha --require fixtures/preprocess-to-patch.js specs && cd -", "test-only": "cd test && mocha specs && cd -",
"lint": "eslint .", "lint": "eslint .",
"lint-fix": "npm run lint -- --fix", "lint-fix": "npm run lint -- --fix",
"precommit": "lint-staged", "precommit": "lint-staged",

View File

@ -1,6 +0,0 @@
"use strict"
const babelEslint = require("../..")
// Apply monkeypatch to eslint-scope.
babelEslint.parse("var x = 0;")

View File

@ -223,3 +223,14 @@ function strictSuite() {
// it // it
}); });
} }
describe("https://github.com/babel/babel-eslint/issues/558", () => {
it("doesn't crash with eslint-plugin-import", () => {
const engine = new eslint.CLIEngine({ ignore: false });
engine.executeOnFiles([
"fixtures/eslint-plugin-import/a.js",
"fixtures/eslint-plugin-import/b.js",
"fixtures/eslint-plugin-import/c.js",
]);
});
});

View File

@ -1,45 +0,0 @@
"use strict";
const eslint = require("eslint");
const assert = require("assert");
const babelEslint = require("../..");
const espree = require("espree");
const assertImplementsAST = require("../helpers/assert-implements-ast");
describe("https://github.com/babel/babel-eslint/issues/558", () => {
it("don't crash with eslint-plugin-import", () => {
const engine = new eslint.CLIEngine({ ignore: false });
engine.executeOnFiles([
"../test/fixtures/eslint-plugin-import/a.js",
"../test/fixtures/eslint-plugin-import/b.js",
"../test/fixtures/eslint-plugin-import/c.js",
]);
});
/*
* This test ensures that the enhanced referencer does not get used if eslint-scope has already been
* monkeypatched, because this causes some correctness issues. For example, if the enhanced referencer
* is used after the original referencer is monkeypatched, type annotation references are counted twice.
*/
it("does not visit type annotations multiple times after monkeypatching and calling parseForESLint()", () => {
assertImplementsAST(
espree.parse("foo", { sourceType: "module" }),
babelEslint.parse("foo", {})
);
const parseResult = babelEslint.parseForESLint(
"type Foo = {}; function x(): Foo {}",
{
eslintVisitorKeys: true,
eslintScopeManager: true,
}
);
assert(parseResult.visitorKeys);
assert(parseResult.scopeManager);
const fooVariable = parseResult.scopeManager.getDeclaredVariables(
parseResult.ast.body[0]
)[0];
assert.strictEqual(fooVariable.references.length, 1);
});
});