You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Filter synthetic identifiers from outer scope derives (#1953)
* Fix: Filter synthetic identifiers from outer scope derives
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>
* fix(ts-transformers): keep synthetic params in callbacks with multiple 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>
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments