refactor: use option-validator in preset-typescript (#12347)
This commit is contained in:
parent
ab5a90ce47
commit
2e3eec6646
@ -29,12 +29,6 @@ export default declare((api, opts) => {
|
|||||||
const development = !!opts.development;
|
const development = !!opts.development;
|
||||||
const useBuiltIns = !!opts.useBuiltIns;
|
const useBuiltIns = !!opts.useBuiltIns;
|
||||||
|
|
||||||
if (typeof development !== "boolean") {
|
|
||||||
throw new Error(
|
|
||||||
"@babel/preset-react 'development' option must be a boolean.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const transformReactJSXPlugin =
|
const transformReactJSXPlugin =
|
||||||
runtime === "automatic" && development
|
runtime === "automatic" && development
|
||||||
? transformReactJSXDevelopment
|
? transformReactJSXDevelopment
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-plugin-utils": "workspace:^7.10.4",
|
"@babel/helper-plugin-utils": "workspace:^7.10.4",
|
||||||
|
"@babel/helper-validator-option": "workspace:^7.12.1",
|
||||||
"@babel/plugin-transform-typescript": "workspace:^7.12.1"
|
"@babel/plugin-transform-typescript": "workspace:^7.12.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@ -1,35 +1,34 @@
|
|||||||
import { declare } from "@babel/helper-plugin-utils";
|
import { declare } from "@babel/helper-plugin-utils";
|
||||||
import transformTypeScript from "@babel/plugin-transform-typescript";
|
import transformTypeScript from "@babel/plugin-transform-typescript";
|
||||||
|
import { OptionValidator } from "@babel/helper-validator-option";
|
||||||
|
const v = new OptionValidator("@babel/preset-typescript");
|
||||||
|
|
||||||
export default declare(
|
export default declare((api, opts) => {
|
||||||
(
|
api.assertVersion(7);
|
||||||
api,
|
|
||||||
{
|
const {
|
||||||
allExtensions = false,
|
|
||||||
allowDeclareFields,
|
allowDeclareFields,
|
||||||
allowNamespaces,
|
allowNamespaces,
|
||||||
jsxPragma,
|
jsxPragma,
|
||||||
jsxPragmaFrag = "React.Fragment",
|
|
||||||
isTSX = false,
|
|
||||||
onlyRemoveTypeImports,
|
onlyRemoveTypeImports,
|
||||||
},
|
} = opts;
|
||||||
) => {
|
|
||||||
api.assertVersion(7);
|
|
||||||
|
|
||||||
if (typeof jsxPragmaFrag !== "string") {
|
const jsxPragmaFrag = v.validateStringOption(
|
||||||
throw new Error(".jsxPragmaFrag must be a string, or undefined");
|
"jsxPragmaFrag",
|
||||||
}
|
opts.jsxPragmaFrag,
|
||||||
|
"React.Fragment",
|
||||||
|
);
|
||||||
|
|
||||||
if (typeof allExtensions !== "boolean") {
|
const allExtensions = v.validateBooleanOption(
|
||||||
throw new Error(".allExtensions must be a boolean, or undefined");
|
"allExtensions",
|
||||||
}
|
opts.allExtensions,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
if (typeof isTSX !== "boolean") {
|
const isTSX = v.validateBooleanOption("isTSX", opts.isTSX, false);
|
||||||
throw new Error(".isTSX must be a boolean, or undefined");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isTSX && !allExtensions) {
|
if (isTSX) {
|
||||||
throw new Error("isTSX:true requires allExtensions:true");
|
v.invariant(allExtensions, "isTSX:true requires allExtensions:true");
|
||||||
}
|
}
|
||||||
|
|
||||||
const pluginOptions = isTSX => ({
|
const pluginOptions = isTSX => ({
|
||||||
@ -63,5 +62,4 @@ export default declare(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|||||||
@ -3134,6 +3134,7 @@ __metadata:
|
|||||||
"@babel/core": "workspace:*"
|
"@babel/core": "workspace:*"
|
||||||
"@babel/helper-plugin-test-runner": "workspace:*"
|
"@babel/helper-plugin-test-runner": "workspace:*"
|
||||||
"@babel/helper-plugin-utils": "workspace:^7.10.4"
|
"@babel/helper-plugin-utils": "workspace:^7.10.4"
|
||||||
|
"@babel/helper-validator-option": "workspace:^7.12.1"
|
||||||
"@babel/plugin-transform-typescript": "workspace:^7.12.1"
|
"@babel/plugin-transform-typescript": "workspace:^7.12.1"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@babel/core": ^7.0.0-0
|
"@babel/core": ^7.0.0-0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user