Skip to content

fix(compile): preserve Redis class helper captures - #10876

Closed
proggeramlug wants to merge 1 commit into
mainfrom
fix/10660-super-capture
Closed

proggeramlug wants to merge 1 commit into
mainfrom
fix/10660-super-capture

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Closes #10660

@redis/client emits its private-field helper bindings as one comma-separated top-level var declaration spread across multiple lines. Perry's CommonJS hoist-safety scanner stopped at the first newline, missed the later bindings, and incorrectly moved RedisClient outside the module factory. That severed the class methods' captures of helpers such as _RedisClient_isolationPool, leaving capture slot 7 undefined.

Continue scanning across physical newlines only when a top-level comma proves the declaration continues. ASI-terminated declarations keep their existing behavior.

Validation:

  • cargo test -p perry cjs_wrap::tests --bin perry (108 passed)
  • patched compiler collected and generated all 543 modules in the real Redis harness; final runtime verification is in progress against the matching static runtime

Summary by CodeRabbit

  • Bug Fixes
    • Fixed CommonJS handling for multiline, comma-separated variable declarations.
    • Classes that depend on helper variables declared later in the same declaration now remain correctly scoped within their module.
    • Prevented runtime issues involving private-field helpers and dependent classes.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 6f93fe46-43aa-4a87-b5a8-a45355232273

📥 Commits

Reviewing files that changed from the base of the PR and between 89dd494 and cf8209f.

📒 Files selected for processing (3)
  • changelog.d/10660-cjs-multiline-var-hoist.md
  • crates/perry/src/commands/compile/cjs_wrap/hoist_classes.rs
  • crates/perry/src/commands/compile/cjs_wrap/tests/hoist_scanner.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The CommonJS top-level declaration scanner now handles comma-separated var declarators across physical lines. A regression test verifies that a dependent class remains inside the module factory. A changelog entry documents the fix.

Changes

CommonJS multiline variable hoisting

Layer / File(s) Summary
Scanner behavior and regression coverage
crates/perry/src/commands/compile/cjs_wrap/hoist_classes.rs, crates/perry/src/commands/compile/cjs_wrap/tests/hoist_scanner.rs, changelog.d/10660-cjs-multiline-var-hoist.md
The scanner continues a var declaration after a top-level comma, including across newlines, while preserving newline termination for ASI-terminated declarations. The regression test verifies that RedisClient is not hoisted when it captures a later helper binding. The changelog records the fix.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The changes address #10660 directly. The scanner now keeps comma-separated var declarations across physical newlines, and the regression test confirms that a dependent RedisClient class remains in… Provide completed Redis harness runtime verification that constructs and uses RedisClient without Cannot read private member from an object whose class did not declare it.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main fix: preserving Redis class helper captures during compilation.
Description check ✅ Passed The description explains the bug, cause, fix, linked issue, and validation results. It does not use the template headings or include the checklist, but it contains the required core information and is…
Out of Scope Changes check ✅ Passed The changed scanner logic, regression test, and changelog entry all support the #10660 CommonJS hoisting fix. No unrelated production behavior or unrelated files appear in the reviewed changes.
Full details: Linked Issues check

Explanation

The changes address #10660 directly. The scanner now keeps comma-separated var declarations across physical newlines, and the regression test confirms that a dependent RedisClient class remains inside the CommonJS factory. The summary reports 108 passing cjs_wrap tests and successful collection and generation of 543 Redis modules. However, final Redis runtime verification was still in progress, so the available evidence does not establish that the private-field error is eliminated during execution.

Full details: Docstring Coverage

Explanation

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

  • 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

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.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Closing after full real-package validation disproved the hypothesis: the patched 543-module Redis binary still throws the original private-helper error, and the installed @redis/client declaration is a single physical line. The scanner regression is real in isolation but does not fix #10660, so this should not merge as the issue fix.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed via merge train 252 (#10892) as v0.5.1632 — merge commit 841b605c97.

Carried with #10866, #10876, #10867, #10874 and #10862, which all touch overlapping surfaces.

Train-side work: #10867 and #10874 each add a module declaration to the same regression-test index (additive — both kept, sorted by issue); #10862's version-bump commits were excluded, since contributor PRs do not bump; and collect_modules.rs was allowlisted because it sat at exactly 2000 lines on main, so the one line these PRs add between them failed the cap.

Validation: 173 gap fixtures across seven areas, zero regressions, re-run against the current base after v0.5.1631 changed canonical_dir's path resolution — relevant because two of these PRs are about module resolution. All ratchets, cargo fmt, and cargo check --workspace --all-targets under -D warnings clean.

Closing here rather than merging — a train lands the commits directly.

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

Labels

None yet

Projects

None yet

1 participant