fix(codegen): publish self namespace re-exports as live accessors (#10160) - #10162
proggeramlug wants to merge 1 commit into
Conversation
…rryTS#10160) `export * as Self from "./self"` lowered to a NestedNamespace entry whose value was a plain load of the module's own `@__perry_ns_<prefix>` global — inside the populator that builds that very namespace, before the global is stored. The dynamic `import()` namespace therefore carried the key with an `undefined` value while the static import path still resolved. OpenCode uses this self re-export in 265 modules and reads it through dynamic imports in its command bootstrap, so every real command failed with `Cannot read properties of undefined (reading 'Service')`. Self-referencing entries are now published like LocalVar/ForeignVar live bindings: the populator marks them live and hands `js_create_namespace` a getter singleton, and the getter wrapper loads the namespace global at read time. Foreign `export * as` entries keep the direct load. Claude-Session: https://claude.ai/code/session_01GixUo7gwcatEk4kibdeCWF
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe code generator now handles ChangesSelf-namespace export resolution
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: High Merge Risk: ⚪ Minimal · up to The self-namespace export behavior is covered by the updated generator and regression tests, with no actionable merge risk identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
export * as Self from "./self"(a module re-exporting its own namespace — OpenCode does this in 265 modules) wasundefinedwhen read through a dynamicimport()namespace, while the static import resolved. TheNestedNamespaceentry's value was a plain load of the module's own@__perry_ns_<prefix>global emitted inside the populator that builds that namespace, i.e. before the global is stored. OpenCode's command bootstrap reads it exactly that way (const { InstanceStore } = await import("@/project/instance-store")), so every real command (run,models,serve, TUI) died withCannot read properties of undefined (reading 'Service').Changes
emit_namespace_populator(helpers.rs): a self-referencingNestedNamespaceentry is published as a live binding — flagged live and materialized as ajs_closure_alloc_singletonof its__perry_ns_get_<prefix>__<i>wrapper, likeLocalVar/ForeignVar. Foreignexport * asentries keep the direct load of the target's global.@__perry_ns_<prefix>at read time.crates/perry/tests/source_graph_export_regressions/issue_10160.rs): self re-export through a dynamic namespace (destructuring, property read, recursionns.Self.Self === ns.Self), through a staticimport * as, and a foreignexport * ason a dynamic namespace (unchanged behaviour).changelog.d/10160-self-namespace-dynamic-import.md.Known separate gap, left alone:
mod.Self === StaticBindingisfalseunder Perry (the static import binding and the dynamic namespace are not the same object); ESM makes them identical.Related issue
Fixes #10160
Test plan
cargo test -p perry --test source_graph_export_regressions issue_10160— 3 passed (Linux x86-64 build host, dedicated target dir)cargo fmt --all -- --check,./scripts/check_file_size.shdyn destructured: object function/dyn use: store-ok!)opencode models/runare the acceptance rungs (results will be posted on tracking: OpenCode v1.18.30 — complete native build from real TypeScript (no stripping, no bundle), startup faster than bun #10107)Checklist
fix:prefix convention used in the logCONTRIBUTING.mdand agree to the Code of Conducthttps://claude.ai/code/session_01GixUo7gwcatEk4kibdeCWF
Summary by CodeRabbit
Bug Fixes
export * as Selfcorrectly resolves through dynamic imports.Tests