Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* @flow */

export const input = `
function foo<X>() {
let bar: X;
}
`;

export const expected = `
import t from "flow-runtime";

function foo() {
const X = t.typeParameter("X");
let _barType = X,
bar;
}
`;

export const annotated = `
import t from "flow-runtime";

function foo() {
let bar;
}

t.annotate(foo, t.function(_fn => {
const X = _fn.typeParameter("X");
return [];
}));
`;
13 changes: 7 additions & 6 deletions packages/babel-plugin-flow-runtime/src/transformVisitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,17 @@ export default function transformVisitors (context: ConversionContext): Object {
if (!id.has('typeAnnotation')) {
return;
}
if (!shouldCheck) {
return;
}
if (!id.isIdentifier()) {
invariant(id.isArrayPattern() || id.isObjectPattern());
const init = path.get('init');
let wrapped = init.node;
if (shouldCheck) {
wrapped = context.assert(
convert(context, id.get('typeAnnotation')),
wrapped
);
}
wrapped = context.assert(
convert(context, id.get('typeAnnotation')),
wrapped
);
if (wrapped !== init.node) {
context.replacePath(init, wrapped);
}
Expand Down