-
Notifications
You must be signed in to change notification settings - Fork 32
Enhanced AST Code Generation with Runtime Schema Support #159
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
Closed
devin-ai-integration
wants to merge
9
commits into
main
from
devin/1750703762-enhance-ast-code-generation
Closed
Enhanced AST Code Generation with Runtime Schema Support #159
devin-ai-integration
wants to merge
9
commits into
main
from
devin/1750703762-enhance-ast-code-generation
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
- Add generateTsAstCodeFromPgAstWithSchema function that uses runtime schema to determine node wrapping - Implement field-based node type detection for complex AST structures - Add comprehensive tests for wrapped vs unwrapped node generation - Support correct builder paths: t.ast.*() for unwrapped nodes, t.nodes.*() for wrapped nodes - Maintain backward compatibility with existing generateTsAstCodeFromPgAst function Co-Authored-By: Dan Lynch <[email protected]>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Fixed multi-field object processing in traverse() to check parent field specs - WithClause now correctly generates t.ast.withClause instead of t.nodes.withClause - Updated snapshot test to reflect correct expected output - All 42 tests passing Co-Authored-By: Dan Lynch <[email protected]>
…a system - Remove isNode field from FieldSpec interface in runtime-schema/types.ts - Update runtime schema generator to not include isNode in FieldSpec objects - Remove isNode field from NodeSpec interface in both types.ts and store.ts - Update generateRuntimeSchemaTypeScript method to match new interface - Fix logic in generateTsAstCodeFromPgAstWithSchema to determine node wrapping by checking field type directly - Update README documentation to reflect schema changes - All tests now pass with the simplified schema structure Co-Authored-By: Dan Lynch <[email protected]>
- Update 7 test snapshots in __fixtures__/output/runtime-schema/ - Remove isNode fields from all generated runtime schema outputs - All runtime-schema tests now pass with the updated schema structure Co-Authored-By: Dan Lynch <[email protected]>
- Include the main snapshot file that was missed in previous commit - Complete the snapshot updates for isNode field removal Co-Authored-By: Dan Lynch <[email protected]>
…ed from FieldSpec - Add isNode field back to NodeSpec interface while keeping it removed from FieldSpec - Update runtime schema generator to include isNode in NodeSpec objects - Update TypeScript generation to reflect correct interface structure - Regenerate all runtime schema files and test snapshots - Maintain enhanced AST generation functionality with corrected schema Co-Authored-By: Dan Lynch <[email protected]>
… interface and objects - Add isNode: boolean field to NodeSpec interface in test utility file - Add isNode: true to all NodeSpec objects to match corrected interface structure - Resolves TypeScript compilation error in CI meta tests - Meta tests now pass locally with updated schema structure Co-Authored-By: Dan Lynch <[email protected]>
- Enhanced ensureCorrectExtension() method to be more robust: - Handle edge cases with null/empty inputs - Ensure expectedExt starts with dot - Better handling of multiple extensions (e.g., .d.ts, .spec.ts) - Standardized all file writing methods to use ensureCorrectExtension(): - writeTypes(), writeEnums(), writeUtilsEnums() - writeAstHelpers(), writeWrappedAstHelpers() - writeCodeToFile(), writeEnumMaps(), writeRuntimeSchema() - Consistent extension handling for both TypeScript (.ts) and JSON (.json) files - Updated test snapshots to reflect corrected file extension behavior - Prevents double extension bugs (e.g., .ts.ts) across all file generation Co-Authored-By: Dan Lynch <[email protected]>
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.
Enhanced AST Code Generation with Runtime Schema Support
Overview
This PR enhances the
generateTsAstCodeFromPgAst()function by adding a newgenerateTsAstCodeFromPgAstWithSchema()function that uses runtime schema information to determine whether nodes should be wrapped or not, generating code with correct builder paths.Changes Made
New Function:
generateTsAstCodeFromPgAstWithSchemaisNodeproperty to determine node wrappingt.ast.*()calls for unwrapped nodes andt.nodes.*()calls for wrapped nodesKey Features
generateTsAstCodeFromPgAstfunction remains unchangedImplementation Details
findNodeTypeByFields()helper function for dynamic node type identificationgetValueNode()function with proper array handlingTests Added
Example Usage
Generated Code Examples
The enhanced function now correctly generates:
t.nodes.selectStmt({...})for wrapped SelectStmt nodest.nodes.withClause({...})for wrapped WithClause nodest.ast.limitOption(...)for unwrapped enum valuesTesting
Link to Devin run
https://app.devin.ai/sessions/3fc9c4d281d84299922c41d82c9c0477
Requested by
Dan Lynch ([email protected])