-
Notifications
You must be signed in to change notification settings - Fork 11
refactor(ts-transformers): Simplify dataflow analyzer internal types #2191
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
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
Contributor
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.
No issues found across 1 file
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 Net result: -38 lines, simpler types, clearer data flow. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
0ae57d3 to
cb1c3c3
Compare
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.
Two key simplifications to the data flow analysis code:
Replace localNodes with expressionToNodeId Map
Eliminate DataFlowScopeInternal type
aggregatedSet in favor of on-demand computationNet result: -38 lines, simpler types, clearer data flow.
A third major simplification is pending to unify logical paths for handling synthetic and non-synthetic nodes.
Summary by cubic
Simplifies the data flow analyzer by removing localNodes and DataFlowScopeInternal, switching to an expression→node map and on-demand scope aggregation. Also unifies synthetic/non-synthetic handling with safe symbol/type lookups and complete JSX handling.
Written for commit cb1c3c3. Summary will update automatically on new commits.