Commit 819fa28
authored
refactor(ts-transformers): Simplify dataflow analyzer internal types (commontoolsinc#2191)
* refactor(ts-transformers): Simplify dataflow analyzer internal types
Two key simplifications to the data flow analysis code:
1. Replace localNodes with expressionToNodeId Map
- Eliminates InternalAnalysis.localNodes field entirely
- Parent-child relationships now tracked via O(1) Map lookup
- Reduces merge complexity (no more localNodes concatenation)
- ~30 lines removed across return sites
2. Eliminate DataFlowScopeInternal type
- Merge into DataFlowScope by computing enriched parameters eagerly
- Remove pre-computed `aggregated` Set in favor of on-demand computation
- getAggregatedSymbols() walks parent chain when needed
- Remove toDataFlowScope() conversion function
* refactor(ts-transformers): Unify synthetic/non-synthetic analysis paths
Remove the separate ~300 line synthetic node handling block by integrating
fallback logic into the unified expression handlers. This refactoring:
- Adds tryGetSymbol/tryGetType helpers that gracefully handle synthetic nodes
- Updates each expression handler to try checker methods first, then fall back
to heuristics when dealing with synthetic nodes
- Removes duplicate logic that was maintained in two places
- Adds proper handlers for JsxSelfClosingElement and JsxFragment
Net result: 214 lines removed (432 deletions, 218 insertions)
* refactor(ts-transformers): Complete JSX handling in dataflow analyzer
The dataflow analyzer now provides complete, self-contained analysis
for JSX elements including both attributes and children.
Previously, attribute analysis used `ts.isExpression(attr)` which
always returned false for JsxAttribute nodes (dead code). The system
worked because the OpaqueRefJSXTransformer handled JSX at the visitor
level, but this created unclear contracts and hidden coupling.
Now the analyzer properly handles:
- JsxAttribute with expression initializers: `value={expr}`
- JsxSpreadAttribute: `{...expr}`
- JsxElement children (JsxExpression, nested elements)
- JsxSelfClosingElement
- JsxFragment
This makes the analyzer's contract clear: callers get correct results
regardless of how they traverse the AST.1 parent 3e1d2ea commit 819fa28
1 file changed
+260
-451
lines changed
0 commit comments