Skip to content
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

V2 with typescript compiler #2

Merged
merged 4 commits into from
Dec 30, 2024
Merged

V2 with typescript compiler #2

merged 4 commits into from
Dec 30, 2024

Conversation

theBGuy
Copy link
Owner

@theBGuy theBGuy commented Dec 30, 2024

Description

This pull request migrates the code's parsing logic from using Babel-based tools to utilizing the official TypeScript compiler API (typescript library). This change enhances the reliability, type safety, and ease of maintenance when processing TypeScript and JSX/TSX files.

Additionally this pull request includes significant updates to the project configuration, codebase, and documentation. The changes focus on integrating Biome for linting and formatting, refactoring TypeScript components, updating dependencies, and improving documentation.

Key Changes:

  • Switch to TypeScript Compiler (typescript):

    • Replaced the Babel parsing and AST manipulation with the TypeScript compiler API.
    • Used ts.createSourceFile to parse TypeScript and JSX/TSX files and generate an AST.
    • The transformation logic is now implemented using the TypeScript
      TransformationContext and ts.visitEachChild instead of Babel’s traversal and
      transformation methods.
  • Improved Type Handling:

    • TypeScript’s native AST is now directly used, which ensures better handling of TypeScript-specific syntax, such as type annotations, interfaces, and generics.
  • Property Removal Logic:

    • Added logic to remove unused properties from the StyleSheet.create call in TypeScript files.
    • The properties are filtered based on whether they are being used in the code, and any unused properties are removed from the object literal. If no properties remain, the StyleSheet.create call is completely removed.
  • File Output Optimization:

    • Introduced a check to ensure files are only written if modifications were made (i.e., if properties were removed from the StyleSheet.create call).
      If no changes are detected, the file is left untouched, improving performance and reducing unnecessary writes.

Configuration and Dependencies:

  • biome.jsonc: Added Biome configuration to enable import organization, linting, and formatting rules.
  • package.json: Removed Babel dependencies and added Biome as a new dependency.

Code Refactoring:

  • example/_clean.tsx: Replaced TestComponent with a new TypeScriptComponent that includes TypeScript typing and a sample function.
  • src/index.ts: Refactored to replace Babel with TypeScript for parsing and transforming files, and updated the command-line interface options. [1] [2]

Documentation:

  • readme.md: Updated to reflect the support for TypeScript React Native projects and added a warning about code formatting during the cleaning process. [1] [2]

Testing:

  • test/index.test.ts: Added new test cases for TypeScript files and updated existing tests to reflect the changes in the codebase. [1] [2] [3]

@theBGuy theBGuy merged commit 196ead2 into master Dec 30, 2024
@theBGuy theBGuy deleted the v2-with-typescript-compiler branch December 30, 2024 05:28
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.

1 participant