diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index 7399d65c9f..bf4e5acaff 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -5,7 +5,7 @@ import { types as t } from "@babel/core"; export default declare(api => { api.assertVersion(7); - const FLOW_DIRECTIVE = "@flow"; + const FLOW_DIRECTIVE = /(@flow(\s+(strict(-local)?|weak))?|@noflow)/; let skipStrip = false; @@ -28,7 +28,7 @@ export default declare(api => { if (comments) { for (const comment of (comments: Array)) { - if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) { + if (FLOW_DIRECTIVE.test(comment.value)) { directiveFound = true; // remove flow directive diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-noflow/input.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-noflow/input.js new file mode 100644 index 0000000000..5d6ff3552a --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-noflow/input.js @@ -0,0 +1,2 @@ +// @noflow +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-noflow/output.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-noflow/output.js new file mode 100644 index 0000000000..6d3cec7eee --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-noflow/output.js @@ -0,0 +1 @@ +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict-local/input.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict-local/input.js new file mode 100644 index 0000000000..02271a151c --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict-local/input.js @@ -0,0 +1,2 @@ +// @flow strict-local +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict-local/output.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict-local/output.js new file mode 100644 index 0000000000..6d3cec7eee --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict-local/output.js @@ -0,0 +1 @@ +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict/input.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict/input.js new file mode 100644 index 0000000000..08a31836de --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict/input.js @@ -0,0 +1,2 @@ +// @flow strict +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict/output.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict/output.js new file mode 100644 index 0000000000..6d3cec7eee --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-strict/output.js @@ -0,0 +1 @@ +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-weak/input.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-weak/input.js new file mode 100644 index 0000000000..1e784b3507 --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-weak/input.js @@ -0,0 +1,2 @@ +// @flow weak +const a = 1; \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-weak/output.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-weak/output.js new file mode 100644 index 0000000000..6d3cec7eee --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-comment-weak/output.js @@ -0,0 +1 @@ +const a = 1; \ No newline at end of file