diff --git a/packages/babel-core/src/config/files/module-types.ts b/packages/babel-core/src/config/files/module-types.ts index d9a43822eba7..dae2dd3360c0 100644 --- a/packages/babel-core/src/config/files/module-types.ts +++ b/packages/babel-core/src/config/files/module-types.ts @@ -71,13 +71,20 @@ function loadCtsDefault(filepath: string) { presets: [ [ "@babel/preset-typescript", - { - allowDeclareFields: true, - disallowAmbiguousJSXLike: true, - allExtensions: true, - onlyRemoveTypeImports: true, - optimizeConstEnums: true, - }, + process.env.BABEL_8_BREAKING + ? { + disallowAmbiguousJSXLike: true, + allExtensions: true, + onlyRemoveTypeImports: true, + optimizeConstEnums: true, + } + : { + allowDeclareFields: true, + disallowAmbiguousJSXLike: true, + allExtensions: true, + onlyRemoveTypeImports: true, + optimizeConstEnums: true, + }, ], ], }; diff --git a/packages/babel-core/test/config-ts.js b/packages/babel-core/test/config-ts.js index d7643802bba2..985d9c38546e 100644 --- a/packages/babel-core/test/config-ts.js +++ b/packages/babel-core/test/config-ts.js @@ -3,25 +3,28 @@ import path from "path"; import { fileURLToPath } from "url"; import { createRequire } from "module"; import { register } from "ts-node"; +import semver from "semver"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const require = createRequire(import.meta.url); describe("@babel/core config with ts", () => { - it("should work with simple .cts", () => { - const config = loadPartialConfigSync({ - configFile: path.join( - __dirname, - "fixtures/config-ts/simple-cts/babel.config.cts", - ), - }); + semver.gte(process.version, "12.0.0") + ? it + : it.skip("should work with simple .cts", () => { + const config = loadPartialConfigSync({ + configFile: path.join( + __dirname, + "fixtures/config-ts/simple-cts/babel.config.cts", + ), + }); - expect(config.options.targets).toMatchInlineSnapshot(` + expect(config.options.targets).toMatchInlineSnapshot(` Object { "node": "12.0.0", } `); - }); + }); it("should throw with invalid .ts register", () => { require.extensions[".ts"] = () => {