/
index.js
77 lines (73 loc) 路 2.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { declare } from "@babel/helper-plugin-utils";
import transformTypeScript from "@babel/plugin-transform-typescript";
import normalizeOptions from "./normalize-options";
export default declare((api, opts) => {
api.assertVersion(7);
const {
allExtensions,
allowNamespaces,
disallowAmbiguousJSXLike,
isTSX,
jsxPragma,
jsxPragmaFrag,
onlyRemoveTypeImports,
optimizeConstEnums,
} = normalizeOptions(opts);
const pluginOptions = process.env.BABEL_8_BREAKING
? (isTSX, disallowAmbiguousJSXLike) => ({
allowNamespaces,
disallowAmbiguousJSXLike,
isTSX,
jsxPragma,
jsxPragmaFrag,
onlyRemoveTypeImports,
optimizeConstEnums,
})
: (isTSX, disallowAmbiguousJSXLike) => ({
allowDeclareFields: opts.allowDeclareFields,
allowNamespaces,
disallowAmbiguousJSXLike,
isTSX,
jsxPragma,
jsxPragmaFrag,
onlyRemoveTypeImports,
optimizeConstEnums,
});
return {
overrides: allExtensions
? [
{
plugins: [
[
transformTypeScript,
pluginOptions(isTSX, disallowAmbiguousJSXLike),
],
],
},
]
: // Only set 'test' if explicitly requested, since it requires that
// Babel is being called`
[
{
test: /\.ts$/,
plugins: [[transformTypeScript, pluginOptions(false, false)]],
},
{
test: /\.mts$/,
sourceType: "module",
plugins: [[transformTypeScript, pluginOptions(false, true)]],
},
{
test: /\.cts$/,
sourceType: "script",
plugins: [[transformTypeScript, pluginOptions(false, true)]],
},
{
test: /\.tsx$/,
// disallowAmbiguousJSXLike is a no-op when parsing TSX, since it's
// always disallowed.
plugins: [[transformTypeScript, pluginOptions(true, false)]],
},
],
};
});