Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Oct 24, 2025

Fixes bug where variables in shorthand assignments inside map callbacks weren't captured. Filters ShorthandPropertyAssignment from declarations and checks if identifiers match callback parameters.


Summary by cubic

Fixes incorrect capturing in map callbacks when using object shorthand, and prevents synthetic callback params from leaking into outer derives. This resolves runtime errors and aligns closure behavior with expected JSX map patterns.

  • Bug Fixes
    • Capture outer variables in shorthand property assignments inside map callbacks by treating ShorthandPropertyAssignment as non-declarations and checking callback parameters. Addresses CT-1004 where destructured recipe params weren’t moved into the closed-over scope.
    • Filter synthetic identifiers (no symbol) in outer-scope derive analysis. Keep synthetic params when inside a map-callback scope; drop them only at outer scope with multiple real captures. Prevents ReferenceError in nested map within conditionals.

@seefeldb seefeldb requested a review from mathpirate October 24, 2025 00:58
@linear
Copy link

linear bot commented Oct 24, 2025

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="packages/ts-transformers/src/closures/transformer.ts">

<violation number="1" location="packages/ts-transformers/src/closures/transformer.ts:187">
Array-destructured map parameters (e.g. `([item]) =&gt; ({ item })`) also trigger the `realDeclarations.length === 0` path, but this branch never recognizes ArrayBindingPattern names, so `item` is mis-classified as an outer capture and the transform emits `params: { item }` with `item` undefined at runtime. Please treat array patterns the same way as object ones here.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Fixes bug where variables in shorthand assignments inside map callbacks weren't captured. Filters ShorthandPropertyAssignment from declarations and checks if identifiers match callback parameters.
Array-destructured map parameters (e.g., `([item]) => ({ item })`) were
triggering the `realDeclarations.length === 0` path but the branch never
recognized ArrayBindingPattern names. This caused identifiers like `item`
to be mis-classified as outer captures, resulting in `params: { item }`
with `item` undefined at runtime.

This fix treats array binding patterns the same way as object binding
patterns by checking if identifiers match array-destructured parameter
names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@seefeldb seefeldb merged commit 260e93a into main Oct 24, 2025
8 checks passed
@seefeldb seefeldb deleted the berni/ct-1004-destructured-recipe-param-isnt-moved-into-closed-over branch October 24, 2025 01:58
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.

2 participants