-
Notifications
You must be signed in to change notification settings - Fork 9
Fix: Filter synthetic identifiers from outer scope derives #1953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seefeldb
merged 3 commits into
main
from
berni/ct-1003-derive-in-map-in-derive-gets-element-not-defined
Oct 24, 2025
Merged
Fix: Filter synthetic identifiers from outer scope derives #1953
seefeldb
merged 3 commits into
main
from
berni/ct-1003-derive-in-map-in-derive-gets-element-not-defined
Oct 24, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fixes a bug where synthetic identifiers created by ClosureTransformer were leaking into derive calls in outer scopes, causing ReferenceError at runtime. The fix adds heuristic filtering in filterRelevantDataFlows() to detect when synthetic identifiers (those without symbol information) are being incorrectly included in outer-scope expressions. The heuristic: - Identifies synthetic vs non-synthetic dataflows by checking for symbol info - When mixing both: if non-synthetic flows all have outer-scope symbols (2+), we're at outer scope → filter synthetic ones - Otherwise we're inside a callback with captures → keep everything This approach is robust as it relies on symbol presence rather than hardcoded identifier names, so it won't break if user code happens to use variables named "element", "index", etc. Also adds test case for nested map within conditional to prevent regression and updates expected output for map-nested-conditional to correctly derive element properties. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this 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 3 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/transformers/opaque-ref/helpers.ts">
<violation number="1" location="packages/ts-transformers/src/transformers/opaque-ref/helpers.ts:152">
This heuristic treats callbacks that capture multiple outer variables as outer-scope expressions, so it drops the synthetic map parameter data flows; when a callback references two captured identifiers plus the synthetic parameter, the synthetic flow is removed and the derive call breaks.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
…e captures
The heuristic for filtering synthetic dataflows was too aggressive. It
treated callbacks that capture 2+ outer variables as outer-scope
expressions, which caused it to drop synthetic map parameter dataflows.
This broke derive calls when a callback referenced multiple captured
identifiers plus the synthetic parameter.
Example that was breaking:
```tsx
items.map((item, index) => (
<div>
{item.name} - {cell1.value} - {cell2.value} - {index}
</div>
))
```
The heuristic saw 2 outer-scope symbols (cell1, cell2) and incorrectly
filtered out the synthetic parameters (item, index).
Fix:
- Check if dataflows belong to a map callback scope before applying
the "2+ outer captures" heuristic
- If in a map callback scope, keep all dataflows (synthetic and captures)
- Only filter out ignored parameters
- This allows callbacks to legitimately capture multiple outer variables
while still using synthetic map parameters
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug where synthetic identifiers created by ClosureTransformer were leaking into derive calls in outer scopes, causing ReferenceError at runtime.
The fix adds heuristic filtering in filterRelevantDataFlows() to detect when synthetic identifiers (those without symbol information) are being incorrectly included in outer-scope expressions. The heuristic:
This approach is robust as it relies on symbol presence rather than hardcoded identifier names, so it won't break if user code happens to use variables named "element", "index", etc.
Also adds test case for nested map within conditional to prevent regression and updates expected output for map-nested-conditional to correctly derive element properties.
🤖 Generated with Claude Code
Summary by cubic
Fixes a runtime ReferenceError caused by synthetic identifiers leaking into outer-scope derive calls in nested map scenarios. Adds a heuristic to filter these synthetic params when analyzing outer scope.