From a262e99abd7db0f36bd0c3ce30f1c5e02d0608a8 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 7 Jul 2015 10:52:43 +0100 Subject: [PATCH] strip flow directives in flow transformer - fixes #1934 --- src/babel/transformation/transformers/other/flow.js | 7 +++++++ .../transformation/flow/strip-directive/actual.js | 9 +++++++++ .../transformation/flow/strip-directive/expected.js | 1 + 3 files changed, 17 insertions(+) create mode 100644 test/core/fixtures/transformation/flow/strip-directive/actual.js create mode 100644 test/core/fixtures/transformation/flow/strip-directive/expected.js diff --git a/src/babel/transformation/transformers/other/flow.js b/src/babel/transformation/transformers/other/flow.js index f058924a59..84dda2a7d5 100644 --- a/src/babel/transformation/transformers/other/flow.js +++ b/src/babel/transformation/transformers/other/flow.js @@ -5,6 +5,13 @@ export var metadata = { }; export var visitor = { + Program(node, parent, scope, file) { + for (var comment of (file.ast.comments: Array)) { + if (comment.value.indexOf("@flow") >= 0) { + comment._displayed = true; + } + } + }, Flow() { this.dangerouslyRemove(); }, diff --git a/test/core/fixtures/transformation/flow/strip-directive/actual.js b/test/core/fixtures/transformation/flow/strip-directive/actual.js new file mode 100644 index 0000000000..575f234bbc --- /dev/null +++ b/test/core/fixtures/transformation/flow/strip-directive/actual.js @@ -0,0 +1,9 @@ +/*@flow*/ + +/* @flow */ + +/** + * @flow + */ + +foo(); diff --git a/test/core/fixtures/transformation/flow/strip-directive/expected.js b/test/core/fixtures/transformation/flow/strip-directive/expected.js new file mode 100644 index 0000000000..a280f9a5cc --- /dev/null +++ b/test/core/fixtures/transformation/flow/strip-directive/expected.js @@ -0,0 +1 @@ +foo();