# `.map()` after fallback expression not transformed to `mapWithPattern` ## Summary When `.map()` is called on an expression that includes a fallback (`|| []` or `?? []`), the `.map()` is not transformed to `mapWithPattern`. This causes runtime errors when the callback accesses variables from outer scopes. ## Repro ```typescript messages.map((msg) => { // Any of these patterns fail: const x = computed(() => (msg.reactions) || []); {x.map((r) => )} // Or inline: {(msg.reactions || []).map((r) => )} {(msg.reactions ?? []).map((r) => )} }) ``` **Minimal repro file**: `packages/ts-transformers/test/fixtures/pending/computed-var-then-map.input.tsx` ```bash # See untransformed .map() in output deno task ct dev packages/ts-transformers/test/fixtures/pending/computed-var-then-map.input.tsx --no-run # Runtime error deno task ct charm new packages/ts-transformers/test/fixtures/pending/computed-var-then-map.input.tsx \ -a http://localhost:8000 -s test -i claude.key ``` ## Expected - `.map()` after fallback should be transformed to `.mapWithPattern()` - Outer scope variables (`msg.id`) should be captured in params ## Actual - Fallback becomes: `derive({ msg }, ({ msg }) => msg.reactions || [])` - But `.map()` on that result stays as plain `.map()` - Runtime error: `"Cell with parent cell not found in current frame. Likely a closure that should have been transformed."` ## Root Cause In `map-strategy.ts`, the checks for whether `.map()` needs transformation both fail: 1. **`isDeriveCall(target)`** — Only detects *direct* `derive()` call expressions, not identifiers or complex expressions that evaluate to derive results 2. **`isOpaqueRefType(targetType)`** — The type registry stores the *unwrapped* callback return type (`Reaction[] | never[]`), not `OpaqueRef`. So the type check fails. The `|| []` fallback expression gets wrapped in a derive by the transformer, but the resulting `.map()` call doesn't recognize its target as needing transformation. ## Workaround Use direct property access without fallback: ```typescript // Works - msg.reactions is recognized as OpaqueRef {msg.reactions.map((r) => )} ``` This requires making the property non-optional and ensuring it's always an array. ## Potential Fixes 1. **Track derive result identifiers**: When a variable is assigned from a derive call, mark it so `isDeriveCall()` can recognize the identifier 2. **Store OpaqueRef type in registry**: Instead of storing the unwrapped callback return type, store `OpaqueRef` so `isOpaqueRefType()` works 3. **Check parent expression**: When `.map()` target is a complex expression involving `||` or `??`, check if either operand is an opaque type