@reckona/mreact-compiler 0.0.66 → 0.0.68

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 (71) hide show
  1. package/dist/compiler-module-context.js.map +1 -1
  2. package/dist/diagnostics.js.map +1 -1
  3. package/dist/emit-client.js.map +1 -1
  4. package/dist/emit-compat.js.map +1 -1
  5. package/dist/emit-escape-helper.js.map +1 -1
  6. package/dist/emit-server-shared.js.map +1 -1
  7. package/dist/emit-server-stream.js.map +1 -1
  8. package/dist/emit-server.js.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal.js.map +1 -1
  11. package/dist/ir.js.map +1 -1
  12. package/dist/oxc-analysis-types.js.map +1 -1
  13. package/dist/oxc-await-analysis.js.map +1 -1
  14. package/dist/oxc-await-ids.js.map +1 -1
  15. package/dist/oxc-await-validation.js.map +1 -1
  16. package/dist/oxc-bindings.js.map +1 -1
  17. package/dist/oxc-body-lowering.js.map +1 -1
  18. package/dist/oxc-child-analysis.js.map +1 -1
  19. package/dist/oxc-code-utils.js.map +1 -1
  20. package/dist/oxc-component-detection.js.map +1 -1
  21. package/dist/oxc-component-props.js.map +1 -1
  22. package/dist/oxc-component-references.js.map +1 -1
  23. package/dist/oxc-dom-lowering.js.map +1 -1
  24. package/dist/oxc-expression-utils.js.map +1 -1
  25. package/dist/oxc-jsx-attributes.js.map +1 -1
  26. package/dist/oxc-jsx-text.js.map +1 -1
  27. package/dist/oxc-nested-lowering.js.map +1 -1
  28. package/dist/oxc-node-utils.js.map +1 -1
  29. package/dist/oxc-raw-jsx.js.map +1 -1
  30. package/dist/oxc-render-values.js.map +1 -1
  31. package/dist/oxc-runtime-emit.js.map +1 -1
  32. package/dist/oxc-transform.js.map +1 -1
  33. package/dist/oxc.js.map +1 -1
  34. package/dist/transform.js.map +1 -1
  35. package/dist/types.js.map +1 -1
  36. package/package.json +4 -3
  37. package/src/compiler-module-context.ts +31 -0
  38. package/src/diagnostics.ts +184 -0
  39. package/src/emit-client.ts +837 -0
  40. package/src/emit-compat.ts +567 -0
  41. package/src/emit-escape-helper.ts +45 -0
  42. package/src/emit-server-shared.ts +384 -0
  43. package/src/emit-server-stream.ts +2558 -0
  44. package/src/emit-server.ts +1827 -0
  45. package/src/index.ts +44 -0
  46. package/src/internal.ts +1905 -0
  47. package/src/ir.ts +151 -0
  48. package/src/oxc-analysis-types.ts +5 -0
  49. package/src/oxc-await-analysis.ts +165 -0
  50. package/src/oxc-await-ids.ts +62 -0
  51. package/src/oxc-await-validation.ts +117 -0
  52. package/src/oxc-bindings.ts +70 -0
  53. package/src/oxc-body-lowering.ts +430 -0
  54. package/src/oxc-child-analysis.ts +791 -0
  55. package/src/oxc-code-utils.ts +19 -0
  56. package/src/oxc-component-detection.ts +459 -0
  57. package/src/oxc-component-props.ts +170 -0
  58. package/src/oxc-component-references.ts +613 -0
  59. package/src/oxc-dom-lowering.ts +127 -0
  60. package/src/oxc-expression-utils.ts +42 -0
  61. package/src/oxc-jsx-attributes.ts +110 -0
  62. package/src/oxc-jsx-text.ts +84 -0
  63. package/src/oxc-nested-lowering.ts +319 -0
  64. package/src/oxc-node-utils.ts +65 -0
  65. package/src/oxc-raw-jsx.ts +239 -0
  66. package/src/oxc-render-values.ts +620 -0
  67. package/src/oxc-runtime-emit.ts +212 -0
  68. package/src/oxc-transform.ts +77 -0
  69. package/src/oxc.ts +932 -0
  70. package/src/transform.ts +634 -0
  71. package/src/types.ts +117 -0
@@ -0,0 +1,19 @@
1
+ export function stripOxcGeneratedImports(code: string): string {
2
+ return code
3
+ .split("\n")
4
+ .filter(
5
+ (line) =>
6
+ !/^\s*import\s+\{.*\}\s+from\s+["@']@reckona\/mreact-compat\/jsx-runtime/.test(line),
7
+ )
8
+ .join("\n");
9
+ }
10
+
11
+ export function normalizeOxcExpressionCode(code: string): string {
12
+ return code
13
+ .trim()
14
+ .replace(/;$/, "")
15
+ .replace(/\/\* @__PURE__ \*\/\s*/g, "")
16
+ .replace(/children: \(\(([^()]+)\) =>/g, "children: ($1) =>")
17
+ .replace(/\(\(([^()]+)\) =>/g, "($1) =>")
18
+ .replace(/children: ([A-Za-z_$][\w$.]*)/g, "children: ($1)");
19
+ }
@@ -0,0 +1,459 @@
1
+ import { readArray, readObject, unwrapOxcParentheses } from "./oxc-node-utils.js";
2
+ import type { AnalyzeModuleOptions } from "./types.js";
3
+
4
+ export function collectOxcExportedFunctionNames(program: unknown): string[] {
5
+ return readArray(readObject(program).body).flatMap((statement) => {
6
+ const object = readObject(statement);
7
+
8
+ if (object.type === "ExportDefaultDeclaration") {
9
+ const declaration = unwrapOxcComponentFunctionLikeInitializer(readObject(object.declaration));
10
+ const id = readObject(declaration?.id);
11
+ return [typeof id.name === "string" ? id.name : "DefaultExport"];
12
+ }
13
+
14
+ if (object.type !== "ExportNamedDeclaration") {
15
+ return [];
16
+ }
17
+
18
+ const declaration = readObject(object.declaration);
19
+
20
+ if (declaration.type === "FunctionDeclaration") {
21
+ const id = readObject(declaration.id);
22
+ return typeof id.name === "string" ? [id.name] : [];
23
+ }
24
+
25
+ const variableComponent = readOxcVariableComponentDeclaration(declaration);
26
+ return variableComponent === undefined ? [] : [variableComponent.name];
27
+ });
28
+ }
29
+
30
+ export function collectOxcPlainComponentNames(program: unknown): string[] {
31
+ return readArray(readObject(program).body).flatMap((statement) => {
32
+ const component = readOxcPlainComponent(statement);
33
+ return component === undefined ? [] : [component.name];
34
+ });
35
+ }
36
+
37
+ export function collectOxcExportedComponents(program: unknown): string[] {
38
+ const body = readArray(readObject(program).body);
39
+ const components: string[] = [];
40
+
41
+ for (const statement of body) {
42
+ const object = readObject(statement);
43
+
44
+ if (object.type === "ExportDefaultDeclaration") {
45
+ const declaration = unwrapOxcComponentFunctionLikeInitializer(readObject(object.declaration));
46
+
47
+ if (declaration !== undefined && hasOxcFunctionLikeComponentReturn(declaration)) {
48
+ components.push("default");
49
+ }
50
+ continue;
51
+ }
52
+
53
+ if (object.type !== "ExportNamedDeclaration") {
54
+ continue;
55
+ }
56
+
57
+ const declaration = readObject(object.declaration);
58
+
59
+ if (declaration.type === "FunctionDeclaration" && hasComponentReturn(declaration.body)) {
60
+ const id = readObject(declaration.id);
61
+
62
+ if (typeof id.name === "string") {
63
+ components.push(id.name);
64
+ }
65
+ continue;
66
+ }
67
+
68
+ const variableComponent = readOxcVariableComponentDeclaration(declaration);
69
+
70
+ if (variableComponent !== undefined) {
71
+ components.push(variableComponent.name);
72
+ }
73
+ }
74
+
75
+ return components;
76
+ }
77
+
78
+ export function collectOxcAsyncComponentNames(program: unknown): Set<string> {
79
+ const names = new Set<string>();
80
+ const body = readArray(readObject(program).body);
81
+
82
+ for (const statement of body) {
83
+ const object = readObject(statement);
84
+ const declaration =
85
+ object.type === "ExportDefaultDeclaration" || object.type === "ExportNamedDeclaration"
86
+ ? readObject(object.declaration)
87
+ : object;
88
+ const functionLike =
89
+ declaration.type === "VariableDeclaration"
90
+ ? readOxcVariableComponentDeclaration(declaration)?.initializer
91
+ : unwrapOxcComponentFunctionLikeInitializer(declaration);
92
+
93
+ if (
94
+ functionLike === undefined ||
95
+ functionLike.async !== true ||
96
+ !hasOxcFunctionLikeComponentReturn(functionLike)
97
+ ) {
98
+ continue;
99
+ }
100
+
101
+ if (object.type === "ExportDefaultDeclaration") {
102
+ const id = readObject(functionLike.id);
103
+ names.add(typeof id.name === "string" ? id.name : "DefaultExport");
104
+ continue;
105
+ }
106
+
107
+ const id = readObject(functionLike.id);
108
+
109
+ if (typeof id.name === "string") {
110
+ names.add(id.name);
111
+ }
112
+ }
113
+
114
+ return names;
115
+ }
116
+
117
+ export function isOxcExportedJsxComponent(statement: unknown): boolean {
118
+ const object = readObject(statement);
119
+
120
+ if (object.type === "ExportDefaultDeclaration") {
121
+ const declaration = unwrapOxcComponentFunctionLikeInitializer(readObject(object.declaration));
122
+ return declaration !== undefined && hasOxcFunctionLikeComponentReturn(declaration);
123
+ }
124
+
125
+ if (object.type !== "ExportNamedDeclaration") {
126
+ return false;
127
+ }
128
+
129
+ const declaration = readObject(object.declaration);
130
+ return (
131
+ (declaration.type === "FunctionDeclaration" && hasComponentReturn(declaration.body)) ||
132
+ readOxcVariableComponentDeclaration(declaration) !== undefined
133
+ );
134
+ }
135
+
136
+ export function isOxcJsxComponentStatement(statement: unknown): boolean {
137
+ return isOxcExportedJsxComponent(statement) || readOxcPlainComponent(statement) !== undefined;
138
+ }
139
+
140
+ export function isOxcExportedFunctionLike(statement: unknown): boolean {
141
+ const object = readObject(statement);
142
+
143
+ if (object.type === "ExportDefaultDeclaration") {
144
+ return unwrapOxcComponentFunctionLikeInitializer(readObject(object.declaration)) !== undefined;
145
+ }
146
+
147
+ if (object.type !== "ExportNamedDeclaration") {
148
+ return false;
149
+ }
150
+
151
+ const declaration = readObject(object.declaration);
152
+
153
+ return (
154
+ declaration.type === "FunctionDeclaration" ||
155
+ unwrapOxcComponentFunctionLikeInitializer(declaration) !== undefined
156
+ );
157
+ }
158
+
159
+ export function isOxcUnsupportedExportedFunction(
160
+ statement: unknown,
161
+ options?: AnalyzeModuleOptions,
162
+ ): boolean {
163
+ if (options?.compatReactNodeReturn === true) {
164
+ return false;
165
+ }
166
+
167
+ const object = readObject(statement);
168
+
169
+ if (object.type !== "ExportNamedDeclaration") {
170
+ return false;
171
+ }
172
+
173
+ const declaration = readObject(object.declaration);
174
+ const id = readObject(declaration.id);
175
+
176
+ return (
177
+ declaration.type === "FunctionDeclaration" &&
178
+ typeof id.name === "string" &&
179
+ /^[A-Z]/.test(id.name) &&
180
+ !hasComponentReturn(declaration.body) &&
181
+ !hasOnlyNullReturns(declaration.body)
182
+ );
183
+ }
184
+
185
+ export function readOxcVariableComponentDeclaration(
186
+ declaration: Record<string, unknown>,
187
+ ): { name: string; initializer: Record<string, unknown> } | undefined {
188
+ if (declaration.type !== "VariableDeclaration") {
189
+ return undefined;
190
+ }
191
+
192
+ for (const declarator of readArray(declaration.declarations)) {
193
+ const object = readObject(declarator);
194
+ const id = readObject(object.id);
195
+
196
+ if (typeof id.name !== "string" || !/^[A-Z]/.test(id.name)) {
197
+ continue;
198
+ }
199
+
200
+ const initializer = unwrapOxcComponentFunctionLikeInitializer(readObject(object.init));
201
+
202
+ if (initializer !== undefined && hasOxcFunctionLikeComponentReturn(initializer)) {
203
+ return { name: id.name, initializer };
204
+ }
205
+ }
206
+
207
+ return undefined;
208
+ }
209
+
210
+ export function readOxcPlainComponent(
211
+ statement: unknown,
212
+ ): { name: string; initializer: Record<string, unknown> } | undefined {
213
+ const object = readObject(statement);
214
+
215
+ if (object.type === "FunctionDeclaration" && hasComponentReturn(object.body)) {
216
+ const id = readObject(object.id);
217
+ return typeof id.name === "string" ? { name: id.name, initializer: object } : undefined;
218
+ }
219
+
220
+ return readOxcVariableComponentDeclaration(object);
221
+ }
222
+
223
+ export function unwrapOxcComponentFunctionLikeInitializer(
224
+ expression: Record<string, unknown>,
225
+ ): Record<string, unknown> | undefined {
226
+ const unwrapped = unwrapOxcParentheses(expression);
227
+
228
+ if (
229
+ unwrapped.type === "ArrowFunctionExpression" ||
230
+ unwrapped.type === "FunctionExpression" ||
231
+ unwrapped.type === "FunctionDeclaration"
232
+ ) {
233
+ return unwrapped;
234
+ }
235
+
236
+ if (unwrapped.type !== "CallExpression") {
237
+ return undefined;
238
+ }
239
+
240
+ const callee = readObject(unwrapped.callee);
241
+
242
+ if (callee.type !== "Identifier" || (callee.name !== "memo" && callee.name !== "forwardRef")) {
243
+ return undefined;
244
+ }
245
+
246
+ const firstArg = readObject(readArray(unwrapped.arguments)[0]);
247
+
248
+ return unwrapOxcComponentFunctionLikeInitializer(firstArg);
249
+ }
250
+
251
+ export function hasOxcFunctionLikeJsxReturn(functionLike: Record<string, unknown>): boolean {
252
+ const body = unwrapOxcParentheses(readObject(functionLike.body));
253
+
254
+ if (isOxcJsxReturnExpression(body)) {
255
+ return true;
256
+ }
257
+
258
+ return hasJsxReturn(body);
259
+ }
260
+
261
+ export function hasOxcFunctionLikeComponentReturn(functionLike: Record<string, unknown>): boolean {
262
+ const body = unwrapOxcParentheses(readObject(functionLike.body));
263
+
264
+ if (hasOxcFunctionLikeJsxReturn(functionLike)) {
265
+ return true;
266
+ }
267
+
268
+ if (isOxcComponentCallExpression(body)) {
269
+ return true;
270
+ }
271
+
272
+ return hasComponentCallReturn(body);
273
+ }
274
+
275
+ export function hasJsxReturn(body: unknown): boolean {
276
+ return readArray(readObject(body).body).some((statement) => {
277
+ const object = readObject(statement);
278
+
279
+ if (object.type === "ReturnStatement") {
280
+ return isOxcJsxReturnExpression(readObject(object.argument));
281
+ }
282
+
283
+ return hasNestedJsxReturn(object);
284
+ });
285
+ }
286
+
287
+ export function hasComponentReturn(body: unknown): boolean {
288
+ return hasJsxReturn(body) || hasComponentCallReturn(body);
289
+ }
290
+
291
+ export function hasOnlyNullReturns(body: unknown): boolean {
292
+ const returns = collectReturnArguments(readObject(body));
293
+ return returns.length > 0 && returns.every(isNullReturnArgument);
294
+ }
295
+
296
+ export function hasComponentCallReturn(body: unknown): boolean {
297
+ return readArray(readObject(body).body).some((statement) => {
298
+ const object = readObject(statement);
299
+
300
+ if (object.type === "ReturnStatement") {
301
+ return isOxcComponentCallExpression(unwrapOxcParentheses(readObject(object.argument)));
302
+ }
303
+
304
+ return hasNestedComponentCallReturn(object);
305
+ });
306
+ }
307
+
308
+ function hasNestedJsxReturn(statement: Record<string, unknown>): boolean {
309
+ if (statement.type === "SwitchStatement") {
310
+ return readArray(statement.cases).some((switchCase) =>
311
+ readArray(readObject(switchCase).consequent).some((child) => {
312
+ const object = readObject(child);
313
+ return (
314
+ object.type === "ReturnStatement" &&
315
+ isOxcJsxReturnExpression(readObject(object.argument))
316
+ );
317
+ }),
318
+ );
319
+ }
320
+
321
+ if (statement.type === "IfStatement") {
322
+ return (
323
+ hasJsxReturn({ body: [statement.consequent] }) ||
324
+ hasJsxReturn({ body: [statement.alternate] })
325
+ );
326
+ }
327
+
328
+ if (statement.type === "BlockStatement") {
329
+ return hasJsxReturn(statement);
330
+ }
331
+
332
+ return false;
333
+ }
334
+
335
+ function hasNestedComponentCallReturn(statement: Record<string, unknown>): boolean {
336
+ if (statement.type === "SwitchStatement") {
337
+ return readArray(statement.cases).some((switchCase) =>
338
+ readArray(readObject(switchCase).consequent).some((child) => {
339
+ const object = readObject(child);
340
+ return (
341
+ object.type === "ReturnStatement" &&
342
+ isOxcComponentCallExpression(unwrapOxcParentheses(readObject(object.argument)))
343
+ );
344
+ }),
345
+ );
346
+ }
347
+
348
+ if (statement.type === "IfStatement") {
349
+ return (
350
+ hasComponentCallReturn({ body: [statement.consequent] }) ||
351
+ hasComponentCallReturn({ body: [statement.alternate] })
352
+ );
353
+ }
354
+
355
+ if (statement.type === "BlockStatement") {
356
+ return hasComponentCallReturn(statement);
357
+ }
358
+
359
+ return false;
360
+ }
361
+
362
+ function collectReturnArguments(statement: Record<string, unknown>): Record<string, unknown>[] {
363
+ if (statement.type === "ReturnStatement") {
364
+ return [readObject(statement.argument)];
365
+ }
366
+
367
+ if (statement.type === "BlockStatement") {
368
+ return readArray(statement.body).flatMap((child) => collectReturnArguments(readObject(child)));
369
+ }
370
+
371
+ if (statement.type === "IfStatement") {
372
+ return [
373
+ ...collectReturnArguments(readObject(statement.consequent)),
374
+ ...collectReturnArguments(readObject(statement.alternate)),
375
+ ];
376
+ }
377
+
378
+ if (statement.type === "SwitchStatement") {
379
+ return readArray(statement.cases).flatMap((switchCase) =>
380
+ readArray(readObject(switchCase).consequent).flatMap((child) =>
381
+ collectReturnArguments(readObject(child)),
382
+ ),
383
+ );
384
+ }
385
+
386
+ return [];
387
+ }
388
+
389
+ function isNullReturnArgument(argument: Record<string, unknown>): boolean {
390
+ return (
391
+ argument.type === "NullLiteral" ||
392
+ (argument.type === "Literal" && argument.value === null)
393
+ );
394
+ }
395
+
396
+ export function isOxcComponentCallExpression(expression: Record<string, unknown>): boolean {
397
+ if (expression.type !== "CallExpression") {
398
+ return false;
399
+ }
400
+
401
+ const callee = unwrapOxcParentheses(readObject(expression.callee));
402
+
403
+ if (callee.type === "Identifier") {
404
+ return typeof callee.name === "string" && /^[A-Z]/.test(callee.name);
405
+ }
406
+
407
+ if (callee.type === "MemberExpression") {
408
+ const object = readObject(callee.object);
409
+ const property = readObject(callee.property);
410
+ return (
411
+ object.type === "Identifier" &&
412
+ typeof object.name === "string" &&
413
+ /^[A-Z]/.test(object.name) &&
414
+ property.type === "Identifier" &&
415
+ typeof property.name === "string" &&
416
+ /^[A-Z]/.test(property.name)
417
+ );
418
+ }
419
+
420
+ return false;
421
+ }
422
+
423
+ export function isJsxRoot(type: unknown): boolean {
424
+ return type === "JSXElement" || type === "JSXFragment" || type === "JSXSelfClosingElement";
425
+ }
426
+
427
+ function isOxcJsxReturnExpression(expression: Record<string, unknown>): boolean {
428
+ const unwrapped = unwrapOxcParentheses(expression);
429
+
430
+ if (isJsxRoot(unwrapped.type)) {
431
+ return true;
432
+ }
433
+
434
+ if (unwrapped.type === "LogicalExpression") {
435
+ return (
436
+ unwrapped.operator === "&&" &&
437
+ isOxcJsxReturnBranch(readObject(unwrapped.right))
438
+ );
439
+ }
440
+
441
+ if (unwrapped.type === "ConditionalExpression") {
442
+ return (
443
+ isOxcJsxReturnBranch(readObject(unwrapped.consequent)) &&
444
+ isOxcJsxReturnBranch(readObject(unwrapped.alternate))
445
+ );
446
+ }
447
+
448
+ return false;
449
+ }
450
+
451
+ function isOxcJsxReturnBranch(expression: Record<string, unknown>): boolean {
452
+ const unwrapped = unwrapOxcParentheses(expression);
453
+
454
+ if (unwrapped.type === "Literal" && (unwrapped.value === null || unwrapped.value === false)) {
455
+ return true;
456
+ }
457
+
458
+ return isOxcJsxReturnExpression(unwrapped);
459
+ }
@@ -0,0 +1,170 @@
1
+ import { unsupportedRefAttributeDiagnostic } from "./diagnostics.js";
2
+ import type { ComponentPropIr, JsxNodeIr } from "./ir.js";
3
+ import type { OxcBodyStatementJsxMode } from "./oxc-analysis-types.js";
4
+ import { stripOxcGeneratedImports } from "./oxc-code-utils.js";
5
+ import {
6
+ getOxcLocation,
7
+ readArray,
8
+ readObject,
9
+ readSource,
10
+ unwrapOxcParentheses,
11
+ } from "./oxc-node-utils.js";
12
+ import { containsOxcJsxSyntax } from "./oxc-render-values.js";
13
+ import { transformJsxWithOxc } from "./oxc-transform.js";
14
+ import type { Diagnostic } from "./types.js";
15
+
16
+ export type AnalyzeOxcJsxNodeCallback = (
17
+ node: Record<string, unknown>,
18
+ bodyStatementJsx?: OxcBodyStatementJsxMode,
19
+ ) => JsxNodeIr;
20
+
21
+ export function analyzeOxcComponentProp(
22
+ code: string,
23
+ attr: unknown,
24
+ analyzeJsxNode: AnalyzeOxcJsxNodeCallback,
25
+ diagnostics: Pick<Diagnostic, "level" | "code" | "message" | "loc">[] = [],
26
+ options: {
27
+ allowRef?: boolean;
28
+ resolveExpressionCode?: (expression: Record<string, unknown>) => string;
29
+ } = {},
30
+ ): ComponentPropIr[] {
31
+ const object = readObject(attr);
32
+
33
+ if (object.type === "JSXSpreadAttribute") {
34
+ return [{ kind: "spread-prop", code: readSource(code, readObject(object.argument)) }];
35
+ }
36
+
37
+ if (object.type !== "JSXAttribute") {
38
+ return [];
39
+ }
40
+
41
+ const name = String(readObject(object.name).name);
42
+ const value = readObject(object.value);
43
+
44
+ if (name === "ref" && options.allowRef !== true) {
45
+ diagnostics.push(unsupportedRefAttributeDiagnostic(getOxcLocation(code, object.name)));
46
+ }
47
+
48
+ if (value.type === "Literal") {
49
+ return [{ kind: "prop", name, code: JSON.stringify(value.value) }];
50
+ }
51
+
52
+ if (value.type === "JSXExpressionContainer") {
53
+ const expression = unwrapOxcParentheses(readObject(value.expression));
54
+
55
+ if (expression.type === "JSXElement" || expression.type === "JSXFragment") {
56
+ return [
57
+ {
58
+ kind: "render-prop",
59
+ name,
60
+ children: [analyzeJsxNode(expression)],
61
+ },
62
+ ];
63
+ }
64
+
65
+ return [
66
+ {
67
+ kind: "prop",
68
+ name,
69
+ code:
70
+ expression.type === "ArrowFunctionExpression" && containsOxcJsxSyntax(expression)
71
+ ? stripOxcGeneratedImports(transformJsxWithOxc(readSource(code, expression)))
72
+ : (options.resolveExpressionCode?.(expression) ?? readSource(code, expression)),
73
+ },
74
+ ];
75
+ }
76
+
77
+ return [{ kind: "prop", name, code: "true" }];
78
+ }
79
+
80
+ export function readOxcConsumerRenderProp(
81
+ code: string,
82
+ children: readonly unknown[],
83
+ analyzeJsxNode: AnalyzeOxcJsxNodeCallback,
84
+ bodyStatementJsx?: OxcBodyStatementJsxMode,
85
+ ): ComponentPropIr | undefined {
86
+ for (const child of children) {
87
+ const object = readObject(child);
88
+
89
+ if (object.type !== "JSXExpressionContainer") {
90
+ continue;
91
+ }
92
+
93
+ const expression = unwrapOxcParentheses(readObject(object.expression));
94
+
95
+ if (expression.type !== "ArrowFunctionExpression") {
96
+ continue;
97
+ }
98
+
99
+ const renderer = analyzeOxcArrowJsxRenderer(
100
+ code,
101
+ expression,
102
+ analyzeJsxNode,
103
+ bodyStatementJsx,
104
+ );
105
+
106
+ return {
107
+ kind: "render-prop",
108
+ name: "children",
109
+ valueName: renderer.valueName,
110
+ children: renderer.children,
111
+ };
112
+ }
113
+
114
+ return undefined;
115
+ }
116
+
117
+ export function analyzeOxcSingleArrowJsxChild(
118
+ code: string,
119
+ children: readonly unknown[],
120
+ analyzeJsxNode: AnalyzeOxcJsxNodeCallback,
121
+ bodyStatementJsx?: OxcBodyStatementJsxMode,
122
+ ): {
123
+ valueName: string;
124
+ children: JsxNodeIr[];
125
+ } {
126
+ for (const child of children) {
127
+ const object = readObject(child);
128
+
129
+ if (object.type !== "JSXExpressionContainer") {
130
+ continue;
131
+ }
132
+
133
+ const expression = unwrapOxcParentheses(readObject(object.expression));
134
+
135
+ if (expression.type === "ArrowFunctionExpression") {
136
+ return analyzeOxcArrowJsxRenderer(code, expression, analyzeJsxNode, bodyStatementJsx);
137
+ }
138
+ }
139
+
140
+ return {
141
+ valueName: "_value",
142
+ children: [],
143
+ };
144
+ }
145
+
146
+ export function analyzeOxcArrowJsxRenderer(
147
+ code: string,
148
+ arrow: Record<string, unknown>,
149
+ analyzeJsxNode: AnalyzeOxcJsxNodeCallback,
150
+ bodyStatementJsx?: OxcBodyStatementJsxMode,
151
+ ): {
152
+ valueName: string;
153
+ children: JsxNodeIr[];
154
+ } {
155
+ const firstParameter = readObject(readArray(arrow.params)[0]);
156
+ const valueName = typeof firstParameter.name === "string" ? firstParameter.name : "_value";
157
+ const body = unwrapOxcParentheses(readObject(arrow.body));
158
+
159
+ if (body.type === "JSXElement" || body.type === "JSXFragment") {
160
+ return {
161
+ valueName,
162
+ children: [analyzeJsxNode(body, bodyStatementJsx)],
163
+ };
164
+ }
165
+
166
+ return {
167
+ valueName,
168
+ children: [{ kind: "expr", code: readSource(code, body) }],
169
+ };
170
+ }