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

Prevent parseForESLint() behavior from changing after parse() is called #559

Merged
merged 6 commits into from
Dec 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/analyze-scope.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Loading