@mmapp/react-compiler 0.1.0-alpha.1 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/ATOM-PIPELINE.md +144 -0
  2. package/README.md +88 -40
  3. package/dist/babel/index.js +113 -6
  4. package/dist/babel/index.mjs +2 -2
  5. package/dist/chunk-3USIFFE4.mjs +2190 -0
  6. package/dist/chunk-45YMGEVT.mjs +186 -0
  7. package/dist/chunk-4FN2AISW.mjs +148 -0
  8. package/dist/chunk-4OPI5L7G.mjs +2593 -0
  9. package/dist/chunk-4RYTKOOJ.mjs +186 -0
  10. package/dist/chunk-5RKTOVR5.mjs +244 -0
  11. package/dist/chunk-5YDMOO4X.mjs +214 -0
  12. package/dist/chunk-64ZWEMLJ.mjs +148 -0
  13. package/dist/chunk-6XP4KSWQ.mjs +2190 -0
  14. package/dist/chunk-72QWL54I.mjs +175 -0
  15. package/dist/chunk-7B4TRI7C.mjs +4835 -0
  16. package/dist/chunk-7ZKGHTNB.mjs +4952 -0
  17. package/dist/chunk-CIESM3BP.mjs +33 -0
  18. package/dist/chunk-DE3ZGQAC.mjs +148 -0
  19. package/dist/chunk-DMCY3BBG.mjs +1933 -0
  20. package/dist/chunk-DPIK3PJS.mjs +244 -0
  21. package/dist/chunk-E5IVH4RE.mjs +186 -0
  22. package/dist/chunk-E6FZNUR5.mjs +4953 -0
  23. package/dist/chunk-EJRBDQDP.mjs +2607 -0
  24. package/dist/chunk-ELO4TXJL.mjs +186 -0
  25. package/dist/chunk-FKRO52XH.mjs +3446 -0
  26. package/dist/chunk-FL4YAKU6.mjs +4941 -0
  27. package/dist/chunk-FYT47UBU.mjs +5076 -0
  28. package/dist/chunk-GCLGPOJZ.mjs +148 -0
  29. package/dist/chunk-GXB4JOP7.mjs +5072 -0
  30. package/dist/chunk-HFXOUMTD.mjs +175 -0
  31. package/dist/chunk-HWIZ47US.mjs +214 -0
  32. package/dist/chunk-IB7MNPQL.mjs +4953 -0
  33. package/dist/chunk-ICSIHQCG.mjs +148 -0
  34. package/dist/chunk-JLA5VNQ3.mjs +186 -0
  35. package/dist/chunk-JQLWFCTM.mjs +214 -0
  36. package/dist/chunk-KFJJCQAL.mjs +148 -0
  37. package/dist/chunk-KJUIIEQE.mjs +186 -0
  38. package/dist/chunk-KNWTHRVQ.mjs +175 -0
  39. package/dist/chunk-KSG4XSZF.mjs +175 -0
  40. package/dist/chunk-LF5N6DOU.mjs +175 -0
  41. package/dist/chunk-LJQCM2IM.mjs +214 -0
  42. package/dist/chunk-NW6555WJ.mjs +186 -0
  43. package/dist/chunk-OMZE6VLQ.mjs +214 -0
  44. package/dist/chunk-P4BR7WVO.mjs +2190 -0
  45. package/dist/chunk-QQHVYH2X.mjs +244 -0
  46. package/dist/chunk-S5QLWLLT.mjs +186 -0
  47. package/dist/chunk-SCWGT2FY.mjs +2190 -0
  48. package/dist/chunk-SMKJUSB3.mjs +2190 -0
  49. package/dist/chunk-VCAY2KGM.mjs +175 -0
  50. package/dist/chunk-WECAV6QB.mjs +148 -0
  51. package/dist/chunk-WMKBXUCE.mjs +3228 -0
  52. package/dist/chunk-XAJ5BKKL.mjs +4947 -0
  53. package/dist/chunk-XG2X7AEA.mjs +175 -0
  54. package/dist/chunk-XG7Z23NQ.mjs +148 -0
  55. package/dist/chunk-XWZAOCQ7.mjs +2607 -0
  56. package/dist/chunk-Y6MA7ULW.mjs +148 -0
  57. package/dist/chunk-YMS7Q7LG.mjs +214 -0
  58. package/dist/chunk-ZA37XTGA.mjs +175 -0
  59. package/dist/cli/index.js +1616 -366
  60. package/dist/cli/index.mjs +8 -8
  61. package/dist/codemod/cli.mjs +1 -1
  62. package/dist/codemod/index.mjs +1 -1
  63. package/dist/dev-server-RmGHIntF.d.mts +113 -0
  64. package/dist/dev-server-RmGHIntF.d.ts +113 -0
  65. package/dist/dev-server.d.mts +1 -1
  66. package/dist/dev-server.d.ts +1 -1
  67. package/dist/dev-server.js +982 -53
  68. package/dist/dev-server.mjs +5 -5
  69. package/dist/envelope.js +113 -6
  70. package/dist/envelope.mjs +3 -3
  71. package/dist/index.d.mts +5 -1
  72. package/dist/index.d.ts +5 -1
  73. package/dist/index.js +992 -63
  74. package/dist/index.mjs +8 -8
  75. package/{src/cli/init.ts → dist/init-7JQMAAXS.mjs} +70 -95
  76. package/dist/init-EHO4VQ22.mjs +369 -0
  77. package/dist/init-UC3FWPIW.mjs +367 -0
  78. package/dist/init-UNSMVKIK.mjs +366 -0
  79. package/dist/init-UNV5XIDE.mjs +367 -0
  80. package/dist/project-compiler-2P4N4DR7.mjs +10 -0
  81. package/dist/project-compiler-D2LCC27O.mjs +10 -0
  82. package/dist/project-compiler-EJ3GANJE.mjs +10 -0
  83. package/dist/project-compiler-LOQKVRZJ.mjs +10 -0
  84. package/dist/project-compiler-RQ6OQKRM.mjs +10 -0
  85. package/dist/project-compiler-VWNNCHGO.mjs +10 -0
  86. package/dist/project-compiler-XVAAU4C5.mjs +10 -0
  87. package/dist/project-compiler-YES5FGMD.mjs +10 -0
  88. package/dist/project-compiler-ZKMQDLGU.mjs +10 -0
  89. package/dist/project-decompiler-FLXCEJHS.mjs +7 -0
  90. package/dist/project-decompiler-VLPR22QF.mjs +7 -0
  91. package/dist/pull-FUS5QYZS.mjs +109 -0
  92. package/dist/pull-LD5ENLGY.mjs +109 -0
  93. package/dist/testing/index.js +113 -6
  94. package/dist/testing/index.mjs +2 -2
  95. package/dist/vite/index.js +113 -6
  96. package/dist/vite/index.mjs +3 -3
  97. package/examples/uber-app/app/admin/fleet.tsx +19 -19
  98. package/package.json +4 -3
  99. package/compile-blueprint-chat.mjs +0 -99
  100. package/compile-blueprint-glass-console.mjs +0 -98
  101. package/compile-chat-defs.mjs +0 -92
  102. package/examples/uber-app/tests/payment.test.tsx +0 -129
  103. package/examples/uber-app/tests/ride-flow.test.tsx +0 -123
  104. package/package.json.backup +0 -86
  105. package/scripts/decompile.ts +0 -226
  106. package/scripts/seed-auth.ts +0 -267
  107. package/scripts/seed-uber.ts +0 -248
  108. package/scripts/validate-uber.ts +0 -119
  109. package/seed-blueprint-chat.mjs +0 -444
  110. package/seed-blueprint-glass-console.mjs +0 -445
  111. package/seed-compiled.mjs +0 -318
  112. package/src/RoundTripValidator.ts +0 -400
  113. package/src/__tests__/atom-rendering-coverage.test.ts +0 -680
  114. package/src/__tests__/auth-module-compilation.test.ts +0 -247
  115. package/src/__tests__/auth-template-compilation.test.ts +0 -589
  116. package/src/__tests__/change-extractor.test.ts +0 -142
  117. package/src/__tests__/cli-pull.test.ts +0 -73
  118. package/src/__tests__/cli-test.test.ts +0 -72
  119. package/src/__tests__/component-extractor.test.ts +0 -331
  120. package/src/__tests__/context-extractor.test.ts +0 -145
  121. package/src/__tests__/decompiler.test.ts +0 -718
  122. package/src/__tests__/define-blueprint.test.ts +0 -133
  123. package/src/__tests__/definition-validator.test.ts +0 -519
  124. package/src/__tests__/during-extractor.test.ts +0 -152
  125. package/src/__tests__/effect-extractor.test.ts +0 -107
  126. package/src/__tests__/event-emission.test.ts +0 -127
  127. package/src/__tests__/examples.test.ts +0 -236
  128. package/src/__tests__/full-blueprint-coverage.test.ts +0 -1221
  129. package/src/__tests__/golden-suite.test.ts +0 -403
  130. package/src/__tests__/grammar-island-extractor.test.ts +0 -289
  131. package/src/__tests__/instance-key.test.ts +0 -82
  132. package/src/__tests__/ir-migration.test.ts +0 -255
  133. package/src/__tests__/lock-file.test.ts +0 -117
  134. package/src/__tests__/model-extractor.test.ts +0 -195
  135. package/src/__tests__/model-field-acl.test.ts +0 -237
  136. package/src/__tests__/model-hooks.test.ts +0 -130
  137. package/src/__tests__/model-ref-resolution.test.ts +0 -268
  138. package/src/__tests__/model-roundtrip.test.ts +0 -502
  139. package/src/__tests__/model-runtime.test.ts +0 -112
  140. package/src/__tests__/model-transitions.test.ts +0 -183
  141. package/src/__tests__/nrt-action-trace.test.ts +0 -391
  142. package/src/__tests__/pipeline-hardening.test.ts +0 -413
  143. package/src/__tests__/project-compiler.test.ts +0 -546
  144. package/src/__tests__/project-decompiler.test.ts +0 -343
  145. package/src/__tests__/query-compilation.test.ts +0 -145
  146. package/src/__tests__/round-trip/PLAN.md +0 -158
  147. package/src/__tests__/round-trip/README.md +0 -52
  148. package/src/__tests__/round-trip/RESULTS.md +0 -86
  149. package/src/__tests__/round-trip/fixtures/data-heavy/main.workflow.tsx +0 -55
  150. package/src/__tests__/round-trip/fixtures/data-heavy/mm.config.ts +0 -11
  151. package/src/__tests__/round-trip/fixtures/data-heavy/models/contact.ts +0 -54
  152. package/src/__tests__/round-trip/fixtures/full-workflow/main.workflow.tsx +0 -79
  153. package/src/__tests__/round-trip/fixtures/full-workflow/mm.config.ts +0 -12
  154. package/src/__tests__/round-trip/fixtures/full-workflow/models/order.ts +0 -50
  155. package/src/__tests__/round-trip/fixtures/simple-crud/main.workflow.tsx +0 -25
  156. package/src/__tests__/round-trip/fixtures/simple-crud/mm.config.ts +0 -11
  157. package/src/__tests__/round-trip/fixtures/simple-crud/models/task.ts +0 -32
  158. package/src/__tests__/round-trip/fixtures/view-heavy/main.workflow.tsx +0 -79
  159. package/src/__tests__/round-trip/fixtures/view-heavy/mm.config.ts +0 -10
  160. package/src/__tests__/round-trip/round-trip.test.ts +0 -2598
  161. package/src/__tests__/round-trip-ir.test.ts +0 -300
  162. package/src/__tests__/round-trip.test.ts +0 -1212
  163. package/src/__tests__/route-merging.test.ts +0 -372
  164. package/src/__tests__/router-composition.test.ts +0 -489
  165. package/src/__tests__/router-extractor.test.ts +0 -176
  166. package/src/__tests__/server-action-extractor.test.ts +0 -128
  167. package/src/__tests__/smart-type-inference.test.ts +0 -365
  168. package/src/__tests__/source-envelope.test.ts +0 -284
  169. package/src/__tests__/source-fidelity.test.ts +0 -516
  170. package/src/__tests__/state-extractor.test.ts +0 -115
  171. package/src/__tests__/strict-mode.test.ts +0 -227
  172. package/src/__tests__/transition-effect-extractor.test.ts +0 -119
  173. package/src/__tests__/transition-extractor.test.ts +0 -68
  174. package/src/__tests__/ts-to-expression.test.ts +0 -462
  175. package/src/__tests__/type-generator.test.ts +0 -201
  176. package/src/__tests__/uber-validation.test.ts +0 -502
  177. package/src/action-compiler.ts +0 -361
  178. package/src/babel/emitters/experience-transform.ts +0 -199
  179. package/src/babel/emitters/ir-to-tsx-emitter.ts +0 -110
  180. package/src/babel/emitters/pure-form-emitter.ts +0 -1023
  181. package/src/babel/emitters/runtime-glue-emitter.ts +0 -39
  182. package/src/babel/extractors/change-extractor.ts +0 -199
  183. package/src/babel/extractors/component-extractor.ts +0 -907
  184. package/src/babel/extractors/computed-extractor.ts +0 -262
  185. package/src/babel/extractors/context-extractor.ts +0 -277
  186. package/src/babel/extractors/during-extractor.ts +0 -295
  187. package/src/babel/extractors/effect-extractor.ts +0 -340
  188. package/src/babel/extractors/event-extractor.ts +0 -235
  189. package/src/babel/extractors/grammar-island-extractor.ts +0 -302
  190. package/src/babel/extractors/model-extractor.ts +0 -1018
  191. package/src/babel/extractors/router-extractor.ts +0 -303
  192. package/src/babel/extractors/server-action-extractor.ts +0 -173
  193. package/src/babel/extractors/server-action-hook-extractor.ts +0 -72
  194. package/src/babel/extractors/server-state-extractor.ts +0 -88
  195. package/src/babel/extractors/state-extractor.ts +0 -214
  196. package/src/babel/extractors/transition-effect-extractor.ts +0 -176
  197. package/src/babel/extractors/transition-extractor.ts +0 -143
  198. package/src/babel/index.ts +0 -24
  199. package/src/babel/transpilers/ts-to-expression.ts +0 -674
  200. package/src/babel/visitor.ts +0 -807
  201. package/src/cli/auth.ts +0 -255
  202. package/src/cli/build.ts +0 -288
  203. package/src/cli/deploy.ts +0 -206
  204. package/src/cli/index.ts +0 -328
  205. package/src/cli/installer.ts +0 -261
  206. package/src/cli/lock-file.ts +0 -94
  207. package/src/cli/mmrc.ts +0 -22
  208. package/src/cli/pull.ts +0 -172
  209. package/src/cli/registry-client.ts +0 -175
  210. package/src/cli/test.ts +0 -397
  211. package/src/cli/type-generator.ts +0 -243
  212. package/src/codemod/__tests__/forward.test.ts +0 -239
  213. package/src/codemod/__tests__/reverse.test.ts +0 -145
  214. package/src/codemod/__tests__/round-trip.test.ts +0 -137
  215. package/src/codemod/annotation.ts +0 -97
  216. package/src/codemod/classify.ts +0 -197
  217. package/src/codemod/cli.ts +0 -207
  218. package/src/codemod/control-flow.ts +0 -409
  219. package/src/codemod/forward.ts +0 -244
  220. package/src/codemod/import-manager.ts +0 -171
  221. package/src/codemod/index.ts +0 -120
  222. package/src/codemod/reverse.ts +0 -197
  223. package/src/codemod/rules.ts +0 -174
  224. package/src/codemod/state-transform.ts +0 -126
  225. package/src/decompiler/ast-builder.ts +0 -538
  226. package/src/decompiler/config-generator.ts +0 -151
  227. package/src/decompiler/index.ts +0 -315
  228. package/src/decompiler/project-decompiler.ts +0 -1776
  229. package/src/decompiler/project.ts +0 -862
  230. package/src/decompiler/split-strategy.ts +0 -140
  231. package/src/decompiler/state-emitter.ts +0 -1053
  232. package/src/decompiler/sx-emitter.ts +0 -318
  233. package/src/decompiler/workspace-hydrator.ts +0 -189
  234. package/src/dev-server.ts +0 -238
  235. package/src/envelope/fs-tree.ts +0 -217
  236. package/src/envelope/source-envelope.ts +0 -264
  237. package/src/envelope.ts +0 -315
  238. package/src/incremental-compiler.ts +0 -401
  239. package/src/index.ts +0 -99
  240. package/src/model-compiler.ts +0 -277
  241. package/src/project-compiler.ts +0 -1629
  242. package/src/route-extractor.ts +0 -333
  243. package/src/testing/index.ts +0 -32
  244. package/src/testing/snapshot.ts +0 -252
  245. package/src/testing/test-utils.ts +0 -226
  246. package/src/types.ts +0 -68
  247. package/src/vite/index.ts +0 -288
  248. package/test-compile.mjs +0 -142
  249. package/tsconfig.json +0 -25
  250. package/tsup.config.ts +0 -23
  251. package/vitest.config.ts +0 -9
@@ -1,243 +0,0 @@
1
- /**
2
- * Type Generator — converts a WorkflowDefinition into a TypeScript .d.ts file.
3
- *
4
- * Generates:
5
- * - defineModel() call with `as const` assertion
6
- * - Field types mapped to TypeScript types
7
- * - State names as union type
8
- * - Transition names as union type
9
- */
10
-
11
- import type { WorkflowDefinitionResponse } from './registry-client';
12
-
13
- /** Map workflow field types to TypeScript types */
14
- const FIELD_TYPE_MAP: Record<string, string> = {
15
- string: 'string',
16
- text: 'string',
17
- email: 'string',
18
- url: 'string',
19
- phone: 'string',
20
- password: 'string',
21
- slug: 'string',
22
- color: 'string',
23
- number: 'number',
24
- integer: 'number',
25
- float: 'number',
26
- decimal: 'number',
27
- currency: 'number',
28
- percentage: 'number',
29
- boolean: 'boolean',
30
- date: 'string',
31
- datetime: 'string',
32
- time: 'string',
33
- timestamp: 'string',
34
- json: 'unknown',
35
- object: 'Record<string, unknown>',
36
- array: 'unknown[]',
37
- file: 'string',
38
- image: 'string',
39
- reference: 'string',
40
- enum: 'string',
41
- select: 'string',
42
- };
43
-
44
- function getTsType(fieldType: string): string {
45
- return FIELD_TYPE_MAP[fieldType] ?? 'unknown';
46
- }
47
-
48
- function escapeStringLiteral(s: string): string {
49
- return s.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
50
- }
51
-
52
- function serializeDefault(value: unknown): string {
53
- if (value === undefined || value === null) return "''";
54
- if (typeof value === 'string') return `'${escapeStringLiteral(value)}'`;
55
- if (typeof value === 'number' || typeof value === 'boolean') return String(value);
56
- if (Array.isArray(value)) return JSON.stringify(value);
57
- return JSON.stringify(value);
58
- }
59
-
60
- /**
61
- * Generate a .d.ts file from a workflow definition response.
62
- */
63
- export function generateTypeDeclaration(def: WorkflowDefinitionResponse): string {
64
- const lines: string[] = [];
65
-
66
- lines.push("import { defineModel } from '@mindmatrix/react';");
67
- lines.push('');
68
- lines.push('declare const _default: ReturnType<typeof defineModel<{');
69
- lines.push(` readonly slug: '${escapeStringLiteral(def.slug)}';`);
70
- lines.push(` readonly version: '${escapeStringLiteral(def.version || '1.0.0')}';`);
71
-
72
- // Fields
73
- if (def.fields && def.fields.length > 0) {
74
- lines.push(' readonly fields: {');
75
- for (const field of def.fields) {
76
- const props: string[] = [];
77
- props.push(`readonly type: '${escapeStringLiteral(field.type)}'`);
78
-
79
- if (field.default_value !== undefined && field.default_value !== null) {
80
- props.push(`readonly default: ${serializeDefault(field.default_value)}`);
81
- } else {
82
- // Provide a sensible default based on type
83
- const tsType = getTsType(field.type);
84
- if (tsType === 'string') props.push("readonly default: ''");
85
- else if (tsType === 'number') props.push('readonly default: 0');
86
- else if (tsType === 'boolean') props.push('readonly default: false');
87
- }
88
-
89
- if (field.validation?.enum && field.validation.enum.length > 0) {
90
- const enumValues = field.validation.enum
91
- .map(v => `'${escapeStringLiteral(v)}'`)
92
- .join(', ');
93
- props.push(`readonly enum: readonly [${enumValues}]`);
94
- }
95
-
96
- if (field.required) {
97
- props.push('readonly required: true');
98
- }
99
-
100
- lines.push(` readonly ${field.name}: { ${props.join('; ')} };`);
101
- }
102
- lines.push(' };');
103
- } else {
104
- lines.push(' readonly fields: {};');
105
- }
106
-
107
- // States
108
- if (def.states && def.states.length > 0) {
109
- lines.push(' readonly states: {');
110
- for (const state of def.states) {
111
- const stateProps: string[] = [];
112
- if (state.type === 'initial') {
113
- stateProps.push("readonly type: 'initial'");
114
- } else if (state.type === 'final') {
115
- stateProps.push("readonly type: 'final'");
116
- }
117
- lines.push(` readonly ${state.name}: { ${stateProps.join('; ')} };`);
118
- }
119
- lines.push(' };');
120
- } else {
121
- lines.push(' readonly states: {};');
122
- }
123
-
124
- // Transitions
125
- if (def.transitions && def.transitions.length > 0) {
126
- lines.push(' readonly transitions: {');
127
- for (const transition of def.transitions) {
128
- const tProps: string[] = [];
129
-
130
- // from — use first element as string literal, or union if multiple
131
- if (transition.from.length === 1) {
132
- tProps.push(`readonly from: '${escapeStringLiteral(transition.from[0])}'`);
133
- } else if (transition.from.length > 1) {
134
- const fromUnion = transition.from.map(f => `'${escapeStringLiteral(f)}'`).join(' | ');
135
- tProps.push(`readonly from: ${fromUnion}`);
136
- }
137
-
138
- tProps.push(`readonly to: '${escapeStringLiteral(transition.to)}'`);
139
-
140
- lines.push(` readonly ${transition.name}: { ${tProps.join('; ')} };`);
141
- }
142
- lines.push(' };');
143
- } else {
144
- lines.push(' readonly transitions: {};');
145
- }
146
-
147
- lines.push('}>>;');
148
- lines.push('export default _default;');
149
- lines.push('');
150
-
151
- // Also export state and transition union types for convenience
152
- if (def.states && def.states.length > 0) {
153
- const stateUnion = def.states.map(s => `'${escapeStringLiteral(s.name)}'`).join(' | ');
154
- lines.push(`export type States = ${stateUnion};`);
155
- }
156
-
157
- if (def.transitions && def.transitions.length > 0) {
158
- const transitionUnion = def.transitions.map(t => `'${escapeStringLiteral(t.name)}'`).join(' | ');
159
- lines.push(`export type Transitions = ${transitionUnion};`);
160
- }
161
-
162
- if (def.fields && def.fields.length > 0) {
163
- lines.push('');
164
- lines.push('export interface Fields {');
165
- for (const field of def.fields) {
166
- const tsType = getTsType(field.type);
167
- lines.push(` ${field.name}: ${tsType};`);
168
- }
169
- lines.push('}');
170
- }
171
-
172
- lines.push('');
173
-
174
- return lines.join('\n');
175
- }
176
-
177
- /**
178
- * Generate a full source index.ts for a workflow package (--full mode).
179
- */
180
- export function generateFullSource(def: WorkflowDefinitionResponse): string {
181
- const lines: string[] = [];
182
-
183
- lines.push("import { defineModel } from '@mindmatrix/react';");
184
- lines.push('');
185
- lines.push('export default defineModel({');
186
- lines.push(` slug: '${escapeStringLiteral(def.slug)}',`);
187
- lines.push(` version: '${escapeStringLiteral(def.version || '1.0.0')}',`);
188
-
189
- if (def.fields && def.fields.length > 0) {
190
- lines.push(' fields: {');
191
- for (const field of def.fields) {
192
- const props: string[] = [];
193
- props.push(`type: '${escapeStringLiteral(field.type)}'`);
194
- if (field.default_value !== undefined && field.default_value !== null) {
195
- props.push(`default: ${serializeDefault(field.default_value)}`);
196
- }
197
- if (field.validation?.enum) {
198
- const enumValues = field.validation.enum
199
- .map(v => `'${escapeStringLiteral(v)}'`)
200
- .join(', ');
201
- props.push(`enum: [${enumValues}] as const`);
202
- }
203
- if (field.required) {
204
- props.push('required: true');
205
- }
206
- lines.push(` ${field.name}: { ${props.join(', ')} },`);
207
- }
208
- lines.push(' },');
209
- }
210
-
211
- if (def.states && def.states.length > 0) {
212
- lines.push(' states: {');
213
- for (const state of def.states) {
214
- if (state.type === 'initial' || state.type === 'final') {
215
- lines.push(` ${state.name}: { type: '${state.type}' },`);
216
- } else {
217
- lines.push(` ${state.name}: {},`);
218
- }
219
- }
220
- lines.push(' },');
221
- }
222
-
223
- if (def.transitions && def.transitions.length > 0) {
224
- lines.push(' transitions: {');
225
- for (const transition of def.transitions) {
226
- const tProps: string[] = [];
227
- if (transition.from.length === 1) {
228
- tProps.push(`from: '${escapeStringLiteral(transition.from[0])}'`);
229
- } else {
230
- const fromArr = transition.from.map(f => `'${escapeStringLiteral(f)}'`).join(', ');
231
- tProps.push(`from: [${fromArr}]`);
232
- }
233
- tProps.push(`to: '${escapeStringLiteral(transition.to)}'`);
234
- lines.push(` ${transition.name}: { ${tProps.join(', ')} },`);
235
- }
236
- lines.push(' },');
237
- }
238
-
239
- lines.push('} as const);');
240
- lines.push('');
241
-
242
- return lines.join('\n');
243
- }
@@ -1,239 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { transform } from '../index';
3
-
4
- function forward(source: string): string {
5
- return transform(source, { direction: 'forward', annotate: false }).code;
6
- }
7
-
8
- function forwardAnnotated(source: string): string {
9
- return transform(source, { direction: 'forward', annotate: true }).code;
10
- }
11
-
12
- describe('forward transform', () => {
13
- describe('element mapping', () => {
14
- it('div with flex → Row', () => {
15
- const input = `const App = () => <div className="flex items-center gap-2">hello</div>;`;
16
- const output = forward(input);
17
- expect(output).toContain('<Row');
18
- expect(output).toContain('items-center gap-2');
19
- expect(output).not.toContain('"flex ');
20
- });
21
-
22
- it('div with flex flex-col → Stack', () => {
23
- const input = `const App = () => <div className="flex flex-col gap-4">hello</div>;`;
24
- const output = forward(input);
25
- expect(output).toContain('<Stack');
26
- expect(output).toContain('gap-4');
27
- expect(output).not.toContain('flex-col');
28
- expect(output).not.toContain('"flex ');
29
- });
30
-
31
- it('div with grid → Grid', () => {
32
- const input = `const App = () => <div className="grid grid-cols-3 gap-2">hello</div>;`;
33
- const output = forward(input);
34
- expect(output).toContain('<Grid');
35
- expect(output).not.toContain('"grid ');
36
- });
37
-
38
- it('div without flex/grid → Stack', () => {
39
- const input = `const App = () => <div className="p-4 bg-gray-800">hello</div>;`;
40
- const output = forward(input);
41
- expect(output).toContain('<Stack');
42
- expect(output).toContain('p-4 bg-gray-800');
43
- });
44
-
45
- it('span → Text', () => {
46
- const input = `const App = () => <span className="text-sm text-gray-300">hello</span>;`;
47
- const output = forward(input);
48
- expect(output).toContain('<Text');
49
- expect(output).toContain('text-sm text-gray-300');
50
- });
51
-
52
- it('p → Text', () => {
53
- const input = `const App = () => <p className="text-base">content</p>;`;
54
- const output = forward(input);
55
- expect(output).toContain('<Text');
56
- });
57
-
58
- it('h1-h6 → Text with variant', () => {
59
- const input = `const App = () => <h2 className="font-bold">Title</h2>;`;
60
- const output = forward(input);
61
- expect(output).toContain('<Text');
62
- expect(output).toContain('variant="h2"');
63
- });
64
-
65
- it('button → Button', () => {
66
- const input = `const App = () => <button className="px-4 py-2" onClick={handleClick}>Go</button>;`;
67
- const output = forward(input);
68
- expect(output).toContain('<Button');
69
- expect(output).toContain('onPress');
70
- expect(output).not.toContain('onClick');
71
- });
72
-
73
- it('a → Link', () => {
74
- const input = `const App = () => <a href="/page" className="text-blue-400">Link</a>;`;
75
- const output = forward(input);
76
- expect(output).toContain('<Link');
77
- });
78
-
79
- it('input → TextInput', () => {
80
- const input = `const App = () => <input type="text" className="w-full" />;`;
81
- const output = forward(input);
82
- expect(output).toContain('<TextInput');
83
- });
84
-
85
- it('textarea → TextInput multiline', () => {
86
- const input = `const App = () => <textarea className="w-full h-20" />;`;
87
- const output = forward(input);
88
- expect(output).toContain('<TextInput');
89
- expect(output).toContain('multiline');
90
- });
91
-
92
- it('img → Image', () => {
93
- const input = `const App = () => <img src="/avatar.png" className="w-9 h-9 rounded-full" />;`;
94
- const output = forward(input);
95
- expect(output).toContain('<Image');
96
- });
97
-
98
- it('preserves motion.div untouched', () => {
99
- const input = `const App = () => <motion.div className="flex" initial={{ opacity: 0 }}>hi</motion.div>;`;
100
- const output = forward(input);
101
- expect(output).toContain('motion.div');
102
- });
103
-
104
- it('preserves PascalCase components', () => {
105
- const input = `const App = () => <MyComponent className="flex">hi</MyComponent>;`;
106
- const output = forward(input);
107
- expect(output).toContain('<MyComponent');
108
- });
109
- });
110
-
111
- describe('className cleanup', () => {
112
- it('removes flex from Row className', () => {
113
- const input = `const App = () => <div className="flex items-center gap-2">hi</div>;`;
114
- const output = forward(input);
115
- // Should have items-center gap-2 but not flex
116
- expect(output).toMatch(/className="items-center gap-2"/);
117
- });
118
-
119
- it('removes flex and flex-col from Stack className', () => {
120
- const input = `const App = () => <div className="flex flex-col gap-4 p-2">hi</div>;`;
121
- const output = forward(input);
122
- expect(output).toMatch(/className="gap-4 p-2"/);
123
- });
124
-
125
- it('handles cn() utility', () => {
126
- const input = `const App = () => <div className={cn("flex items-center", isActive && "bg-blue-500")}>hi</div>;`;
127
- const output = forward(input);
128
- expect(output).toContain('<Row');
129
- expect(output).toContain('"items-center"');
130
- });
131
-
132
- it('handles template literals', () => {
133
- const input = 'const App = () => <div className={`flex items-center ${cls}`}>hi</div>;';
134
- const output = forward(input);
135
- expect(output).toContain('<Row');
136
- });
137
- });
138
-
139
- describe('control flow', () => {
140
- it('converts && conditional to <Show>', () => {
141
- const input = `const App = () => <div className="flex">{visible && <span>hi</span>}</div>;`;
142
- const output = forward(input);
143
- expect(output).toContain('<Show');
144
- expect(output).toContain('when={visible}');
145
- });
146
-
147
- it('converts .map() to <Each>', () => {
148
- const input = `const App = () => <div className="flex flex-col">{items.map(item => <span key={item.id}>{item.name}</span>)}</div>;`;
149
- const output = forward(input);
150
- expect(output).toContain('<Each');
151
- expect(output).toContain('items={items}');
152
- });
153
-
154
- it('converts ternary to dual <Show>', () => {
155
- const input = `const App = () => <div className="flex">{active ? <span>on</span> : <span>off</span>}</div>;`;
156
- const output = forward(input);
157
- expect(output).toContain('<Show');
158
- // Should have two Show elements
159
- const showCount = (output.match(/<Show/g) || []).length;
160
- expect(showCount).toBe(2);
161
- });
162
- });
163
-
164
- describe('annotations', () => {
165
- it('adds @mm-original annotation when enabled', () => {
166
- const output = forwardAnnotated(
167
- `const App = () => <div className="flex items-center">hi</div>;`,
168
- );
169
- expect(output).toContain('@mm-original');
170
- expect(output).toContain('div');
171
- });
172
-
173
- it('omits annotation when disabled', () => {
174
- const output = forward(
175
- `const App = () => <div className="flex items-center">hi</div>;`,
176
- );
177
- expect(output).not.toContain('@mm-original');
178
- });
179
- });
180
-
181
- describe('imports', () => {
182
- it('adds atom import', () => {
183
- const input = `import React from 'react';\nconst App = () => <div className="flex">hi</div>;`;
184
- const output = forward(input);
185
- expect(output).toContain('@mindmatrix/react/atoms');
186
- expect(output).toContain('Row');
187
- });
188
- });
189
-
190
- describe('real-world patterns', () => {
191
- it('transforms a channel list item', () => {
192
- const input = `
193
- const ChannelItem = ({ channel }) => (
194
- <div className="flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-gray-800">
195
- <span className="text-sm text-gray-300 truncate flex-1">{channel.name}</span>
196
- {channel.unread > 0 && (
197
- <span className="bg-blue-500 text-white text-xs px-1.5 rounded-full">
198
- {channel.unread}
199
- </span>
200
- )}
201
- </div>
202
- );`;
203
- const output = forward(input);
204
- expect(output).toContain('<Row');
205
- expect(output).toContain('<Text');
206
- expect(output).toContain('<Show');
207
- expect(output).toContain('when={channel.unread > 0}');
208
- expect(output).toContain('hover:bg-gray-800');
209
- });
210
-
211
- it('transforms a message list', () => {
212
- const input = `
213
- const Messages = ({ messages }) => (
214
- <div className="flex flex-col gap-1">
215
- {messages.map((msg) => (
216
- <div key={msg.id} className="flex items-start gap-3 px-4">
217
- <img src={msg.avatar} className="w-9 h-9 rounded-full" />
218
- <div className="flex flex-col flex-1 min-w-0">
219
- <span className="font-semibold">{msg.sender}</span>
220
- <p className="text-sm">{msg.content}</p>
221
- </div>
222
- </div>
223
- ))}
224
- </div>
225
- );`;
226
- const output = forward(input);
227
- expect(output).toContain('<Stack');
228
- expect(output).toContain('<Each');
229
- expect(output).toContain('<Row');
230
- expect(output).toContain('<Image');
231
- expect(output).toContain('<Text');
232
- // Verify all Tailwind classes preserved
233
- expect(output).toContain('gap-1');
234
- expect(output).toContain('items-start gap-3 px-4');
235
- expect(output).toContain('w-9 h-9 rounded-full');
236
- expect(output).toContain('font-semibold');
237
- });
238
- });
239
- });
@@ -1,145 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { transform } from '../index';
3
-
4
- function reverse(source: string): string {
5
- return transform(source, { direction: 'reverse' }).code;
6
- }
7
-
8
- describe('reverse transform', () => {
9
- describe('element mapping', () => {
10
- it('Row → div with flex', () => {
11
- const input = `const App = () => <Row className="items-center gap-2">hello</Row>;`;
12
- const output = reverse(input);
13
- expect(output).toContain('<div');
14
- expect(output).toContain('flex items-center gap-2');
15
- });
16
-
17
- it('Stack → div with flex flex-col', () => {
18
- const input = `const App = () => <Stack className="gap-4 p-2">hello</Stack>;`;
19
- const output = reverse(input);
20
- expect(output).toContain('<div');
21
- expect(output).toContain('flex flex-col gap-4 p-2');
22
- });
23
-
24
- it('Grid → div with grid', () => {
25
- const input = `const App = () => <Grid className="grid-cols-3">hello</Grid>;`;
26
- const output = reverse(input);
27
- expect(output).toContain('<div');
28
- expect(output).toContain('grid grid-cols-3');
29
- });
30
-
31
- it('Text → span', () => {
32
- const input = `const App = () => <Text className="text-sm">hello</Text>;`;
33
- const output = reverse(input);
34
- expect(output).toContain('<span');
35
- });
36
-
37
- it('Text with variant="h2" → h2', () => {
38
- const input = `const App = () => <Text variant="h2" className="font-bold">Title</Text>;`;
39
- const output = reverse(input);
40
- expect(output).toContain('<h2');
41
- expect(output).not.toContain('variant=');
42
- });
43
-
44
- it('Button → button with onClick', () => {
45
- const input = `const App = () => <Button className="px-4" onPress={handleClick}>Go</Button>;`;
46
- const output = reverse(input);
47
- expect(output).toContain('<button');
48
- expect(output).toContain('onClick');
49
- expect(output).not.toContain('onPress');
50
- });
51
-
52
- it('Link → a', () => {
53
- const input = `const App = () => <Link href="/page">Go</Link>;`;
54
- const output = reverse(input);
55
- expect(output).toContain('<a');
56
- });
57
-
58
- it('TextInput → input', () => {
59
- const input = `const App = () => <TextInput className="w-full" />;`;
60
- const output = reverse(input);
61
- expect(output).toContain('<input');
62
- });
63
-
64
- it('TextInput multiline → textarea', () => {
65
- const input = `const App = () => <TextInput multiline className="w-full" />;`;
66
- const output = reverse(input);
67
- expect(output).toContain('<textarea');
68
- expect(output).not.toContain('multiline');
69
- });
70
-
71
- it('Image → img', () => {
72
- const input = `const App = () => <Image src="/avatar.png" className="w-9 h-9" />;`;
73
- const output = reverse(input);
74
- expect(output).toContain('<img');
75
- });
76
- });
77
-
78
- describe('control flow', () => {
79
- it('Show → conditional &&', () => {
80
- const input = `const App = () => <div><Show when={visible}><span>hi</span></Show></div>;`;
81
- const output = reverse(input);
82
- expect(output).toContain('visible &&');
83
- expect(output).not.toContain('<Show');
84
- });
85
-
86
- it('Each → .map()', () => {
87
- const input = `const App = () => <div><Each items={items} as="item">{(item) => <span>{item.name}</span>}</Each></div>;`;
88
- const output = reverse(input);
89
- expect(output).toContain('.map(');
90
- expect(output).not.toContain('<Each');
91
- });
92
-
93
- it('Each with keyField restores key prop', () => {
94
- const input = `const App = () => <div><Each items={items} as="item" keyField={item.id}>{(item) => <span>{item.name}</span>}</Each></div>;`;
95
- const output = reverse(input);
96
- expect(output).toContain('.map(');
97
- expect(output).toContain('key={');
98
- });
99
- });
100
-
101
- describe('className injection', () => {
102
- it('adds flex to Row without className', () => {
103
- const input = `const App = () => <Row>hello</Row>;`;
104
- const output = reverse(input);
105
- expect(output).toContain('className="flex"');
106
- });
107
-
108
- it('adds flex flex-col to Stack without className', () => {
109
- const input = `const App = () => <Stack>hello</Stack>;`;
110
- const output = reverse(input);
111
- expect(output).toContain('className="flex flex-col"');
112
- });
113
-
114
- it('preserves existing classes when injecting', () => {
115
- const input = `const App = () => <Row className="items-center gap-2">hello</Row>;`;
116
- const output = reverse(input);
117
- expect(output).toContain('flex items-center gap-2');
118
- });
119
- });
120
-
121
- describe('imports', () => {
122
- it('removes atom imports', () => {
123
- const input = `import { Row, Text } from '@mindmatrix/react/atoms';\nconst App = () => <Row><Text>hi</Text></Row>;`;
124
- const output = reverse(input);
125
- expect(output).not.toContain("from '@mindmatrix/react/atoms'");
126
- });
127
-
128
- it('preserves non-atom imports', () => {
129
- const input = `import { Row } from '@mindmatrix/react/atoms';\nimport { cn } from './utils';\nconst App = () => <Row>hi</Row>;`;
130
- const output = reverse(input);
131
- expect(output).toContain("from './utils'");
132
- });
133
- });
134
-
135
- describe('annotation-guided reverse', () => {
136
- it('uses @mm-original to restore exact tag', () => {
137
- const input = `const App = () => (
138
- /* @mm-original main */
139
- <Stack className="p-4">hello</Stack>
140
- );`;
141
- const output = reverse(input);
142
- expect(output).toContain('<main');
143
- });
144
- });
145
- });