Throw if annotation found without directive
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
function foo(numVal, strVal) {}
|
||||
@@ -0,0 +1 @@
|
||||
function foo(numVal, strVal) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "A @flow directive is required when using Flow annotations with babel-preset-react or the `requireDirective` option."
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
function foo(numVal: number, strVal: string) {}
|
||||
3
packages/babel-preset-react/test/fixtures/flow/throws-without-directive/options.json
vendored
Normal file
3
packages/babel-preset-react/test/fixtures/flow/throws-without-directive/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "A @flow directive is required when using Flow annotations with babel-preset-react or the `requireDirective` option."
|
||||
}
|
||||
Reference in New Issue
Block a user