Refactor type generation to use AST parsing and TypeScript compiler API - #1
Merged
Conversation
- 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
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
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.
Summary
php-parserAST instead of regex for more reliable extractionts.factory) instead of string templatesprettyPrintoption to control formatting of generated runtime JavaScripttypescript@^5as a peer dependency (required for code generation)Breaking Changes
Enum label method renamed: The plugin now looks for
label()instead ofgetLabel()when extracting enum labels. Update your PHP enums accordingly: