From 2b9ee42ded0436254cf8c37d53bffe78b186131c Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Thu, 10 Jan 2019 18:28:40 -0500 Subject: [PATCH] Remove monkeypatching dead code (babel/babel-eslint#737) --- .../babel-eslint-parser/lib/analyze-scope.js | 5 --- eslint/babel-eslint-parser/package.json | 2 +- .../test/fixtures/preprocess-to-patch.js | 6 --- .../test/specs/integration.js | 11 +++++ .../z_parser-for-eslint-after-patched.js | 45 ------------------- 5 files changed, 12 insertions(+), 57 deletions(-) delete mode 100644 eslint/babel-eslint-parser/test/fixtures/preprocess-to-patch.js delete mode 100644 eslint/babel-eslint-parser/test/specs/z_parser-for-eslint-after-patched.js diff --git a/eslint/babel-eslint-parser/lib/analyze-scope.js b/eslint/babel-eslint-parser/lib/analyze-scope.js index aa3431a4cc..ed2dab6509 100644 --- a/eslint/babel-eslint-parser/lib/analyze-scope.js +++ b/eslint/babel-eslint-parser/lib/analyze-scope.js @@ -327,11 +327,6 @@ module.exports = function(ast, parserOptions) { fallback, }; - if (OriginalReferencer._babelEslintPatched) { - require("./patch-eslint-scope")(parserOptions); - return escope.analyze(ast, options); - } - options.childVisitorKeys = childVisitorKeys; const scopeManager = new escope.ScopeManager(options); diff --git a/eslint/babel-eslint-parser/package.json b/eslint/babel-eslint-parser/package.json index e43b064a5e..31de034c4c 100644 --- a/eslint/babel-eslint-parser/package.json +++ b/eslint/babel-eslint-parser/package.json @@ -14,7 +14,7 @@ "homepage": "https://github.com/babel/babel-eslint", "scripts": { "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-fix": "npm run lint -- --fix", "precommit": "lint-staged", diff --git a/eslint/babel-eslint-parser/test/fixtures/preprocess-to-patch.js b/eslint/babel-eslint-parser/test/fixtures/preprocess-to-patch.js deleted file mode 100644 index 8cb4c54fb6..0000000000 --- a/eslint/babel-eslint-parser/test/fixtures/preprocess-to-patch.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict" - -const babelEslint = require("../..") - -// Apply monkeypatch to eslint-scope. -babelEslint.parse("var x = 0;") diff --git a/eslint/babel-eslint-parser/test/specs/integration.js b/eslint/babel-eslint-parser/test/specs/integration.js index 4e0851d8a4..27caec55cb 100644 --- a/eslint/babel-eslint-parser/test/specs/integration.js +++ b/eslint/babel-eslint-parser/test/specs/integration.js @@ -223,3 +223,14 @@ function strictSuite() { // 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", + ]); + }); +}); diff --git a/eslint/babel-eslint-parser/test/specs/z_parser-for-eslint-after-patched.js b/eslint/babel-eslint-parser/test/specs/z_parser-for-eslint-after-patched.js deleted file mode 100644 index bc787db349..0000000000 --- a/eslint/babel-eslint-parser/test/specs/z_parser-for-eslint-after-patched.js +++ /dev/null @@ -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); - }); -});