Skip to content

Rework: replace custom TS codegen with SWC AST#93

Merged
renardeinside merged 15 commits intomainfrom
rework/swc-codegen
Feb 19, 2026
Merged

Rework: replace custom TS codegen with SWC AST#93
renardeinside merged 15 commits intomainfrom
rework/swc-codegen

Conversation

@renardeinside
Copy link
Copy Markdown
Collaborator

Summary

  • Replace the custom 694-line emit.rs string-based TS emitter with SWC AST-based codegen (builders.rs + codegen.rs)
  • Reduce bloat in the new SWC approach: delete dead code, add ts_kw! macro, eliminate string-formatted types, merge duplicate helpers
  • Net result: proper AST-based codegen with -170 lines vs the initial SWC rework

Changes

  • builders.rs (1,081 → 908 lines): deleted 8 unused functions, replaced 7 keyword wrappers with ts_kw! macro, deleted 78-line ir_type_to_string bridge, merged 3 duplicate helper pairs, added promise_type/data_wrapper_type/ts_omit/ts_type_param helpers
  • codegen.rs (958 → 985 lines): replaced all format!() + ts_type_ref() string hacks with proper SWC AST construction for return types, hook options, and mutation types
  • utils.rs: deleted unused format_param_access + test
  • mod.rs: tests updated to use normalize_ws() for multiline SWC output

Test plan

  • cargo check -p apx-core — clean compilation, no warnings
  • cargo test -p apx-core openapi — all 90 tests pass
  • TypeScript compilation tests verify generated code is valid TS

🤖 Generated with Claude Code

renardeinside and others added 15 commits February 18, 2026 20:48
…uter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ve stale addons

- Simplify _base.py: drop Generic[T], abstract get_instance, as_depends
- Fix _defaults.py: use @staticmethod, fix ConfigDependency Depends() target
- Fix SQL addon: remove double-wrapping, update addon.toml to match exports
- Extract apply_python_edits from apply_backend_addon for reuse in init
- Fix init to apply Python AST edits (imports + Dependencies aliases) from addon manifests
- Remove genie, lakebase, serving-endpoint addons (use old Dependency API)
- Add tests verifying Dependencies class gets Sql member after addon apply

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the custom TypeScript AST (TsExpr, TsStmt, TsFunction, TsModule)
and the custom Emit trait with SWC's swc_ecma_ast + swc_ecma_codegen.

- Add swc_common, swc_ecma_ast, swc_ecma_codegen, swc_atoms dependencies
- Create ir/builders.rs with ergonomic helpers for SWC AST construction
- Rewrite codegen.rs to produce swc_ecma_ast::Module
- Rewrite emitter.rs to use SWC's Emitter for code output
- Slim types.rs to type-only IR (TsType, TsProp, TsTypeDef, TypeRef)
- Delete emit.rs (694 lines of custom emission code)
- Update 5 test assertions for SWC formatting differences

All 91 openapi tests pass. Net reduction of ~300 lines of custom code,
with emission correctness now guaranteed by SWC.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@renardeinside renardeinside merged commit bf62a7c into main Feb 19, 2026
3 checks passed
@renardeinside renardeinside deleted the rework/swc-codegen branch February 19, 2026 14:24
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