Skip to content

fix: enforce implicit return assertion for non-empty function bodies#301

Open
ncthuc2004 wants to merge 1 commit into
gajus:masterfrom
ncthuc2004:issuehunt-2-implicit-return-check
Open

fix: enforce implicit return assertion for non-empty function bodies#301
ncthuc2004 wants to merge 1 commit into
gajus:masterfrom
ncthuc2004:issuehunt-2-implicit-return-check

Conversation

@ncthuc2004
Copy link
Copy Markdown

@ncthuc2004 ncthuc2004 commented May 16, 2026

Summary

  • fix implicit return assertion insertion for non-empty function bodies in babel-plugin-flow-runtime
  • correct last-statement check so a synthetic return; is added when there is no explicit ReturnStatement
  • add regression fixture for a function body with statements and no explicit return

Why

Issue #2 reports missing return assertions for implicit returns.
The current condition uses incorrect boolean precedence and fails to append return; in non-empty bodies unless the last statement is explicitly return.

Validation

  • targeted transform test:
    • TEST_FILTER=2-implicit-function-return-with-body
    • npx mocha --opts NUL --require @babel/polyfill --require ./test-polyfill.js src/__tests__/transform.test.js --timeout 10000
  • result: 1 passing

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant