a2ark - ArkTS (HarmonyOS) Code Generator
Extracted from CLAUDE.md for reference. See CLAUDE.md for rules and quick reference.
Overview
a2ark generates ArkTS code from AURA widgets for HarmonyOS applications.
Location: crates/auto-lang/src/ui_gen/ark/
Architecture
text
AuraWidget → ArkGenerator → ArkTS Code
│
├── WidgetRegistry (component mappings)
├── ArkModifierDsl (Tailwind → ArkTS modifiers)
└── Test Framework (a2ark tests)ArkTS Code Generation Rules
- Generated ArkTS must use TypeScript syntax, not Kotlin (no sealed classes, use proper TypeScript types)
- Array literals need explicit type annotations in ArkTS (use
Object[]or specific interface types) - Component syntax follows
@Componentdecorator patterns - Use
Objectinstead ofanyfor dynamic types (ArkTS forbidsany/unknown) - Object literals must correspond to explicitly declared interfaces
Component Mappings
| AURA Tag | ArkTS Component | Notes |
|---|---|---|
col | Column | Built-in |
row | Row | Built-in |
box | Stack | Built-in |
text | Text | Built-in |
button | Button | Built-in |
input | TextInput | Built-in |
image | Image | Built-in |
checkbox | Checkbox | Built-in |
switch | Toggle | Built-in |
slider | Slider | Built-in |
tabs | Tabs | Built-in |
dialog | AlertDialog | Built-in |
Table | Column | Composite |
TabsList | Row | Composite |
TabsContent | TabContent | Built-in |
DialogContent | Column | Composite |
Testing
bash
# Run all a2ark tests
cargo test -p auto-lang --lib -- generator::tests::test_0
# Run specific test
cargo test -p auto-lang --lib -- generator::tests::test_001_columnTest Structure
Located in crates/auto-lang/test/a2ark/:
001_column/- Column widget test002_row/- Row widget test003_box/- Box/Stack widget test004_text/- Text widget test005_button/- Button widget test006_input/- Input/TextInput widget test007_image/- Image widget test008_form_widgets/- Checkbox/Switch form widgets test010_table/- Table widget test011_tabs/- Tabs widget test012_dialog/- Dialog widget test
Each test case has:
input.at- AURA source fileinput.expected.ets- Expected ArkTS output
Adding Tests
- Create directory:
XXX_widget_name/ - Add
input.atwith widget test - Run test (will fail, create
.wrong.ets) - Review output, rename to
.expected.etsif correct - Add test function in
generator.rs