Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Fix: Prevent parseForESLint() behavior from changing after parse() is…
Browse files Browse the repository at this point in the history
… called (fixes #558)(#559)

* Prevent parseForESLint() behavior from changing after parse() is called

(fixes #558, fixes eslint/eslint#9767)

* Avoid using the enhanced referencer after monkeypatching

* Chore: add test for #558

* Pass correct scope analyzer options

* fix escope patch and improve tests

* remove process.exit(1)
  • Loading branch information
not-an-aardvark authored and mysticatea committed Dec 25, 2017
1 parent 893a5e3 commit e4bed5a
Show file tree
Hide file tree
Showing 17 changed files with 779 additions and 444 deletions.
9 changes: 8 additions & 1 deletion lib/analyze-scope.js
Expand Up @@ -318,9 +318,16 @@ module.exports = function(ast, parserOptions) {
impliedStrict: false,
sourceType: ast.sourceType,
ecmaVersion: parserOptions.ecmaVersion || 6,
childVisitorKeys,
fallback,
};

if (OriginalReferencer._babelEslintPatched) {
require("./patch-eslint-scope")(parserOptions);
return escope.analyze(ast, options);
}

options.childVisitorKeys = childVisitorKeys;

const scopeManager = new escope.ScopeManager(options);
const referencer = new Referencer(options, scopeManager);

Expand Down
15 changes: 8 additions & 7 deletions lib/index.js
@@ -1,18 +1,19 @@
"use strict";

let patched = false;

exports.parse = function(code, options) {
patched = true;
return require("./parse-with-patch")(code, options);
return exports.parseForESLint(code, options).ast;
};

exports.parseForESLint = function(code, options) {
if (!patched && options.eslintVisitorKeys && options.eslintScopeManager) {
options = options || {};
options.ecmaVersion = options.ecmaVersion || 6;
options.sourceType = options.sourceType || "module";
options.allowImportExportEverywhere =
options.allowImportExportEverywhere || false;

if (options.eslintVisitorKeys && options.eslintScopeManager) {
return require("./parse-with-scope")(code, options);
}

patched = true;
return { ast: require("./parse-with-patch")(code, options) };
};

Expand Down

0 comments on commit e4bed5a

Please sign in to comment.