@mmapp/react-compiler 0.1.0-alpha.18 → 0.1.0-alpha.20

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