Throw if annotation found without directive

This commit is contained in:
Brian Ng
2017-08-03 21:54:36 -05:00
parent 57da9bdbed
commit af5f34ace5
11 changed files with 21 additions and 5 deletions

View File

@@ -55,4 +55,5 @@ require("babel-core").transform("code", {
`boolean`, defaults to `false`.
Setting this to true will only strip annotations and declarations from files
that contain the `// @flow` directive.
that contain the `// @flow` directive. It will also throw errors for any Flow
annotations found in files without the directive.

View File

@@ -47,7 +47,13 @@ export default function({ types: t }) {
},
Flow(path) {
if (skipStrip) return;
if (skipStrip) {
throw path.buildCodeFrameError(
"A @flow directive is required when using Flow annotations with " +
"babel-preset-react or the `requireDirective` option.",
);
}
path.remove();
},

View File

@@ -0,0 +1,3 @@
{
"throws": "A @flow directive is required when using Flow annotations with babel-preset-react or the `requireDirective` option."
}

View File

@@ -14,8 +14,10 @@ And with the `development` option:
- [transform-react-jsx-self](https://babeljs.io/docs/plugins/transform-react-jsx-self/)
- [transform-react-jsx-source](https://babeljs.io/docs/plugins/transform-react-jsx-source/)
Note: Flow annotations and declarations will _only_ be removed in files that
have the `// @flow ` directive.
Note: This preset sets the `requireDirective` option on
`transform-flow-strip-types`. This means Flow annotations and declarations
will _only_ be removed in files that have a `// @flow ` directive. It will also
throw errors for any Flow annotations found in files without the directive.
```js
// @flow

View File

@@ -1 +0,0 @@
function foo(numVal: number, strVal: string) {}

View File

@@ -0,0 +1,3 @@
{
"throws": "A @flow directive is required when using Flow annotations with babel-preset-react or the `requireDirective` option."
}