Skip to content

Refactor type generation to use AST parsing and TypeScript compiler API - #1

Merged
joshmanders merged 11 commits into
masterfrom
improvements
Jan 6, 2026
Merged

Refactor type generation to use AST parsing and TypeScript compiler API#1
joshmanders merged 11 commits into
masterfrom
improvements

Conversation

@joshmanders

@joshmanders joshmanders commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Refactored PHP parsing to use php-parser AST instead of regex for more reliable extraction
  • Refactored TypeScript code generation to use the TypeScript Compiler API (ts.factory) instead of string templates
  • Added prettyPrint option to control formatting of generated runtime JavaScript
  • Added typescript@^5 as a peer dependency (required for code generation)
  • Added comprehensive test suite with 100 tests covering all generators and utilities

Breaking Changes

  • Enum label method renamed: The plugin now looks for label() instead of getLabel() when extracting enum labels. Update your PHP enums accordingly:

    // Before
    public function getLabel(): string { ... }
    
    // After
    public function label(): string { ... }

- Add php-parser package for proper PHP AST parsing
- Use parseEval() which doesn't require <?php tags
- Support numeric enum values (string | number)
- Extract enum cases, model casts, and resource fields from AST
- Add docblock array shape extraction for type hints
- Add printNode/printNodes for AST to string conversion
- Add createEnum for enum declarations
- Add createObjectLiteral/createConstObject for object expressions
- Add createTypeAlias/createTypeLiteral for type declarations
- Add createImportType for type-only imports
- Add parseTypeString for parsing type strings to AST nodes
- Support configurable multiLine formatting for pretty printing
- Replace manual string building with TypeScript factory API
- Use createEnum for traditional enums
- Use createDeclareConstWithType for enums with labels
- Use createObjectLiteral for runtime enum values
- Add prettyPrint parameter to generateEnumRuntime
- Replace manual string building with TypeScript factory API
- Use createTypeAlias for resource type declarations
- Use createTypeLiteral for property signatures
- Use createImportType for enum imports
- Add prettyPrint option to ResourceGeneratorOptions
- Add prettyPrint option to ResourceTypesPluginOptions (default: true)
- Pass prettyPrint through to enum and resource generators
- Refactor options handling to use nullish coalescing
- Add vitest as dev dependency with test scripts
- Add typescript as peer dependency for code generation
- Add php-parser as runtime dependency
- Add tests for php-parser (enum parsing, model casts, docblocks)
- Add tests for ts-generator (all utility functions)
- Add tests for enum generator (TypeScript and runtime output)
- Add tests for resource generator (type inference, imports)
- Add tests for type-mapper utilities
- Include PHP fixture files for integration tests
@joshmanders
joshmanders merged commit f0a685a into master Jan 6, 2026
1 check passed
@joshmanders
joshmanders deleted the improvements branch January 6, 2026 05:14
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