fix (codemods/react/update-react-imports): resolve issues with detecting imports like * as React, add support for TypeScript structures, and fix MouseEvent handling in the codemod #9
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.
📚 Description
This PR introduces the following updates:
Fix Issue with Import Detection (e.g.,
import * as React from 'react'
):This update resolves an issue where imports like
import * as React from 'react'
were not being detected correctly by the codemod. This fix ensures that the codemod properly identifies and transforms such import statements, which is especially useful in projects using modern React patterns.Support for TypeScript Structures:
Added support for handling TypeScript-specific constructs such as interfaces, enums, and type imports. This allows the codemod to seamlessly process TypeScript code and apply necessary transformations, enhancing the migration and refactoring process for TypeScript projects.
Fix MouseEvent Handling:
A fix for an issue where
MouseEvent
was not being handled properly during transformations. This bug was causing certain UI-related codemods to fail or behave incorrectly. With this fix,MouseEvent
handling is now accurate, improving the reliability of transformations that involve DOM events.🔗 Linked Issue
Fixes #325 - [update-react-imports] skips files that contain type imports
🧪 Test Plan
import * as React from 'react'
📄 Documentation to Update
import * as React from 'react'
pattern insrc/index.ts
.src/index.ts
.MouseEvent
handling, describing common scenarios where this fix applies and how it improves transformation reliability insrc/index.ts
.src/test.ts
and__testfixtures__
.