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

Commit 05e030a

Browse files
Prevent parseForESLint() behavior from changing after parse() is called
(fixes #558, fixes eslint/eslint#9767)
1 parent 893a5e3 commit 05e030a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
"use strict";
22

3-
let patched = false;
4-
53
exports.parse = function(code, options) {
6-
patched = true;
74
return require("./parse-with-patch")(code, options);
85
};
96

107
exports.parseForESLint = function(code, options) {
11-
if (!patched && options.eslintVisitorKeys && options.eslintScopeManager) {
8+
if (options.eslintVisitorKeys && options.eslintScopeManager) {
129
return require("./parse-with-scope")(code, options);
1310
}
1411

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

test/babel-eslint.js

+12
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,16 @@ describe("Public API", () => {
539539
babelEslint.parseNoPatch("foo", {})
540540
);
541541
});
542+
543+
it("still provides a custom scope with parseForESLint after calling parse()", () => {
544+
assertImplementsAST(
545+
espree.parse("foo", { sourceType: "module" }),
546+
babelEslint.parse("foo", {})
547+
);
548+
const parseForESLintResult = babelEslint.parseForESLint("foo", {
549+
eslintVisitorKeys: true,
550+
eslintScopeManager: true,
551+
});
552+
assert(parseForESLintResult.visitorKeys);
553+
});
542554
});

0 commit comments

Comments
 (0)