Skip to content

Commit

Permalink
chore: check version lazily in babel-eslint-parser (#11647)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed May 31, 2020
1 parent b1923fd commit 30d7236
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions eslint/babel-eslint-parser/src/index.js
@@ -1,6 +1,6 @@
import semver from "semver";
import {
version as CURRENT_BABEL_VERSION,
version as babelCoreVersion,
parseSync as babelParse,
} from "@babel/core";
import packageJson from "../package.json";
Expand All @@ -12,17 +12,19 @@ import convert from "./convert";
import analyzeScope from "./analyze-scope";
import visitorKeys from "./visitor-keys";

const SUPPORTED_BABEL_VERSION_RANGE =
packageJson.peerDependencies["@babel/core"];
const IS_RUNNING_SUPPORTED_VERSION = semver.satisfies(
CURRENT_BABEL_VERSION,
SUPPORTED_BABEL_VERSION_RANGE,
);
let isRunningSupportedVersion;

function baseParse(code, options) {
if (!IS_RUNNING_SUPPORTED_VERSION) {
if (typeof isRunningSupportedVersion !== "boolean") {
isRunningSupportedVersion = semver.satisfies(
babelCoreVersion,
packageJson.peerDependencies["@babel/core"],
);
}

if (!isRunningSupportedVersion) {
throw new Error(
`babel-eslint@${packageJson.version} does not support @babel/core@${CURRENT_BABEL_VERSION}. Please downgrade to babel-eslint@^10 or upgrade to @babel/core@${SUPPORTED_BABEL_VERSION_RANGE}`,
`@babel/eslint-parser@${packageJson.version} does not support @babel/core@${babelCoreVersion}. Please upgrade to @babel/core@${packageJson.peerDependencies["@babel/core"]}`,
);
}

Expand Down

0 comments on commit 30d7236

Please sign in to comment.