gajus / gajus/flow-runtime

Add assertions when implicitly returning from a function

Open
#2 3 comments 0 reactions 0 assignees View on GitHub
:dollar: Funded on Issuehunt enhancement low-priority
Dominant language
JavaScript
Stars
797
Forks
49
PR merge metrics
No merged PRs in 30d

Description

[Issuehunt badges](https://oss.issuehunt.io/r/gajus/flow-runtime/issues/2)

Currently if a function implicitly returns undefined (by leaving the function without an explicit `return ` statement) we won't generate a check for it, e.g:

```js
function foo (): string {
// no return
}
```
currently compiles to:
```js
function foo () {
const _returnType = t.return(t.string());
// no return
}
```

We should insert a call to `_returnType.assert(undefined)` at these points.

---

IssueHunt Summary

### Backers (Total: $20.00)

- [issuehunt issuehunt](https://oss.issuehunt.io/u/issuehunt) ($20.00)

### Submitted pull Requests
- [#249 For #2: Add explicit return (with assetion) if last function statement is not return one](https://oss.issuehunt.io/r/gajus/flow-runtime/pull/249)
- [#301 fix: enforce implicit return assertion for non-empty function bodies](https://oss.issuehunt.io/r/gajus/flow-runtime/pull/301)
- [#306 Fix implicit return assertions after fallthrough statements](https://oss.issuehunt.io/r/gajus/flow-runtime/pull/306)
---

#### [Become a backer now!](https://oss.issuehunt.io/r/gajus/flow-runtime/issues/2)
#### [Or submit a pull request to get the deposits!](https://oss.issuehunt.io/r/gajus/flow-runtime/issues/2)
### Tips

- Checkout the [Issuehunt explorer](https://oss.issuehunt.io/r/gajus/flow-runtime/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://oss.issuehunt.io/r/new) on IssueHunt to raise funds.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue provides a JavaScript function example and the expected generated assertion, but names no files or tests. Start by tracing the Babel plugin's function-return handling for fallthrough paths. Done means implicitly returning undefined produces a _returnType.assert(undefined) call, with coverage for the shown case and other fallthrough statements.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.