Skip to content

Commit

Permalink
[babel 8] Do not use syntax plugins for syntax enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 31, 2023
1 parent 0f68219 commit 576d9b4
Show file tree
Hide file tree
Showing 33 changed files with 86 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
import type { PluginAPI, PluginObject } from "@babel/core";

export default function ({ types: t }: PluginAPI): PluginObject {
return {
inherits: syntaxObjectRestSpread.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-object-rest-spread").default,

visitor: {
CallExpression(path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@babel/plugin"
],
"dependencies": {
"@babel/plugin-syntax-optional-catch-binding": "^7.8.3"
"@babel/plugin-syntax-optional-catch-binding": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
import type { PluginAPI, PluginObject } from "@babel/core";

export default function ({ types: t }: PluginAPI): PluginObject {
return {
inherits: syntaxOptionalCatchBinding.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-optional-catch-binding").default,

visitor: {
CatchClause(path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/helper-plugin-test-runner": "workspace:^",
"@babel/plugin-syntax-class-static-block": "^7.14.5",
"@babel/preset-env": "workspace:^"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"plugins": [
"transform-class-properties",
"@babel/plugin-syntax-class-static-block"
],
"plugins": ["transform-class-properties"],
"throws": "Static class blocks are not enabled. Please add `@babel/plugin-transform-class-static-block` to your configuration."
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/helper-environment-visitor": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^",
"@babel/helper-remap-async-to-generator": "workspace:^",
"@babel/plugin-syntax-async-generators": "^7.8.4"
"@babel/plugin-syntax-async-generators": "condition:BABEL_8_BREAKING ? : ^7.8.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { declare } from "@babel/helper-plugin-utils";
import remapAsyncToGenerator from "@babel/helper-remap-async-to-generator";
import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
import type { NodePath, Visitor } from "@babel/traverse";
import { traverse, types as t, type PluginPass } from "@babel/core";
import rewriteForAwait from "./for-await";
Expand Down Expand Up @@ -95,7 +94,10 @@ export default declare(api => {

return {
name: "transform-async-generator-functions",
inherits: syntaxAsyncGenerators.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-async-generators").default,

visitor: {
Program(path, state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@babel/helper-create-class-features-plugin": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-class-static-block": "^7.14.5"
"@babel/plugin-syntax-class-static-block": "condition:BABEL_8_BREAKING ? : ^7.14.5"
},
"peerDependencies": {
"@babel/core": "^7.12.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxClassStaticBlock from "@babel/plugin-syntax-class-static-block";
import type { Scope } from "@babel/traverse";

import {
Expand Down Expand Up @@ -30,7 +29,10 @@ export default declare(({ types: t, template, assertVersion }) => {

return {
name: "transform-class-static-block",
inherits: syntaxClassStaticBlock.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-class-static-block").default,

pre() {
// Enable this in @babel/helper-create-class-features-plugin, so that it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-dynamic-import": "^7.8.3"
"@babel/plugin-syntax-dynamic-import": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-plugin-transform-dynamic-import/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";

const SUPPORTED_MODULES = ["commonjs", "amd", "systemjs"];

Expand All @@ -21,7 +20,10 @@ export default declare(api => {

return {
name: "transform-dynamic-import",
inherits: syntaxDynamicImport.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-dynamic-import").default,

pre() {
// We keep using the old name, for compatibility with older
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-export-namespace-from": "^7.8.3"
"@babel/plugin-syntax-export-namespace-from": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxExportNamespaceFrom from "@babel/plugin-syntax-export-namespace-from";
import { types as t } from "@babel/core";

export default declare(api => {
api.assertVersion(7);

return {
name: "transform-export-namespace-from",
inherits: syntaxExportNamespaceFrom.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-export-namespace-from").default,

visitor: {
ExportNamedDeclaration(path) {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-json-strings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-json-strings": "^7.8.3"
"@babel/plugin-syntax-json-strings": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-plugin-transform-json-strings/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxJsonStrings from "@babel/plugin-syntax-json-strings";
import type * as t from "@babel/types";
import type { NodePath } from "@babel/traverse";

Expand All @@ -18,7 +17,10 @@ export default declare(api => {

return {
name: "transform-json-strings",
inherits: syntaxJsonStrings.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-json-strings").default,

visitor: {
"DirectiveLiteral|StringLiteral"({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-logical-assignment-operators": "^7.10.4"
"@babel/plugin-syntax-logical-assignment-operators": "condition:BABEL_8_BREAKING ? : ^7.10.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/helper-plugin-test-runner": "workspace:^",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-transform-nullish-coalescing-operator": "workspace:^"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-logical-assignment-operators",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxLogicalAssignmentOperators from "@babel/plugin-syntax-logical-assignment-operators";
import { types as t } from "@babel/core";

export default declare(api => {
api.assertVersion(7);

return {
name: "transform-logical-assignment-operators",
inherits: syntaxLogicalAssignmentOperators.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-logical-assignment-operators").default,

visitor: {
AssignmentExpression(path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/helper-plugin-test-runner": "workspace:^",
"@babel/plugin-external-helpers": "workspace:^",
"@babel/plugin-syntax-class-static-block": "^7.14.5",
"@babel/plugin-syntax-object-rest-spread": "^7.8.3"
"@babel/plugin-external-helpers": "workspace:^"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-modules-commonjs",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"plugins": [
"transform-modules-commonjs",
"@babel/plugin-syntax-class-static-block"
]
"plugins": ["transform-modules-commonjs"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
},
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/helper-plugin-test-runner": "workspace:^",
"@babel/plugin-syntax-dynamic-import": "^7.8.3"
"@babel/helper-plugin-test-runner": "workspace:^"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-modules-systemjs",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3"
"@babel/plugin-syntax-nullish-coalescing-operator": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxNullishCoalescingOperator from "@babel/plugin-syntax-nullish-coalescing-operator";
import { types as t, template } from "@babel/core";

export interface Options {
Expand All @@ -12,7 +11,10 @@ export default declare((api, { loose = false }: Options) => {

return {
name: "transform-nullish-coalescing-operator",
inherits: syntaxNullishCoalescingOperator.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-nullish-coalescing-operator").default,

visitor: {
LogicalExpression(path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-numeric-separator": "^7.10.4"
"@babel/plugin-syntax-numeric-separator": "condition:BABEL_8_BREAKING ? : ^7.10.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxNumericSeparator from "@babel/plugin-syntax-numeric-separator";
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";

Expand All @@ -23,7 +22,10 @@ export default declare(api => {

return {
name: "transform-numeric-separator",
inherits: syntaxNumericSeparator.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-numeric-separator").default,

visitor: {
NumericLiteral: remover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/compat-data": "workspace:^",
"@babel/helper-compilation-targets": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-object-rest-spread": "^7.8.3",
"@babel/plugin-syntax-object-rest-spread": "condition:BABEL_8_BREAKING ? : ^7.8.3",
"@babel/plugin-transform-parameters": "workspace:^"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
import { types as t } from "@babel/core";
import type { PluginPass } from "@babel/core";
import type { NodePath, Scope } from "@babel/traverse";
Expand Down Expand Up @@ -285,7 +284,10 @@ export default declare((api, opts: Options) => {

return {
name: "transform-object-rest-spread",
inherits: syntaxObjectRestSpread.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-object-rest-spread").default,

visitor: {
// function a({ b, ...c }) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-optional-catch-binding": "^7.8.3"
"@babel/plugin-syntax-optional-catch-binding": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";

export default declare(api => {
api.assertVersion(7);

return {
name: "transform-optional-catch-binding",
inherits: syntaxOptionalCatchBinding.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-optional-catch-binding").default,

visitor: {
CatchClause(path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@babel/helper-plugin-utils": "workspace:^",
"@babel/helper-skip-transparent-expression-wrappers": "workspace:^",
"@babel/plugin-syntax-optional-chaining": "^7.8.3"
"@babel/plugin-syntax-optional-chaining": "condition:BABEL_8_BREAKING ? : ^7.8.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { declare } from "@babel/helper-plugin-utils";
import syntaxOptionalChaining from "@babel/plugin-syntax-optional-chaining";
import { transform } from "./transform";
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";
Expand All @@ -16,7 +15,10 @@ export default declare((api, options: Options) => {

return {
name: "transform-optional-chaining",
inherits: syntaxOptionalChaining.default,
inherits: USE_ESM
? undefined
: // eslint-disable-next-line no-restricted-globals
require("@babel/plugin-syntax-optional-chaining").default,

visitor: {
"OptionalCallExpression|OptionalMemberExpression"(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/helper-annotate-as-pure": "workspace:^",
"@babel/helper-create-class-features-plugin": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^",
"@babel/plugin-syntax-private-property-in-object": "^7.14.5"
"@babel/plugin-syntax-private-property-in-object": "condition:BABEL_8_BREAKING ? : ^7.14.5"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
Expand Down
Loading

0 comments on commit 576d9b4

Please sign in to comment.