Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 4, 2023
1 parent e395515 commit a30d703
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 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
45 changes: 24 additions & 21 deletions packages/babel-core/test/config-ts.js
Expand Up @@ -3,6 +3,7 @@ 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);
Expand Down Expand Up @@ -38,33 +39,35 @@ describe("@babel/core config with ts", () => {
delete require.extensions[".ts"];
});

it("should work with ts-node", () => {
const service = register({
experimentalResolver: true,
compilerOptions: {
module: "CommonJS",
},
});
service.enabled(true);
semver.gte(process.version, "12.0.0")
? it
: it.skip("should work with ts-node", () => {
const service = register({
experimentalResolver: true,
compilerOptions: {
module: "CommonJS",
},
});
service.enabled(true);

require(path.join(
__dirname,
"fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts",
));
require(path.join(
__dirname,
"fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts",
));

const config = loadPartialConfigSync({
configFile: path.join(
__dirname,
"fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts",
),
});
const config = loadPartialConfigSync({
configFile: path.join(
__dirname,
"fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts",
),
});

service.enabled(false);
service.enabled(false);

expect(config.options.targets).toMatchInlineSnapshot(`
expect(config.options.targets).toMatchInlineSnapshot(`
Object {
"node": "12.0.0",
}
`);
});
});
});

0 comments on commit a30d703

Please sign in to comment.