Repository navigation
fix(oracles): own object-literal functions reached via dynamic lookup or whole-value reference - #197
schiller-manuel wants to merge 1 commit into
Conversation
… or whole-value reference
When an owned function accesses a module-level object literal dynamically
(e.g. handlers[message.method]) or passes it as a whole value (e.g.
Object.values(handlers), dispatch(handlers)), which member is called is
unknown statically, so ownership now brings every function defined inside
the declaration's value into the caller's tree — matching the existing
rule for classes passed as values.
Static property reads (handlers.openProject(), handlers['openProject']())
and direct owns entries naming the data variable (src/x.ts#handlers) still
leave unreferenced sibling methods and function properties unowned. This
also fixes two related reference-resolution issues in owners.mjs:
- skip PropertyAssignment declaration names when walking module-level data
so arrow/function property assignments behave consistently with methods
- resolve ShorthandPropertyAssignment value symbols ({ fnA, fnB })
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 27 minutes. View limit details
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. |
|
Problem
When an owned function dispatches dynamically through a module-level object literal (e.g.
const handlers = { initialize: ..., openProject() {}, transform() {}, closeProject() {} }; handlers[message.method](params)) or passes it as a whole value (dispatch(handlers),Object.values(handlers)),oracle-gapsreported the object literal's methods as unowned warnings.Findings
Checking
owners.mjsandgap-report-static-oracle.property.test.mjs:D_FNS.used()leavesspareunowned:a method of read module data that nothing calls unowned).ownsentries naming the variable (owns: ['src/sut.ts#D_FNS']leaves methods unowned:a method of module data that an entry names unowned).handlers[key]) and whole-value references (dispatch(handlers),Object.values(handlers)) were not excluded by any law — this was an oversight compared to classes, where the existing law already states: "A class passed as a value brings all its methods, because which one is called is unknown statically".owners.mjs:referencesOfonly skippedts.isFunctionLike(child), soPropertyAssignmentdeclaration names (initialize: (p) => ...) were accidentally visited as references, pulling arrow/function properties in even on static dot-reads and directownsentries while missingMethodDeclarations.ShorthandPropertyAssignment(const handlers = { fnA, fnB }) resolved to the shorthand property declaration rather than its value symbol (getShorthandAssignmentValueSymbol).Changes
packages/oracles/oracle-gaps/owners.mjs:export default, ormodule.exports =) is referenced dynamically (handlers[key]) or as a whole value (dispatch(handlers),Object.values(handlers), etc.), bring every function defined inside its value's span into the caller's ownership tree.handlers.openProject(), resolved literalhandlers['openProject']()), type-only/typeofpositions (keyof typeof handlers), and directowns: ['src/x.ts#handlers']entries leaving sibling functions unowned.PropertyAssignmentdeclaration names inreferencesOfso arrow/function properties and method declarations behave consistently.ShorthandPropertyAssignmentvalue symbols viachecker.getShorthandAssignmentValueSymbol.packages/oracles/tests/oracle-gaps-owns-through-calls.test.ts:keyof typeoftype queries, direct dataownsentries, whole-value passing,Object.freeze/nested tables, shorthand properties, and cross-file/default/namespace imports.packages/oracles/skills/oracles-design/SKILL.md(Step 6, Ownership):ownsentries for object-literal dispatch maps.Validation
pnpm test— passedpnpm --filter @tanstack/oracles test:oracle-gaps:fast— passed (5 test files, 33,899 tests, including allgap-report-static-oraclemodule-data laws)pnpm --filter @tanstack/oracles test:oracle-gaps:shards— passed (5 shards)pnpm --filter @tanstack/oracles test:pr-shards— passed (7 partitions)pnpm lint:check— passedpnpm format:check— passedpnpm typecheck— passedpnpm build— passed