Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 3, 2023
1 parent e395515 commit a4e0d98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
21 changes: 14 additions & 7 deletions packages/babel-core/src/config/files/module-types.ts
Expand Up @@ -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,
},
],
],
};
Expand Down
21 changes: 12 additions & 9 deletions packages/babel-core/test/config-ts.js
Expand Up @@ -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"] = () => {
Expand Down

0 comments on commit a4e0d98

Please sign in to comment.