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

Commit

Permalink
Prevent parseForESLint() behavior from changing after parse() is called
Browse files Browse the repository at this point in the history
(fixes #558, fixes eslint/eslint#9767)
  • Loading branch information
not-an-aardvark committed Dec 25, 2017
1 parent 893a5e3 commit 05e030a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
"use strict";

let patched = false;

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

exports.parseForESLint = function(code, options) {
if (!patched && options.eslintVisitorKeys && options.eslintScopeManager) {
if (options.eslintVisitorKeys && options.eslintScopeManager) {
return require("./parse-with-scope")(code, options);
}

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

Expand Down
12 changes: 12 additions & 0 deletions test/babel-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,16 @@ describe("Public API", () => {
babelEslint.parseNoPatch("foo", {})
);
});

it("still provides a custom scope with parseForESLint after calling parse()", () => {
assertImplementsAST(
espree.parse("foo", { sourceType: "module" }),
babelEslint.parse("foo", {})
);
const parseForESLintResult = babelEslint.parseForESLint("foo", {
eslintVisitorKeys: true,
eslintScopeManager: true,
});
assert(parseForESLintResult.visitorKeys);
});
});

0 comments on commit 05e030a

Please sign in to comment.