Skip to content

Hoist module-level function declarations - #9

Open
puskuruk wants to merge 1 commit into
mainfrom
fix/hoist-module-function-declarations
Open

puskuruk wants to merge 1 commit into
mainfrom
fix/hoist-module-function-declarations

Conversation

@puskuruk

@puskuruk puskuruk commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

A module-level function declaration read before its position in the module body was not yet instantiated; function bodies already hoisted theirs. Module bodies now install their function declarations first, like Node.

  • fa65e86 Instantiate module-level function declarations before the module body's statements, as a function body's already are (gate: 28 corpus and 434 runtime programs moved to the hoisted install, gained module-function-declaration-read-before-its-position)

Verification: npm run build passed, npm run gate -- --write exit 0 (28 corpus and 434 runtime programs moved to the hoisted install, 0 drift rows on certified programs), node scripts/run-runtime-tests.mjs --only module-function-declaration-read-before-its-position 1 ok, prettier clean.

Related

Independent of the other three compiler fixes (#7, #8, #10); all four go into compiler release 1.0.38, which node-compat geastack/node-compat#8 (compile hello-nest ahead of time) needs.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected initialization of top-level function declarations, allowing them to be used before their textual declaration.
  • Tests
    • Added coverage verifying that routes are registered and the application starts when a function is called before its declaration.
    • Updated expected baseline hashes for affected fixtures.

…'s statements, as a function body's already are (gate: 28 corpus and 434 runtime programs moved to the hoisted install, gained module-function-declaration-read-before-its-position)
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b88c4aa-c874-4475-aa84-41682c9e4b5f
📥 Commits

Reviewing files that changed from the base of the PR and between d56bfb5 and fa65e86.

📒 Files selected for processing: 4
  • scripts/emitted-baseline-corpus.txt
  • scripts/emitted-baseline-runtime.txt
  • src/semantics/normalize/producers/allocations.ts
  • test/runtime/module-function-declaration-read-before-its-position.runtime.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Top-level function declarations now qualify for hoisted initialization. A runtime test checks that a function can be called before its textual declaration to register routes. The emitted-baseline corpus updates expected hashes for multiple fixtures.

Changes: Top-level function declaration hoisting

Layer / File(s) Summary
Hoisting behavior and runtime verification
src/semantics/normalize/producers/allocations.ts, test/runtime/module-function-declaration-read-before-its-position.runtime.ts, scripts/emitted-baseline-corpus.txt
The allocation check accepts source-file-level function declarations while preserving the block-level rule. The runtime test calls defineRoutes before its declaration and checks the registered routes and listening output. Expected emitted-baseline hashes are updated.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: dashersw

Merge Risk: ⚪ Minimal · up to fa65e

Module-level function declarations can now be called before their textual position while retaining normal module-binding behavior. No material merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: hoisting module-level function declarations.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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