Skip to content

Commit

Permalink
fix flow-comment - object destructuring (#9893)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and nicolo-ribaudo committed Apr 26, 2019
1 parent 80a5a2e commit 7101308
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/babel-plugin-transform-flow-comments/src/index.js
Expand Up @@ -127,6 +127,17 @@ export default declare(api => {
}
wrapInFlowComment(path, parent);
},
ObjectPattern(path) {
const { node } = path;
if (node.typeAnnotation) {
const typeAnnotation = path.get("typeAnnotation");
path.addComment(
"trailing",
generateComment(typeAnnotation, typeAnnotation.node),
);
typeAnnotation.remove();
}
},

Flow(path) {
const { parent } = path;
Expand Down
@@ -0,0 +1,3 @@
function add({ a, b }: {a: number, b: number}): number {
return a + b;
}
@@ -0,0 +1,10 @@
function add({
a,
b
}
/*: {a: number, b: number}*/
)
/*: number*/
{
return a + b;
}
@@ -0,0 +1 @@
const { a, b }: { a: number, b: number } = { a: 1, b: 2 };
@@ -0,0 +1,9 @@
const {
a,
b
}
/*: { a: number, b: number }*/
= {
a: 1,
b: 2
};

0 comments on commit 7101308

Please sign in to comment.