Skip to content

Commit

Permalink
Require exact Babel 8 version in assertVersion (#15955)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored Oct 13, 2023
1 parent 418dd21 commit 1e15165
Show file tree
Hide file tree
Showing 110 changed files with 545 additions and 118 deletions.
9 changes: 4 additions & 5 deletions eslint/babel-eslint-parser/src/parse.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ let isRunningMinSupportedCoreVersion = null;

module.exports = function parse(code, options, client) {
// Ensure we're using a version of `@babel/core` that includes `parse()` and `tokTypes`.
let minSupportedCoreVersion = ">=7.2.0";
// TODO(Babel 8): Update all the version checks
if (process.env.BABEL_8_BREAKING) {
minSupportedCoreVersion += " || >=8.0.0-0";
}
const minSupportedCoreVersion =
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: ">=7.2.0";

if (typeof isRunningMinSupportedCoreVersion !== "boolean") {
isRunningMinSupportedCoreVersion = semver.satisfies(
Expand Down
4 changes: 0 additions & 4 deletions packages/babel-core/src/config/helpers/config-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ function assertVersion(range: string | number): void {
if (typeof range !== "string") {
throw new Error("Expected string or integer value.");
}
// TODO(Babel 8): Update all the version checks
if (process.env.BABEL_8_BREAKING) {
range += ` || ^8.0.0-0`;
}

if (semver.satisfies(coreVersion, range)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { declare } from "@babel/helper-plugin-utils";
import { shouldTransform } from "./util.ts";

export default declare(api => {
api.assertVersion("^7.16.0");
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.16.0",
);

return {
name: "plugin-bugfix-safari-id-destructuring-collision-in-function-expression",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

const noDocumentAll = api.assumption("noDocumentAll") ?? false;
const pureGetters = api.assumption("pureGetters") ?? false;
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-external-helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export interface Options {
}

export default declare((api, options: Options) => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

const { helperVersion = "7.0.0-beta.0", whitelist = false } = options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import hoistVariables from "@babel/helper-hoist-variables";
import type * as t from "@babel/types";

export default declare(({ types: t, assertVersion }) => {
assertVersion("^7.13.0");
assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.13.0",
);

return {
name: "proposal-async-do-expressions",
Expand Down
12 changes: 10 additions & 2 deletions packages/babel-plugin-proposal-decorators/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ interface Options extends SyntaxOptions {
export type { Options };

export default declare((api, options: Options) => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

// Options are validated in @babel/plugin-syntax-decorators
if (!process.env.BABEL_8_BREAKING) {
Expand All @@ -45,7 +49,11 @@ export default declare((api, options: Options) => {
) {
return transformer2023_05(api, options, version);
} else if (!process.env.BABEL_8_BREAKING) {
api.assertVersion("^7.0.2");
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.0.2",
);
return createClassFeaturePlugin({
name: "proposal-decorators",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ export default function (
version: "2023-05" | "2023-01" | "2022-03" | "2021-12",
): PluginObject {
if (process.env.BABEL_8_BREAKING) {
assertVersion("^7.21.0");
assertVersion(process.env.IS_PUBLISH ? PACKAGE_JSON.version : "^7.21.0");
} else {
if (version === "2023-05" || version === "2023-01") {
assertVersion("^7.21.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import type { NodePath, Visitor } from "@babel/traverse";
import type * as t from "@babel/types";

export default declare(function ({ assertVersion, assumption, types: t }) {
assertVersion("^7.17.0");
assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.17.0",
);
const {
assignmentExpression,
assignmentPattern,
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-proposal-do-expressions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { declare } from "@babel/helper-plugin-utils";
import syntaxDoExpressions from "@babel/plugin-syntax-do-expressions";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "proposal-do-expressions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export interface Options {
}

export default declare((api, options: Options) => {
api.assertVersion("^7.19.0");
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.19.0",
);

const { runtime } = options;
if (runtime !== undefined && typeof runtime !== "boolean") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const enum USING_KIND {
}

export default declare(api => {
api.assertVersion("^7.22.0");
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.22.0",
);

const TOP_LEVEL_USING = new Map<t.Node, USING_KIND>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import syntaxExportDefaultFrom from "@babel/plugin-syntax-export-default-from";
import { types as t } from "@babel/core";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "proposal-export-default-from",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-proposal-function-bind/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { types as t } from "@babel/core";
import type { Scope } from "@babel/traverse";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

function getTempId(scope: Scope) {
let id = scope.path.getData("functionBind");
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-proposal-function-sent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { types as t } from "@babel/core";
import type { Visitor } from "@babel/traverse";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

const isFunctionSent = (node: t.MetaProperty) =>
t.isIdentifier(node.meta, { name: "function" }) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type * as t from "@babel/types";
import syntaxImportAttributes from "@babel/plugin-syntax-import-attributes";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "proposal-import-attributes-to-assertions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { types as t } from "@babel/core";
import type { Scope } from "@babel/traverse";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

/**
* a function to figure out if a call expression has
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const visitorsPerProposal = {
};

export default declare((api, options: Options) => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

const { proposal } = options;

Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-proposal-record-and-tuple/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ type Cache = Map<string, string>;
type ImportCache = WeakMap<t.Program, Cache>;

export default declare<State>((api, options: Options) => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

const polyfillModuleName = v.validateStringOption(
"polyfillModuleName",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-proposal-regexp-modifiers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { createRegExpFeaturePlugin } from "@babel/helper-create-regexp-features-
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion("^7.19.0");
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: "^7.19.0",
);

return createRegExpFeaturePlugin({
name: "proposal-regexp-modifiers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import syntaxThrowExpressions from "@babel/plugin-syntax-throw-expressions";
import { types as t } from "@babel/core";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "proposal-throw-expressions",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-async-do-expressions",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-syntax-decimal/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-decimal",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-syntax-decorators/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export interface Options {
}

export default declare((api, options: Options) => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

let { version } = options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-destructuring-private",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-syntax-do-expressions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-do-expressions",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-explicit-resource-management",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-export-default-from",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-syntax-flow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { declare } from "@babel/helper-plugin-utils";
import type { FlowPluginOptions } from "@babel/parser";

export default declare((api, options: FlowPluginOptions) => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

// When enabled and plugins includes flow, all files should be parsed as if
// the @flow pragma was provided.
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin-syntax-function-bind/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { declare } from "@babel/helper-plugin-utils";

export default declare(api => {
api.assertVersion(7);
api.assertVersion(
process.env.BABEL_8_BREAKING && process.env.IS_PUBLISH
? PACKAGE_JSON.version
: 7,
);

return {
name: "syntax-function-bind",
Expand Down
Loading

0 comments on commit 1e15165

Please sign in to comment.