diff --git a/packages/babel-plugin-flow-runtime/src/__tests__/__fixtures__/bugs/2-implicit-function-return-after-statement.js b/packages/babel-plugin-flow-runtime/src/__tests__/__fixtures__/bugs/2-implicit-function-return-after-statement.js new file mode 100644 index 0000000..f85830d --- /dev/null +++ b/packages/babel-plugin-flow-runtime/src/__tests__/__fixtures__/bugs/2-implicit-function-return-after-statement.js @@ -0,0 +1,18 @@ +/* @flow */ + +export const input = ` +function testFunction() : string { + const value = "hello"; +} +`; + +export const expected = ` +import t from "flow-runtime"; + +function testFunction() { + const _returnType = t.return(t.string()); + + const value = "hello"; + return _returnType.assert(); +} +`; diff --git a/packages/babel-plugin-flow-runtime/src/transformVisitors.js b/packages/babel-plugin-flow-runtime/src/transformVisitors.js index e88d0f7..f1e062e 100644 --- a/packages/babel-plugin-flow-runtime/src/transformVisitors.js +++ b/packages/babel-plugin-flow-runtime/src/transformVisitors.js @@ -504,7 +504,7 @@ export default function transformVisitors (context: ConversionContext): Object { if (body.node.body // do not add if last statement is return one && (body.node.body.length === 0 - || !body.node.body[ body.node.body.length - 1].type === "ReturnStatement") + || body.node.body[body.node.body.length - 1].type !== 'ReturnStatement') ) { // we do not add arguments here // only "return;"