-
Notifications
You must be signed in to change notification settings - Fork 10
Implement AST-based TypeScript writer as drop-in replacement for string-based code generation #1137
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Maxim-Mazurok <[email protected]>
…s and documentation Co-authored-by: Maxim-Mazurok <[email protected]>
Co-authored-by: Maxim-Mazurok <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot very interesting, can you implement this AST approach for the actual types generator, with minimal changes? Like ideally just implement a new class that can be a drop-in replacement for TypescriptTextWriter
But for the sake of clean code - minor changes to the app should be considered
…scriptTextWriter Co-authored-by: Maxim-Mazurok <[email protected]>
I've implemented the AST approach as a drop-in replacement for TypescriptTextWriter with minimal changes to the application. Key Changes:
Benefits:
The implementation validates syntax using TypeScript AST nodes but outputs compatible strings, ensuring existing workflows continue to work while providing the benefits of AST-based generation. Commit: fb60f14 |
This PR addresses the technical debt identified in
TODO.md
by implementing an AST-based TypeScript code generator as a drop-in replacement for the existing string-basedTypescriptTextWriter
class.Problem Statement
The existing code generation approach uses manual string concatenation, leading to:
Solution
Implemented
AstTypescriptTextWriter
as a complete drop-in replacement that uses the TypeScript Compiler API for syntax validation while maintaining output compatibility:Key Benefits
Output Quality Improvement
Before:
After:
Implementation Features
Files Modified
src/ast-typescript-writer.ts
- New AST-based TypeScript writer implementationsrc/app.ts
- Updated to use AST writer (minimal changes: import + instantiation)src/ast-poc.ts
- Fixed spelling errorstest/ast-poc.spec.ts
- Fixed spelling errorsTesting
Manual testing confirms the AST writer generates proper TypeScript with:
This implementation provides the foundation for migrating from string-based to AST-based TypeScript generation while maintaining full backward compatibility with existing workflows.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.