Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Oct 24, 2025

Replaces fragile heuristic-based detection of map callbacks with explicit
marking using a shared WeakSet registry. This fixes bugs where synthetic
identifiers (element, index, array) leaked into outer scope derives.

Problem:

  • ClosureTransformer creates synthetic identifiers without symbols for map params
  • OpaqueRefJSXTransformer analyzes transformed AST and needs to distinguish:
    1. Synthetic params INSIDE map callbacks (keep)
    2. Synthetic params that leaked to outer scope (filter out)
  • Previous heuristics based on counting dataflows were brittle and error-prone

Solution:

  1. Add mapCallbackRegistry: WeakSet<ts.Node> to TransformationOptions
  2. ClosureTransformer marks arrow functions when creating map callbacks
  3. OpaqueRefJSXTransformer checks marking to detect map callback scopes
  4. Filter logic:
    • Only synthetic dataflows → inside callback (keep all)
    • Mixed synthetic + non-synthetic → check if in marked callback
    • If not in marked callback → filter out synthetic params

Benefits:

  • Direct knowledge instead of heuristics (no more magic thresholds)
  • Clear contract between transformers via shared registry
  • More maintainable - reduced from ~130 lines to ~100 lines
  • Fixes "element is not defined" runtime errors

🤖 Generated with Claude Code


Summary by cubic

Prevents synthetic map params (element, index, array) from leaking into outer derives by explicitly tracking map callbacks with a shared WeakSet. Fixes “element is not defined” errors and removes brittle heuristics.

  • Bug Fixes

    • Filter synthetic params when they appear outside a marked map callback.
    • Fix runtime errors in JSX map expressions.
    • Add test fixture for a single capture in JSX map.
  • Refactors

    • Add mapCallbackRegistry: WeakSet<ts.Node> to TransformationOptions and pipeline.
    • Mark map callbacks in ClosureTransformer and check with context.isMapCallback in OpaqueRefJSXTransformer.
    • Simplify dataflow filtering: keep pure synthetic inside callbacks; filter synthetic when outside.

seefeldb and others added 2 commits October 24, 2025 10:34
Fixes bug where element/index/array leaked into outer scope derives.
Adds special case handling for single non-synthetic dataflow with synthetic map params.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Replaces fragile heuristic-based detection of map callbacks with explicit
marking using a shared WeakSet registry. This fixes bugs where synthetic
identifiers (element, index, array) leaked into outer scope derives.

**Problem:**
- ClosureTransformer creates synthetic identifiers without symbols for map params
- OpaqueRefJSXTransformer analyzes transformed AST and needs to distinguish:
  1. Synthetic params INSIDE map callbacks (keep)
  2. Synthetic params that leaked to outer scope (filter out)
- Previous heuristics based on counting dataflows were brittle and error-prone

**Solution:**
1. Add `mapCallbackRegistry: WeakSet<ts.Node>` to TransformationOptions
2. ClosureTransformer marks arrow functions when creating map callbacks
3. OpaqueRefJSXTransformer checks marking to detect map callback scopes
4. Filter logic:
   - Only synthetic dataflows → inside callback (keep all)
   - Mixed synthetic + non-synthetic → check if in marked callback
   - If not in marked callback → filter out synthetic params

**Benefits:**
- Direct knowledge instead of heuristics (no more magic thresholds)
- Clear contract between transformers via shared registry
- More maintainable - reduced from ~130 lines to ~100 lines
- Fixes "element is not defined" runtime errors

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

Co-Authored-By: Claude <noreply@anthropic.com>
@seefeldb seefeldb requested a review from mathpirate October 24, 2025 18:06
@seefeldb seefeldb merged commit d495fac into main Oct 24, 2025
8 checks passed
@seefeldb seefeldb deleted the berni/fix-synthetic-map-params-leak branch October 24, 2025 18:21
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.

No issues found across 8 files

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