| Q | A <!--(Can use an emoji 👍) --> | ------------------------ | --- | Fixed Issues? | | Patch: Bug Fix? | | Major: Breaking Change? | | Minor: New Feature? | | Tests Added + Pass? | Yes | Documentation PR | <!-- If so, add `[skip ci]` to your commit message to skip CI --> | Any Dependency Changes? | | License | MIT The `all` option landed in https://github.com/babel/babel/pull/7934/files#diff-3a8233bcd2766d2c7d87f23f944f7726R3 but it is only exposed from the plugin, not the preset, so this exposes it there too since the flow preset is what we want people to use.
30 lines
767 B
JavaScript
30 lines
767 B
JavaScript
import { declare } from "@babel/helper-plugin-utils";
|
|
|
|
export default declare((api, options) => {
|
|
api.assertVersion(7);
|
|
|
|
// When enabled and plugins includes flow, all files should be parsed as if
|
|
// the @flow pragma was provided.
|
|
const { all } = options;
|
|
|
|
if (typeof all !== "boolean" && typeof all !== "undefined") {
|
|
throw new Error(".all must be a boolean, or undefined");
|
|
}
|
|
|
|
return {
|
|
manipulateOptions(opts, parserOpts) {
|
|
// If the file has already enabled TS, assume that this is not a
|
|
// valid Flowtype file.
|
|
if (
|
|
parserOpts.plugins.some(
|
|
p => (Array.isArray(p) ? p[0] : p) === "typescript",
|
|
)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
parserOpts.plugins.push(["flow", { all }]);
|
|
},
|
|
};
|
|
});
|