Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: check version lazily in babel-eslint-parser #11647

Merged
merged 1 commit into from May 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"]}`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message still had the old package name.

);
}

Expand Down