@reckona/mreact-compiler 0.0.160 → 0.0.162

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 (58) hide show
  1. package/dist/boundary-graph.d.ts +13 -0
  2. package/dist/boundary-graph.d.ts.map +1 -1
  3. package/dist/boundary-graph.js +1 -0
  4. package/dist/boundary-graph.js.map +1 -1
  5. package/dist/compiler-module-context.d.ts +2 -0
  6. package/dist/compiler-module-context.d.ts.map +1 -1
  7. package/dist/compiler-module-context.js +1 -0
  8. package/dist/compiler-module-context.js.map +1 -1
  9. package/dist/diagnostics.d.ts +1 -0
  10. package/dist/diagnostics.d.ts.map +1 -1
  11. package/dist/diagnostics.js +1 -0
  12. package/dist/diagnostics.js.map +1 -1
  13. package/dist/emit-server-stream.d.ts.map +1 -1
  14. package/dist/emit-server-stream.js +70 -4
  15. package/dist/emit-server-stream.js.map +1 -1
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/internal.d.ts +35 -0
  21. package/dist/internal.d.ts.map +1 -1
  22. package/dist/internal.js +24 -15
  23. package/dist/internal.js.map +1 -1
  24. package/dist/ir.d.ts +21 -0
  25. package/dist/ir.d.ts.map +1 -1
  26. package/dist/ir.js.map +1 -1
  27. package/dist/oxc-compat-create-element.d.ts +2 -0
  28. package/dist/oxc-compat-create-element.d.ts.map +1 -1
  29. package/dist/oxc-compat-create-element.js +93 -18
  30. package/dist/oxc-compat-create-element.js.map +1 -1
  31. package/dist/oxc-transform.d.ts +1 -0
  32. package/dist/oxc-transform.d.ts.map +1 -1
  33. package/dist/oxc-transform.js +1 -0
  34. package/dist/oxc-transform.js.map +1 -1
  35. package/dist/oxc.d.ts +4 -0
  36. package/dist/oxc.d.ts.map +1 -1
  37. package/dist/oxc.js +180 -21
  38. package/dist/oxc.js.map +1 -1
  39. package/dist/transform.d.ts +2 -0
  40. package/dist/transform.d.ts.map +1 -1
  41. package/dist/transform.js +2 -0
  42. package/dist/transform.js.map +1 -1
  43. package/dist/types.d.ts +20 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js.map +1 -1
  46. package/package.json +2 -2
  47. package/src/boundary-graph.ts +13 -0
  48. package/src/compiler-module-context.ts +2 -0
  49. package/src/diagnostics.ts +1 -0
  50. package/src/emit-server-stream.ts +103 -8
  51. package/src/index.ts +2 -0
  52. package/src/internal.ts +35 -15
  53. package/src/ir.ts +21 -0
  54. package/src/oxc-compat-create-element.ts +132 -25
  55. package/src/oxc-transform.ts +1 -0
  56. package/src/oxc.ts +330 -12
  57. package/src/transform.ts +2 -0
  58. package/src/types.ts +34 -0
package/src/oxc.ts CHANGED
@@ -71,8 +71,10 @@ import {
71
71
  type OxcChildAnalysisContext,
72
72
  } from "./oxc-child-analysis.js";
73
73
  import {
74
+ analyzeCompatCreateElementFunctionRoot,
74
75
  analyzeCompatCreateElementRoot,
75
76
  collectCompatCreateElementNames,
77
+ collectCompatRenderToStringNames,
76
78
  collectFunctionShadowedNames,
77
79
  hasLowerableCompatCreateElementReturn,
78
80
  } from "./oxc-compat-create-element.js";
@@ -95,6 +97,7 @@ import {
95
97
  import { containsRawJsxInIr } from "./oxc-raw-jsx.js";
96
98
  import type { AnalyzeModuleOptions, CompileTarget, Diagnostic } from "./types.js";
97
99
 
100
+ /** Reports OXC analysis parity data used by compiler migration and diagnostics tests. */
98
101
  export interface OxcParityResult {
99
102
  matches: boolean;
100
103
  oxc: {
@@ -151,6 +154,7 @@ function createOxcChildAnalysisContext(
151
154
  };
152
155
  }
153
156
 
157
+ /** Compares OXC component discovery and IR output against parity expectations for one module. */
154
158
  export function analyzeOxcParity(input: AnalyzeToIrInput): OxcParityResult {
155
159
  const oxc = parseSync(input.filename, input.code, {
156
160
  lang: "tsx",
@@ -182,6 +186,7 @@ export function analyzeOxcParity(input: AnalyzeToIrInput): OxcParityResult {
182
186
  };
183
187
  }
184
188
 
189
+ /** Analyzes source code into compiler IR using OXC parsing and lowering. */
185
190
  export function analyzeWithOxc(input: AnalyzeToIrInput): AnalyzeToIrOutput {
186
191
  return analyzeCompilerModuleContextWithOxc(createCompilerModuleContextWithOxc(input), {
187
192
  target: input.target,
@@ -189,6 +194,7 @@ export function analyzeWithOxc(input: AnalyzeToIrInput): AnalyzeToIrOutput {
189
194
  });
190
195
  }
191
196
 
197
+ /** Analyzes a cached OXC compiler module context into compiler IR. */
192
198
  export function analyzeCompilerModuleContextWithOxc(
193
199
  context: CompilerModuleContext,
194
200
  input: Omit<AnalyzeToIrInput, "code" | "filename">,
@@ -245,11 +251,23 @@ function analyzeOxcToIr(
245
251
  : undefined;
246
252
  const localJsxReturnFunctionNames =
247
253
  target === "server" ? collectOxcLocalJsxReturnFunctionNames(program) : new Set<string>();
248
- // Stream emit keeps interpreting compat trees for now; only the string
249
- // pipeline lowers createElement calls.
250
254
  const compatCreateElementNames =
251
- target === "server" && options?.serverOutput !== "stream"
252
- ? collectCompatCreateElementNames(program)
255
+ target === "server" ? collectCompatCreateElementNames(program) : new Set<string>();
256
+ const compatRenderToStringNames =
257
+ target === "server" ? collectCompatRenderToStringNames(program) : new Set<string>();
258
+ const compatCreateElementLocalFunctionLikes =
259
+ target === "server"
260
+ ? collectCompatCreateElementLocalFunctionLikes(program)
261
+ : new Map<string, Record<string, unknown>>();
262
+ const compatRenderToStringLowerableTargets =
263
+ target === "server"
264
+ ? collectCompatRenderToStringLowerableTargets(
265
+ code,
266
+ body,
267
+ compatCreateElementNames,
268
+ compatRenderToStringNames,
269
+ compatCreateElementLocalFunctionLikes,
270
+ )
253
271
  : new Set<string>();
254
272
  const localJsxHelperHtmlParameters =
255
273
  target === "server"
@@ -277,7 +295,15 @@ function analyzeOxcToIr(
277
295
 
278
296
  if (
279
297
  isOxcJsxComponentStatement(statement, localJsxReturnFunctionNames) ||
280
- isCompatCreateElementComponentStatement(code, statement, compatCreateElementNames) ||
298
+ isCompatCreateElementComponentStatement(
299
+ code,
300
+ statement,
301
+ compatCreateElementNames,
302
+ compatRenderToStringNames,
303
+ compatCreateElementLocalFunctionLikes,
304
+ compatRenderToStringLowerableTargets,
305
+ options?.serverOutput,
306
+ ) ||
281
307
  (options?.compatReactNodeReturn === true && isOxcExportedFunctionLike(statement))
282
308
  ) {
283
309
  const declaration = readObject(readObject(statement).declaration);
@@ -342,6 +368,9 @@ function analyzeOxcToIr(
342
368
  diagnostics,
343
369
  options?.bodyStatementJsx ?? "dom-node",
344
370
  compatCreateElementNames,
371
+ compatRenderToStringNames,
372
+ compatCreateElementLocalFunctionLikes,
373
+ compatRenderToStringLowerableTargets,
345
374
  moduleRenderValueBindings,
346
375
  options?.compatReactNodeReturn === true,
347
376
  options?.serverOutput,
@@ -553,32 +582,292 @@ function readCompatCreateElementPlainComponent(
553
582
  return undefined;
554
583
  }
555
584
 
585
+ function collectCompatCreateElementLocalFunctionLikes(
586
+ program: unknown,
587
+ ): Map<string, Record<string, unknown>> {
588
+ const functionLikes = new Map<string, Record<string, unknown>>();
589
+
590
+ for (const statement of readArray(readObject(program).body)) {
591
+ const object = readObject(statement);
592
+ const declaration =
593
+ object.type === "ExportNamedDeclaration" ? readObject(object.declaration) : object;
594
+
595
+ if (declaration.type === "FunctionDeclaration") {
596
+ const id = readObject(declaration.id);
597
+
598
+ if (typeof id.name === "string") {
599
+ functionLikes.set(id.name, declaration);
600
+ }
601
+ continue;
602
+ }
603
+
604
+ if (declaration.type !== "VariableDeclaration") {
605
+ continue;
606
+ }
607
+
608
+ for (const declarator of readArray(declaration.declarations)) {
609
+ const declaratorObject = readObject(declarator);
610
+ const id = readObject(declaratorObject.id);
611
+ const initializer = unwrapOxcComponentFunctionLikeInitializer(
612
+ readObject(declaratorObject.init),
613
+ );
614
+
615
+ if (typeof id.name === "string" && initializer !== undefined) {
616
+ functionLikes.set(id.name, initializer);
617
+ }
618
+ }
619
+ }
620
+
621
+ return functionLikes;
622
+ }
623
+
624
+ function collectCompatRenderToStringLowerableTargets(
625
+ code: string,
626
+ body: readonly unknown[],
627
+ createElementNames: ReadonlySet<string>,
628
+ renderToStringNames: ReadonlySet<string>,
629
+ localFunctionLikes: ReadonlyMap<string, Record<string, unknown>>,
630
+ ): Set<string> {
631
+ const targets = new Set<string>();
632
+
633
+ if (createElementNames.size === 0 || renderToStringNames.size === 0) {
634
+ return targets;
635
+ }
636
+
637
+ for (const statement of body) {
638
+ const functionLike = unwrapOxcStatementFunctionLike(statement);
639
+
640
+ if (functionLike === undefined) {
641
+ continue;
642
+ }
643
+
644
+ const targetName = readCompatRenderToStringWrapperTargetName(
645
+ code,
646
+ functionLike,
647
+ renderToStringNames,
648
+ );
649
+ const targetFunctionLike =
650
+ targetName === undefined ? undefined : localFunctionLikes.get(targetName);
651
+
652
+ if (
653
+ targetName !== undefined &&
654
+ targetFunctionLike !== undefined &&
655
+ analyzeCompatCreateElementFunctionRoot(code, targetFunctionLike, createElementNames) !==
656
+ undefined
657
+ ) {
658
+ targets.add(targetName);
659
+ }
660
+ }
661
+
662
+ return targets;
663
+ }
664
+
665
+ function unwrapOxcStatementFunctionLike(statement: unknown): Record<string, unknown> | undefined {
666
+ const object = readObject(statement);
667
+ const declaration =
668
+ object.type === "ExportNamedDeclaration" || object.type === "ExportDefaultDeclaration"
669
+ ? readObject(object.declaration)
670
+ : object;
671
+
672
+ if (declaration.type === "FunctionDeclaration") {
673
+ return declaration;
674
+ }
675
+
676
+ if (declaration.type !== "VariableDeclaration") {
677
+ return unwrapOxcComponentFunctionLikeInitializer(declaration);
678
+ }
679
+
680
+ for (const declarator of readArray(declaration.declarations)) {
681
+ const initializer = unwrapOxcComponentFunctionLikeInitializer(
682
+ readObject(readObject(declarator).init),
683
+ );
684
+
685
+ if (initializer !== undefined) {
686
+ return initializer;
687
+ }
688
+ }
689
+
690
+ return undefined;
691
+ }
692
+
693
+ function readCompatRenderToStringWrapperTargetName(
694
+ code: string,
695
+ functionLike: Record<string, unknown>,
696
+ renderToStringNames: ReadonlySet<string>,
697
+ ): string | undefined {
698
+ const expression = readCompatRenderToStringWrapperReturnExpression(functionLike);
699
+
700
+ if (expression === undefined) {
701
+ return undefined;
702
+ }
703
+
704
+ return readCompatRenderToStringTargetName(
705
+ expression,
706
+ renderToStringNames,
707
+ collectFunctionShadowedNames(functionLike, renderToStringNames),
708
+ );
709
+ }
710
+
711
+ function readCompatRenderToStringWrapperReturnExpression(
712
+ functionLike: Record<string, unknown>,
713
+ ): Record<string, unknown> | undefined {
714
+ const body = unwrapOxcParentheses(readObject(functionLike.body));
715
+
716
+ if (body.type !== "BlockStatement") {
717
+ return body;
718
+ }
719
+
720
+ for (const statement of readArray(body.body)) {
721
+ const statementObject = readObject(statement);
722
+
723
+ if (statementObject.type === "ReturnStatement") {
724
+ return unwrapOxcParentheses(readObject(statementObject.argument));
725
+ }
726
+ }
727
+
728
+ return undefined;
729
+ }
730
+
731
+ function readCompatRenderToStringTargetName(
732
+ expression: Record<string, unknown>,
733
+ renderToStringNames: ReadonlySet<string>,
734
+ shadowedNames: ReadonlySet<string>,
735
+ ): string | undefined {
736
+ if (
737
+ renderToStringNames.size === 0 ||
738
+ expression.type !== "CallExpression" ||
739
+ expression.optional === true
740
+ ) {
741
+ return undefined;
742
+ }
743
+
744
+ const callee = unwrapOxcParentheses(readObject(expression.callee));
745
+
746
+ if (
747
+ callee.type !== "Identifier" ||
748
+ typeof callee.name !== "string" ||
749
+ !renderToStringNames.has(callee.name) ||
750
+ shadowedNames.has(callee.name)
751
+ ) {
752
+ return undefined;
753
+ }
754
+
755
+ const args = readArray(expression.arguments);
756
+
757
+ if (args.length !== 1) {
758
+ return undefined;
759
+ }
760
+
761
+ const target = unwrapOxcParentheses(readObject(args[0]));
762
+
763
+ return target.type === "Identifier" && typeof target.name === "string" ? target.name : undefined;
764
+ }
765
+
766
+ function hasCompatRenderToStringWrapperReturn(
767
+ code: string,
768
+ functionLike: Record<string, unknown>,
769
+ renderToStringNames: ReadonlySet<string>,
770
+ ): boolean {
771
+ return (
772
+ readCompatRenderToStringWrapperTargetName(code, functionLike, renderToStringNames) !== undefined
773
+ );
774
+ }
775
+
776
+ function analyzeCompatRenderToStringWrapperRoot(
777
+ code: string,
778
+ functionLike: Record<string, unknown>,
779
+ returnExpression: Record<string, unknown>,
780
+ createElementNames: ReadonlySet<string>,
781
+ renderToStringNames: ReadonlySet<string>,
782
+ localFunctionLikes: ReadonlyMap<string, Record<string, unknown>>,
783
+ ): ComponentIr["root"] | undefined {
784
+ const targetName = readCompatRenderToStringTargetName(
785
+ returnExpression,
786
+ renderToStringNames,
787
+ collectFunctionShadowedNames(functionLike, renderToStringNames),
788
+ );
789
+
790
+ if (targetName === undefined) {
791
+ return undefined;
792
+ }
793
+
794
+ const targetFunctionLike = localFunctionLikes.get(targetName);
795
+ const lowered =
796
+ targetFunctionLike === undefined
797
+ ? undefined
798
+ : analyzeCompatCreateElementFunctionRoot(code, targetFunctionLike, createElementNames);
799
+
800
+ if (lowered !== undefined) {
801
+ return lowered;
802
+ }
803
+
804
+ return {
805
+ kind: "expr",
806
+ code: normalizeOxcExpressionCode(readSource(code, returnExpression)),
807
+ renderMode: "html",
808
+ };
809
+ }
810
+
556
811
  function isCompatCreateElementComponentStatement(
557
812
  code: string,
558
813
  statement: unknown,
559
814
  names: ReadonlySet<string>,
815
+ renderToStringNames: ReadonlySet<string>,
816
+ localFunctionLikes: ReadonlyMap<string, Record<string, unknown>>,
817
+ renderToStringLowerableTargets: ReadonlySet<string>,
818
+ serverOutput?: AnalyzeModuleOptions["serverOutput"],
560
819
  ): boolean {
561
- if (names.size === 0) {
820
+ if (names.size === 0 && renderToStringNames.size === 0) {
562
821
  return false;
563
822
  }
564
823
 
565
824
  const object = readObject(statement);
566
825
 
567
826
  if (object.type === "ExportDefaultDeclaration") {
568
- return readCompatCreateElementFunctionLike(code, readObject(object.declaration), names) !== undefined;
827
+ const functionLike = unwrapOxcComponentFunctionLikeInitializer(readObject(object.declaration));
828
+
829
+ return (
830
+ readCompatCreateElementFunctionLike(code, readObject(object.declaration), names) !==
831
+ undefined ||
832
+ (functionLike !== undefined &&
833
+ hasCompatRenderToStringWrapperReturn(code, functionLike, renderToStringNames))
834
+ );
569
835
  }
570
836
 
571
837
  if (object.type === "ExportNamedDeclaration") {
572
838
  const declaration = readObject(object.declaration);
573
839
 
574
840
  if (declaration.type === "FunctionDeclaration") {
575
- return hasLowerableCompatCreateElementReturn(code, declaration, names);
841
+ return (
842
+ hasLowerableCompatCreateElementReturn(code, declaration, names) ||
843
+ hasCompatRenderToStringWrapperReturn(code, declaration, renderToStringNames)
844
+ );
576
845
  }
577
846
 
578
847
  return readCompatCreateElementPlainComponent(code, declaration, names) !== undefined;
579
848
  }
580
849
 
581
- return readCompatCreateElementPlainComponent(code, statement, names) !== undefined;
850
+ const plainComponent = readCompatCreateElementPlainComponent(code, statement, names);
851
+
852
+ if (serverOutput === "stream") {
853
+ return (
854
+ plainComponent !== undefined &&
855
+ renderToStringLowerableTargets.has(plainComponent.name) &&
856
+ localFunctionLikes.get(plainComponent.name) === plainComponent.initializer
857
+ );
858
+ }
859
+
860
+ if (plainComponent !== undefined) {
861
+ return true;
862
+ }
863
+
864
+ const functionLike = unwrapOxcStatementFunctionLike(statement);
865
+
866
+ if (functionLike === undefined) {
867
+ return false;
868
+ }
869
+
870
+ return hasCompatRenderToStringWrapperReturn(code, functionLike, renderToStringNames);
582
871
  }
583
872
 
584
873
  function analyzeOxcComponent(
@@ -589,6 +878,9 @@ function analyzeOxcComponent(
589
878
  diagnostics: Diagnostic[],
590
879
  bodyStatementJsx: OxcBodyStatementJsxMode,
591
880
  compatCreateElementNames: ReadonlySet<string>,
881
+ compatRenderToStringNames: ReadonlySet<string>,
882
+ compatCreateElementLocalFunctionLikes: ReadonlyMap<string, Record<string, unknown>>,
883
+ compatRenderToStringLowerableTargets: ReadonlySet<string>,
592
884
  moduleRenderValueBindings: Set<string>,
593
885
  compatReactNodeReturn: boolean,
594
886
  serverOutput: AnalyzeModuleOptions["serverOutput"],
@@ -606,7 +898,8 @@ function analyzeOxcComponent(
606
898
  if (
607
899
  declaration === undefined ||
608
900
  (!hasOxcFunctionLikeComponentReturn(declaration) &&
609
- !hasLowerableCompatCreateElementReturn(code, declaration, compatCreateElementNames))
901
+ !hasLowerableCompatCreateElementReturn(code, declaration, compatCreateElementNames) &&
902
+ !hasCompatRenderToStringWrapperReturn(code, declaration, compatRenderToStringNames))
610
903
  ) {
611
904
  return [];
612
905
  }
@@ -624,6 +917,8 @@ function analyzeOxcComponent(
624
917
  diagnostics,
625
918
  bodyStatementJsx,
626
919
  compatCreateElementNames,
920
+ compatRenderToStringNames,
921
+ compatCreateElementLocalFunctionLikes,
627
922
  moduleRenderValueBindings,
628
923
  compatReactNodeReturn,
629
924
  serverOutput,
@@ -640,12 +935,18 @@ function analyzeOxcComponent(
640
935
  if (object.type !== "ExportNamedDeclaration") {
641
936
  const plainComponent =
642
937
  readOxcPlainComponent(statement) ??
643
- readCompatCreateElementPlainComponent(code, statement, compatCreateElementNames);
938
+ (serverOutput === "stream"
939
+ ? undefined
940
+ : readCompatCreateElementPlainComponent(code, statement, compatCreateElementNames));
644
941
 
645
942
  if (plainComponent === undefined) {
646
943
  return [];
647
944
  }
648
945
 
946
+ if (compatRenderToStringLowerableTargets.has(plainComponent.name)) {
947
+ return [];
948
+ }
949
+
649
950
  return [
650
951
  {
651
952
  ...analyzeOxcFunctionLikeComponent(
@@ -658,6 +959,8 @@ function analyzeOxcComponent(
658
959
  diagnostics,
659
960
  bodyStatementJsx,
660
961
  compatCreateElementNames,
962
+ compatRenderToStringNames,
963
+ compatCreateElementLocalFunctionLikes,
661
964
  moduleRenderValueBindings,
662
965
  compatReactNodeReturn,
663
966
  serverOutput,
@@ -694,6 +997,8 @@ function analyzeOxcComponent(
694
997
  diagnostics,
695
998
  bodyStatementJsx,
696
999
  compatCreateElementNames,
1000
+ compatRenderToStringNames,
1001
+ compatCreateElementLocalFunctionLikes,
697
1002
  moduleRenderValueBindings,
698
1003
  compatReactNodeReturn,
699
1004
  serverOutput,
@@ -711,7 +1016,8 @@ function analyzeOxcComponent(
711
1016
  (!compatReactNodeReturn &&
712
1017
  !hasComponentReturn(declaration.body) &&
713
1018
  !hasLocalJsxHelperCallReturn(declaration.body, localJsxReturnFunctionNames) &&
714
- !hasLowerableCompatCreateElementReturn(code, declaration, compatCreateElementNames))
1019
+ !hasLowerableCompatCreateElementReturn(code, declaration, compatCreateElementNames) &&
1020
+ !hasCompatRenderToStringWrapperReturn(code, declaration, compatRenderToStringNames))
715
1021
  ) {
716
1022
  return [];
717
1023
  }
@@ -733,6 +1039,8 @@ function analyzeOxcComponent(
733
1039
  diagnostics,
734
1040
  bodyStatementJsx,
735
1041
  compatCreateElementNames,
1042
+ compatRenderToStringNames,
1043
+ compatCreateElementLocalFunctionLikes,
736
1044
  moduleRenderValueBindings,
737
1045
  compatReactNodeReturn,
738
1046
  serverOutput,
@@ -783,6 +1091,8 @@ function analyzeOxcFunctionLikeComponent(
783
1091
  diagnostics: Diagnostic[],
784
1092
  bodyStatementJsx: OxcBodyStatementJsxMode,
785
1093
  compatCreateElementNames: ReadonlySet<string>,
1094
+ compatRenderToStringNames: ReadonlySet<string>,
1095
+ compatCreateElementLocalFunctionLikes: ReadonlyMap<string, Record<string, unknown>>,
786
1096
  moduleRenderValueBindings: Set<string>,
787
1097
  compatReactNodeReturn: boolean,
788
1098
  serverOutput: AnalyzeModuleOptions["serverOutput"],
@@ -869,6 +1179,14 @@ function analyzeOxcFunctionLikeComponent(
869
1179
  names: compatCreateElementNames,
870
1180
  shadowed: collectFunctionShadowedNames(functionLike, compatCreateElementNames),
871
1181
  })) ??
1182
+ analyzeCompatRenderToStringWrapperRoot(
1183
+ code,
1184
+ functionLike,
1185
+ returnExpression,
1186
+ compatCreateElementNames,
1187
+ compatRenderToStringNames,
1188
+ compatCreateElementLocalFunctionLikes,
1189
+ ) ??
872
1190
  (isJsxRoot(returnExpression.type) || returnExpression.type === "JSXFragment"
873
1191
  ? analyzeOxcJsxNode(code, returnExpression, childAnalysisContext)
874
1192
  : isOxcComponentCallExpression(returnExpression)
package/src/transform.ts CHANGED
@@ -15,6 +15,7 @@ import type {
15
15
  TransformOutput,
16
16
  } from "./types.js";
17
17
 
18
+ /** Compiles one mreact source module into client or server JavaScript output. */
18
19
  export function transform(input: TransformInput): TransformOutput {
19
20
  return transformWithAnalyzer(input, (analyzeTarget, analyzeOptions) =>
20
21
  analyzeWithOxc({
@@ -26,6 +27,7 @@ export function transform(input: TransformInput): TransformOutput {
26
27
  );
27
28
  }
28
29
 
30
+ /** Compiles a pre-parsed compiler module context into client or server JavaScript output. */
29
31
  export function transformCompilerModuleContext(
30
32
  input: TransformInput & { moduleContext: CompilerModuleContext },
31
33
  ): TransformOutput {
package/src/types.ts CHANGED
@@ -15,14 +15,25 @@ import type {
15
15
  TransformOutput as SharedTransformOutput,
16
16
  } from "@reckona/mreact-shared/compiler-contract";
17
17
 
18
+ /** Names whether the compiler emits client or server output. */
18
19
  export type CompileTarget = SharedCompileTarget;
20
+
21
+ /** Names the server renderer output format produced by the compiler. */
19
22
  export type ServerOutputMode = SharedServerOutputMode;
23
+
24
+ /** Names how the server renderer should emit bootstrap scripts. */
20
25
  export type ServerBootstrapMode = SharedServerBootstrapMode;
26
+
27
+ /** Names the parser backend used by the compiler. */
21
28
  export type ParserMode = "oxc";
29
+
30
+ /** Names the frontend implementation that produced compiler metadata. */
22
31
  export type CompilerFrontend = SharedCompilerFrontend;
23
32
 
33
+ /** Names how JSX found in component body statements should be lowered. */
24
34
  export type BodyStatementJsxMode = "dom-node" | "compat-object" | "server-string" | "unsupported";
25
35
 
36
+ /** Configures lower-level module analysis before code emission. */
26
37
  export interface AnalyzeModuleOptions {
27
38
  topLevelJsx?: "diagnostic" | "compat-object" | "server-string";
28
39
  bodyStatementJsx?: BodyStatementJsxMode;
@@ -34,6 +45,7 @@ export interface AnalyzeModuleOptions {
34
45
  compatReactNodeReturnRenderMode?: "react-node";
35
46
  }
36
47
 
48
+ /** Configures a single compiler transform call. */
37
49
  export interface TransformInput {
38
50
  code: string;
39
51
  filename: string;
@@ -54,19 +66,41 @@ export interface TransformInput {
54
66
  reactSuspenseRevealScriptSrc?: string;
55
67
  }
56
68
 
69
+ /** Configures imports for the server HTML escape helper emitted by the compiler. */
57
70
  export interface ServerEscapeOptions {
58
71
  batchImportName: string;
59
72
  batchImportSource: string;
60
73
  }
61
74
 
75
+ /** Describes emitted code, source map data, diagnostics, and metadata from a transform. */
62
76
  export type TransformOutput = SharedTransformOutput;
77
+
78
+ /** Describes a compiler diagnostic message. */
63
79
  export type Diagnostic = SharedDiagnostic;
80
+
81
+ /** Describes a suggested fix attached to a compiler diagnostic. */
64
82
  export type DiagnosticSuggestion = SharedDiagnosticSuggestion;
83
+
84
+ /** Describes a one-based source location for diagnostics and metadata. */
65
85
  export type SourceLocation = SharedSourceLocation;
86
+
87
+ /** Describes metadata collected for one transformed module. */
66
88
  export type ModuleMetadata = SharedModuleMetadata;
89
+
90
+ /** Describes compiler frontend metadata for one transformed module. */
67
91
  export type CompilerMetadata = SharedModuleMetadata["compiler"];
92
+
93
+ /** Describes a client boundary reference discovered during compilation. */
68
94
  export type ClientReferenceMetadata = SharedClientReferenceMetadata;
95
+
96
+ /** Describes one compiled component discovered in a module. */
69
97
  export type ComponentMetadata = SharedComponentMetadata;
98
+
99
+ /** Describes a runtime import required by emitted compiler output. */
70
100
  export type RuntimeImport = SharedRuntimeImport;
101
+
102
+ /** Describes event hydration metadata emitted for server-rendered handlers. */
71
103
  export type EventHydrationManifestMetadata = SharedEventHydrationManifestMetadata;
104
+
105
+ /** Describes one event hydration entry in a compiler metadata manifest. */
72
106
  export type EventHydrationEntryMetadata = SharedEventHydrationEntryMetadata;