@mmapp/react-compiler 0.1.0-alpha.17 → 0.1.0-alpha.19

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 (190) hide show
  1. package/dist/babel/index.d.mts +1 -1
  2. package/dist/babel/index.d.ts +1 -1
  3. package/dist/babel/index.js +9 -6
  4. package/dist/babel/index.mjs +1 -1
  5. package/dist/chunk-26U577GB.mjs +3465 -0
  6. package/dist/chunk-2FBDFAX6.mjs +2362 -0
  7. package/dist/chunk-2REDFOER.mjs +931 -0
  8. package/dist/{chunk-FPAMQXKB.mjs → chunk-2UTXM2QX.mjs} +10 -20
  9. package/dist/chunk-2YDQTFAL.mjs +879 -0
  10. package/dist/chunk-2ZRKQE74.mjs +175 -0
  11. package/dist/chunk-3QHG2JWV.mjs +154 -0
  12. package/dist/chunk-466OWSTT.mjs +186 -0
  13. package/dist/chunk-467SFYOD.mjs +3127 -0
  14. package/dist/chunk-4AIJO7DZ.mjs +214 -0
  15. package/dist/chunk-4D43TZYL.mjs +7495 -0
  16. package/dist/chunk-4HX4PI4R.mjs +734 -0
  17. package/dist/chunk-4VU56NTZ.mjs +544 -0
  18. package/dist/chunk-4XHK6FWL.mjs +2058 -0
  19. package/dist/chunk-52C2JKH2.mjs +186 -0
  20. package/dist/chunk-52XHYD2V.mjs +214 -0
  21. package/dist/chunk-5GUFFFGL.mjs +148 -0
  22. package/dist/chunk-5N2FDDS6.mjs +214 -0
  23. package/dist/chunk-5ZSJXWZT.mjs +1646 -0
  24. package/dist/chunk-6CQOAAMV.mjs +1803 -0
  25. package/dist/chunk-6SEVAAVT.mjs +3516 -0
  26. package/dist/chunk-6YLR5ZDA.mjs +2829 -0
  27. package/dist/chunk-77UJB356.mjs +244 -0
  28. package/dist/chunk-7QOAJPQF.mjs +774 -0
  29. package/dist/chunk-A5RCMIBP.mjs +1795 -0
  30. package/dist/chunk-A63R3GKH.mjs +1803 -0
  31. package/dist/chunk-ABNTZXF5.mjs +951 -0
  32. package/dist/chunk-ADHWW56I.mjs +214 -0
  33. package/dist/chunk-AOGY2GK6.mjs +3292 -0
  34. package/dist/chunk-AXXUXRNA.mjs +1434 -0
  35. package/dist/chunk-BZLU5YK5.mjs +1025 -0
  36. package/dist/chunk-C7XCDDBH.mjs +1802 -0
  37. package/dist/chunk-CHLVKMQW.mjs +175 -0
  38. package/dist/chunk-CKGOZAB7.mjs +939 -0
  39. package/dist/chunk-CSXYDIVC.mjs +214 -0
  40. package/dist/chunk-CXTV4VGG.mjs +148 -0
  41. package/dist/chunk-D34RAZUX.mjs +2223 -0
  42. package/dist/chunk-DDIC7WM6.mjs +3127 -0
  43. package/dist/chunk-DPUQOBU6.mjs +4810 -0
  44. package/dist/chunk-E6MDVTGT.mjs +148 -0
  45. package/dist/chunk-EGKMUEM6.mjs +544 -0
  46. package/dist/chunk-EO6SYNCG.mjs +175 -0
  47. package/dist/chunk-EQGA6A6D.mjs +121 -0
  48. package/dist/chunk-EY2CSXYA.mjs +822 -0
  49. package/dist/chunk-FF5BQVII.mjs +148 -0
  50. package/dist/chunk-FIQ65CDR.mjs +925 -0
  51. package/dist/chunk-FOZXJFAR.mjs +186 -0
  52. package/dist/chunk-G2IAZ5Q6.mjs +148 -0
  53. package/dist/chunk-G7SMOWOL.mjs +828 -0
  54. package/dist/chunk-GK7NU6DO.mjs +214 -0
  55. package/dist/chunk-GMW45YVD.mjs +868 -0
  56. package/dist/chunk-HDSCPEHY.mjs +4061 -0
  57. package/dist/chunk-HJELFNEA.mjs +186 -0
  58. package/dist/chunk-HOIUP6IF.mjs +690 -0
  59. package/dist/chunk-HRJGDPNE.mjs +148 -0
  60. package/dist/chunk-I3AU7GRD.mjs +120 -0
  61. package/dist/chunk-I3VQQJZ6.mjs +2843 -0
  62. package/dist/chunk-IPTX5MJU.mjs +3223 -0
  63. package/dist/chunk-ITGUSH2Z.mjs +2783 -0
  64. package/dist/chunk-IXHBCAMF.mjs +3306 -0
  65. package/dist/chunk-J7JUAHS4.mjs +186 -0
  66. package/dist/chunk-J7TWJ3TM.mjs +2784 -0
  67. package/dist/chunk-JDPLDGVF.mjs +4810 -0
  68. package/dist/chunk-JK72MQ4N.mjs +877 -0
  69. package/dist/chunk-K2HHCAS2.mjs +148 -0
  70. package/dist/chunk-K5HX2SVL.mjs +1902 -0
  71. package/dist/chunk-KAUEQ2F3.mjs +148 -0
  72. package/dist/chunk-KFVVOS5N.mjs +925 -0
  73. package/dist/chunk-KIH4AN3Y.mjs +154 -0
  74. package/dist/chunk-KPDMN5IX.mjs +175 -0
  75. package/dist/chunk-LZL2IRCH.mjs +186 -0
  76. package/dist/chunk-MIZV3TAN.mjs +3293 -0
  77. package/dist/chunk-MRH4J7IX.mjs +2846 -0
  78. package/dist/chunk-NKBL5GUC.mjs +186 -0
  79. package/dist/chunk-NQCNSCF6.mjs +148 -0
  80. package/dist/chunk-NRP5J3BR.mjs +4811 -0
  81. package/dist/chunk-NTB7OEX2.mjs +2918 -0
  82. package/dist/chunk-NUPJYPFU.mjs +801 -0
  83. package/dist/chunk-NVQUTSQX.mjs +3128 -0
  84. package/dist/chunk-OGMG64EY.mjs +148 -0
  85. package/dist/chunk-OL5B2HTH.mjs +175 -0
  86. package/dist/chunk-OPJKP747.mjs +7506 -0
  87. package/dist/chunk-OQLGGBNE.mjs +2918 -0
  88. package/dist/chunk-OW4AQUDL.mjs +544 -0
  89. package/dist/chunk-OWI6XWCD.mjs +3375 -0
  90. package/dist/chunk-OZT2EAF2.mjs +2776 -0
  91. package/dist/chunk-PBRBRKIQ.mjs +175 -0
  92. package/dist/chunk-PRUMNNDI.mjs +3192 -0
  93. package/dist/chunk-QPNHDTSM.mjs +4839 -0
  94. package/dist/chunk-RNEIAJDR.mjs +897 -0
  95. package/dist/chunk-RY7POBNT.mjs +3127 -0
  96. package/dist/chunk-S6FJ4DXL.mjs +1813 -0
  97. package/dist/chunk-SU4E6E7B.mjs +3153 -0
  98. package/dist/chunk-SYUUKW5A.mjs +3379 -0
  99. package/dist/chunk-THB5SX2S.mjs +113 -0
  100. package/dist/chunk-THFYE5ZX.mjs +244 -0
  101. package/dist/chunk-TK3QMXIP.mjs +2921 -0
  102. package/dist/chunk-TRR2NPAV.mjs +248 -0
  103. package/dist/chunk-TTTTOT7P.mjs +1803 -0
  104. package/dist/chunk-TXONBY6A.mjs +7509 -0
  105. package/dist/chunk-U2PX3JSY.mjs +1933 -0
  106. package/dist/chunk-UASOWKDI.mjs +186 -0
  107. package/dist/chunk-UDDTWG5J.mjs +734 -0
  108. package/dist/chunk-UIWLAQCL.mjs +175 -0
  109. package/dist/chunk-UL2XZEMA.mjs +3128 -0
  110. package/dist/chunk-US3AVDAI.mjs +3456 -0
  111. package/dist/chunk-V5DIDOTT.mjs +148 -0
  112. package/dist/chunk-VLTKQDJ3.mjs +244 -0
  113. package/dist/chunk-VVC42PTS.mjs +175 -0
  114. package/dist/chunk-VX3T3NIR.mjs +897 -0
  115. package/dist/chunk-WBYMW4NQ.mjs +3450 -0
  116. package/dist/chunk-XMWUHQVV.mjs +939 -0
  117. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  118. package/dist/chunk-YCWC2SCO.mjs +148 -0
  119. package/dist/chunk-YFS6JMYO.mjs +3342 -0
  120. package/dist/chunk-ZE67HOSN.mjs +148 -0
  121. package/dist/chunk-ZSK5TPIV.mjs +148 -0
  122. package/dist/cli/index.js +317 -656
  123. package/dist/cli/index.mjs +8 -8
  124. package/dist/config-PL24KEWL.mjs +219 -0
  125. package/dist/dev-server-Bs_sz2DG.d.mts +111 -0
  126. package/dist/dev-server-Bs_sz2DG.d.ts +111 -0
  127. package/dist/dev-server-RmGHIntF.d.mts +113 -0
  128. package/dist/dev-server-RmGHIntF.d.ts +113 -0
  129. package/dist/dev-server.js +194 -526
  130. package/dist/dev-server.mjs +4 -4
  131. package/dist/engine-binary-KQB23JDR.mjs +97 -0
  132. package/dist/envelope-DD7v0v6E.d.mts +265 -0
  133. package/dist/envelope-DD7v0v6E.d.ts +265 -0
  134. package/dist/envelope.js +9 -6
  135. package/dist/envelope.mjs +2 -2
  136. package/dist/index-B5gSgvnd.d.mts +44 -0
  137. package/dist/index-B5gSgvnd.d.ts +44 -0
  138. package/dist/index-Bs0MnR54.d.mts +103 -0
  139. package/dist/index-Bs0MnR54.d.ts +103 -0
  140. package/dist/index-DR0nNc_f.d.mts +101 -0
  141. package/dist/index-DR0nNc_f.d.ts +101 -0
  142. package/dist/index-revho_gS.d.mts +104 -0
  143. package/dist/index-revho_gS.d.ts +104 -0
  144. package/dist/index-vQjwYekL.d.mts +104 -0
  145. package/dist/index-vQjwYekL.d.ts +104 -0
  146. package/dist/index.d.mts +2 -2
  147. package/dist/index.d.ts +2 -2
  148. package/dist/index.js +198 -528
  149. package/dist/index.mjs +9 -8
  150. package/dist/init-2XLTUF7O.mjs +407 -0
  151. package/dist/init-7FJENUDK.mjs +407 -0
  152. package/dist/init-DQDX3QK6.mjs +369 -0
  153. package/dist/init-K3GVM4JS.mjs +538 -0
  154. package/dist/init-NXS5BJN3.mjs +454 -0
  155. package/dist/init-UC3FWPIW.mjs +367 -0
  156. package/dist/init-UNV5XIDE.mjs +367 -0
  157. package/dist/project-compiler-2HOPO7GC.mjs +10 -0
  158. package/dist/project-compiler-D245L5QR.mjs +10 -0
  159. package/dist/project-compiler-FUQRMB4X.mjs +10 -0
  160. package/dist/project-compiler-LA5OBI5P.mjs +10 -0
  161. package/dist/project-compiler-OP2VVGJQ.mjs +10 -0
  162. package/dist/project-compiler-PZNFE6AH.mjs +10 -0
  163. package/dist/project-compiler-QBVF6MFI.mjs +10 -0
  164. package/dist/project-compiler-VFR6CSDX.mjs +10 -0
  165. package/dist/project-compiler-WMJZA4UH.mjs +10 -0
  166. package/dist/project-compiler-XXS27TZT.mjs +10 -0
  167. package/dist/project-compiler-YYGDSHY5.mjs +10 -0
  168. package/dist/project-decompiler-5GY2KSG4.mjs +7 -0
  169. package/dist/project-decompiler-7I2OMUVY.mjs +7 -0
  170. package/dist/project-decompiler-US7GAVIC.mjs +7 -0
  171. package/dist/pull-2Q53HF3H.mjs +107 -0
  172. package/dist/pull-5AFHD3QG.mjs +109 -0
  173. package/dist/pull-65GUSX6F.mjs +109 -0
  174. package/dist/pull-6LVI4LMM.mjs +109 -0
  175. package/dist/pull-A2QUHW4K.mjs +109 -0
  176. package/dist/pull-B6T5BUKV.mjs +109 -0
  177. package/dist/pull-CKHWZT33.mjs +109 -0
  178. package/dist/pull-GM74ERRT.mjs +109 -0
  179. package/dist/pull-JBEQWVPE.mjs +109 -0
  180. package/dist/pull-P44LDRWB.mjs +109 -0
  181. package/dist/pull-W2US3T3E.mjs +109 -0
  182. package/dist/testing/index.js +9 -6
  183. package/dist/testing/index.mjs +1 -1
  184. package/dist/verify-3PPS4XAM.mjs +1833 -0
  185. package/dist/verify-GKEH5FZQ.mjs +1833 -0
  186. package/dist/verify-HDKUNHZ4.mjs +1833 -0
  187. package/dist/verify-SEIXUGN4.mjs +1833 -0
  188. package/dist/vite/index.js +10 -7
  189. package/dist/vite/index.mjs +2 -2
  190. package/package.json +2 -2
@@ -0,0 +1,3516 @@
1
+ // src/babel/visitor.ts
2
+ import * as t13 from "@babel/types";
3
+
4
+ // src/babel/extractors/state-extractor.ts
5
+ import * as t from "@babel/types";
6
+ function inferFieldType(typeAnnotation, defaultValue) {
7
+ if (typeAnnotation) {
8
+ if (t.isTSNumberKeyword(typeAnnotation)) return "number";
9
+ if (t.isTSStringKeyword(typeAnnotation)) return "text";
10
+ if (t.isTSBooleanKeyword(typeAnnotation)) return "boolean";
11
+ if (t.isTSTypeReference(typeAnnotation)) {
12
+ const typeName = t.isIdentifier(typeAnnotation.typeName) ? typeAnnotation.typeName.name : "";
13
+ if (typeName === "Date") return "date";
14
+ }
15
+ if (t.isTSArrayType(typeAnnotation) || t.isTSTypeLiteral(typeAnnotation) || t.isTSTupleType(typeAnnotation)) {
16
+ return "json";
17
+ }
18
+ }
19
+ if (defaultValue) {
20
+ if (t.isNumericLiteral(defaultValue)) return "number";
21
+ if (t.isStringLiteral(defaultValue)) return "text";
22
+ if (t.isBooleanLiteral(defaultValue)) return "boolean";
23
+ if (t.isArrayExpression(defaultValue) || t.isObjectExpression(defaultValue)) {
24
+ return "json";
25
+ }
26
+ if (t.isNewExpression(defaultValue) && t.isIdentifier(defaultValue.callee)) {
27
+ if (defaultValue.callee.name === "Date") return "date";
28
+ }
29
+ }
30
+ return "text";
31
+ }
32
+ function extractDefaultValue(arg) {
33
+ if (t.isNumericLiteral(arg)) return arg.value;
34
+ if (t.isStringLiteral(arg)) return arg.value;
35
+ if (t.isBooleanLiteral(arg)) return arg.value;
36
+ if (t.isNullLiteral(arg)) return null;
37
+ if (t.isArrayExpression(arg)) {
38
+ return arg.elements.map(
39
+ (el) => el && t.isExpression(el) ? extractDefaultValue(el) : null
40
+ );
41
+ }
42
+ if (t.isObjectExpression(arg)) {
43
+ const obj = {};
44
+ arg.properties.forEach((prop) => {
45
+ if (t.isObjectProperty(prop) && t.isIdentifier(prop.key) && t.isExpression(prop.value)) {
46
+ obj[prop.key.name] = extractDefaultValue(prop.value);
47
+ }
48
+ });
49
+ return obj;
50
+ }
51
+ return void 0;
52
+ }
53
+ function extractStates(path, state) {
54
+ const parent = path.parentPath;
55
+ if (!parent.isVariableDeclarator()) return;
56
+ const id = parent.node.id;
57
+ if (!t.isArrayPattern(id) || id.elements.length < 1) return;
58
+ const firstElement = id.elements[0];
59
+ if (!t.isIdentifier(firstElement)) return;
60
+ const fieldName = firstElement.name;
61
+ const args = path.node.arguments;
62
+ const defaultValue = args.length > 0 && t.isExpression(args[0]) ? args[0] : null;
63
+ let typeAnnotation = null;
64
+ if (path.node.typeParameters && t.isTSTypeParameterInstantiation(path.node.typeParameters)) {
65
+ const params = path.node.typeParameters.params;
66
+ if (params.length > 0) {
67
+ typeAnnotation = params[0];
68
+ }
69
+ }
70
+ const fieldType = inferFieldType(typeAnnotation, defaultValue);
71
+ const fieldDefaultValue = defaultValue ? extractDefaultValue(defaultValue) : void 0;
72
+ const field = {
73
+ name: fieldName,
74
+ type: fieldType,
75
+ default_value: fieldDefaultValue
76
+ };
77
+ const compilerState = state;
78
+ if (!compilerState.fields) compilerState.fields = [];
79
+ if (!compilerState.fields.some((f) => f.name === fieldName)) {
80
+ compilerState.fields.push(field);
81
+ }
82
+ }
83
+
84
+ // src/babel/extractors/effect-extractor.ts
85
+ import * as t2 from "@babel/types";
86
+ function analyzeCallbackBody(body, actionCounter) {
87
+ const actions = [];
88
+ for (const statement of body) {
89
+ if (t2.isExpressionStatement(statement)) {
90
+ const expr = statement.expression;
91
+ if (t2.isCallExpression(expr) && t2.isIdentifier(expr.callee)) {
92
+ const calleeName = expr.callee.name;
93
+ const args = expr.arguments;
94
+ if (calleeName === "setField" && args.length >= 2) {
95
+ const field = t2.isStringLiteral(args[0]) ? args[0].value : void 0;
96
+ const arg1 = args[1];
97
+ if (field !== void 0 && !t2.isArgumentPlaceholder(arg1)) {
98
+ const value = extractValue(arg1);
99
+ actions.push({
100
+ id: `auto_${++actionCounter.value}`,
101
+ type: "set_field",
102
+ mode: "auto",
103
+ config: { field, value }
104
+ });
105
+ }
106
+ } else if (calleeName === "setMemory" && args.length >= 2) {
107
+ const key = t2.isStringLiteral(args[0]) ? args[0].value : void 0;
108
+ const arg1 = args[1];
109
+ if (key !== void 0 && !t2.isArgumentPlaceholder(arg1)) {
110
+ const value = extractValue(arg1);
111
+ actions.push({
112
+ id: `auto_${++actionCounter.value}`,
113
+ type: "set_memory",
114
+ mode: "auto",
115
+ config: { key, value }
116
+ });
117
+ }
118
+ } else if (calleeName.startsWith("set") && args.length >= 1) {
119
+ const fieldName = calleeName.slice(3).charAt(0).toLowerCase() + calleeName.slice(4);
120
+ const arg0 = args[0];
121
+ if (!t2.isArgumentPlaceholder(arg0)) {
122
+ const value = extractValue(arg0);
123
+ actions.push({
124
+ id: `auto_${++actionCounter.value}`,
125
+ type: "set_field",
126
+ mode: "auto",
127
+ config: { field: fieldName, value }
128
+ });
129
+ }
130
+ }
131
+ } else if (t2.isCallExpression(expr)) {
132
+ const callee = expr.callee;
133
+ const args = expr.arguments;
134
+ if (t2.isMemberExpression(callee) && t2.isIdentifier(callee.object) && callee.object.name === "console" && t2.isIdentifier(callee.property) && callee.property.name === "log" && args.length > 0) {
135
+ const arg0 = args[0];
136
+ if (!t2.isArgumentPlaceholder(arg0)) {
137
+ const message = extractValue(arg0);
138
+ actions.push({
139
+ id: `auto_${++actionCounter.value}`,
140
+ type: "log_event",
141
+ mode: "auto",
142
+ config: { message }
143
+ });
144
+ }
145
+ } else {
146
+ actions.push({
147
+ id: `auto_${++actionCounter.value}`,
148
+ type: "custom",
149
+ mode: "auto",
150
+ config: { expression: generateCode(expr) }
151
+ });
152
+ }
153
+ }
154
+ }
155
+ }
156
+ return actions;
157
+ }
158
+ function extractValue(node) {
159
+ if (t2.isNumericLiteral(node)) return node.value;
160
+ if (t2.isStringLiteral(node)) return node.value;
161
+ if (t2.isBooleanLiteral(node)) return node.value;
162
+ if (t2.isNullLiteral(node)) return null;
163
+ if (t2.isArrayExpression(node)) {
164
+ return node.elements.map((el) => el && t2.isExpression(el) ? extractValue(el) : null);
165
+ }
166
+ if (t2.isObjectExpression(node)) {
167
+ const obj = {};
168
+ node.properties.forEach((prop) => {
169
+ if (t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && t2.isExpression(prop.value)) {
170
+ obj[prop.key.name] = extractValue(prop.value);
171
+ }
172
+ });
173
+ return obj;
174
+ }
175
+ return generateCode(node);
176
+ }
177
+ function generateCode(node) {
178
+ if (t2.isIdentifier(node)) return node.name;
179
+ if (t2.isNumericLiteral(node)) return String(node.value);
180
+ if (t2.isStringLiteral(node)) return `"${node.value}"`;
181
+ if (t2.isBooleanLiteral(node)) return String(node.value);
182
+ if (t2.isNullLiteral(node)) return "null";
183
+ if (t2.isCallExpression(node) && t2.isMemberExpression(node.callee) && t2.isIdentifier(node.callee.object) && node.callee.object.name === "Date" && t2.isIdentifier(node.callee.property) && node.callee.property.name === "now") {
184
+ return "now()";
185
+ }
186
+ if (t2.isCallExpression(node) && t2.isMemberExpression(node.callee) && t2.isNewExpression(node.callee.object) && t2.isIdentifier(node.callee.object.callee) && node.callee.object.callee.name === "Date" && t2.isIdentifier(node.callee.property) && node.callee.property.name === "toISOString") {
187
+ return "now()";
188
+ }
189
+ if (t2.isBinaryExpression(node)) {
190
+ return `(${generateCode(node.left)} ${node.operator} ${generateCode(node.right)})`;
191
+ }
192
+ if (t2.isLogicalExpression(node)) {
193
+ return `(${generateCode(node.left)} ${node.operator} ${generateCode(node.right)})`;
194
+ }
195
+ if (t2.isConditionalExpression(node)) {
196
+ return `(${generateCode(node.test)} ? ${generateCode(node.consequent)} : ${generateCode(node.alternate)})`;
197
+ }
198
+ if (t2.isUnaryExpression(node) && node.prefix) {
199
+ return `${node.operator}${generateCode(node.argument)}`;
200
+ }
201
+ if (t2.isTemplateLiteral(node)) {
202
+ return node.quasis.map((q, i) => {
203
+ const raw = q.value.raw;
204
+ if (i < node.expressions.length) return raw + "${" + generateCode(node.expressions[i]) + "}";
205
+ return raw;
206
+ }).join("");
207
+ }
208
+ if (t2.isMemberExpression(node)) {
209
+ const obj = generateCode(node.object);
210
+ if (node.computed) {
211
+ return `${obj}[${generateCode(node.property)}]`;
212
+ }
213
+ const prop = t2.isIdentifier(node.property) ? node.property.name : "[property]";
214
+ return `${obj}.${prop}`;
215
+ }
216
+ if (t2.isCallExpression(node)) {
217
+ if (t2.isIdentifier(node.callee)) {
218
+ const args = node.arguments.map((a) => generateCode(a)).join(", ");
219
+ return `${node.callee.name}(${args})`;
220
+ }
221
+ if (t2.isMemberExpression(node.callee)) {
222
+ const obj = generateCode(node.callee.object);
223
+ const prop = t2.isIdentifier(node.callee.property) ? node.callee.property.name : "[method]";
224
+ const args = node.arguments.map((a) => generateCode(a)).join(", ");
225
+ return `${obj}.${prop}(${args})`;
226
+ }
227
+ }
228
+ if (t2.isArrowFunctionExpression(node)) {
229
+ if (t2.isExpression(node.body)) {
230
+ const params = node.params;
231
+ if (params.length === 1 && t2.isIdentifier(params[0])) {
232
+ const paramName = params[0].name;
233
+ const bodyCode = generateCode(node.body);
234
+ return bodyCode.replace(new RegExp(`\\b${paramName}\\b`, "g"), "$prev");
235
+ }
236
+ }
237
+ return "[Function]";
238
+ }
239
+ if (t2.isFunctionExpression(node)) return "[Function]";
240
+ if (t2.isArrayExpression(node)) {
241
+ const elements = node.elements.map((el) => el ? generateCode(el) : "undefined").join(", ");
242
+ return `[${elements}]`;
243
+ }
244
+ if (t2.isObjectExpression(node)) {
245
+ const props = node.properties.map((p) => {
246
+ if (t2.isObjectProperty(p)) {
247
+ const key = t2.isIdentifier(p.key) ? p.key.name : t2.isStringLiteral(p.key) ? `"${p.key.value}"` : "[key]";
248
+ if (p.shorthand && t2.isIdentifier(p.value)) return key;
249
+ return `${key}: ${generateCode(p.value)}`;
250
+ }
251
+ if (t2.isSpreadElement(p)) return `...${generateCode(p.argument)}`;
252
+ return "";
253
+ }).filter(Boolean).join(", ");
254
+ return `{ ${props} }`;
255
+ }
256
+ if (t2.isTSAsExpression(node)) return generateCode(node.expression);
257
+ if (t2.isTSNonNullExpression(node)) return generateCode(node.expression);
258
+ return "[Expression]";
259
+ }
260
+ function ensureState(states, stateName) {
261
+ if (!states.has(stateName)) {
262
+ states.set(stateName, {
263
+ name: stateName,
264
+ type: "REGULAR",
265
+ on_enter: [],
266
+ during: [],
267
+ on_exit: []
268
+ });
269
+ }
270
+ return states.get(stateName);
271
+ }
272
+ function extractEffects(path, state) {
273
+ const callee = path.node.callee;
274
+ if (!t2.isIdentifier(callee)) return;
275
+ const hookName = callee.name;
276
+ const args = path.node.arguments;
277
+ if ((hookName === "useOnEnter" || hookName === "useOnExit") && args.length >= 2) {
278
+ const stateArg = args[0];
279
+ const callbackArg = args[1];
280
+ if (!t2.isStringLiteral(stateArg)) return;
281
+ const stateName = stateArg.value;
282
+ let callbackBody = [];
283
+ if (t2.isArrowFunctionExpression(callbackArg) || t2.isFunctionExpression(callbackArg)) {
284
+ const body = callbackArg.body;
285
+ if (t2.isBlockStatement(body)) {
286
+ callbackBody = body.body;
287
+ } else if (t2.isExpression(body)) {
288
+ callbackBody = [t2.expressionStatement(body)];
289
+ }
290
+ }
291
+ const compilerState = state;
292
+ if (!compilerState.states) compilerState.states = /* @__PURE__ */ new Map();
293
+ if (!compilerState.actionCounter) compilerState.actionCounter = 0;
294
+ const stateDefinition = ensureState(compilerState.states, stateName);
295
+ const actions = analyzeCallbackBody(callbackBody, { value: compilerState.actionCounter });
296
+ compilerState.actionCounter += actions.length;
297
+ if (hookName === "useOnEnter") {
298
+ stateDefinition.on_enter.push(...actions);
299
+ } else if (hookName === "useOnExit") {
300
+ stateDefinition.on_exit.push(...actions);
301
+ }
302
+ }
303
+ }
304
+
305
+ // src/babel/extractors/transition-extractor.ts
306
+ import * as t3 from "@babel/types";
307
+ function extractTransitions(path, state) {
308
+ const callee = path.node.callee;
309
+ if (!t3.isIdentifier(callee) || callee.name !== "useTransition") return;
310
+ const args = path.node.arguments;
311
+ if (args.length < 1) return;
312
+ const nameArg = args[0];
313
+ if (!t3.isStringLiteral(nameArg)) return;
314
+ const transitionName = nameArg.value;
315
+ const compilerState = state;
316
+ if (!compilerState.transitions) compilerState.transitions = [];
317
+ const existing = compilerState.transitions.find((tr) => tr.name === transitionName);
318
+ if (existing) return;
319
+ let from = [];
320
+ let to = "";
321
+ if (args.length >= 2 && t3.isObjectExpression(args[1])) {
322
+ const opts = args[1];
323
+ for (const prop of opts.properties) {
324
+ if (!t3.isObjectProperty(prop) || !t3.isIdentifier(prop.key)) continue;
325
+ if (prop.key.name === "from") {
326
+ if (t3.isArrayExpression(prop.value)) {
327
+ from = prop.value.elements.filter((el) => t3.isStringLiteral(el)).map((el) => el.value);
328
+ } else if (t3.isStringLiteral(prop.value)) {
329
+ from = [prop.value.value];
330
+ }
331
+ } else if (prop.key.name === "to") {
332
+ if (t3.isStringLiteral(prop.value)) {
333
+ to = prop.value.value;
334
+ }
335
+ }
336
+ }
337
+ }
338
+ const transition = {
339
+ name: transitionName,
340
+ from,
341
+ to,
342
+ actions: [],
343
+ conditions: []
344
+ };
345
+ compilerState.transitions.push(transition);
346
+ }
347
+ function inferTransitionStates(transitions, states) {
348
+ const stateArray = Array.from(states.values());
349
+ const startStates = stateArray.filter((s) => s.type === "START");
350
+ const regularStates = stateArray.filter((s) => s.type === "REGULAR");
351
+ const needsInference = transitions.filter((t14) => t14.from.length === 0 || !t14.to);
352
+ if (needsInference.length === 0) return;
353
+ if (startStates.length === 1 && regularStates.length > 0) {
354
+ needsInference.forEach((t14, idx) => {
355
+ if (t14.from.length === 0) {
356
+ t14.from = [startStates[0].name];
357
+ }
358
+ if (!t14.to) {
359
+ t14.to = regularStates[idx % regularStates.length]?.name || startStates[0].name;
360
+ }
361
+ });
362
+ } else {
363
+ const allStateNames = stateArray.map((s) => s.name);
364
+ needsInference.forEach((t14, idx) => {
365
+ if (t14.from.length === 0 && allStateNames.length > 0) {
366
+ t14.from = [allStateNames[0]];
367
+ }
368
+ if (!t14.to && allStateNames.length > 1) {
369
+ t14.to = allStateNames[Math.min(idx + 1, allStateNames.length - 1)];
370
+ }
371
+ });
372
+ }
373
+ }
374
+
375
+ // src/babel/extractors/event-extractor.ts
376
+ import * as t4 from "@babel/types";
377
+ function analyzeEventCallback(body) {
378
+ const actions = [];
379
+ for (const statement of body) {
380
+ if (t4.isExpressionStatement(statement)) {
381
+ const expr = statement.expression;
382
+ if (t4.isCallExpression(expr) && t4.isIdentifier(expr.callee)) {
383
+ const calleeName = expr.callee.name;
384
+ const args = expr.arguments;
385
+ if (calleeName === "setField" && args.length >= 2) {
386
+ const field = t4.isStringLiteral(args[0]) ? args[0].value : void 0;
387
+ const expression = generateExpression(args[1]);
388
+ if (field) {
389
+ actions.push({
390
+ type: "set_field",
391
+ field,
392
+ expression
393
+ });
394
+ }
395
+ } else if (calleeName === "setMemory" && args.length >= 2) {
396
+ const key = t4.isStringLiteral(args[0]) ? args[0].value : void 0;
397
+ const expression = generateExpression(args[1]);
398
+ if (key) {
399
+ actions.push({
400
+ type: "set_memory",
401
+ key,
402
+ expression
403
+ });
404
+ }
405
+ }
406
+ } else if (t4.isCallExpression(expr)) {
407
+ const callee = expr.callee;
408
+ const args = expr.arguments;
409
+ if (t4.isMemberExpression(callee) && t4.isIdentifier(callee.object) && callee.object.name === "console" && t4.isIdentifier(callee.property) && callee.property.name === "log") {
410
+ const message = args.length > 0 ? generateExpression(args[0]) : "";
411
+ actions.push({
412
+ type: "log_event",
413
+ message
414
+ });
415
+ }
416
+ }
417
+ }
418
+ }
419
+ return actions;
420
+ }
421
+ function generateExpression(node) {
422
+ if (t4.isStringLiteral(node)) return node.value;
423
+ if (t4.isNumericLiteral(node)) return String(node.value);
424
+ if (t4.isBooleanLiteral(node)) return String(node.value);
425
+ if (t4.isNullLiteral(node)) return "null";
426
+ if (t4.isIdentifier(node)) return node.name;
427
+ if (t4.isBinaryExpression(node)) {
428
+ return `(${generateExpression(node.left)} ${node.operator} ${generateExpression(node.right)})`;
429
+ }
430
+ if (t4.isLogicalExpression(node)) {
431
+ return `(${generateExpression(node.left)} ${node.operator} ${generateExpression(node.right)})`;
432
+ }
433
+ if (t4.isConditionalExpression(node)) {
434
+ return `(${generateExpression(node.test)} ? ${generateExpression(node.consequent)} : ${generateExpression(node.alternate)})`;
435
+ }
436
+ if (t4.isUnaryExpression(node) && node.prefix) {
437
+ return `${node.operator}${generateExpression(node.argument)}`;
438
+ }
439
+ if (t4.isCallExpression(node) && t4.isIdentifier(node.callee)) {
440
+ const args = node.arguments.map((arg) => generateExpression(arg)).join(", ");
441
+ return `${node.callee.name}(${args})`;
442
+ }
443
+ if (t4.isCallExpression(node) && t4.isMemberExpression(node.callee)) {
444
+ const obj = generateExpression(node.callee.object);
445
+ const prop = t4.isIdentifier(node.callee.property) ? node.callee.property.name : "[method]";
446
+ const args = node.arguments.map((arg) => generateExpression(arg)).join(", ");
447
+ return `${obj}.${prop}(${args})`;
448
+ }
449
+ if (t4.isMemberExpression(node)) {
450
+ const obj = generateExpression(node.object);
451
+ if (node.computed) {
452
+ const prop2 = generateExpression(node.property);
453
+ return `${obj}[${prop2}]`;
454
+ }
455
+ const prop = t4.isIdentifier(node.property) ? node.property.name : "[property]";
456
+ return `${obj}.${prop}`;
457
+ }
458
+ if (t4.isTemplateLiteral(node)) {
459
+ return node.quasis.map((q, i) => {
460
+ const raw = q.value.raw;
461
+ if (i < node.expressions.length) return raw + "${" + generateExpression(node.expressions[i]) + "}";
462
+ return raw;
463
+ }).join("");
464
+ }
465
+ if (t4.isArrayExpression(node)) {
466
+ const elements = node.elements.map((el) => el ? generateExpression(el) : "undefined").join(", ");
467
+ return `[${elements}]`;
468
+ }
469
+ if (t4.isObjectExpression(node)) {
470
+ const props = node.properties.map((p) => {
471
+ if (t4.isObjectProperty(p)) {
472
+ const key = t4.isIdentifier(p.key) ? p.key.name : t4.isStringLiteral(p.key) ? `"${p.key.value}"` : "[key]";
473
+ if (p.shorthand && t4.isIdentifier(p.value)) return key;
474
+ return `${key}: ${generateExpression(p.value)}`;
475
+ }
476
+ if (t4.isSpreadElement(p)) return `...${generateExpression(p.argument)}`;
477
+ return "";
478
+ }).filter(Boolean).join(", ");
479
+ return `{ ${props} }`;
480
+ }
481
+ if (t4.isTSAsExpression(node)) return generateExpression(node.expression);
482
+ if (t4.isTSNonNullExpression(node)) return generateExpression(node.expression);
483
+ return "[Expression]";
484
+ }
485
+ function ensureState2(states, stateName) {
486
+ if (!states.has(stateName)) {
487
+ states.set(stateName, {
488
+ name: stateName,
489
+ type: "REGULAR",
490
+ on_enter: [],
491
+ during: [],
492
+ on_exit: []
493
+ });
494
+ }
495
+ return states.get(stateName);
496
+ }
497
+ function extractEvents(path, state) {
498
+ const callee = path.node.callee;
499
+ if (!t4.isIdentifier(callee) || callee.name !== "useOnEvent") return;
500
+ const args = path.node.arguments;
501
+ if (args.length < 2) return;
502
+ const patternArg = args[0];
503
+ const callbackArg = args[1];
504
+ const optionsArg = args.length > 2 ? args[2] : null;
505
+ if (!t4.isStringLiteral(patternArg)) return;
506
+ const pattern = patternArg.value;
507
+ let callbackBody = [];
508
+ if (t4.isArrowFunctionExpression(callbackArg) || t4.isFunctionExpression(callbackArg)) {
509
+ const body = callbackArg.body;
510
+ if (t4.isBlockStatement(body)) {
511
+ callbackBody = body.body;
512
+ } else if (t4.isExpression(body)) {
513
+ callbackBody = [t4.expressionStatement(body)];
514
+ }
515
+ }
516
+ let stateName = null;
517
+ if (optionsArg && t4.isObjectExpression(optionsArg)) {
518
+ const whileProp = optionsArg.properties.find(
519
+ (prop) => t4.isObjectProperty(prop) && t4.isIdentifier(prop.key) && prop.key.name === "while"
520
+ );
521
+ if (whileProp && t4.isObjectProperty(whileProp) && t4.isStringLiteral(whileProp.value)) {
522
+ stateName = whileProp.value.value;
523
+ }
524
+ }
525
+ const actions = analyzeEventCallback(callbackBody);
526
+ const subscription = {
527
+ match: pattern,
528
+ conditions: [],
529
+ actions
530
+ };
531
+ const compilerState = state;
532
+ if (!compilerState.states) compilerState.states = /* @__PURE__ */ new Map();
533
+ if (stateName) {
534
+ const stateDefinition = ensureState2(compilerState.states, stateName);
535
+ if (!stateDefinition.on_event) stateDefinition.on_event = [];
536
+ stateDefinition.on_event.push(subscription);
537
+ } else {
538
+ if (!compilerState.events) compilerState.events = [];
539
+ compilerState.events.push(subscription);
540
+ }
541
+ }
542
+
543
+ // src/babel/extractors/component-extractor.ts
544
+ import * as t5 from "@babel/types";
545
+ var nodeIdCounter = 0;
546
+ var localFieldMap = /* @__PURE__ */ new Map();
547
+ var setterToFieldMap = /* @__PURE__ */ new Map();
548
+ var derivedVarMap = /* @__PURE__ */ new Map();
549
+ function toSnakeCase(str) {
550
+ return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
551
+ }
552
+ var STATIC_EVAL_FAIL = Symbol("STATIC_EVAL_FAIL");
553
+ function tryStaticEval(node) {
554
+ if (t5.isStringLiteral(node)) return node.value;
555
+ if (t5.isNumericLiteral(node)) return node.value;
556
+ if (t5.isBooleanLiteral(node)) return node.value;
557
+ if (t5.isNullLiteral(node)) return null;
558
+ if (t5.isIdentifier(node) && node.name === "undefined") return void 0;
559
+ if (t5.isUnaryExpression(node) && node.operator === "-" && t5.isNumericLiteral(node.argument)) {
560
+ return -node.argument.value;
561
+ }
562
+ if (t5.isArrayExpression(node)) {
563
+ const result = [];
564
+ for (const el of node.elements) {
565
+ if (el === null) {
566
+ result.push(null);
567
+ continue;
568
+ }
569
+ if (t5.isSpreadElement(el)) return STATIC_EVAL_FAIL;
570
+ const val = tryStaticEval(el);
571
+ if (val === STATIC_EVAL_FAIL) return STATIC_EVAL_FAIL;
572
+ result.push(val);
573
+ }
574
+ return result;
575
+ }
576
+ if (t5.isObjectExpression(node)) {
577
+ const result = {};
578
+ for (const prop of node.properties) {
579
+ if (t5.isSpreadElement(prop) || t5.isObjectMethod(prop)) return STATIC_EVAL_FAIL;
580
+ if (!t5.isObjectProperty(prop)) return STATIC_EVAL_FAIL;
581
+ let key;
582
+ if (t5.isIdentifier(prop.key)) key = prop.key.name;
583
+ else if (t5.isStringLiteral(prop.key)) key = prop.key.value;
584
+ else if (t5.isNumericLiteral(prop.key)) key = String(prop.key.value);
585
+ else return STATIC_EVAL_FAIL;
586
+ if (!t5.isExpression(prop.value)) return STATIC_EVAL_FAIL;
587
+ const val = tryStaticEval(prop.value);
588
+ if (val === STATIC_EVAL_FAIL) return STATIC_EVAL_FAIL;
589
+ result[key] = val;
590
+ }
591
+ return result;
592
+ }
593
+ if (t5.isTemplateLiteral(node) && node.expressions.length === 0) {
594
+ return node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
595
+ }
596
+ return STATIC_EVAL_FAIL;
597
+ }
598
+ function initLocalFieldMaps(fields) {
599
+ localFieldMap.clear();
600
+ setterToFieldMap.clear();
601
+ for (const field of fields) {
602
+ const camelName = field.name;
603
+ const snakeName = toSnakeCase(camelName);
604
+ localFieldMap.set(camelName, snakeName);
605
+ const setterName = "set" + camelName.charAt(0).toUpperCase() + camelName.slice(1);
606
+ setterToFieldMap.set(setterName, snakeName);
607
+ }
608
+ }
609
+ function registerDerivedVar(name, init) {
610
+ derivedVarMap.set(name, init);
611
+ }
612
+ function resetNodeIdCounter() {
613
+ nodeIdCounter = 0;
614
+ derivedVarMap.clear();
615
+ }
616
+ function jsxToExperienceNode(node) {
617
+ if (t5.isJSXFragment(node)) {
618
+ return {
619
+ id: `fragment_${++nodeIdCounter}`,
620
+ children: extractChildren(node.children)
621
+ };
622
+ }
623
+ const element = node.openingElement;
624
+ const componentName = resolveComponentName(element.name);
625
+ const id = generateNodeId(componentName);
626
+ const config = {};
627
+ const bindings = {};
628
+ let visibleWhen;
629
+ let layout;
630
+ const layoutMap = {
631
+ Stack: "stack",
632
+ Row: "row",
633
+ Grid: "grid",
634
+ Tabs: "tabs",
635
+ Column: "column"
636
+ };
637
+ if (layoutMap[componentName]) {
638
+ layout = layoutMap[componentName];
639
+ }
640
+ for (const attr of element.attributes) {
641
+ if (t5.isJSXAttribute(attr) && t5.isJSXIdentifier(attr.name)) {
642
+ const attrName = attr.name.name;
643
+ const attrValue = attr.value;
644
+ if (attrName === "visible_when" && t5.isStringLiteral(attrValue)) {
645
+ visibleWhen = attrValue.value;
646
+ } else if (attrName === "data-slot" && t5.isStringLiteral(attrValue)) {
647
+ config.slot = attrValue.value;
648
+ } else if (t5.isJSXExpressionContainer(attrValue)) {
649
+ const expr = attrValue.expression;
650
+ if (t5.isJSXEmptyExpression(expr)) continue;
651
+ if (t5.isNumericLiteral(expr)) {
652
+ config[attrName] = expr.value;
653
+ } else if (t5.isBooleanLiteral(expr)) {
654
+ config[attrName] = expr.value;
655
+ } else if (t5.isStringLiteral(expr)) {
656
+ config[attrName] = expr.value;
657
+ } else if (t5.isIdentifier(expr)) {
658
+ const snakeName = localFieldMap.get(expr.name);
659
+ bindings[attrName] = snakeName ? `$local.${snakeName}` : `$instance.${expr.name}`;
660
+ } else if (isEventHandlerProp(attrName) && (t5.isArrowFunctionExpression(expr) || t5.isFunctionExpression(expr))) {
661
+ const decomposed = decomposeHandlerToSeq(expr);
662
+ if (decomposed) {
663
+ bindings[attrName] = decomposed;
664
+ } else {
665
+ bindings[attrName] = generateExpression2(expr);
666
+ }
667
+ } else if (t5.isExpression(expr)) {
668
+ const staticVal = tryStaticEval(expr);
669
+ if (staticVal !== STATIC_EVAL_FAIL) {
670
+ config[attrName] = staticVal;
671
+ } else {
672
+ bindings[attrName] = generateExpression2(expr);
673
+ }
674
+ }
675
+ } else if (t5.isStringLiteral(attrValue)) {
676
+ config[attrName] = attrValue.value;
677
+ } else if (attrValue === null) {
678
+ config[attrName] = true;
679
+ }
680
+ } else if (t5.isJSXSpreadAttribute(attr)) {
681
+ if (t5.isIdentifier(attr.argument)) {
682
+ bindings["..." + attr.argument.name] = `$instance.${attr.argument.name}`;
683
+ }
684
+ }
685
+ }
686
+ const children = extractChildren(node.children);
687
+ const experienceNode = {
688
+ id,
689
+ component: componentName,
690
+ ...layout && { layout },
691
+ ...Object.keys(bindings).length > 0 && { bindings },
692
+ ...Object.keys(config).length > 0 && { config },
693
+ ...visibleWhen && { visible_when: visibleWhen },
694
+ ...children.length > 0 && { children }
695
+ };
696
+ return experienceNode;
697
+ }
698
+ function resolveComponentName(name) {
699
+ if (t5.isJSXIdentifier(name)) return name.name;
700
+ if (t5.isJSXMemberExpression(name)) {
701
+ const obj = resolveComponentName(name.object);
702
+ return `${obj}.${name.property.name}`;
703
+ }
704
+ if (t5.isJSXNamespacedName(name)) {
705
+ return `${name.namespace.name}:${name.name.name}`;
706
+ }
707
+ return "div";
708
+ }
709
+ function extractChildren(children) {
710
+ const nodes = [];
711
+ for (const child of children) {
712
+ if (t5.isJSXElement(child)) {
713
+ nodes.push(jsxToExperienceNode(child));
714
+ } else if (t5.isJSXFragment(child)) {
715
+ nodes.push(jsxToExperienceNode(child));
716
+ } else if (t5.isJSXText(child)) {
717
+ const text = child.value.trim();
718
+ if (text) {
719
+ nodes.push({
720
+ id: `text_${++nodeIdCounter}`,
721
+ component: "Text",
722
+ config: { value: text }
723
+ });
724
+ }
725
+ } else if (t5.isJSXExpressionContainer(child)) {
726
+ const expr = child.expression;
727
+ if (t5.isJSXEmptyExpression(expr)) continue;
728
+ if (t5.isConditionalExpression(expr)) {
729
+ const condExpr = generateExpression2(expr.test);
730
+ if (t5.isJSXElement(expr.consequent) || t5.isJSXFragment(expr.consequent)) {
731
+ const consequent = jsxToExperienceNode(expr.consequent);
732
+ consequent.visible_when = condExpr;
733
+ nodes.push(consequent);
734
+ }
735
+ if (t5.isJSXElement(expr.alternate) || t5.isJSXFragment(expr.alternate)) {
736
+ const alternate = jsxToExperienceNode(expr.alternate);
737
+ alternate.visible_when = `not(${condExpr})`;
738
+ nodes.push(alternate);
739
+ }
740
+ } else if (t5.isLogicalExpression(expr) && expr.operator === "&&") {
741
+ const condExpr = generateExpression2(expr.left);
742
+ if (t5.isJSXElement(expr.right) || t5.isJSXFragment(expr.right)) {
743
+ const element = jsxToExperienceNode(expr.right);
744
+ element.visible_when = condExpr;
745
+ nodes.push(element);
746
+ }
747
+ } else if (t5.isCallExpression(expr) && t5.isMemberExpression(expr.callee) && t5.isIdentifier(expr.callee.property) && expr.callee.property.name === "map" && expr.arguments.length > 0) {
748
+ const listSource = generateExpression2(expr.callee.object);
749
+ const mapFn = expr.arguments[0];
750
+ let itemTemplate = null;
751
+ let itemAlias = "item";
752
+ if (t5.isArrowFunctionExpression(mapFn) || t5.isFunctionExpression(mapFn)) {
753
+ if (mapFn.params.length > 0 && t5.isIdentifier(mapFn.params[0])) {
754
+ itemAlias = mapFn.params[0].name;
755
+ }
756
+ const body = mapFn.body;
757
+ if (t5.isJSXElement(body) || t5.isJSXFragment(body)) {
758
+ itemTemplate = jsxToExperienceNode(body);
759
+ } else if (t5.isBlockStatement(body)) {
760
+ for (const stmt of body.body) {
761
+ if (t5.isReturnStatement(stmt) && stmt.argument) {
762
+ if (t5.isJSXElement(stmt.argument) || t5.isJSXFragment(stmt.argument)) {
763
+ itemTemplate = jsxToExperienceNode(stmt.argument);
764
+ }
765
+ break;
766
+ }
767
+ }
768
+ }
769
+ }
770
+ nodes.push({
771
+ id: `each_${++nodeIdCounter}`,
772
+ component: "Each",
773
+ bindings: { items: listSource.startsWith("$") ? listSource : `$instance.${listSource}` },
774
+ config: { as: itemAlias },
775
+ ...itemTemplate ? { children: [itemTemplate] } : {}
776
+ });
777
+ } else if ((t5.isArrowFunctionExpression(expr) || t5.isFunctionExpression(expr)) && extractJSXFromCallback(expr)) {
778
+ const jsxNode = extractJSXFromCallback(expr);
779
+ nodes.push(jsxToExperienceNode(jsxNode));
780
+ } else if (t5.isIdentifier(expr)) {
781
+ const snakeName = localFieldMap.get(expr.name);
782
+ const bindingPath = snakeName ? `$local.${snakeName}` : `$instance.${expr.name}`;
783
+ nodes.push({
784
+ id: `text_${++nodeIdCounter}`,
785
+ component: "Text",
786
+ bindings: { value: bindingPath }
787
+ });
788
+ } else if (t5.isExpression(expr)) {
789
+ const exprStr = generateExpression2(expr);
790
+ if (exprStr !== "[Expression]") {
791
+ nodes.push({
792
+ id: `text_${++nodeIdCounter}`,
793
+ component: "Text",
794
+ bindings: { value: exprStr }
795
+ });
796
+ }
797
+ }
798
+ }
799
+ }
800
+ return nodes;
801
+ }
802
+ function generateNodeId(componentName) {
803
+ const id = componentName.replace(/\./g, "-").replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
804
+ return `${id}_${++nodeIdCounter}`;
805
+ }
806
+ function generateExpression2(node) {
807
+ if (t5.isIdentifier(node)) {
808
+ const snakeName = localFieldMap.get(node.name);
809
+ if (snakeName) return `$local.${snakeName}`;
810
+ const derivedInit = derivedVarMap.get(node.name);
811
+ if (derivedInit) return `(${generateExpression2(derivedInit)})`;
812
+ return node.name;
813
+ }
814
+ if (t5.isStringLiteral(node)) return `"${node.value.replace(/"/g, '\\"')}"`;
815
+ if (t5.isNumericLiteral(node)) return String(node.value);
816
+ if (t5.isBooleanLiteral(node)) return String(node.value);
817
+ if (t5.isNullLiteral(node)) return "null";
818
+ if (t5.isMemberExpression(node) || t5.isOptionalMemberExpression(node)) {
819
+ const obj = t5.isExpression(node.object) ? generateExpression2(node.object) : "[object]";
820
+ const optional = node.optional ? "?." : ".";
821
+ if (node.computed) {
822
+ const prop2 = t5.isExpression(node.property) ? generateExpression2(node.property) : "0";
823
+ return `${obj}[${prop2}]`;
824
+ }
825
+ const prop = t5.isIdentifier(node.property) ? node.property.name : "[property]";
826
+ return `${obj}${optional}${prop}`;
827
+ }
828
+ if (t5.isBinaryExpression(node)) {
829
+ return `(${generateExpression2(node.left)} ${node.operator} ${generateExpression2(node.right)})`;
830
+ }
831
+ if (t5.isLogicalExpression(node)) {
832
+ return `(${generateExpression2(node.left)} ${node.operator} ${generateExpression2(node.right)})`;
833
+ }
834
+ if (t5.isConditionalExpression(node)) {
835
+ return `(${generateExpression2(node.test)} ? ${generateExpression2(node.consequent)} : ${generateExpression2(node.alternate)})`;
836
+ }
837
+ if (t5.isUnaryExpression(node) && node.prefix) {
838
+ const space = node.operator === "typeof" || node.operator === "void" || node.operator === "delete" ? " " : "";
839
+ return `${node.operator}${space}${generateExpression2(node.argument)}`;
840
+ }
841
+ if (t5.isCallExpression(node) || t5.isOptionalCallExpression(node)) {
842
+ if (t5.isIdentifier(node.callee)) {
843
+ const setterFieldName = setterToFieldMap.get(node.callee.name);
844
+ if (setterFieldName) {
845
+ if (node.arguments.length >= 1) {
846
+ const arg = node.arguments[0];
847
+ if ((t5.isArrowFunctionExpression(arg) || t5.isFunctionExpression(arg)) && arg.params.length >= 1 && t5.isIdentifier(arg.params[0])) {
848
+ const paramName = arg.params[0].name;
849
+ const bodyExpr = t5.isExpression(arg.body) ? generateExpression2(arg.body) : "undefined";
850
+ const resolved = bodyExpr.replace(
851
+ new RegExp(`(?<![.$\\w])${paramName}(?![\\w])`, "g"),
852
+ `$local.${setterFieldName}`
853
+ );
854
+ return `$action.setLocal("${setterFieldName}")(${resolved})`;
855
+ }
856
+ const argStr = t5.isExpression(arg) ? generateExpression2(arg) : "undefined";
857
+ return `$action.setLocal("${setterFieldName}")(${argStr})`;
858
+ }
859
+ return `$action.setLocal("${setterFieldName}")`;
860
+ }
861
+ const args = node.arguments.map((a) => t5.isExpression(a) ? generateExpression2(a) : t5.isSpreadElement(a) ? `...${generateExpression2(a.argument)}` : "undefined").join(", ");
862
+ return `${node.callee.name}(${args})`;
863
+ }
864
+ if (t5.isMemberExpression(node.callee) || t5.isOptionalMemberExpression(node.callee)) {
865
+ const obj = generateExpression2(node.callee.object);
866
+ const optional = node.callee.optional ? "?." : ".";
867
+ const prop = t5.isIdentifier(node.callee.property) ? node.callee.property.name : "[method]";
868
+ const args = node.arguments.map((a) => t5.isExpression(a) ? generateExpression2(a) : t5.isSpreadElement(a) ? `...${generateExpression2(a.argument)}` : "undefined").join(", ");
869
+ return `${obj}${optional}${prop}(${args})`;
870
+ }
871
+ if (t5.isExpression(node.callee)) {
872
+ const callee = generateExpression2(node.callee);
873
+ const args = node.arguments.map((a) => t5.isExpression(a) ? generateExpression2(a) : "undefined").join(", ");
874
+ return `(${callee})(${args})`;
875
+ }
876
+ }
877
+ if (t5.isTemplateLiteral(node)) {
878
+ const parts = node.quasis.map((q, i) => {
879
+ const raw = q.value.raw;
880
+ if (i < node.expressions.length) {
881
+ return raw + "${" + generateExpression2(node.expressions[i]) + "}";
882
+ }
883
+ return raw;
884
+ }).join("");
885
+ return "`" + parts + "`";
886
+ }
887
+ if (t5.isArrowFunctionExpression(node)) {
888
+ const params = node.params.map((p) => {
889
+ if (t5.isIdentifier(p)) return p.name;
890
+ if (t5.isRestElement(p) && t5.isIdentifier(p.argument)) return `...${p.argument.name}`;
891
+ if (t5.isAssignmentPattern(p) && t5.isIdentifier(p.left)) {
892
+ return `${p.left.name} = ${t5.isExpression(p.right) ? generateExpression2(p.right) : "undefined"}`;
893
+ }
894
+ return "_";
895
+ }).join(", ");
896
+ if (t5.isExpression(node.body)) {
897
+ return `(${params}) => ${generateExpression2(node.body)}`;
898
+ }
899
+ if (t5.isBlockStatement(node.body)) {
900
+ const bodyStr = generateBlockStatement(node.body);
901
+ return `(${params}) => { ${bodyStr} }`;
902
+ }
903
+ }
904
+ if (t5.isArrayExpression(node)) {
905
+ const elements = node.elements.map((el) => {
906
+ if (el === null) return "undefined";
907
+ if (t5.isSpreadElement(el)) return `...${generateExpression2(el.argument)}`;
908
+ return t5.isExpression(el) ? generateExpression2(el) : "undefined";
909
+ }).join(", ");
910
+ return `[${elements}]`;
911
+ }
912
+ if (t5.isObjectExpression(node)) {
913
+ const props = node.properties.map((prop) => {
914
+ if (t5.isSpreadElement(prop)) return `...${generateExpression2(prop.argument)}`;
915
+ if (t5.isObjectProperty(prop)) {
916
+ const key = t5.isIdentifier(prop.key) ? prop.key.name : t5.isStringLiteral(prop.key) ? `"${prop.key.value}"` : t5.isNumericLiteral(prop.key) ? String(prop.key.value) : "[key]";
917
+ if (prop.shorthand && t5.isIdentifier(prop.value)) return key;
918
+ const value = t5.isExpression(prop.value) ? generateExpression2(prop.value) : "undefined";
919
+ return `${key}: ${value}`;
920
+ }
921
+ if (t5.isObjectMethod(prop)) {
922
+ const key = t5.isIdentifier(prop.key) ? prop.key.name : "[method]";
923
+ const params = prop.params.map((p) => t5.isIdentifier(p) ? p.name : "_").join(", ");
924
+ const bodyStr = generateBlockStatement(prop.body);
925
+ return `${key}(${params}) { ${bodyStr} }`;
926
+ }
927
+ return "";
928
+ }).filter(Boolean).join(", ");
929
+ return `{ ${props} }`;
930
+ }
931
+ if (t5.isParenthesizedExpression(node)) {
932
+ return `(${generateExpression2(node.expression)})`;
933
+ }
934
+ if (t5.isTSAsExpression(node)) return generateExpression2(node.expression);
935
+ if (t5.isTSNonNullExpression(node)) return generateExpression2(node.expression);
936
+ if (t5.isTSTypeAssertion(node)) return generateExpression2(node.expression);
937
+ if (t5.isSequenceExpression(node)) {
938
+ return `(${node.expressions.map(generateExpression2).join(", ")})`;
939
+ }
940
+ if (t5.isAssignmentExpression(node)) {
941
+ const left = t5.isExpression(node.left) ? generateExpression2(node.left) : "[target]";
942
+ return `(${left} ${node.operator} ${generateExpression2(node.right)})`;
943
+ }
944
+ if (t5.isUpdateExpression(node)) {
945
+ const arg = generateExpression2(node.argument);
946
+ return node.prefix ? `${node.operator}${arg}` : `${arg}${node.operator}`;
947
+ }
948
+ if (t5.isTaggedTemplateExpression(node)) {
949
+ return generateExpression2(node.quasi);
950
+ }
951
+ if (t5.isSpreadElement(node)) {
952
+ return `...${generateExpression2(node.argument)}`;
953
+ }
954
+ if (t5.isYieldExpression(node)) {
955
+ return node.argument ? `yield ${generateExpression2(node.argument)}` : "yield";
956
+ }
957
+ if (t5.isAwaitExpression(node)) {
958
+ return `await ${generateExpression2(node.argument)}`;
959
+ }
960
+ if (t5.isNewExpression(node)) {
961
+ const callee = t5.isExpression(node.callee) ? generateExpression2(node.callee) : "Object";
962
+ const args = node.arguments.map((a) => t5.isExpression(a) ? generateExpression2(a) : "undefined").join(", ");
963
+ return `new ${callee}(${args})`;
964
+ }
965
+ if (t5.isThisExpression(node)) return "this";
966
+ console.warn(`[component-extractor] Unhandled expression type: ${node.type}`);
967
+ return "[Expression]";
968
+ }
969
+ function generateBlockStatement(block) {
970
+ return block.body.map((stmt) => {
971
+ if (t5.isReturnStatement(stmt)) {
972
+ return stmt.argument ? `return ${generateExpression2(stmt.argument)};` : "return;";
973
+ }
974
+ if (t5.isExpressionStatement(stmt)) {
975
+ return `${generateExpression2(stmt.expression)};`;
976
+ }
977
+ if (t5.isVariableDeclaration(stmt)) {
978
+ const decls = stmt.declarations.map((d) => {
979
+ const id = t5.isIdentifier(d.id) ? d.id.name : "_";
980
+ const init = d.init && t5.isExpression(d.init) ? generateExpression2(d.init) : "undefined";
981
+ return `${id} = ${init}`;
982
+ }).join(", ");
983
+ return `${stmt.kind} ${decls};`;
984
+ }
985
+ if (t5.isIfStatement(stmt)) {
986
+ const test = generateExpression2(stmt.test);
987
+ const consequent = t5.isBlockStatement(stmt.consequent) ? `{ ${generateBlockStatement(stmt.consequent)} }` : t5.isExpressionStatement(stmt.consequent) ? `{ ${generateExpression2(stmt.consequent.expression)}; }` : "{}";
988
+ const alternate = stmt.alternate ? t5.isBlockStatement(stmt.alternate) ? ` else { ${generateBlockStatement(stmt.alternate)} }` : t5.isIfStatement(stmt.alternate) ? ` else ${generateBlockStatement(t5.blockStatement([stmt.alternate]))}` : "" : "";
989
+ return `if (${test}) ${consequent}${alternate}`;
990
+ }
991
+ return "/* [Statement] */";
992
+ }).join(" ");
993
+ }
994
+ function extractJSXFromCallback(node) {
995
+ const body = node.body;
996
+ if (t5.isJSXElement(body) || t5.isJSXFragment(body)) {
997
+ return body;
998
+ }
999
+ if (t5.isParenthesizedExpression(body)) {
1000
+ const inner = body.expression;
1001
+ if (t5.isJSXElement(inner) || t5.isJSXFragment(inner)) {
1002
+ return inner;
1003
+ }
1004
+ }
1005
+ if (t5.isBlockStatement(body)) {
1006
+ for (const stmt of body.body) {
1007
+ if (t5.isReturnStatement(stmt) && stmt.argument) {
1008
+ if (t5.isJSXElement(stmt.argument) || t5.isJSXFragment(stmt.argument)) {
1009
+ return stmt.argument;
1010
+ }
1011
+ if (t5.isParenthesizedExpression(stmt.argument)) {
1012
+ const inner = stmt.argument.expression;
1013
+ if (t5.isJSXElement(inner) || t5.isJSXFragment(inner)) {
1014
+ return inner;
1015
+ }
1016
+ }
1017
+ }
1018
+ }
1019
+ }
1020
+ return null;
1021
+ }
1022
+ function isEventHandlerProp(name) {
1023
+ return /^on[A-Z]/.test(name);
1024
+ }
1025
+ function expressionToActionAtom(expr) {
1026
+ if (t5.isCallExpression(expr) || t5.isOptionalCallExpression(expr)) {
1027
+ if (t5.isIdentifier(expr.callee)) {
1028
+ const setterFieldName = setterToFieldMap.get(expr.callee.name);
1029
+ if (setterFieldName && expr.arguments.length >= 1) {
1030
+ const arg = expr.arguments[0];
1031
+ if ((t5.isArrowFunctionExpression(arg) || t5.isFunctionExpression(arg)) && arg.params.length >= 1 && t5.isIdentifier(arg.params[0])) {
1032
+ const paramName = arg.params[0].name;
1033
+ const bodyExpr = t5.isExpression(arg.body) ? generateExpression2(arg.body) : "undefined";
1034
+ const resolved = bodyExpr.replace(
1035
+ new RegExp(`(?<![.$\\w])${paramName}(?![\\w])`, "g"),
1036
+ `$local.${setterFieldName}`
1037
+ );
1038
+ return `$action.setLocal("${setterFieldName}", ${resolved})`;
1039
+ }
1040
+ const argStr = t5.isExpression(arg) ? generateExpression2(arg) : "undefined";
1041
+ return `$action.setLocal("${setterFieldName}", ${argStr})`;
1042
+ }
1043
+ return null;
1044
+ }
1045
+ if (t5.isMemberExpression(expr.callee) || t5.isOptionalMemberExpression(expr.callee)) {
1046
+ const generated = generateExpression2(expr);
1047
+ if (generated.startsWith("$action.")) return generated;
1048
+ }
1049
+ return null;
1050
+ }
1051
+ return null;
1052
+ }
1053
+ function statementToAction(stmt) {
1054
+ if (t5.isExpressionStatement(stmt)) {
1055
+ return expressionToActionAtom(stmt.expression);
1056
+ }
1057
+ if (t5.isIfStatement(stmt)) {
1058
+ const condition = generateExpression2(stmt.test);
1059
+ let thenAction = null;
1060
+ if (t5.isBlockStatement(stmt.consequent)) {
1061
+ const actions = stmt.consequent.body.map((s) => statementToAction(s)).filter(Boolean);
1062
+ if (actions.length === 0 || actions.length !== stmt.consequent.body.length) return null;
1063
+ thenAction = actions.length === 1 ? actions[0] : `$action.seq(${actions.join(", ")})`;
1064
+ } else if (t5.isExpressionStatement(stmt.consequent)) {
1065
+ thenAction = expressionToActionAtom(stmt.consequent.expression);
1066
+ }
1067
+ if (!thenAction) return null;
1068
+ let elseAction = null;
1069
+ if (stmt.alternate) {
1070
+ if (t5.isBlockStatement(stmt.alternate)) {
1071
+ const actions = stmt.alternate.body.map((s) => statementToAction(s)).filter(Boolean);
1072
+ if (actions.length !== stmt.alternate.body.length) return null;
1073
+ elseAction = actions.length === 1 ? actions[0] : `$action.seq(${actions.join(", ")})`;
1074
+ } else if (t5.isIfStatement(stmt.alternate)) {
1075
+ elseAction = statementToAction(stmt.alternate);
1076
+ } else if (t5.isExpressionStatement(stmt.alternate)) {
1077
+ elseAction = expressionToActionAtom(stmt.alternate.expression);
1078
+ }
1079
+ if (!elseAction) return null;
1080
+ }
1081
+ return elseAction ? `$action.when(${condition}, ${thenAction}, ${elseAction})` : `$action.when(${condition}, ${thenAction})`;
1082
+ }
1083
+ return null;
1084
+ }
1085
+ function decomposeHandlerToSeq(node) {
1086
+ if (t5.isArrowFunctionExpression(node) && t5.isExpression(node.body)) {
1087
+ return expressionToActionAtom(node.body);
1088
+ }
1089
+ const body = node.body;
1090
+ if (!t5.isBlockStatement(body)) return null;
1091
+ const actions = [];
1092
+ for (const stmt of body.body) {
1093
+ const action = statementToAction(stmt);
1094
+ if (!action) return null;
1095
+ actions.push(action);
1096
+ }
1097
+ if (actions.length === 0) return null;
1098
+ if (actions.length === 1) return actions[0];
1099
+ return `$action.seq(${actions.join(", ")})`;
1100
+ }
1101
+ function extractComponents(path, state) {
1102
+ const arg = path.node.argument;
1103
+ if (!arg) return;
1104
+ const compilerState = state;
1105
+ if (compilerState.fields && compilerState.fields.length > 0) {
1106
+ initLocalFieldMaps(compilerState.fields);
1107
+ }
1108
+ let experienceNode = null;
1109
+ if (t5.isJSXElement(arg)) {
1110
+ experienceNode = jsxToExperienceNode(arg);
1111
+ } else if (t5.isJSXFragment(arg)) {
1112
+ experienceNode = jsxToExperienceNode(arg);
1113
+ }
1114
+ if (experienceNode) {
1115
+ compilerState.experience = experienceNode;
1116
+ }
1117
+ }
1118
+
1119
+ // src/babel/extractors/during-extractor.ts
1120
+ import * as t6 from "@babel/types";
1121
+ var duringIdCounter = 0;
1122
+ function resetDuringIdCounter() {
1123
+ duringIdCounter = 0;
1124
+ }
1125
+ function analyzeCallbackBody2(body, actionCounter) {
1126
+ const actions = [];
1127
+ for (const statement of body) {
1128
+ if (!t6.isExpressionStatement(statement)) continue;
1129
+ const expr = statement.expression;
1130
+ if (t6.isCallExpression(expr) && t6.isIdentifier(expr.callee)) {
1131
+ const calleeName = expr.callee.name;
1132
+ const args = expr.arguments;
1133
+ if (calleeName === "setField" && args.length >= 2) {
1134
+ const field = t6.isStringLiteral(args[0]) ? args[0].value : void 0;
1135
+ const arg1 = args[1];
1136
+ if (field !== void 0 && !t6.isArgumentPlaceholder(arg1)) {
1137
+ actions.push({
1138
+ id: `auto_${++actionCounter.value}`,
1139
+ type: "set_field",
1140
+ mode: "auto",
1141
+ config: { field, value: extractValue2(arg1) }
1142
+ });
1143
+ }
1144
+ } else if (calleeName === "setMemory" && args.length >= 2) {
1145
+ const key = t6.isStringLiteral(args[0]) ? args[0].value : void 0;
1146
+ const arg1 = args[1];
1147
+ if (key !== void 0 && !t6.isArgumentPlaceholder(arg1)) {
1148
+ actions.push({
1149
+ id: `auto_${++actionCounter.value}`,
1150
+ type: "set_memory",
1151
+ mode: "auto",
1152
+ config: { key, value: extractValue2(arg1) }
1153
+ });
1154
+ }
1155
+ } else if (calleeName.startsWith("set") && calleeName.length > 3 && args.length >= 1) {
1156
+ const fieldName = calleeName.slice(3, 4).toLowerCase() + calleeName.slice(4);
1157
+ const arg0 = args[0];
1158
+ if (!t6.isArgumentPlaceholder(arg0)) {
1159
+ actions.push({
1160
+ id: `auto_${++actionCounter.value}`,
1161
+ type: "set_field",
1162
+ mode: "auto",
1163
+ config: { field: fieldName, value: extractValue2(arg0) }
1164
+ });
1165
+ }
1166
+ }
1167
+ } else if (t6.isCallExpression(expr)) {
1168
+ const callee = expr.callee;
1169
+ if (t6.isMemberExpression(callee) && t6.isIdentifier(callee.object) && callee.object.name === "console" && t6.isIdentifier(callee.property) && callee.property.name === "log" && expr.arguments.length > 0) {
1170
+ const arg0 = expr.arguments[0];
1171
+ if (!t6.isArgumentPlaceholder(arg0)) {
1172
+ actions.push({
1173
+ id: `auto_${++actionCounter.value}`,
1174
+ type: "log_event",
1175
+ mode: "auto",
1176
+ config: { message: extractValue2(arg0) }
1177
+ });
1178
+ }
1179
+ } else {
1180
+ actions.push({
1181
+ id: `auto_${++actionCounter.value}`,
1182
+ type: "custom",
1183
+ mode: "auto",
1184
+ config: { expression: generateCode2(expr) }
1185
+ });
1186
+ }
1187
+ }
1188
+ }
1189
+ return actions;
1190
+ }
1191
+ function extractValue2(node) {
1192
+ if (t6.isNumericLiteral(node)) return node.value;
1193
+ if (t6.isStringLiteral(node)) return node.value;
1194
+ if (t6.isBooleanLiteral(node)) return node.value;
1195
+ if (t6.isNullLiteral(node)) return null;
1196
+ if (t6.isArrayExpression(node)) {
1197
+ return node.elements.map((el) => el && t6.isExpression(el) ? extractValue2(el) : null);
1198
+ }
1199
+ if (t6.isObjectExpression(node)) {
1200
+ const obj = {};
1201
+ node.properties.forEach((prop) => {
1202
+ if (t6.isObjectProperty(prop) && t6.isIdentifier(prop.key) && t6.isExpression(prop.value)) {
1203
+ obj[prop.key.name] = extractValue2(prop.value);
1204
+ }
1205
+ });
1206
+ return obj;
1207
+ }
1208
+ return generateCode2(node);
1209
+ }
1210
+ function generateCode2(node) {
1211
+ if (t6.isIdentifier(node)) return node.name;
1212
+ if (t6.isNumericLiteral(node)) return String(node.value);
1213
+ if (t6.isStringLiteral(node)) return `"${node.value}"`;
1214
+ if (t6.isBooleanLiteral(node)) return String(node.value);
1215
+ if (t6.isNullLiteral(node)) return "null";
1216
+ if (t6.isBinaryExpression(node)) {
1217
+ return `(${generateCode2(node.left)} ${node.operator} ${generateCode2(node.right)})`;
1218
+ }
1219
+ if (t6.isLogicalExpression(node)) {
1220
+ return `(${generateCode2(node.left)} ${node.operator} ${generateCode2(node.right)})`;
1221
+ }
1222
+ if (t6.isConditionalExpression(node)) {
1223
+ return `(${generateCode2(node.test)} ? ${generateCode2(node.consequent)} : ${generateCode2(node.alternate)})`;
1224
+ }
1225
+ if (t6.isUnaryExpression(node) && node.prefix) {
1226
+ return `${node.operator}${generateCode2(node.argument)}`;
1227
+ }
1228
+ if (t6.isCallExpression(node) && t6.isMemberExpression(node.callee) && t6.isIdentifier(node.callee.object) && node.callee.object.name === "Date" && t6.isIdentifier(node.callee.property) && node.callee.property.name === "now") {
1229
+ return "now()";
1230
+ }
1231
+ if (t6.isMemberExpression(node)) {
1232
+ const obj = generateCode2(node.object);
1233
+ if (node.computed) {
1234
+ return `${obj}[${generateCode2(node.property)}]`;
1235
+ }
1236
+ const prop = t6.isIdentifier(node.property) ? node.property.name : "[property]";
1237
+ return `${obj}.${prop}`;
1238
+ }
1239
+ if (t6.isCallExpression(node)) {
1240
+ if (t6.isIdentifier(node.callee)) {
1241
+ const args = node.arguments.map((a) => generateCode2(a)).join(", ");
1242
+ return `${node.callee.name}(${args})`;
1243
+ }
1244
+ if (t6.isMemberExpression(node.callee)) {
1245
+ const obj = generateCode2(node.callee.object);
1246
+ const prop = t6.isIdentifier(node.callee.property) ? node.callee.property.name : "[method]";
1247
+ const args = node.arguments.map((a) => generateCode2(a)).join(", ");
1248
+ return `${obj}.${prop}(${args})`;
1249
+ }
1250
+ }
1251
+ if (t6.isArrowFunctionExpression(node) || t6.isFunctionExpression(node)) {
1252
+ if (t6.isArrowFunctionExpression(node) && t6.isExpression(node.body)) {
1253
+ const params = node.params;
1254
+ if (params.length === 1 && t6.isIdentifier(params[0])) {
1255
+ const paramName = params[0].name;
1256
+ const bodyCode = generateCode2(node.body);
1257
+ return bodyCode.replace(new RegExp(`\\b${paramName}\\b`, "g"), "$prev");
1258
+ }
1259
+ }
1260
+ return "[Function]";
1261
+ }
1262
+ if (t6.isTemplateLiteral(node)) {
1263
+ return node.quasis.map((q, i) => {
1264
+ const raw = q.value.raw;
1265
+ if (i < node.expressions.length) return raw + "${" + generateCode2(node.expressions[i]) + "}";
1266
+ return raw;
1267
+ }).join("");
1268
+ }
1269
+ if (t6.isArrayExpression(node)) {
1270
+ const elements = node.elements.map((el) => el ? generateCode2(el) : "undefined").join(", ");
1271
+ return `[${elements}]`;
1272
+ }
1273
+ if (t6.isObjectExpression(node)) {
1274
+ const props = node.properties.map((p) => {
1275
+ if (t6.isObjectProperty(p)) {
1276
+ const key = t6.isIdentifier(p.key) ? p.key.name : t6.isStringLiteral(p.key) ? `"${p.key.value}"` : "[key]";
1277
+ if (p.shorthand && t6.isIdentifier(p.value)) return key;
1278
+ return `${key}: ${generateCode2(p.value)}`;
1279
+ }
1280
+ if (t6.isSpreadElement(p)) return `...${generateCode2(p.argument)}`;
1281
+ return "";
1282
+ }).filter(Boolean).join(", ");
1283
+ return `{ ${props} }`;
1284
+ }
1285
+ if (t6.isTSAsExpression(node)) return generateCode2(node.expression);
1286
+ if (t6.isTSNonNullExpression(node)) return generateCode2(node.expression);
1287
+ return "[Expression]";
1288
+ }
1289
+ function ensureState3(states, stateName) {
1290
+ if (!states.has(stateName)) {
1291
+ states.set(stateName, {
1292
+ name: stateName,
1293
+ type: "REGULAR",
1294
+ on_enter: [],
1295
+ during: [],
1296
+ on_exit: []
1297
+ });
1298
+ }
1299
+ return states.get(stateName);
1300
+ }
1301
+ function extractDuring(path, state) {
1302
+ const callee = path.node.callee;
1303
+ if (!t6.isIdentifier(callee) || callee.name !== "useWhileIn") return;
1304
+ const args = path.node.arguments;
1305
+ if (args.length < 3) return;
1306
+ const stateArg = args[0];
1307
+ const intervalArg = args[1];
1308
+ const callbackArg = args[2];
1309
+ if (!t6.isStringLiteral(stateArg)) return;
1310
+ const stateName = stateArg.value;
1311
+ let intervalMs = 1e3;
1312
+ if (t6.isNumericLiteral(intervalArg)) {
1313
+ intervalMs = intervalArg.value;
1314
+ }
1315
+ let callbackBody = [];
1316
+ if (t6.isArrowFunctionExpression(callbackArg) || t6.isFunctionExpression(callbackArg)) {
1317
+ const body = callbackArg.body;
1318
+ if (t6.isBlockStatement(body)) {
1319
+ callbackBody = body.body;
1320
+ } else if (t6.isExpression(body)) {
1321
+ callbackBody = [t6.expressionStatement(body)];
1322
+ }
1323
+ }
1324
+ const compilerState = state;
1325
+ if (!compilerState.states) compilerState.states = /* @__PURE__ */ new Map();
1326
+ if (!compilerState.actionCounter) compilerState.actionCounter = 0;
1327
+ const stateDefinition = ensureState3(compilerState.states, stateName);
1328
+ const actions = analyzeCallbackBody2(callbackBody, { value: compilerState.actionCounter });
1329
+ compilerState.actionCounter += actions.length;
1330
+ const duringAction = {
1331
+ id: `during_${++duringIdCounter}`,
1332
+ type: "interval",
1333
+ interval_ms: intervalMs,
1334
+ actions
1335
+ };
1336
+ stateDefinition.during.push(duringAction);
1337
+ }
1338
+
1339
+ // src/babel/extractors/change-extractor.ts
1340
+ import * as t7 from "@babel/types";
1341
+ var watcherIdCounter = 0;
1342
+ function resetWatcherIdCounter() {
1343
+ watcherIdCounter = 0;
1344
+ }
1345
+ function analyzeCallbackBody3(body, actionCounter) {
1346
+ const actions = [];
1347
+ for (const statement of body) {
1348
+ if (!t7.isExpressionStatement(statement)) continue;
1349
+ const expr = statement.expression;
1350
+ if (t7.isCallExpression(expr) && t7.isIdentifier(expr.callee)) {
1351
+ const calleeName = expr.callee.name;
1352
+ const args = expr.arguments;
1353
+ if (calleeName === "setField" && args.length >= 2) {
1354
+ const field = t7.isStringLiteral(args[0]) ? args[0].value : void 0;
1355
+ if (field !== void 0) {
1356
+ actions.push({
1357
+ id: `auto_${++actionCounter.value}`,
1358
+ type: "set_field",
1359
+ mode: "auto",
1360
+ config: { field, value: extractValue3(args[1]) }
1361
+ });
1362
+ }
1363
+ } else if (calleeName === "setMemory" && args.length >= 2) {
1364
+ const key = t7.isStringLiteral(args[0]) ? args[0].value : void 0;
1365
+ if (key !== void 0) {
1366
+ actions.push({
1367
+ id: `auto_${++actionCounter.value}`,
1368
+ type: "set_memory",
1369
+ mode: "auto",
1370
+ config: { key, value: extractValue3(args[1]) }
1371
+ });
1372
+ }
1373
+ } else if (calleeName.startsWith("set") && calleeName.length > 3 && args.length >= 1) {
1374
+ const fieldName = calleeName.slice(3, 4).toLowerCase() + calleeName.slice(4);
1375
+ actions.push({
1376
+ id: `auto_${++actionCounter.value}`,
1377
+ type: "set_field",
1378
+ mode: "auto",
1379
+ config: { field: fieldName, value: extractValue3(args[0]) }
1380
+ });
1381
+ }
1382
+ } else if (t7.isCallExpression(expr)) {
1383
+ const callee = expr.callee;
1384
+ if (t7.isMemberExpression(callee) && t7.isIdentifier(callee.object) && callee.object.name === "console" && t7.isIdentifier(callee.property) && callee.property.name === "log" && expr.arguments.length > 0) {
1385
+ actions.push({
1386
+ id: `auto_${++actionCounter.value}`,
1387
+ type: "log_event",
1388
+ mode: "auto",
1389
+ config: { message: extractValue3(expr.arguments[0]) }
1390
+ });
1391
+ }
1392
+ }
1393
+ }
1394
+ return actions;
1395
+ }
1396
+ function extractValue3(node) {
1397
+ if (t7.isNumericLiteral(node)) return node.value;
1398
+ if (t7.isStringLiteral(node)) return node.value;
1399
+ if (t7.isBooleanLiteral(node)) return node.value;
1400
+ if (t7.isNullLiteral(node)) return null;
1401
+ if (t7.isIdentifier(node)) return node.name;
1402
+ if (t7.isTemplateLiteral(node)) {
1403
+ return node.quasis.map((q, i) => {
1404
+ const raw = q.value.raw;
1405
+ if (i < node.expressions.length) {
1406
+ const expr = node.expressions[i];
1407
+ return raw + "${" + (t7.isIdentifier(expr) ? expr.name : "[expr]") + "}";
1408
+ }
1409
+ return raw;
1410
+ }).join("");
1411
+ }
1412
+ if (t7.isArrayExpression(node)) {
1413
+ return node.elements.map((el) => el && t7.isExpression(el) ? extractValue3(el) : null);
1414
+ }
1415
+ if (t7.isObjectExpression(node)) {
1416
+ const obj = {};
1417
+ node.properties.forEach((prop) => {
1418
+ if (t7.isObjectProperty(prop) && t7.isIdentifier(prop.key) && t7.isExpression(prop.value)) {
1419
+ obj[prop.key.name] = extractValue3(prop.value);
1420
+ }
1421
+ });
1422
+ return obj;
1423
+ }
1424
+ if (t7.isMemberExpression(node)) {
1425
+ const obj = t7.isIdentifier(node.object) ? node.object.name : "[object]";
1426
+ const prop = t7.isIdentifier(node.property) ? node.property.name : "[property]";
1427
+ return `${obj}.${prop}`;
1428
+ }
1429
+ if (t7.isConditionalExpression(node)) {
1430
+ return `(${extractValue3(node.test)} ? ${extractValue3(node.consequent)} : ${extractValue3(node.alternate)})`;
1431
+ }
1432
+ if (t7.isBinaryExpression(node)) {
1433
+ return `(${extractValue3(node.left)} ${node.operator} ${extractValue3(node.right)})`;
1434
+ }
1435
+ if (t7.isLogicalExpression(node)) {
1436
+ return `(${extractValue3(node.left)} ${node.operator} ${extractValue3(node.right)})`;
1437
+ }
1438
+ if (t7.isTSAsExpression(node)) return extractValue3(node.expression);
1439
+ if (t7.isTSNonNullExpression(node)) return extractValue3(node.expression);
1440
+ return "[Expression]";
1441
+ }
1442
+ function extractChangeWatcher(path, state) {
1443
+ const callee = path.node.callee;
1444
+ if (!t7.isIdentifier(callee) || callee.name !== "useOnChange") return;
1445
+ const args = path.node.arguments;
1446
+ if (args.length < 2) return;
1447
+ const fieldArg = args[0];
1448
+ const callbackArg = args[1];
1449
+ if (!t7.isStringLiteral(fieldArg)) return;
1450
+ const field = fieldArg.value;
1451
+ let callbackBody = [];
1452
+ if (t7.isArrowFunctionExpression(callbackArg) || t7.isFunctionExpression(callbackArg)) {
1453
+ const body = callbackArg.body;
1454
+ if (t7.isBlockStatement(body)) {
1455
+ callbackBody = body.body;
1456
+ } else if (t7.isExpression(body)) {
1457
+ callbackBody = [t7.expressionStatement(body)];
1458
+ }
1459
+ }
1460
+ const compilerState = state;
1461
+ if (!compilerState.actionCounter) compilerState.actionCounter = 0;
1462
+ const actions = analyzeCallbackBody3(callbackBody, { value: compilerState.actionCounter });
1463
+ compilerState.actionCounter += actions.length;
1464
+ const watcher = {
1465
+ id: `watcher_${++watcherIdCounter}`,
1466
+ field,
1467
+ actions
1468
+ };
1469
+ if (!compilerState.metadata) compilerState.metadata = {};
1470
+ const meta = compilerState.metadata;
1471
+ if (!meta.fieldWatchers) meta.fieldWatchers = [];
1472
+ meta.fieldWatchers.push(watcher);
1473
+ }
1474
+
1475
+ // src/babel/extractors/transition-effect-extractor.ts
1476
+ import * as t8 from "@babel/types";
1477
+ var transitionEffectIdCounter = 0;
1478
+ function resetTransitionEffectIdCounter() {
1479
+ transitionEffectIdCounter = 0;
1480
+ }
1481
+ function analyzeCallbackBody4(body, actionCounter) {
1482
+ const actions = [];
1483
+ for (const statement of body) {
1484
+ if (!t8.isExpressionStatement(statement)) continue;
1485
+ const expr = statement.expression;
1486
+ if (t8.isCallExpression(expr) && t8.isIdentifier(expr.callee)) {
1487
+ const calleeName = expr.callee.name;
1488
+ const args = expr.arguments;
1489
+ if (calleeName === "setField" && args.length >= 2) {
1490
+ const field = t8.isStringLiteral(args[0]) ? args[0].value : void 0;
1491
+ if (field !== void 0) {
1492
+ actions.push({
1493
+ id: `auto_${++actionCounter.value}`,
1494
+ type: "set_field",
1495
+ mode: "auto",
1496
+ config: { field, value: extractValue4(args[1]) }
1497
+ });
1498
+ }
1499
+ } else if (calleeName === "setMemory" && args.length >= 2) {
1500
+ const key = t8.isStringLiteral(args[0]) ? args[0].value : void 0;
1501
+ if (key !== void 0) {
1502
+ actions.push({
1503
+ id: `auto_${++actionCounter.value}`,
1504
+ type: "set_memory",
1505
+ mode: "auto",
1506
+ config: { key, value: extractValue4(args[1]) }
1507
+ });
1508
+ }
1509
+ } else if (calleeName.startsWith("set") && calleeName.length > 3 && args.length >= 1) {
1510
+ const fieldName = calleeName.slice(3, 4).toLowerCase() + calleeName.slice(4);
1511
+ actions.push({
1512
+ id: `auto_${++actionCounter.value}`,
1513
+ type: "set_field",
1514
+ mode: "auto",
1515
+ config: { field: fieldName, value: extractValue4(args[0]) }
1516
+ });
1517
+ }
1518
+ } else if (t8.isCallExpression(expr)) {
1519
+ const callee = expr.callee;
1520
+ if (t8.isMemberExpression(callee) && t8.isIdentifier(callee.object) && callee.object.name === "console" && t8.isIdentifier(callee.property) && callee.property.name === "log" && expr.arguments.length > 0) {
1521
+ actions.push({
1522
+ id: `auto_${++actionCounter.value}`,
1523
+ type: "log_event",
1524
+ mode: "auto",
1525
+ config: { message: extractValue4(expr.arguments[0]) }
1526
+ });
1527
+ }
1528
+ }
1529
+ }
1530
+ return actions;
1531
+ }
1532
+ function extractValue4(node) {
1533
+ if (t8.isNumericLiteral(node)) return node.value;
1534
+ if (t8.isStringLiteral(node)) return node.value;
1535
+ if (t8.isBooleanLiteral(node)) return node.value;
1536
+ if (t8.isNullLiteral(node)) return null;
1537
+ if (t8.isIdentifier(node)) return node.name;
1538
+ if (t8.isArrayExpression(node)) {
1539
+ return node.elements.map((el) => el && t8.isExpression(el) ? extractValue4(el) : null);
1540
+ }
1541
+ if (t8.isObjectExpression(node)) {
1542
+ const obj = {};
1543
+ node.properties.forEach((prop) => {
1544
+ if (t8.isObjectProperty(prop) && t8.isIdentifier(prop.key) && t8.isExpression(prop.value)) {
1545
+ obj[prop.key.name] = extractValue4(prop.value);
1546
+ }
1547
+ });
1548
+ return obj;
1549
+ }
1550
+ if (t8.isMemberExpression(node)) {
1551
+ const obj = t8.isIdentifier(node.object) ? node.object.name : "[object]";
1552
+ const prop = t8.isIdentifier(node.property) ? node.property.name : "[property]";
1553
+ return `${obj}.${prop}`;
1554
+ }
1555
+ if (t8.isConditionalExpression(node)) {
1556
+ return `(${extractValue4(node.test)} ? ${extractValue4(node.consequent)} : ${extractValue4(node.alternate)})`;
1557
+ }
1558
+ if (t8.isTSAsExpression(node)) return extractValue4(node.expression);
1559
+ if (t8.isTSNonNullExpression(node)) return extractValue4(node.expression);
1560
+ return "[Expression]";
1561
+ }
1562
+ function extractTransitionEffect(path, state) {
1563
+ const callee = path.node.callee;
1564
+ if (!t8.isIdentifier(callee) || callee.name !== "useOnTransition") return;
1565
+ const args = path.node.arguments;
1566
+ if (args.length < 1) return;
1567
+ const callbackArg = args[0];
1568
+ let callbackBody = [];
1569
+ if (t8.isArrowFunctionExpression(callbackArg) || t8.isFunctionExpression(callbackArg)) {
1570
+ const body = callbackArg.body;
1571
+ if (t8.isBlockStatement(body)) {
1572
+ callbackBody = body.body;
1573
+ } else if (t8.isExpression(body)) {
1574
+ callbackBody = [t8.expressionStatement(body)];
1575
+ }
1576
+ }
1577
+ const compilerState = state;
1578
+ if (!compilerState.actionCounter) compilerState.actionCounter = 0;
1579
+ const actions = analyzeCallbackBody4(callbackBody, { value: compilerState.actionCounter });
1580
+ compilerState.actionCounter += actions.length;
1581
+ const effect = {
1582
+ id: `transition_effect_${++transitionEffectIdCounter}`,
1583
+ actions
1584
+ };
1585
+ if (!compilerState.metadata) compilerState.metadata = {};
1586
+ const meta = compilerState.metadata;
1587
+ if (!meta.transitionEffects) meta.transitionEffects = [];
1588
+ meta.transitionEffects.push(effect);
1589
+ }
1590
+
1591
+ // src/babel/extractors/model-extractor.ts
1592
+ import * as t9 from "@babel/types";
1593
+ function tsTypeToFieldType(typeAnnotation) {
1594
+ if (!typeAnnotation) return "text";
1595
+ const annotation = typeAnnotation.typeAnnotation;
1596
+ return resolveType(annotation);
1597
+ }
1598
+ function resolveType(annotation) {
1599
+ if (t9.isTSStringKeyword(annotation)) return "text";
1600
+ if (t9.isTSNumberKeyword(annotation)) return "number";
1601
+ if (t9.isTSBooleanKeyword(annotation)) return "boolean";
1602
+ if (t9.isTSTypeReference(annotation) && t9.isIdentifier(annotation.typeName) && annotation.typeName.name === "Date") {
1603
+ return "datetime";
1604
+ }
1605
+ if (t9.isTSTypeReference(annotation) && t9.isIdentifier(annotation.typeName) && annotation.typeName.name === "Record") {
1606
+ return "json";
1607
+ }
1608
+ if (t9.isTSArrayType(annotation)) {
1609
+ return "multi_select";
1610
+ }
1611
+ if (t9.isTSTypeReference(annotation) && t9.isIdentifier(annotation.typeName) && annotation.typeName.name === "Array") {
1612
+ return "multi_select";
1613
+ }
1614
+ if (t9.isTSUnionType(annotation)) {
1615
+ const allLiterals = annotation.types.every(
1616
+ (t22) => t9.isTSLiteralType(t22) && (t9.isStringLiteral(t22.literal) || t9.isNumericLiteral(t22.literal))
1617
+ );
1618
+ if (allLiterals) return "select";
1619
+ return "text";
1620
+ }
1621
+ if (t9.isTSLiteralType(annotation) && t9.isStringLiteral(annotation.literal)) return "text";
1622
+ if (t9.isTSLiteralType(annotation) && t9.isNumericLiteral(annotation.literal)) return "number";
1623
+ return "text";
1624
+ }
1625
+ function extractUnionOptions(annotation) {
1626
+ if (!t9.isTSUnionType(annotation)) return void 0;
1627
+ const options = [];
1628
+ for (const member of annotation.types) {
1629
+ if (t9.isTSLiteralType(member) && t9.isStringLiteral(member.literal)) {
1630
+ options.push(member.literal.value);
1631
+ }
1632
+ }
1633
+ return options.length > 0 ? options : void 0;
1634
+ }
1635
+ function extractDefaultValue2(fieldType) {
1636
+ switch (fieldType) {
1637
+ case "text":
1638
+ return "";
1639
+ case "rich_text":
1640
+ return "";
1641
+ case "number":
1642
+ return 0;
1643
+ case "boolean":
1644
+ return false;
1645
+ case "date":
1646
+ return null;
1647
+ case "datetime":
1648
+ return null;
1649
+ case "select":
1650
+ return "";
1651
+ case "multi_select":
1652
+ return [];
1653
+ case "url":
1654
+ return "";
1655
+ case "json":
1656
+ return {};
1657
+ default:
1658
+ return null;
1659
+ }
1660
+ }
1661
+ function extractFieldsFromInterface(declaration) {
1662
+ const fields = [];
1663
+ for (const member of declaration.body.body) {
1664
+ if (!t9.isTSPropertySignature(member)) continue;
1665
+ if (!t9.isIdentifier(member.key)) continue;
1666
+ const name = member.key.name;
1667
+ const required = !member.optional;
1668
+ const typeAnno = member.typeAnnotation;
1669
+ const fieldType = tsTypeToFieldType(typeAnno);
1670
+ const field = {
1671
+ name,
1672
+ type: fieldType,
1673
+ label: name.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase()),
1674
+ required,
1675
+ default_value: extractDefaultValue2(fieldType)
1676
+ };
1677
+ if (typeAnno) {
1678
+ const options = extractUnionOptions(typeAnno.typeAnnotation);
1679
+ if (options) {
1680
+ field.validation = { options };
1681
+ }
1682
+ }
1683
+ fields.push(field);
1684
+ }
1685
+ return fields;
1686
+ }
1687
+ function extractTransitionsFromObject(init, actionCounter) {
1688
+ const transitions = [];
1689
+ for (const prop of init.properties) {
1690
+ if (!t9.isObjectProperty(prop)) continue;
1691
+ if (!t9.isIdentifier(prop.key) && !t9.isStringLiteral(prop.key)) continue;
1692
+ if (!t9.isObjectExpression(prop.value)) continue;
1693
+ const name = t9.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
1694
+ const config = extractObjectLiteral(prop.value);
1695
+ let from = [];
1696
+ if (typeof config.from === "string") {
1697
+ from = [config.from];
1698
+ } else if (Array.isArray(config.from)) {
1699
+ from = config.from.map(String);
1700
+ }
1701
+ const to = String(config.to || "");
1702
+ const conditions = [];
1703
+ if (config.guard) {
1704
+ conditions.push(parseGuardExpression(config.guard));
1705
+ }
1706
+ if (config.conditions && Array.isArray(config.conditions)) {
1707
+ for (const cond of config.conditions) {
1708
+ conditions.push(cond);
1709
+ }
1710
+ }
1711
+ const actions = [];
1712
+ if (config.actions && Array.isArray(config.actions)) {
1713
+ for (const action of config.actions) {
1714
+ if (typeof action === "object" && action !== null) {
1715
+ actions.push({
1716
+ id: `auto_${++actionCounter.value}`,
1717
+ type: action.type || "custom",
1718
+ mode: "auto",
1719
+ config: action
1720
+ });
1721
+ }
1722
+ }
1723
+ }
1724
+ transitions.push({
1725
+ name,
1726
+ from,
1727
+ to,
1728
+ description: config.description,
1729
+ conditions: conditions.length > 0 ? conditions : void 0,
1730
+ actions,
1731
+ roles: config.roles,
1732
+ auto: config.auto,
1733
+ required_fields: config.required_fields
1734
+ });
1735
+ }
1736
+ return transitions;
1737
+ }
1738
+ function parseGuardExpression(guard) {
1739
+ const simpleMatch = guard.match(
1740
+ /^(\$?\w+(?:\.\w+)*)\s*(not_in|is_set|is_empty|contains|>=|<=|!=|==|>|<|in)\s*(.+)?$/
1741
+ );
1742
+ if (simpleMatch) {
1743
+ const [, field, op, rawValue] = simpleMatch;
1744
+ const operatorMap = {
1745
+ "==": "eq",
1746
+ "!=": "ne",
1747
+ ">": "gt",
1748
+ ">=": "gte",
1749
+ "<": "lt",
1750
+ "<=": "lte",
1751
+ "in": "in",
1752
+ "not_in": "not_in",
1753
+ "contains": "contains",
1754
+ "is_set": "is_set",
1755
+ "is_empty": "is_empty"
1756
+ };
1757
+ const operator = operatorMap[op];
1758
+ if (operator) {
1759
+ let value = rawValue?.trim();
1760
+ if (value === void 0 || value === "") {
1761
+ return { field, operator };
1762
+ }
1763
+ if (typeof value === "string") {
1764
+ if (value.startsWith('"') && value.endsWith('"')) {
1765
+ value = value.slice(1, -1);
1766
+ } else if (value.startsWith("'") && value.endsWith("'")) {
1767
+ value = value.slice(1, -1);
1768
+ } else if (value === "true") {
1769
+ value = true;
1770
+ } else if (value === "false") {
1771
+ value = false;
1772
+ } else if (value === "null") {
1773
+ value = null;
1774
+ } else if (!isNaN(Number(value))) {
1775
+ value = Number(value);
1776
+ }
1777
+ }
1778
+ return { field, operator, value };
1779
+ }
1780
+ }
1781
+ return { expression: guard };
1782
+ }
1783
+ function extractHooksFromObject(init, states, actionCounter) {
1784
+ for (const prop of init.properties) {
1785
+ if (!t9.isObjectProperty(prop)) continue;
1786
+ if (!t9.isIdentifier(prop.key) && !t9.isStringLiteral(prop.key)) continue;
1787
+ const hookName = t9.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
1788
+ const hookConfig = t9.isObjectExpression(prop.value) ? extractObjectLiteral(prop.value) : {};
1789
+ const enterMatch = hookName.match(/^on_enter_(.+)$/);
1790
+ const exitMatch = hookName.match(/^on_exit_(.+)$/);
1791
+ if (!enterMatch && !exitMatch) continue;
1792
+ const stateName = enterMatch ? enterMatch[1] : exitMatch[1];
1793
+ const phase = enterMatch ? "on_enter" : "on_exit";
1794
+ if (!states.has(stateName)) {
1795
+ states.set(stateName, {
1796
+ name: stateName,
1797
+ type: "REGULAR",
1798
+ on_enter: [],
1799
+ during: [],
1800
+ on_exit: []
1801
+ });
1802
+ }
1803
+ const state = states.get(stateName);
1804
+ if (hookConfig.emit && typeof hookConfig.emit === "string") {
1805
+ const action = {
1806
+ id: `auto_${++actionCounter.value}`,
1807
+ type: "emit_event",
1808
+ mode: "auto",
1809
+ config: { event: hookConfig.emit }
1810
+ };
1811
+ state[phase].push(action);
1812
+ }
1813
+ if (hookConfig.actions && Array.isArray(hookConfig.actions)) {
1814
+ for (const handler of hookConfig.actions) {
1815
+ if (typeof handler === "string") {
1816
+ const action = {
1817
+ id: `auto_${++actionCounter.value}`,
1818
+ type: "server_action",
1819
+ mode: "auto",
1820
+ config: { handler }
1821
+ };
1822
+ state[phase].push(action);
1823
+ }
1824
+ }
1825
+ }
1826
+ }
1827
+ }
1828
+ function applyFieldOptions(fields, init) {
1829
+ const options = extractObjectLiteral(init);
1830
+ for (const [fieldName, opts] of Object.entries(options)) {
1831
+ const field = fields.find((f) => f.name === fieldName);
1832
+ if (!field) continue;
1833
+ if (opts.scope || opts.persistence || opts.sync) {
1834
+ field.state_home = {
1835
+ scope: opts.scope || "instance",
1836
+ persistence: opts.persistence || "durable",
1837
+ sync: opts.sync || "none"
1838
+ };
1839
+ }
1840
+ if (opts.computed && typeof opts.computed === "string") {
1841
+ field.computed = opts.computed;
1842
+ }
1843
+ if (opts.computed_deps && Array.isArray(opts.computed_deps)) {
1844
+ field.computed_deps = opts.computed_deps.map(String);
1845
+ }
1846
+ if (opts.visible_in_states && Array.isArray(opts.visible_in_states)) {
1847
+ field.visible_in_states = opts.visible_in_states.map(String);
1848
+ }
1849
+ if (opts.editable_in_states && Array.isArray(opts.editable_in_states)) {
1850
+ field.editable_in_states = opts.editable_in_states.map(String);
1851
+ }
1852
+ if (opts.visible_to_roles && Array.isArray(opts.visible_to_roles)) {
1853
+ field.visible_to_roles = opts.visible_to_roles.map(String);
1854
+ }
1855
+ if (opts.editable_by_roles && Array.isArray(opts.editable_by_roles)) {
1856
+ field.editable_by_roles = opts.editable_by_roles.map(String);
1857
+ }
1858
+ if (opts.visible_when && typeof opts.visible_when === "string") {
1859
+ field.visible_when = opts.visible_when;
1860
+ }
1861
+ if (opts.editable_when && typeof opts.editable_when === "string") {
1862
+ field.editable_when = opts.editable_when;
1863
+ }
1864
+ if (opts.validation && typeof opts.validation === "object") {
1865
+ const val = opts.validation;
1866
+ const validation = field.validation || {};
1867
+ if (val.min !== void 0) validation.min = Number(val.min);
1868
+ if (val.max !== void 0) validation.max = Number(val.max);
1869
+ if (val.minLength !== void 0) validation.minLength = Number(val.minLength);
1870
+ if (val.maxLength !== void 0) validation.maxLength = Number(val.maxLength);
1871
+ if (val.options && Array.isArray(val.options)) {
1872
+ validation.options = val.options.map(String);
1873
+ }
1874
+ if (val.rules && Array.isArray(val.rules)) {
1875
+ validation.rules = val.rules.map((r) => ({
1876
+ expression: String(r.expression || ""),
1877
+ message: String(r.message || ""),
1878
+ severity: r.severity === "warning" ? "warning" : "error"
1879
+ }));
1880
+ }
1881
+ field.validation = validation;
1882
+ }
1883
+ }
1884
+ }
1885
+ function extractObjectLiteral(node) {
1886
+ const obj = {};
1887
+ for (const prop of node.properties) {
1888
+ if (!t9.isObjectProperty(prop)) continue;
1889
+ const key = t9.isIdentifier(prop.key) ? prop.key.name : t9.isStringLiteral(prop.key) ? prop.key.value : null;
1890
+ if (!key) continue;
1891
+ obj[key] = extractNodeValue(prop.value);
1892
+ }
1893
+ return obj;
1894
+ }
1895
+ function extractNodeValue(node) {
1896
+ if (t9.isStringLiteral(node)) return node.value;
1897
+ if (t9.isNumericLiteral(node)) return node.value;
1898
+ if (t9.isBooleanLiteral(node)) return node.value;
1899
+ if (t9.isNullLiteral(node)) return null;
1900
+ if (t9.isArrayExpression(node)) {
1901
+ return node.elements.map((el) => {
1902
+ if (!el) return null;
1903
+ if (t9.isSpreadElement(el)) return "[Spread]";
1904
+ return extractNodeValue(el);
1905
+ });
1906
+ }
1907
+ if (t9.isObjectExpression(node)) {
1908
+ return extractObjectLiteral(node);
1909
+ }
1910
+ if (t9.isTemplateLiteral(node)) {
1911
+ return node.quasis.map((q) => q.value.raw).join("${}");
1912
+ }
1913
+ if (t9.isIdentifier(node)) {
1914
+ if (node.name === "undefined") return void 0;
1915
+ return node.name;
1916
+ }
1917
+ if (t9.isConditionalExpression(node)) {
1918
+ return `(${extractNodeValue(node.test)} ? ${extractNodeValue(node.consequent)} : ${extractNodeValue(node.alternate)})`;
1919
+ }
1920
+ if (t9.isBinaryExpression(node)) {
1921
+ return `(${extractNodeValue(node.left)} ${node.operator} ${extractNodeValue(node.right)})`;
1922
+ }
1923
+ if (t9.isLogicalExpression(node)) {
1924
+ return `(${extractNodeValue(node.left)} ${node.operator} ${extractNodeValue(node.right)})`;
1925
+ }
1926
+ if (t9.isMemberExpression(node)) {
1927
+ const obj = t9.isIdentifier(node.object) ? node.object.name : "[object]";
1928
+ const prop = t9.isIdentifier(node.property) ? node.property.name : "[property]";
1929
+ return `${obj}.${prop}`;
1930
+ }
1931
+ if (t9.isTSAsExpression(node)) return extractNodeValue(node.expression);
1932
+ if (t9.isTSNonNullExpression(node)) return extractNodeValue(node.expression);
1933
+ return "[Expression]";
1934
+ }
1935
+ function isModelFile(path, filename) {
1936
+ if (filename && /\/models\//.test(filename)) return true;
1937
+ let hasInterface = false;
1938
+ let hasTransitions = false;
1939
+ for (const node of path.node.body) {
1940
+ if (t9.isExportNamedDeclaration(node)) {
1941
+ if (t9.isTSInterfaceDeclaration(node.declaration)) {
1942
+ hasInterface = true;
1943
+ }
1944
+ if (t9.isVariableDeclaration(node.declaration)) {
1945
+ for (const decl of node.declaration.declarations) {
1946
+ if (t9.isIdentifier(decl.id) && decl.id.name === "transitions") {
1947
+ hasTransitions = true;
1948
+ }
1949
+ }
1950
+ }
1951
+ }
1952
+ }
1953
+ return hasInterface && hasTransitions;
1954
+ }
1955
+ function extractModelFile(path, state) {
1956
+ const compilerState = state;
1957
+ if (!compilerState.actionCounter) compilerState.actionCounter = 0;
1958
+ const actionCounter = { value: compilerState.actionCounter };
1959
+ let interfaceName = "";
1960
+ for (const node of path.node.body) {
1961
+ if (!t9.isExportNamedDeclaration(node)) continue;
1962
+ const declaration = node.declaration;
1963
+ if (t9.isTSInterfaceDeclaration(declaration)) {
1964
+ interfaceName = declaration.id.name;
1965
+ const fields = extractFieldsFromInterface(declaration);
1966
+ compilerState.fields.push(...fields);
1967
+ for (const field of fields) {
1968
+ if (field.validation?.options && field.validation.options.length > 0) {
1969
+ for (const option of field.validation.options) {
1970
+ if (!compilerState.states.has(option)) {
1971
+ compilerState.states.set(option, {
1972
+ name: option,
1973
+ type: "REGULAR",
1974
+ on_enter: [],
1975
+ during: [],
1976
+ on_exit: []
1977
+ });
1978
+ }
1979
+ }
1980
+ const firstState = compilerState.states.get(field.validation.options[0]);
1981
+ if (firstState) firstState.type = "START";
1982
+ break;
1983
+ }
1984
+ }
1985
+ if (!compilerState.metadata.name) {
1986
+ compilerState.metadata.name = interfaceName;
1987
+ }
1988
+ }
1989
+ if (t9.isVariableDeclaration(declaration)) {
1990
+ for (const decl of declaration.declarations) {
1991
+ if (!t9.isIdentifier(decl.id) || !decl.init) continue;
1992
+ const varName = decl.id.name;
1993
+ if (varName === "transitions" && t9.isObjectExpression(decl.init)) {
1994
+ const transitions = extractTransitionsFromObject(decl.init, actionCounter);
1995
+ compilerState.transitions.push(...transitions);
1996
+ for (const trans of transitions) {
1997
+ for (const fromState of trans.from) {
1998
+ if (!compilerState.states.has(fromState)) {
1999
+ compilerState.states.set(fromState, {
2000
+ name: fromState,
2001
+ type: "REGULAR",
2002
+ on_enter: [],
2003
+ during: [],
2004
+ on_exit: []
2005
+ });
2006
+ }
2007
+ }
2008
+ if (trans.to && !compilerState.states.has(trans.to)) {
2009
+ compilerState.states.set(trans.to, {
2010
+ name: trans.to,
2011
+ type: "REGULAR",
2012
+ on_enter: [],
2013
+ during: [],
2014
+ on_exit: []
2015
+ });
2016
+ }
2017
+ }
2018
+ }
2019
+ if (varName === "endStates" && t9.isArrayExpression(decl.init)) {
2020
+ for (const el of decl.init.elements) {
2021
+ if (t9.isStringLiteral(el)) {
2022
+ if (!compilerState.states.has(el.value)) {
2023
+ compilerState.states.set(el.value, {
2024
+ name: el.value,
2025
+ type: "END",
2026
+ on_enter: [],
2027
+ during: [],
2028
+ on_exit: []
2029
+ });
2030
+ } else {
2031
+ compilerState.states.get(el.value).type = "END";
2032
+ }
2033
+ }
2034
+ }
2035
+ }
2036
+ if (varName === "cancelledStates" && t9.isArrayExpression(decl.init)) {
2037
+ for (const el of decl.init.elements) {
2038
+ if (t9.isStringLiteral(el)) {
2039
+ if (!compilerState.states.has(el.value)) {
2040
+ compilerState.states.set(el.value, {
2041
+ name: el.value,
2042
+ type: "CANCELLED",
2043
+ on_enter: [],
2044
+ during: [],
2045
+ on_exit: []
2046
+ });
2047
+ } else {
2048
+ compilerState.states.get(el.value).type = "CANCELLED";
2049
+ }
2050
+ }
2051
+ }
2052
+ }
2053
+ if (varName === "hooks" && t9.isObjectExpression(decl.init)) {
2054
+ extractHooksFromObject(decl.init, compilerState.states, actionCounter);
2055
+ }
2056
+ if (varName === "runtime" && t9.isStringLiteral(decl.init)) {
2057
+ compilerState.metadata.runtime = decl.init.value;
2058
+ }
2059
+ if (varName === "fieldOptions" && t9.isObjectExpression(decl.init)) {
2060
+ applyFieldOptions(compilerState.fields, decl.init);
2061
+ }
2062
+ }
2063
+ }
2064
+ }
2065
+ compilerState.actionCounter = actionCounter.value;
2066
+ if (interfaceName && compilerState.metadata.__slugAutoFallback) {
2067
+ compilerState.metadata.slug = interfaceName.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
2068
+ delete compilerState.metadata.__slugAutoFallback;
2069
+ }
2070
+ }
2071
+
2072
+ // src/babel/extractors/server-action-extractor.ts
2073
+ import * as t10 from "@babel/types";
2074
+ function isServerActionFile(filename) {
2075
+ if (!filename) return false;
2076
+ return /\.server\.(ts|tsx|js|jsx)$/.test(filename);
2077
+ }
2078
+ function extractServerActions(path, state) {
2079
+ const compilerState = state;
2080
+ const serverActions = [];
2081
+ for (const node of path.node.body) {
2082
+ if (t10.isExportNamedDeclaration(node)) {
2083
+ const decl = node.declaration;
2084
+ if (t10.isFunctionDeclaration(decl) && decl.id) {
2085
+ const action = extractFunctionAction(decl);
2086
+ if (action) {
2087
+ const comments = node.leadingComments || decl.leadingComments || [];
2088
+ action.description = extractDescription(comments);
2089
+ serverActions.push(action);
2090
+ }
2091
+ }
2092
+ if (t10.isVariableDeclaration(decl)) {
2093
+ for (const varDecl of decl.declarations) {
2094
+ if (!t10.isIdentifier(varDecl.id)) continue;
2095
+ const init = varDecl.init;
2096
+ if (t10.isArrowFunctionExpression(init) || t10.isFunctionExpression(init)) {
2097
+ const action = {
2098
+ name: varDecl.id.name,
2099
+ async: init.async || false,
2100
+ params: init.params.filter((p) => t10.isIdentifier(p)).map((p) => p.name)
2101
+ };
2102
+ if (init.params.length > 0) {
2103
+ const firstParam = init.params[0];
2104
+ if (t10.isIdentifier(firstParam) && firstParam.typeAnnotation) {
2105
+ action.contextType = extractTypeName(firstParam.typeAnnotation);
2106
+ }
2107
+ }
2108
+ serverActions.push(action);
2109
+ }
2110
+ }
2111
+ }
2112
+ }
2113
+ }
2114
+ if (serverActions.length > 0) {
2115
+ if (!compilerState.metadata) compilerState.metadata = {};
2116
+ compilerState.metadata.serverActions = serverActions;
2117
+ }
2118
+ }
2119
+ function extractFunctionAction(decl) {
2120
+ if (!decl.id) return null;
2121
+ const action = {
2122
+ name: decl.id.name,
2123
+ async: decl.async || false,
2124
+ params: decl.params.filter((p) => t10.isIdentifier(p)).map((p) => p.name)
2125
+ };
2126
+ if (decl.params.length > 0) {
2127
+ const firstParam = decl.params[0];
2128
+ if (t10.isIdentifier(firstParam) && firstParam.typeAnnotation) {
2129
+ action.contextType = extractTypeName(firstParam.typeAnnotation);
2130
+ }
2131
+ }
2132
+ return action;
2133
+ }
2134
+ function extractTypeName(annotation) {
2135
+ if (t10.isTSTypeAnnotation(annotation)) {
2136
+ const typeNode = annotation.typeAnnotation;
2137
+ if (t10.isTSTypeReference(typeNode) && t10.isIdentifier(typeNode.typeName)) {
2138
+ return typeNode.typeName.name;
2139
+ }
2140
+ }
2141
+ return void 0;
2142
+ }
2143
+ function extractDescription(comments) {
2144
+ for (const comment of comments) {
2145
+ if (comment.type !== "CommentBlock") continue;
2146
+ const lines = comment.value.split("\n");
2147
+ for (const line of lines) {
2148
+ const trimmed = line.replace(/^\s*\*\s?/, "").trim();
2149
+ if (trimmed && !trimmed.startsWith("@")) {
2150
+ return trimmed;
2151
+ }
2152
+ }
2153
+ }
2154
+ return void 0;
2155
+ }
2156
+
2157
+ // src/babel/extractors/grammar-island-extractor.ts
2158
+ import * as t11 from "@babel/types";
2159
+ var GRAMMAR_TAGS = /* @__PURE__ */ new Set(["cedar", "sql", "cron", "dmn", "graphql", "jsonpath"]);
2160
+ function parseCedar(source) {
2161
+ const policies = [];
2162
+ const policyRegex = /(permit|forbid)\s*\(([^)]*)\)(?:\s*when\s*\{([^}]*)\})?/g;
2163
+ let match;
2164
+ while ((match = policyRegex.exec(source)) !== null) {
2165
+ const [, effect, scope, condition] = match;
2166
+ const parts = scope.split(",").map((s) => s.trim());
2167
+ const policy = {
2168
+ effect,
2169
+ conditions: []
2170
+ };
2171
+ for (const part of parts) {
2172
+ if (part.startsWith("principal")) {
2173
+ policy.principal = part;
2174
+ } else if (part.startsWith("action")) {
2175
+ policy.action = part;
2176
+ } else if (part.startsWith("resource")) {
2177
+ policy.resource = part;
2178
+ }
2179
+ }
2180
+ if (condition) {
2181
+ policy.conditions.push(condition.trim());
2182
+ }
2183
+ policies.push(policy);
2184
+ }
2185
+ return { policies };
2186
+ }
2187
+ function parseCron(source) {
2188
+ const trimmed = source.trim();
2189
+ const parts = trimmed.split(/\s+/);
2190
+ const valid = parts.length === 5;
2191
+ return {
2192
+ expression: trimmed,
2193
+ fields: {
2194
+ minute: parts[0] || "*",
2195
+ hour: parts[1] || "*",
2196
+ dayOfMonth: parts[2] || "*",
2197
+ month: parts[3] || "*",
2198
+ dayOfWeek: parts[4] || "*"
2199
+ },
2200
+ valid
2201
+ };
2202
+ }
2203
+ function parseDmn(source) {
2204
+ const lines = source.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
2205
+ const rules = [];
2206
+ const headers = [];
2207
+ let hitPolicy = "first";
2208
+ if (lines.length === 0) return { hitPolicy, rules, headers };
2209
+ const headerLine = lines[0];
2210
+ const headerCells = headerLine.split("|").map((c) => c.trim()).filter((c) => c.length > 0);
2211
+ headers.push(...headerCells);
2212
+ const outputStartIndex = headers.length - 1;
2213
+ let dataStart = 1;
2214
+ if (lines.length > 1 && /^[|\s-]+$/.test(lines[1])) {
2215
+ dataStart = 2;
2216
+ }
2217
+ const hitPolicyMatch = source.match(/@hitPolicy\s*=\s*"?(\w+)"?/);
2218
+ if (hitPolicyMatch) {
2219
+ hitPolicy = hitPolicyMatch[1];
2220
+ }
2221
+ for (let i = dataStart; i < lines.length; i++) {
2222
+ const cells = lines[i].split("|").map((c) => c.trim()).filter((c) => c.length > 0);
2223
+ if (cells.length < headers.length) continue;
2224
+ const inputs = {};
2225
+ const output = {};
2226
+ for (let j = 0; j < headers.length; j++) {
2227
+ if (j >= outputStartIndex) {
2228
+ output[headers[j]] = cells[j];
2229
+ } else {
2230
+ inputs[headers[j]] = cells[j];
2231
+ }
2232
+ }
2233
+ rules.push({ inputs, output });
2234
+ }
2235
+ return { hitPolicy, rules, headers };
2236
+ }
2237
+ function extractGrammarIsland(path, state, slug) {
2238
+ const tag = path.node.tag;
2239
+ if (!t11.isIdentifier(tag)) return;
2240
+ const tagName = tag.name;
2241
+ if (!GRAMMAR_TAGS.has(tagName)) return;
2242
+ const compilerState = state;
2243
+ const quasi = path.node.quasi;
2244
+ let rawSource = "";
2245
+ for (let i = 0; i < quasi.quasis.length; i++) {
2246
+ rawSource += quasi.quasis[i].value.raw;
2247
+ if (i < quasi.expressions.length) {
2248
+ const expr = quasi.expressions[i];
2249
+ if (t11.isIdentifier(expr)) {
2250
+ rawSource += `\${${expr.name}}`;
2251
+ } else {
2252
+ rawSource += `\${expr_${i}}`;
2253
+ }
2254
+ }
2255
+ }
2256
+ rawSource = rawSource.trim();
2257
+ let parsed = void 0;
2258
+ switch (tagName) {
2259
+ case "cedar":
2260
+ parsed = parseCedar(rawSource);
2261
+ break;
2262
+ case "cron":
2263
+ parsed = parseCron(rawSource);
2264
+ break;
2265
+ case "dmn":
2266
+ parsed = parseDmn(rawSource);
2267
+ break;
2268
+ case "sql":
2269
+ parsed = { query: rawSource };
2270
+ break;
2271
+ case "graphql":
2272
+ parsed = { query: rawSource };
2273
+ break;
2274
+ case "jsonpath":
2275
+ parsed = { expression: rawSource };
2276
+ break;
2277
+ }
2278
+ const island = {
2279
+ slug,
2280
+ contextTag: tagName,
2281
+ rawSource,
2282
+ parsed
2283
+ };
2284
+ if (!compilerState.metadata) compilerState.metadata = {};
2285
+ const meta = compilerState.metadata;
2286
+ if (!meta.grammarIslands) meta.grammarIslands = [];
2287
+ meta.grammarIslands.push(island);
2288
+ }
2289
+ function extractGrammarIslands(path, state) {
2290
+ path.traverse({
2291
+ TaggedTemplateExpression(templatePath) {
2292
+ const tag = templatePath.node.tag;
2293
+ if (!t11.isIdentifier(tag) || !GRAMMAR_TAGS.has(tag.name)) return;
2294
+ let slug = "unnamed";
2295
+ const parent = templatePath.parentPath;
2296
+ if (parent && parent.isVariableDeclarator() && t11.isIdentifier(parent.node.id)) {
2297
+ slug = parent.node.id.name;
2298
+ }
2299
+ if (parent && parent.isObjectProperty() && t11.isIdentifier(parent.node.key)) {
2300
+ slug = parent.node.key.name;
2301
+ }
2302
+ if (parent && parent.isObjectProperty() && t11.isStringLiteral(parent.node.key)) {
2303
+ slug = parent.node.key.value;
2304
+ }
2305
+ extractGrammarIsland(templatePath, state, slug);
2306
+ }
2307
+ });
2308
+ }
2309
+
2310
+ // src/babel/extractors/context-extractor.ts
2311
+ import * as t12 from "@babel/types";
2312
+ function hasContextCreation(path) {
2313
+ let found = false;
2314
+ path.traverse({
2315
+ CallExpression(callPath) {
2316
+ if (t12.isIdentifier(callPath.node.callee, { name: "createContext" })) {
2317
+ found = true;
2318
+ callPath.stop();
2319
+ }
2320
+ }
2321
+ });
2322
+ return found;
2323
+ }
2324
+ function extractContextWorkflows(path, state) {
2325
+ const compilerState = state;
2326
+ const contextWorkflows = [];
2327
+ const contextNames = /* @__PURE__ */ new Map();
2328
+ path.traverse({
2329
+ // Detect: const XContext = createContext(...)
2330
+ VariableDeclarator(declPath) {
2331
+ const init = declPath.node.init;
2332
+ if (!init || !t12.isCallExpression(init)) return;
2333
+ if (!t12.isIdentifier(init.callee, { name: "createContext" })) return;
2334
+ if (!t12.isIdentifier(declPath.node.id)) return;
2335
+ const contextName = declPath.node.id.name;
2336
+ contextNames.set(contextName, contextName);
2337
+ const workflow = {
2338
+ name: contextName,
2339
+ fields: [],
2340
+ reducerActions: []
2341
+ };
2342
+ const typeParams = init.typeParameters;
2343
+ if (typeParams && t12.isTSTypeParameterInstantiation(typeParams)) {
2344
+ const typeArg = typeParams.params[0];
2345
+ if (t12.isTSTypeReference(typeArg) && t12.isIdentifier(typeArg.typeName)) {
2346
+ const interfaceName = typeArg.typeName.name;
2347
+ extractFieldsFromInterface2(path, interfaceName, workflow);
2348
+ }
2349
+ }
2350
+ if (init.arguments.length > 0 && t12.isObjectExpression(init.arguments[0])) {
2351
+ workflow.initialState = extractObjectLiteral2(init.arguments[0]);
2352
+ }
2353
+ contextWorkflows.push(workflow);
2354
+ },
2355
+ // Detect useReducer(reducer, initialState) and extract reducer cases
2356
+ CallExpression(callPath) {
2357
+ if (!t12.isIdentifier(callPath.node.callee, { name: "useReducer" })) return;
2358
+ const args = callPath.node.arguments;
2359
+ if (args.length < 1) return;
2360
+ const reducerArg = args[0];
2361
+ if (!t12.isIdentifier(reducerArg)) return;
2362
+ const reducerName = reducerArg.name;
2363
+ const actions = extractReducerActions(path, reducerName);
2364
+ if (contextWorkflows.length > 0) {
2365
+ const lastWorkflow = contextWorkflows[contextWorkflows.length - 1];
2366
+ lastWorkflow.reducerActions = actions;
2367
+ lastWorkflow.reducerName = reducerName;
2368
+ }
2369
+ }
2370
+ });
2371
+ if (contextWorkflows.length > 0) {
2372
+ if (!compilerState.metadata) compilerState.metadata = {};
2373
+ const meta = compilerState.metadata;
2374
+ meta.contextWorkflows = contextWorkflows;
2375
+ }
2376
+ }
2377
+ function extractFieldsFromInterface2(path, interfaceName, workflow) {
2378
+ path.traverse({
2379
+ TSInterfaceDeclaration(ifacePath) {
2380
+ if (!t12.isIdentifier(ifacePath.node.id, { name: interfaceName })) return;
2381
+ for (const prop of ifacePath.node.body.body) {
2382
+ if (!t12.isTSPropertySignature(prop)) continue;
2383
+ if (!t12.isIdentifier(prop.key)) continue;
2384
+ const field = {
2385
+ name: prop.key.name,
2386
+ type: extractTSType(prop.typeAnnotation),
2387
+ optional: prop.optional || false
2388
+ };
2389
+ workflow.fields.push(field);
2390
+ }
2391
+ }
2392
+ });
2393
+ }
2394
+ function extractTSType(annotation) {
2395
+ if (!annotation || !t12.isTSTypeAnnotation(annotation)) return "unknown";
2396
+ const typeNode = annotation.typeAnnotation;
2397
+ if (t12.isTSStringKeyword(typeNode)) return "string";
2398
+ if (t12.isTSNumberKeyword(typeNode)) return "number";
2399
+ if (t12.isTSBooleanKeyword(typeNode)) return "boolean";
2400
+ if (t12.isTSArrayType(typeNode)) return `${extractTSTypeNode(typeNode.elementType)}[]`;
2401
+ if (t12.isTSTypeReference(typeNode) && t12.isIdentifier(typeNode.typeName)) return typeNode.typeName.name;
2402
+ return "unknown";
2403
+ }
2404
+ function extractTSTypeNode(node) {
2405
+ if (t12.isTSStringKeyword(node)) return "string";
2406
+ if (t12.isTSNumberKeyword(node)) return "number";
2407
+ if (t12.isTSBooleanKeyword(node)) return "boolean";
2408
+ if (t12.isTSTypeReference(node) && t12.isIdentifier(node.typeName)) return node.typeName.name;
2409
+ return "unknown";
2410
+ }
2411
+ function extractReducerActions(path, reducerName) {
2412
+ const actions = [];
2413
+ path.traverse({
2414
+ FunctionDeclaration(funcPath) {
2415
+ if (!funcPath.node.id || funcPath.node.id.name !== reducerName) return;
2416
+ funcPath.traverse({
2417
+ SwitchStatement(switchPath) {
2418
+ for (const switchCase of switchPath.node.cases) {
2419
+ if (!switchCase.test) continue;
2420
+ if (t12.isStringLiteral(switchCase.test)) {
2421
+ actions.push({
2422
+ type: switchCase.test.value
2423
+ });
2424
+ }
2425
+ }
2426
+ }
2427
+ });
2428
+ }
2429
+ });
2430
+ return actions;
2431
+ }
2432
+ function extractObjectLiteral2(obj) {
2433
+ const result = {};
2434
+ for (const prop of obj.properties) {
2435
+ if (!t12.isObjectProperty(prop) || !t12.isIdentifier(prop.key)) continue;
2436
+ if (t12.isStringLiteral(prop.value)) result[prop.key.name] = prop.value.value;
2437
+ else if (t12.isNumericLiteral(prop.value)) result[prop.key.name] = prop.value.value;
2438
+ else if (t12.isBooleanLiteral(prop.value)) result[prop.key.name] = prop.value.value;
2439
+ else if (t12.isNullLiteral(prop.value)) result[prop.key.name] = null;
2440
+ else if (t12.isArrayExpression(prop.value)) result[prop.key.name] = [];
2441
+ else if (t12.isObjectExpression(prop.value)) result[prop.key.name] = extractObjectLiteral2(prop.value);
2442
+ }
2443
+ return result;
2444
+ }
2445
+
2446
+ // src/babel/emitters/pure-form-emitter.ts
2447
+ import { normalizeCategory } from "@mindmatrix/player-core";
2448
+ var PROP_RULES = {
2449
+ Text: {
2450
+ config: { text: "value" },
2451
+ bindings: { text: "value" }
2452
+ },
2453
+ Heading: {
2454
+ config: { text: "value" },
2455
+ bindings: { text: "value" }
2456
+ },
2457
+ Button: {
2458
+ config: { text: "label" },
2459
+ bindings: { text: "label", onPress: "onClick" }
2460
+ }
2461
+ };
2462
+ var COMPONENT_RENAMES = {
2463
+ Heading: "Text"
2464
+ };
2465
+ var RENAME_EXTRA_CONFIG = {
2466
+ Heading: { variant: "h2" }
2467
+ };
2468
+ function normalizeViewNode(node, fieldNames) {
2469
+ if (!node || typeof node !== "object") return node;
2470
+ const originalComponent = node.component;
2471
+ if (originalComponent && COMPONENT_RENAMES[originalComponent]) {
2472
+ node.component = COMPONENT_RENAMES[originalComponent];
2473
+ const extra = RENAME_EXTRA_CONFIG[originalComponent];
2474
+ if (extra) {
2475
+ node.config = { ...extra, ...node.config || {} };
2476
+ }
2477
+ }
2478
+ const rules = PROP_RULES[originalComponent || ""] || PROP_RULES[node.component || ""];
2479
+ if (rules) {
2480
+ if (node.config && rules.config) {
2481
+ for (const [from, to] of Object.entries(rules.config)) {
2482
+ if (from in node.config && !(to in node.config)) {
2483
+ node.config[to] = node.config[from];
2484
+ delete node.config[from];
2485
+ }
2486
+ }
2487
+ }
2488
+ if (node.bindings && rules.bindings) {
2489
+ for (const [from, to] of Object.entries(rules.bindings)) {
2490
+ if (from in node.bindings && !(to in node.bindings)) {
2491
+ node.bindings[to] = node.bindings[from];
2492
+ delete node.bindings[from];
2493
+ }
2494
+ }
2495
+ }
2496
+ }
2497
+ if (node.config && fieldNames.size > 0) {
2498
+ for (const [prop, val] of Object.entries(node.config)) {
2499
+ if (typeof val !== "string") continue;
2500
+ const templateRe = /\{\{(\w+)\}\}|\{(\w+)\}/g;
2501
+ let match;
2502
+ const refs = [];
2503
+ while ((match = templateRe.exec(val)) !== null) {
2504
+ const field = match[1] || match[2];
2505
+ if (fieldNames.has(field)) {
2506
+ refs.push({ full: match[0], field, index: match.index });
2507
+ }
2508
+ }
2509
+ if (refs.length > 0) {
2510
+ const parts = [];
2511
+ let lastEnd = 0;
2512
+ for (const ref of refs) {
2513
+ const before = val.slice(lastEnd, ref.index);
2514
+ if (before) parts.push(`"${before}"`);
2515
+ parts.push(`$instance.state_data.${ref.field}`);
2516
+ lastEnd = ref.index + ref.full.length;
2517
+ }
2518
+ const trailing = val.slice(lastEnd);
2519
+ if (trailing) parts.push(`"${trailing}"`);
2520
+ const expr = `$fn.concat(${parts.join(", ")})`;
2521
+ if (!node.bindings) node.bindings = {};
2522
+ node.bindings[prop] = expr;
2523
+ delete node.config[prop];
2524
+ }
2525
+ }
2526
+ }
2527
+ if (node.bindings) {
2528
+ for (const [prop, expr] of Object.entries(node.bindings)) {
2529
+ if (typeof expr !== "string") continue;
2530
+ if (expr.endsWith(".fire")) {
2531
+ const transitionName = expr.slice(0, -5);
2532
+ node.bindings[prop] = `$action.transition("${transitionName}")`;
2533
+ continue;
2534
+ }
2535
+ if (fieldNames.size > 0 && expr.startsWith("$instance.")) {
2536
+ const field = expr.slice("$instance.".length);
2537
+ if (fieldNames.has(field)) {
2538
+ node.bindings[prop] = `$instance.state_data.${field}`;
2539
+ }
2540
+ }
2541
+ }
2542
+ }
2543
+ if (node.children && Array.isArray(node.children)) {
2544
+ node.children = node.children.map((child) => normalizeViewNode(child, fieldNames));
2545
+ if (node.children.length === 1 && node.children[0].component === "Text") {
2546
+ const textChild = node.children[0];
2547
+ if (textChild.config?.value && !textChild.bindings) {
2548
+ if (!node.config) node.config = {};
2549
+ node.config.text = textChild.config.value;
2550
+ delete node.children;
2551
+ } else if (textChild.bindings?.value && !textChild.config?.value) {
2552
+ if (!node.bindings) node.bindings = {};
2553
+ node.bindings.text = textChild.bindings.value;
2554
+ delete node.children;
2555
+ }
2556
+ }
2557
+ }
2558
+ return node;
2559
+ }
2560
+ function toSnakeCase2(str) {
2561
+ return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
2562
+ }
2563
+ function convertAction(action) {
2564
+ return {
2565
+ id: action.id,
2566
+ action_type: action.type,
2567
+ config: action.config || {},
2568
+ ...action.condition && { condition: action.condition }
2569
+ };
2570
+ }
2571
+ function convertDuringAction(during) {
2572
+ return {
2573
+ id: during.id,
2574
+ type: during.type,
2575
+ ...during.interval_ms !== void 0 && { interval_ms: during.interval_ms },
2576
+ ...during.cron && { cron: during.cron },
2577
+ ...during.delay_ms !== void 0 && { delay_ms: during.delay_ms },
2578
+ actions: during.actions.map(convertAction),
2579
+ ...during.condition && { condition: during.condition }
2580
+ };
2581
+ }
2582
+ function convertOnEvent(sub) {
2583
+ return {
2584
+ match: sub.match,
2585
+ ...sub.description && { description: sub.description },
2586
+ conditions: sub.conditions || [],
2587
+ actions: sub.actions.map((a) => ({
2588
+ type: a.type,
2589
+ ...a.field && { field: a.field },
2590
+ ...a.expression && { expression: a.expression },
2591
+ ...a.key && { key: a.key },
2592
+ ...a.message && { message: a.message },
2593
+ ...a.config && { config: a.config },
2594
+ ...a.conditions && a.conditions.length > 0 && { conditions: a.conditions }
2595
+ }))
2596
+ };
2597
+ }
2598
+ function emitIR(extracted) {
2599
+ const { slug, name, version, description, category, fields, states, transitions } = extracted;
2600
+ const stateArray = Array.from(states.values());
2601
+ if (stateArray.length === 0) {
2602
+ stateArray.push({
2603
+ name: "draft",
2604
+ type: "START",
2605
+ on_enter: [],
2606
+ during: [],
2607
+ on_exit: []
2608
+ });
2609
+ } else {
2610
+ const hasStart = stateArray.some((s) => s.type === "START");
2611
+ if (!hasStart && stateArray.length > 0) {
2612
+ stateArray[0].type = "START";
2613
+ }
2614
+ }
2615
+ inferTransitionStates(transitions, states);
2616
+ const stateNames = new Set(stateArray.map((s) => s.name));
2617
+ for (const transition of transitions) {
2618
+ if (transition.to && !stateNames.has(transition.to)) {
2619
+ stateArray.push({
2620
+ name: transition.to,
2621
+ type: "REGULAR",
2622
+ on_enter: [],
2623
+ during: [],
2624
+ on_exit: []
2625
+ });
2626
+ stateNames.add(transition.to);
2627
+ }
2628
+ }
2629
+ const fieldNames = new Set(fields.map((f) => f.name));
2630
+ let normalizedView;
2631
+ if (extracted.experience) {
2632
+ normalizedView = normalizeViewNode(
2633
+ JSON.parse(JSON.stringify(extracted.experience)),
2634
+ fieldNames
2635
+ );
2636
+ const dataSources = extracted.extraMetadata?.dataSources;
2637
+ if (dataSources && dataSources.length > 0) {
2638
+ normalizedView.dataSources = dataSources;
2639
+ }
2640
+ if (fields.length > 0) {
2641
+ const localDefaults = {};
2642
+ for (const f of fields) {
2643
+ localDefaults[toSnakeCase2(f.name)] = f.default_value ?? null;
2644
+ }
2645
+ if (!normalizedView.config) normalizedView.config = {};
2646
+ normalizedView.config.localDefaults = localDefaults;
2647
+ }
2648
+ }
2649
+ const metadata = {
2650
+ stable_id: `def-${slug}`,
2651
+ provenance: {
2652
+ frontend: "react-compiler",
2653
+ source: `${slug}.workflow.tsx`,
2654
+ compiler_version: "1.0.0"
2655
+ }
2656
+ };
2657
+ if (extracted.fieldWatchers && extracted.fieldWatchers.length > 0) {
2658
+ metadata.fieldWatchers = extracted.fieldWatchers;
2659
+ }
2660
+ if (extracted.transitionEffects && extracted.transitionEffects.length > 0) {
2661
+ metadata.transitionEffects = extracted.transitionEffects;
2662
+ }
2663
+ if (extracted.extraMetadata) {
2664
+ for (const [key, value] of Object.entries(extracted.extraMetadata)) {
2665
+ metadata[key] = value;
2666
+ }
2667
+ }
2668
+ if (extracted.experience) {
2669
+ metadata.experience = extracted.experience;
2670
+ }
2671
+ const ir = {
2672
+ slug,
2673
+ name,
2674
+ version,
2675
+ description,
2676
+ category,
2677
+ fields,
2678
+ states: stateArray,
2679
+ transitions,
2680
+ roles: [],
2681
+ tags: [],
2682
+ metadata
2683
+ };
2684
+ if (normalizedView) {
2685
+ ir.views = { default: normalizedView };
2686
+ }
2687
+ if (extracted.events && extracted.events.length > 0) {
2688
+ ir.on_event = extracted.events;
2689
+ }
2690
+ if (extracted.grammarIslands && extracted.grammarIslands.length > 0) {
2691
+ const extensions = {};
2692
+ for (const island of extracted.grammarIslands) {
2693
+ const key = island.contextTag;
2694
+ if (!extensions[key]) extensions[key] = [];
2695
+ extensions[key].push(island);
2696
+ }
2697
+ ir.extensions = extensions;
2698
+ }
2699
+ return ir;
2700
+ }
2701
+ var emitPureForm = emitIR;
2702
+ function liftAction(action) {
2703
+ const parts = [];
2704
+ if (action.config) {
2705
+ for (const [key, value] of Object.entries(action.config)) {
2706
+ parts.push({
2707
+ slug: key,
2708
+ category: ["atom"],
2709
+ parts: [{ slug: String(value), category: ["atom"] }]
2710
+ });
2711
+ }
2712
+ }
2713
+ if (action.condition) {
2714
+ parts.push({
2715
+ slug: "condition",
2716
+ category: ["expression", "guard"],
2717
+ parts: [{ slug: action.condition, category: ["binding"] }]
2718
+ });
2719
+ }
2720
+ return {
2721
+ slug: action.id,
2722
+ category: normalizeCategory("expression", "mutation", action.type),
2723
+ parts: parts.length > 0 ? parts : void 0
2724
+ };
2725
+ }
2726
+ function liftSchedule(during) {
2727
+ const parts = [];
2728
+ if (during.interval_ms !== void 0) {
2729
+ parts.push({
2730
+ slug: "every",
2731
+ category: ["atom"],
2732
+ parts: [{ slug: String(during.interval_ms), category: ["literal"] }]
2733
+ });
2734
+ }
2735
+ if (during.cron) {
2736
+ parts.push({
2737
+ slug: "cron",
2738
+ category: ["atom"],
2739
+ parts: [{ slug: during.cron, category: ["literal"] }]
2740
+ });
2741
+ }
2742
+ if (during.delay_ms !== void 0) {
2743
+ parts.push({
2744
+ slug: "delay",
2745
+ category: ["atom"],
2746
+ parts: [{ slug: String(during.delay_ms), category: ["literal"] }]
2747
+ });
2748
+ }
2749
+ for (const action of during.actions) {
2750
+ parts.push({
2751
+ slug: "do",
2752
+ category: normalizeCategory("expression", "mutation", action.type),
2753
+ parts: Object.entries(action.config || {}).map(([key, value]) => ({
2754
+ slug: key,
2755
+ category: ["atom"],
2756
+ parts: [{ slug: String(value), category: ["atom"] }]
2757
+ }))
2758
+ });
2759
+ }
2760
+ return {
2761
+ slug: during.id,
2762
+ category: normalizeCategory("schedule", during.type),
2763
+ parts
2764
+ };
2765
+ }
2766
+ function liftState(state) {
2767
+ const parts = [];
2768
+ const tags = [];
2769
+ if (state.type === "START") tags.push("start");
2770
+ if (state.type === "END") tags.push("end");
2771
+ if (state.type === "CANCELLED") tags.push("cancelled");
2772
+ if (state.on_enter && state.on_enter.length > 0) {
2773
+ parts.push({
2774
+ slug: "on_enter",
2775
+ category: normalizeCategory("expression", "sequence"),
2776
+ parts: state.on_enter.map(liftAction)
2777
+ });
2778
+ }
2779
+ if (state.on_exit && state.on_exit.length > 0) {
2780
+ parts.push({
2781
+ slug: "on_exit",
2782
+ category: normalizeCategory("expression", "sequence"),
2783
+ parts: state.on_exit.map(liftAction)
2784
+ });
2785
+ }
2786
+ if (state.during && state.during.length > 0) {
2787
+ for (const d of state.during) {
2788
+ parts.push(liftSchedule(d));
2789
+ }
2790
+ }
2791
+ return {
2792
+ slug: state.name,
2793
+ category: normalizeCategory("state", ...tags),
2794
+ parts: parts.length > 0 ? parts : void 0
2795
+ };
2796
+ }
2797
+ function liftTransition(transition) {
2798
+ const parts = [];
2799
+ if (transition.from && transition.from.length > 0) {
2800
+ parts.push({
2801
+ slug: "from",
2802
+ category: ["part"],
2803
+ parts: transition.from.map((s) => ({ slug: s, category: ["ref"] }))
2804
+ });
2805
+ }
2806
+ if (transition.to) {
2807
+ parts.push({
2808
+ slug: "to",
2809
+ category: ["part"],
2810
+ parts: [{ slug: transition.to, category: ["ref"] }]
2811
+ });
2812
+ }
2813
+ if (transition.actions && transition.actions.length > 0) {
2814
+ parts.push({
2815
+ slug: "actions",
2816
+ category: normalizeCategory("expression", "sequence"),
2817
+ parts: transition.actions.map(liftAction)
2818
+ });
2819
+ }
2820
+ if (transition.conditions && transition.conditions.length > 0) {
2821
+ parts.push({
2822
+ slug: "conditions",
2823
+ category: normalizeCategory("expression", "guard"),
2824
+ parts: transition.conditions.map((c, i) => ({
2825
+ slug: `condition_${i}`,
2826
+ category: normalizeCategory("expression", c.type || "condition"),
2827
+ parts: c.expression ? [{ slug: c.expression, category: ["binding"] }] : void 0
2828
+ }))
2829
+ });
2830
+ }
2831
+ return {
2832
+ slug: transition.name,
2833
+ category: ["transition"],
2834
+ parts
2835
+ };
2836
+ }
2837
+ function liftField(field) {
2838
+ const parts = [];
2839
+ if (field.label) {
2840
+ parts.push({
2841
+ slug: "label",
2842
+ category: ["atom"],
2843
+ parts: [{ slug: field.label, category: ["atom"] }]
2844
+ });
2845
+ }
2846
+ if (field.default_value !== void 0) {
2847
+ parts.push({
2848
+ slug: "default",
2849
+ category: ["atom"],
2850
+ parts: [{ slug: String(field.default_value), category: ["literal"] }]
2851
+ });
2852
+ }
2853
+ if (field.required) {
2854
+ parts.push({ slug: "required", category: ["atom"], parts: [{ slug: "true", category: ["literal"] }] });
2855
+ }
2856
+ if (field.computed) {
2857
+ parts.push({
2858
+ slug: "computed",
2859
+ category: ["expression"],
2860
+ parts: [{ slug: field.computed, category: ["binding"] }]
2861
+ });
2862
+ }
2863
+ return {
2864
+ slug: field.name,
2865
+ category: normalizeCategory("field", field.type),
2866
+ parts: parts.length > 0 ? parts : void 0
2867
+ };
2868
+ }
2869
+ function liftView(node) {
2870
+ const componentTag = (node.component || "stack").toLowerCase().replace(/\s+/g, "-");
2871
+ const parts = [];
2872
+ if (node.config) {
2873
+ for (const [key, value] of Object.entries(node.config)) {
2874
+ parts.push({
2875
+ slug: key,
2876
+ category: ["atom"],
2877
+ parts: [{ slug: String(value), category: ["atom"] }]
2878
+ });
2879
+ }
2880
+ }
2881
+ if (node.bindings) {
2882
+ for (const [key, expr] of Object.entries(node.bindings)) {
2883
+ if (key === "onClick" || key === "onPress") {
2884
+ const match = typeof expr === "string" ? expr.match(/\$action\.transition\("(.+?)"\)/) : null;
2885
+ if (match) {
2886
+ parts.push({
2887
+ slug: key,
2888
+ category: normalizeCategory("expression", "effect", "transition"),
2889
+ parts: [{ slug: match[1], category: ["ref"] }]
2890
+ });
2891
+ } else {
2892
+ parts.push({
2893
+ slug: key,
2894
+ category: normalizeCategory("expression", "binding"),
2895
+ parts: [{ slug: String(expr), category: ["binding"] }]
2896
+ });
2897
+ }
2898
+ } else {
2899
+ parts.push({
2900
+ slug: key,
2901
+ category: normalizeCategory("expression", "binding"),
2902
+ parts: [{ slug: String(expr), category: ["binding"] }]
2903
+ });
2904
+ }
2905
+ }
2906
+ }
2907
+ if (node.visible_when) {
2908
+ const eqMatch = node.visible_when.match(/\$fn\.eq\((.+?),\s*"(.+?)"\)/);
2909
+ if (eqMatch) {
2910
+ parts.push({
2911
+ slug: "visible_when",
2912
+ category: normalizeCategory("expression", "guard"),
2913
+ parts: [{
2914
+ slug: "body",
2915
+ category: normalizeCategory("expression", "eq"),
2916
+ parts: [
2917
+ { slug: "lhs", category: normalizeCategory("expression", "path"), parts: [{ slug: eqMatch[1], category: ["binding"] }] },
2918
+ { slug: "rhs", category: normalizeCategory("expression", "literal"), parts: [{ slug: eqMatch[2], category: ["literal"] }] }
2919
+ ]
2920
+ }]
2921
+ });
2922
+ } else {
2923
+ parts.push({
2924
+ slug: "visible_when",
2925
+ category: normalizeCategory("expression", "guard"),
2926
+ parts: [{ slug: node.visible_when, category: ["binding"] }]
2927
+ });
2928
+ }
2929
+ }
2930
+ if (node.children && node.children.length > 0) {
2931
+ for (const child of node.children) {
2932
+ parts.push(liftView(child));
2933
+ }
2934
+ }
2935
+ return {
2936
+ slug: node.id,
2937
+ category: normalizeCategory("view", componentTag),
2938
+ parts: parts.length > 0 ? parts : void 0
2939
+ };
2940
+ }
2941
+ function emitCanonical(extracted, sourceFilename) {
2942
+ const ir = emitIR(extracted);
2943
+ const parts = [];
2944
+ for (const state of ir.states) {
2945
+ parts.push(liftState(state));
2946
+ }
2947
+ for (const transition of ir.transitions) {
2948
+ parts.push(liftTransition(transition));
2949
+ }
2950
+ for (const field of ir.fields) {
2951
+ parts.push(liftField(field));
2952
+ }
2953
+ if (extracted.experience) {
2954
+ parts.push(liftView(extracted.experience));
2955
+ }
2956
+ parts.push({
2957
+ slug: "manifest",
2958
+ category: normalizeCategory("meta", "manifest"),
2959
+ parts: [
2960
+ {
2961
+ slug: "workflows",
2962
+ category: ["ref-list"],
2963
+ parts: [{ slug: ir.slug, category: ["ref"] }]
2964
+ },
2965
+ {
2966
+ slug: "route",
2967
+ category: ["route"],
2968
+ parts: [
2969
+ { slug: "path", category: ["atom"], parts: [{ slug: `/${ir.slug}`, category: ["atom"] }] },
2970
+ { slug: "label", category: ["atom"], parts: [{ slug: ir.name, category: ["atom"] }] }
2971
+ ]
2972
+ }
2973
+ ]
2974
+ });
2975
+ const category = extracted.category;
2976
+ const categoryArray = category === "workflow" ? ["workflow"] : normalizeCategory("workflow", category);
2977
+ return {
2978
+ slug: ir.slug,
2979
+ category: categoryArray,
2980
+ parts,
2981
+ metadata: {
2982
+ stable_id: `def-${ir.slug}`,
2983
+ provenance: {
2984
+ frontend: "react-compiler",
2985
+ source: sourceFilename || `${ir.slug}.workflow.tsx`,
2986
+ compiler_version: "1.0.0",
2987
+ compiled_at: (/* @__PURE__ */ new Date()).toISOString()
2988
+ }
2989
+ }
2990
+ };
2991
+ }
2992
+ function emitCompiledOutput(extracted, sourceFilename) {
2993
+ return {
2994
+ canonical: emitCanonical(extracted, sourceFilename),
2995
+ ir: emitIR(extracted)
2996
+ };
2997
+ }
2998
+ function foldTextContent(node) {
2999
+ if (!node || typeof node !== "object") return node;
3000
+ if (node.children && Array.isArray(node.children)) {
3001
+ node.children = node.children.map((child) => foldTextContent(child));
3002
+ if (node.children.length === 1 && node.children[0].component === "Text") {
3003
+ const textChild = node.children[0];
3004
+ if (textChild.config?.value && !textChild.bindings) {
3005
+ if (!node.config) node.config = {};
3006
+ node.config.text = textChild.config.value;
3007
+ node.children = void 0;
3008
+ } else if (textChild.bindings?.value && !textChild.config?.value) {
3009
+ if (!node.bindings) node.bindings = {};
3010
+ node.bindings.text = textChild.bindings.value;
3011
+ node.children = void 0;
3012
+ }
3013
+ }
3014
+ if (node.children && node.children.length === 0) {
3015
+ node.children = void 0;
3016
+ }
3017
+ }
3018
+ if (!node.children) delete node.children;
3019
+ return node;
3020
+ }
3021
+ function emitWorkflowDefinition(extracted) {
3022
+ const ir = emitIR(extracted);
3023
+ const states = ir.states.map((s) => ({
3024
+ name: s.name,
3025
+ state_type: s.type,
3026
+ description: s.description || "",
3027
+ on_enter: (s.on_enter || []).map(convertAction),
3028
+ on_exit: (s.on_exit || []).map(convertAction),
3029
+ during: (s.during || []).map(convertDuringAction),
3030
+ on_event: (s.on_event || []).map(convertOnEvent)
3031
+ }));
3032
+ const fields = ir.fields.map((f) => ({
3033
+ name: toSnakeCase2(f.name),
3034
+ field_type: f.type,
3035
+ label: f.label || f.name.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase()),
3036
+ required: f.required || false,
3037
+ default_value: f.default_value ?? null,
3038
+ ...f.validation && { validation: f.validation },
3039
+ ...f.computed && { computed: f.computed },
3040
+ ...f.computed_deps && { computed_deps: f.computed_deps },
3041
+ ...f.visible_in_states && { visible_in_states: f.visible_in_states },
3042
+ ...f.editable_in_states && { editable_in_states: f.editable_in_states },
3043
+ ...f.visible_to_roles && { visible_to_roles: f.visible_to_roles },
3044
+ ...f.editable_by_roles && { editable_by_roles: f.editable_by_roles },
3045
+ ...f.visible_when && { visible_when: f.visible_when },
3046
+ ...f.editable_when && { editable_when: f.editable_when },
3047
+ ...f.state_home && { state_home: f.state_home }
3048
+ }));
3049
+ const transitions = ir.transitions.map((t14) => ({
3050
+ name: t14.name,
3051
+ from: t14.from,
3052
+ to: t14.to,
3053
+ description: t14.description || "",
3054
+ roles: t14.roles || [],
3055
+ auto: t14.auto || false,
3056
+ conditions: t14.conditions || [],
3057
+ actions: (t14.actions || []).map(convertAction),
3058
+ required_fields: t14.required_fields || [],
3059
+ priority: 0
3060
+ }));
3061
+ const state_data = {};
3062
+ for (const f of fields) {
3063
+ state_data[f.name] = f.default_value;
3064
+ }
3065
+ const on_event = (ir.on_event || []).map(convertOnEvent);
3066
+ let views;
3067
+ if (extracted.experience) {
3068
+ const viewRoot = foldTextContent(JSON.parse(JSON.stringify(extracted.experience)));
3069
+ const dataSources = extracted.extraMetadata?.dataSources;
3070
+ if (dataSources && dataSources.length > 0) {
3071
+ viewRoot.dataSources = dataSources;
3072
+ }
3073
+ if (extracted.fields.length > 0) {
3074
+ const localDefaults = {};
3075
+ for (const f of extracted.fields) {
3076
+ localDefaults[toSnakeCase2(f.name)] = f.default_value ?? null;
3077
+ }
3078
+ if (!viewRoot.config) viewRoot.config = {};
3079
+ viewRoot.config.localDefaults = localDefaults;
3080
+ }
3081
+ views = { default: viewRoot };
3082
+ }
3083
+ return {
3084
+ id: `def-${ir.slug}`,
3085
+ slug: ir.slug,
3086
+ name: ir.name,
3087
+ version: ir.version,
3088
+ description: ir.description || "",
3089
+ category: ir.category,
3090
+ states,
3091
+ transitions,
3092
+ fields,
3093
+ state_data,
3094
+ roles: [],
3095
+ child_definitions: [],
3096
+ tags: ir.tags || [],
3097
+ metadata: ir.metadata || {},
3098
+ ...views && { views },
3099
+ ...on_event.length > 0 && { on_event },
3100
+ config: {},
3101
+ is_immutable: false
3102
+ };
3103
+ }
3104
+ function compilerStateToWorkflow(state, metadata) {
3105
+ const fieldWatchers = metadata.fieldWatchers || [];
3106
+ const transitionEffects = metadata.transitionEffects || [];
3107
+ const grammarIslands = metadata.grammarIslands || [];
3108
+ const knownKeys = /* @__PURE__ */ new Set(["slug", "name", "version", "description", "category", "fieldWatchers", "transitionEffects", "grammarIslands"]);
3109
+ const extraMetadata = {};
3110
+ for (const [key, value] of Object.entries(metadata)) {
3111
+ if (!knownKeys.has(key) && value !== void 0) {
3112
+ extraMetadata[key] = value;
3113
+ }
3114
+ }
3115
+ return {
3116
+ slug: metadata.slug || "workflow",
3117
+ name: metadata.name || "Workflow",
3118
+ version: metadata.version || "0.1.0",
3119
+ description: metadata.description,
3120
+ category: metadata.category || "workflow",
3121
+ fields: state.fields || [],
3122
+ states: state.states || /* @__PURE__ */ new Map(),
3123
+ transitions: state.transitions || [],
3124
+ events: state.events || [],
3125
+ experience: state.experience,
3126
+ fieldWatchers: fieldWatchers.length > 0 ? fieldWatchers : void 0,
3127
+ transitionEffects: transitionEffects.length > 0 ? transitionEffects : void 0,
3128
+ grammarIslands: grammarIslands.length > 0 ? grammarIslands : void 0,
3129
+ errors: state.errors,
3130
+ warnings: state.warnings,
3131
+ extraMetadata: Object.keys(extraMetadata).length > 0 ? extraMetadata : void 0
3132
+ };
3133
+ }
3134
+
3135
+ // src/babel/visitor.ts
3136
+ function extractQueryDataSource(path, state) {
3137
+ const args = path.node.arguments;
3138
+ if (args.length < 1) return;
3139
+ const slugArg = args[0];
3140
+ if (!t13.isStringLiteral(slugArg)) return;
3141
+ const slug = slugArg.value;
3142
+ const compilerState = state;
3143
+ const dataSource = {
3144
+ type: "workflow",
3145
+ name: slug,
3146
+ slug,
3147
+ query: "list"
3148
+ };
3149
+ if (args.length > 1 && t13.isObjectExpression(args[1])) {
3150
+ for (const prop of args[1].properties) {
3151
+ if (!t13.isObjectProperty(prop) || !t13.isIdentifier(prop.key)) continue;
3152
+ const key = prop.key.name;
3153
+ if (key === "limit" && t13.isNumericLiteral(prop.value)) {
3154
+ dataSource.pageSize = prop.value.value;
3155
+ dataSource.paginated = true;
3156
+ }
3157
+ if (key === "search" && t13.isStringLiteral(prop.value)) {
3158
+ dataSource.searchFields = [prop.value.value];
3159
+ }
3160
+ if (key === "orderBy" && t13.isStringLiteral(prop.value)) {
3161
+ dataSource.sort = prop.value.value;
3162
+ }
3163
+ }
3164
+ }
3165
+ if (!compilerState.metadata) compilerState.metadata = {};
3166
+ const meta = compilerState.metadata;
3167
+ if (!meta.dataSources) meta.dataSources = [];
3168
+ meta.dataSources.push(dataSource);
3169
+ }
3170
+ function extractMutationDataSource(path, state) {
3171
+ const args = path.node.arguments;
3172
+ if (args.length < 1) return;
3173
+ const slugArg = args[0];
3174
+ if (!t13.isStringLiteral(slugArg)) return;
3175
+ const slug = slugArg.value;
3176
+ const compilerState = state;
3177
+ if (!compilerState.metadata) compilerState.metadata = {};
3178
+ const meta = compilerState.metadata;
3179
+ if (!meta.mutationTargets) meta.mutationTargets = [];
3180
+ meta.mutationTargets.push(slug);
3181
+ }
3182
+ var STRICT_BANNED_HOOKS = {
3183
+ useEffect: "STRICT_USE_EFFECT",
3184
+ useLayoutEffect: "STRICT_USE_LAYOUT_EFFECT",
3185
+ useRef: "STRICT_USE_REF",
3186
+ useMemo: "STRICT_USE_MEMO",
3187
+ useCallback: "STRICT_USE_CALLBACK"
3188
+ };
3189
+ function extractMetadataFromComments(comments, metadata) {
3190
+ for (const comment of comments) {
3191
+ if (comment.type !== "CommentBlock") continue;
3192
+ const lines = comment.value.split("\n");
3193
+ for (const line of lines) {
3194
+ const workflowMatch = line.match(/@workflow\s+(.+)/);
3195
+ if (workflowMatch) {
3196
+ const rest = workflowMatch[1].trim();
3197
+ const kvRegex = /(\w+)="([^"]+)"/g;
3198
+ let kvMatch;
3199
+ let hasKV = false;
3200
+ while ((kvMatch = kvRegex.exec(rest)) !== null) {
3201
+ hasKV = true;
3202
+ const [, key, val] = kvMatch;
3203
+ if (key === "slug") metadata.slug = val;
3204
+ else if (key === "version") metadata.version = val;
3205
+ else if (key === "category") metadata.category = val;
3206
+ else if (key === "description") metadata.description = val;
3207
+ }
3208
+ if (!hasKV) {
3209
+ metadata.slug = rest;
3210
+ }
3211
+ continue;
3212
+ }
3213
+ const match = line.match(/@(\w+)\s+(.+)/);
3214
+ if (match) {
3215
+ const [, tag, value] = match;
3216
+ if (tag === "version") metadata.version = value.trim();
3217
+ if (tag === "category") metadata.category = value.trim();
3218
+ if (tag === "description") metadata.description = value.trim();
3219
+ }
3220
+ }
3221
+ }
3222
+ }
3223
+ function createVisitor(options = {}) {
3224
+ const mode = options.mode;
3225
+ return {
3226
+ Program: {
3227
+ // Initialize compiler state at program entry
3228
+ enter(_path, state) {
3229
+ resetNodeIdCounter();
3230
+ resetDuringIdCounter();
3231
+ resetWatcherIdCounter();
3232
+ resetTransitionEffectIdCounter();
3233
+ const compilerState = {
3234
+ fields: [],
3235
+ states: /* @__PURE__ */ new Map(),
3236
+ transitions: [],
3237
+ events: [],
3238
+ actionCounter: 0,
3239
+ metadata: {},
3240
+ errors: [],
3241
+ warnings: []
3242
+ };
3243
+ const program = _path.node;
3244
+ const leadingComments = program.leadingComments || [];
3245
+ extractMetadataFromComments(leadingComments, compilerState.metadata);
3246
+ if (program.body.length > 0) {
3247
+ const firstStmt = program.body[0];
3248
+ if (firstStmt.leadingComments) {
3249
+ extractMetadataFromComments(firstStmt.leadingComments, compilerState.metadata);
3250
+ }
3251
+ }
3252
+ const exportDeclaration = program.body.find(
3253
+ (node) => t13.isExportNamedDeclaration(node) || t13.isExportDefaultDeclaration(node)
3254
+ );
3255
+ if (exportDeclaration) {
3256
+ if (t13.isExportNamedDeclaration(exportDeclaration)) {
3257
+ const declaration = exportDeclaration.declaration;
3258
+ if (t13.isFunctionDeclaration(declaration)) {
3259
+ if (declaration.id) {
3260
+ compilerState.metadata.name = declaration.id.name;
3261
+ }
3262
+ if (declaration.leadingComments) {
3263
+ extractMetadataFromComments(declaration.leadingComments, compilerState.metadata);
3264
+ }
3265
+ }
3266
+ } else if (t13.isExportDefaultDeclaration(exportDeclaration)) {
3267
+ const declaration = exportDeclaration.declaration;
3268
+ if (t13.isFunctionDeclaration(declaration)) {
3269
+ if (declaration.id) {
3270
+ compilerState.metadata.name = declaration.id.name;
3271
+ }
3272
+ if (declaration.leadingComments) {
3273
+ extractMetadataFromComments(declaration.leadingComments, compilerState.metadata);
3274
+ }
3275
+ } else if (t13.isIdentifier(declaration)) {
3276
+ compilerState.metadata.name = declaration.name;
3277
+ }
3278
+ }
3279
+ }
3280
+ if (!compilerState.metadata.slug && state.filename) {
3281
+ const fileName = state.filename.split("/").pop() || "";
3282
+ compilerState.metadata.slug = fileName.replace(/\.workflow\.(tsx?|jsx?)$/, "").replace(/\.(tsx?|jsx?)$/, "").replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
3283
+ compilerState.metadata.__slugAutoFallback = true;
3284
+ }
3285
+ Object.assign(state, compilerState);
3286
+ if (isModelFile(_path, state.filename)) {
3287
+ extractModelFile(_path, state);
3288
+ state.__isModelFile = true;
3289
+ }
3290
+ extractGrammarIslands(_path, state);
3291
+ if (hasContextCreation(_path)) {
3292
+ extractContextWorkflows(_path, state);
3293
+ }
3294
+ if (isServerActionFile(state.filename)) {
3295
+ extractServerActions(_path, state);
3296
+ state.__isServerActionFile = true;
3297
+ }
3298
+ },
3299
+ // After all extraction, emit Pure Form JSON
3300
+ exit(_path, state) {
3301
+ const compilerState = state;
3302
+ const extracted = compilerStateToWorkflow(compilerState, compilerState.metadata);
3303
+ const ir = emitIR(extracted);
3304
+ const definition = emitWorkflowDefinition(extracted);
3305
+ const canonical = emitCanonical(extracted, state.filename);
3306
+ if (compilerState.errors && compilerState.errors.length > 0) {
3307
+ if (!ir.metadata) ir.metadata = {};
3308
+ ir.metadata.errors = compilerState.errors;
3309
+ }
3310
+ if (compilerState.warnings && compilerState.warnings.length > 0) {
3311
+ if (!ir.metadata) ir.metadata = {};
3312
+ ir.metadata.warnings = compilerState.warnings;
3313
+ }
3314
+ if (!state.file.metadata) state.file.metadata = {};
3315
+ state.file.metadata.mindmatrixIR = ir;
3316
+ state.file.metadata.mindmatrixDefinition = definition;
3317
+ state.file.metadata.mindmatrixCanonical = canonical;
3318
+ }
3319
+ },
3320
+ // Extract metadata from function declarations with JSDoc
3321
+ FunctionDeclaration(path, state) {
3322
+ const comments = path.node.leadingComments || [];
3323
+ const compilerState = state;
3324
+ extractMetadataFromComments(comments, compilerState.metadata);
3325
+ },
3326
+ // Main hook extraction dispatcher
3327
+ CallExpression(path, state) {
3328
+ const callee = path.node.callee;
3329
+ if (!t13.isIdentifier(callee)) return;
3330
+ const compilerState = state;
3331
+ const hookName = callee.name;
3332
+ if (mode === "strict" && STRICT_BANNED_HOOKS[hookName]) {
3333
+ const error = {
3334
+ code: STRICT_BANNED_HOOKS[hookName],
3335
+ message: `${hookName}() is not allowed in strict mode. Use @mindmatrix/react effect hooks instead.`,
3336
+ line: path.node.loc?.start.line,
3337
+ column: path.node.loc?.start.column,
3338
+ severity: "error"
3339
+ };
3340
+ if (!compilerState.errors) compilerState.errors = [];
3341
+ compilerState.errors.push(error);
3342
+ return;
3343
+ }
3344
+ if (mode === "infer" && hookName === "useEffect") {
3345
+ const warning = {
3346
+ code: "INFER_RAW_JSX",
3347
+ message: `useEffect() found in infer mode \u2014 component will be treated as an opaque [raw jsx] grammar island.`,
3348
+ line: path.node.loc?.start.line,
3349
+ column: path.node.loc?.start.column,
3350
+ severity: "warning"
3351
+ };
3352
+ if (!compilerState.warnings) compilerState.warnings = [];
3353
+ compilerState.warnings.push(warning);
3354
+ return;
3355
+ }
3356
+ switch (hookName) {
3357
+ case "useState":
3358
+ extractStates(path, state);
3359
+ break;
3360
+ case "useOnEnter":
3361
+ case "useOnExit":
3362
+ extractEffects(path, state);
3363
+ break;
3364
+ case "useTransition":
3365
+ extractTransitions(path, state);
3366
+ break;
3367
+ case "useOnEvent":
3368
+ extractEvents(path, state);
3369
+ break;
3370
+ case "useWhileIn":
3371
+ extractDuring(path, state);
3372
+ break;
3373
+ case "useOnChange":
3374
+ extractChangeWatcher(path, state);
3375
+ break;
3376
+ case "useOnTransition":
3377
+ extractTransitionEffect(path, state);
3378
+ break;
3379
+ case "useQuery":
3380
+ extractQueryDataSource(path, state);
3381
+ break;
3382
+ case "useMutation":
3383
+ extractMutationDataSource(path, state);
3384
+ break;
3385
+ }
3386
+ },
3387
+ // Strict mode: validate imports
3388
+ ImportDeclaration(path, state) {
3389
+ if (mode !== "strict") return;
3390
+ const compilerState = state;
3391
+ const source = path.node.source.value;
3392
+ if (source.startsWith("@mindmatrix/") || source === "react" || source.startsWith("react/") || source.startsWith(".") || source.startsWith("/")) {
3393
+ return;
3394
+ }
3395
+ const error = {
3396
+ code: "STRICT_FORBIDDEN_IMPORT",
3397
+ message: `Import from '${source}' is not allowed in strict mode. Only @mindmatrix/* and relative imports are permitted.`,
3398
+ line: path.node.loc?.start.line,
3399
+ column: path.node.loc?.start.column,
3400
+ severity: "error"
3401
+ };
3402
+ if (!compilerState.errors) compilerState.errors = [];
3403
+ compilerState.errors.push(error);
3404
+ },
3405
+ // Track derived/computed variable declarations for expression inlining.
3406
+ //
3407
+ // Three cases:
3408
+ // 1. `const hasContent = expr` → registerDerivedVar (inline the expression)
3409
+ // 2. `const users = useQuery(...)` → registerDerivedVar as $instance.{slug}
3410
+ // (data source results are available on $instance by their slug)
3411
+ // 3. `const sendMsg = useMutation(...)` → registerDerivedVar as $action.transition
3412
+ // (mutation results are action callbacks)
3413
+ // 4. `const memo = useMemo(() => expr, [])` → registerDerivedVar with body expr
3414
+ VariableDeclarator(path, state) {
3415
+ const compilerState = state;
3416
+ if (!compilerState.metadata) return;
3417
+ const id = path.node.id;
3418
+ const init = path.node.init;
3419
+ if (t13.isArrayPattern(id)) return;
3420
+ if (!t13.isIdentifier(id) || !init || !t13.isExpression(init)) return;
3421
+ const parentFn = path.getFunctionParent();
3422
+ if (!parentFn) return;
3423
+ const parentNode = parentFn.parentPath;
3424
+ const isExportedDirectly = parentNode?.isExportDefaultDeclaration() || parentNode?.isExportNamedDeclaration();
3425
+ let isExportedByName = false;
3426
+ if (!isExportedDirectly && parentNode?.isVariableDeclarator()) {
3427
+ const varId = parentNode.node.id;
3428
+ if (t13.isIdentifier(varId)) {
3429
+ isExportedByName = varId.name === compilerState.metadata?.name;
3430
+ }
3431
+ }
3432
+ if (!isExportedDirectly && !isExportedByName) return;
3433
+ if (t13.isCallExpression(init) && t13.isIdentifier(init.callee)) {
3434
+ const callee = init.callee.name;
3435
+ if (callee === "useQuery") {
3436
+ registerDerivedVar(id.name, t13.optionalMemberExpression(
3437
+ t13.identifier("$instance"),
3438
+ t13.identifier(id.name),
3439
+ false,
3440
+ // computed
3441
+ true
3442
+ // optional
3443
+ ));
3444
+ return;
3445
+ }
3446
+ if (callee === "useMutation") {
3447
+ registerDerivedVar(id.name, t13.memberExpression(
3448
+ t13.identifier("$action"),
3449
+ t13.identifier("transition")
3450
+ ));
3451
+ return;
3452
+ }
3453
+ if (callee === "useMemo" && init.arguments.length >= 1) {
3454
+ const callback = init.arguments[0];
3455
+ if (t13.isArrowFunctionExpression(callback)) {
3456
+ if (t13.isExpression(callback.body)) {
3457
+ registerDerivedVar(id.name, callback.body);
3458
+ } else if (t13.isBlockStatement(callback.body)) {
3459
+ const retStmt = callback.body.body.find((s) => t13.isReturnStatement(s));
3460
+ if (retStmt?.argument && t13.isExpression(retStmt.argument)) {
3461
+ registerDerivedVar(id.name, retStmt.argument);
3462
+ }
3463
+ }
3464
+ }
3465
+ return;
3466
+ }
3467
+ if (callee.startsWith("use")) return;
3468
+ }
3469
+ registerDerivedVar(id.name, init);
3470
+ },
3471
+ // Extract JSX from function component return.
3472
+ // Only extract from the exported component function's direct return,
3473
+ // not from nested callbacks (Each render functions, helper components, etc.).
3474
+ ReturnStatement(path, state) {
3475
+ if (!t13.isJSXElement(path.node.argument) && !t13.isJSXFragment(path.node.argument)) return;
3476
+ const parentFn = path.getFunctionParent();
3477
+ if (!parentFn) return;
3478
+ const parentNode = parentFn.parentPath;
3479
+ const isExportedDirectly = parentNode?.isExportDefaultDeclaration() || parentNode?.isExportNamedDeclaration();
3480
+ let isExportedByName = false;
3481
+ if (!isExportedDirectly && parentNode?.isVariableDeclarator()) {
3482
+ const varId = parentNode.node.id;
3483
+ if (t13.isIdentifier(varId)) {
3484
+ isExportedByName = varId.name === state.metadata?.name;
3485
+ }
3486
+ }
3487
+ if (isExportedDirectly || isExportedByName) {
3488
+ extractComponents(path, state);
3489
+ }
3490
+ }
3491
+ };
3492
+ }
3493
+
3494
+ // src/babel/index.ts
3495
+ function babelPlugin(api, options = {}) {
3496
+ api.assertVersion(7);
3497
+ return {
3498
+ name: "mindmatrix-react",
3499
+ visitor: createVisitor(options)
3500
+ };
3501
+ }
3502
+
3503
+ export {
3504
+ extractStates,
3505
+ extractEffects,
3506
+ extractTransitions,
3507
+ extractEvents,
3508
+ extractComponents,
3509
+ emitIR,
3510
+ emitPureForm,
3511
+ emitCanonical,
3512
+ emitCompiledOutput,
3513
+ compilerStateToWorkflow,
3514
+ createVisitor,
3515
+ babelPlugin
3516
+ };