@alloy-js/csharp 0.18.0-dev.2 → 0.18.0-dev.21

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 (158) hide show
  1. package/LICENSE +7 -0
  2. package/dist/src/components/ClassDeclaration.d.ts +74 -0
  3. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  4. package/dist/src/components/{Class.js → ClassDeclaration.js} +64 -38
  5. package/dist/src/components/ClassMethod.d.ts +26 -5
  6. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  7. package/dist/src/components/ClassMethod.js +27 -9
  8. package/dist/src/components/EnumDeclaration.d.ts +34 -0
  9. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  10. package/dist/src/components/{Enum.js → EnumDeclaration.js} +25 -5
  11. package/dist/src/components/doc/comment.d.ts +70 -0
  12. package/dist/src/components/doc/comment.d.ts.map +1 -0
  13. package/dist/src/components/doc/comment.js +88 -0
  14. package/dist/src/components/doc/comment.test.d.ts +2 -0
  15. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  16. package/dist/src/components/doc/comment.test.js +348 -0
  17. package/dist/src/components/doc/from-markdown.d.ts +6 -0
  18. package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
  19. package/dist/src/components/doc/from-markdown.js +58 -0
  20. package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
  21. package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
  22. package/dist/src/components/doc/from-markdown.test.js +83 -0
  23. package/dist/src/components/index.d.ts +13 -4
  24. package/dist/src/components/index.d.ts.map +1 -1
  25. package/dist/src/components/index.js +14 -5
  26. package/dist/src/components/interface/declaration.d.ts +47 -0
  27. package/dist/src/components/interface/declaration.d.ts.map +1 -0
  28. package/dist/src/components/interface/declaration.js +77 -0
  29. package/dist/src/components/interface/declaration.test.d.ts +2 -0
  30. package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
  31. package/dist/src/components/interface/declaration.test.js +153 -0
  32. package/dist/src/components/interface/method.d.ts +32 -0
  33. package/dist/src/components/interface/method.d.ts.map +1 -0
  34. package/dist/src/components/interface/method.js +68 -0
  35. package/dist/src/components/interface/method.test.d.ts +2 -0
  36. package/dist/src/components/interface/method.test.d.ts.map +1 -0
  37. package/dist/src/components/interface/method.test.js +279 -0
  38. package/dist/src/components/interface/property.d.ts +38 -0
  39. package/dist/src/components/interface/property.d.ts.map +1 -0
  40. package/dist/src/components/interface/property.js +67 -0
  41. package/dist/src/components/interface/property.test.d.ts +2 -0
  42. package/dist/src/components/interface/property.test.d.ts.map +1 -0
  43. package/dist/src/components/interface/property.test.js +165 -0
  44. package/dist/src/components/parameters/parameters.d.ts +19 -0
  45. package/dist/src/components/parameters/parameters.d.ts.map +1 -0
  46. package/dist/src/components/parameters/parameters.js +43 -0
  47. package/dist/src/components/property/property.d.ts +57 -0
  48. package/dist/src/components/property/property.d.ts.map +1 -0
  49. package/dist/src/components/property/property.js +70 -0
  50. package/dist/src/components/property/property.test.d.ts +2 -0
  51. package/dist/src/components/property/property.test.d.ts.map +1 -0
  52. package/dist/src/components/property/property.test.js +218 -0
  53. package/dist/src/components/record/declaration.d.ts +35 -0
  54. package/dist/src/components/record/declaration.d.ts.map +1 -0
  55. package/dist/src/components/record/declaration.js +90 -0
  56. package/dist/src/components/record/declaration.test.d.ts +2 -0
  57. package/dist/src/components/record/declaration.test.d.ts.map +1 -0
  58. package/dist/src/components/record/declaration.test.js +94 -0
  59. package/dist/src/components/stc/index.d.ts +2 -2
  60. package/dist/src/components/stc/index.d.ts.map +1 -1
  61. package/dist/src/components/stc/index.js +2 -2
  62. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  63. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  64. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  65. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  66. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  67. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  68. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  69. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  70. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  71. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  72. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  73. package/dist/src/components/type-parameters/type-parameters.js +54 -0
  74. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  75. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  76. package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
  77. package/dist/src/components/var/declaration.d.ts +35 -0
  78. package/dist/src/components/var/declaration.d.ts.map +1 -0
  79. package/dist/src/components/var/declaration.js +40 -0
  80. package/dist/src/components/var/declaration.test.d.ts +2 -0
  81. package/dist/src/components/var/declaration.test.d.ts.map +1 -0
  82. package/dist/src/components/var/declaration.test.js +73 -0
  83. package/dist/src/modifiers.d.ts +10 -4
  84. package/dist/src/modifiers.d.ts.map +1 -1
  85. package/dist/src/modifiers.js +9 -32
  86. package/dist/src/name-policy.d.ts +1 -1
  87. package/dist/src/name-policy.d.ts.map +1 -1
  88. package/dist/src/name-policy.js +2 -0
  89. package/dist/test/class-declaration.test.d.ts +2 -0
  90. package/dist/test/class-declaration.test.d.ts.map +1 -0
  91. package/dist/test/class-declaration.test.js +463 -0
  92. package/dist/test/class-method.test.js +37 -14
  93. package/dist/test/enum.test.js +12 -12
  94. package/dist/test/namespace.test.js +8 -8
  95. package/dist/test/project-directory.test.d.ts +2 -0
  96. package/dist/test/project-directory.test.d.ts.map +1 -0
  97. package/dist/test/{projectdirectory.test.js → project-directory.test.js} +8 -8
  98. package/dist/test/sourcefile.test.js +4 -4
  99. package/dist/test/using.test.js +9 -9
  100. package/dist/test/vitest.setup.d.ts +2 -0
  101. package/dist/test/vitest.setup.d.ts.map +1 -0
  102. package/dist/test/vitest.setup.js +1 -0
  103. package/dist/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +21 -21
  105. package/src/components/ClassDeclaration.tsx +213 -0
  106. package/src/components/ClassMethod.tsx +54 -15
  107. package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
  108. package/src/components/doc/comment.test.tsx +337 -0
  109. package/src/components/doc/comment.tsx +152 -0
  110. package/src/components/doc/from-markdown.test.tsx +103 -0
  111. package/src/components/doc/from-markdown.tsx +58 -0
  112. package/src/components/index.ts +13 -4
  113. package/src/components/interface/declaration.test.tsx +143 -0
  114. package/src/components/interface/declaration.tsx +105 -0
  115. package/src/components/interface/method.test.tsx +278 -0
  116. package/src/components/interface/method.tsx +102 -0
  117. package/src/components/interface/property.test.tsx +144 -0
  118. package/src/components/interface/property.tsx +107 -0
  119. package/src/components/parameters/parameters.tsx +74 -0
  120. package/src/components/property/property.test.tsx +187 -0
  121. package/src/components/property/property.tsx +146 -0
  122. package/src/components/record/declaration.test.tsx +73 -0
  123. package/src/components/record/declaration.tsx +109 -0
  124. package/src/components/stc/index.ts +2 -2
  125. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  126. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  127. package/src/components/type-parameters/type-parameter.tsx +35 -0
  128. package/src/components/type-parameters/type-parameters.test.tsx +46 -0
  129. package/src/components/type-parameters/type-parameters.tsx +63 -0
  130. package/src/components/var/declaration.test.tsx +59 -0
  131. package/src/components/var/declaration.tsx +47 -0
  132. package/src/modifiers.ts +25 -42
  133. package/src/name-policy.ts +5 -0
  134. package/temp/api.json +5228 -686
  135. package/test/class-declaration.test.tsx +418 -0
  136. package/test/class-method.test.tsx +24 -14
  137. package/test/enum.test.tsx +11 -11
  138. package/test/namespace.test.tsx +4 -4
  139. package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +4 -4
  140. package/test/sourcefile.test.tsx +2 -2
  141. package/test/using.test.tsx +9 -9
  142. package/test/vitest.setup.ts +1 -0
  143. package/vitest.config.ts +3 -0
  144. package/dist/src/components/Class.d.ts +0 -26
  145. package/dist/src/components/Class.d.ts.map +0 -1
  146. package/dist/src/components/Enum.d.ts +0 -15
  147. package/dist/src/components/Enum.d.ts.map +0 -1
  148. package/dist/src/components/Parameters.d.ts +0 -13
  149. package/dist/src/components/Parameters.d.ts.map +0 -1
  150. package/dist/src/components/Parameters.js +0 -34
  151. package/dist/test/class.test.d.ts +0 -2
  152. package/dist/test/class.test.d.ts.map +0 -1
  153. package/dist/test/class.test.js +0 -298
  154. package/dist/test/projectdirectory.test.d.ts +0 -2
  155. package/dist/test/projectdirectory.test.d.ts.map +0 -1
  156. package/src/components/Class.tsx +0 -149
  157. package/src/components/Parameters.tsx +0 -51
  158. package/test/class.test.tsx +0 -292
@@ -0,0 +1,35 @@
1
+ import * as core from "@alloy-js/core";
2
+ import { AccessModifiers } from "../../modifiers.js";
3
+ export interface RecordModifiers {
4
+ readonly partial?: boolean;
5
+ }
6
+ /** Props to use the {@link RecordDeclaration} component */
7
+ export interface RecordDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, RecordModifiers {
8
+ name: string;
9
+ /** Doc comment */
10
+ doc?: core.Children;
11
+ refkey?: core.Refkey;
12
+ typeParameters?: Record<string, core.Refkey>;
13
+ }
14
+ /**
15
+ * CSharp record declaration.
16
+ * @example
17
+ * ```tsx
18
+ * <RecordDeclaration public name="IMyRecord">
19
+ * <RecordMember public name="MyProperty" type="int" />
20
+ * <RecordMethod public name="MyMethod" returnType="void">
21
+ * <Parameter name="value" type="int" />
22
+ * </RecordMethod>
23
+ * </RecordDeclaration>
24
+ * ```
25
+ * This will produce:
26
+ * ```csharp
27
+ * public record MyIface
28
+ * {
29
+ * public int MyProperty { get; set; }
30
+ * public void MyMethod(int value);
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function RecordDeclaration(props: RecordDeclarationProps): core.Children;
35
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/record/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAID,2DAA2D;AAC3D,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBAwD9D"}
@@ -0,0 +1,90 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import * as core from "@alloy-js/core";
3
+ import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
4
+ import { useCSharpNamePolicy } from "../../name-policy.js";
5
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
6
+ import { CSharpMemberScope } from "../../symbols/scopes.js";
7
+ import { DocWhen } from "../doc/comment.js";
8
+ import { Name } from "../Name.js";
9
+ const getRecordModifiers = makeModifiers(["partial"]);
10
+
11
+ /** Props to use the {@link RecordDeclaration} component */
12
+
13
+ /**
14
+ * CSharp record declaration.
15
+ * @example
16
+ * ```tsx
17
+ * <RecordDeclaration public name="IMyRecord">
18
+ * <RecordMember public name="MyProperty" type="int" />
19
+ * <RecordMethod public name="MyMethod" returnType="void">
20
+ * <Parameter name="value" type="int" />
21
+ * </RecordMethod>
22
+ * </RecordDeclaration>
23
+ * ```
24
+ * This will produce:
25
+ * ```csharp
26
+ * public record MyIface
27
+ * {
28
+ * public int MyProperty { get; set; }
29
+ * public void MyMethod(int value);
30
+ * }
31
+ * ```
32
+ */
33
+ export function RecordDeclaration(props) {
34
+ const name = useCSharpNamePolicy().getName(props.name, "record");
35
+ const thisRecordSymbol = new CSharpOutputSymbol(name, {
36
+ refkeys: props.refkey
37
+ });
38
+
39
+ // this creates a new scope for the record definition.
40
+ // members will automatically "inherit" this scope so
41
+ // that refkeys to them will produce the fully-qualified
42
+ // name e.g. Foo.Bar.
43
+ const thisRecordScope = new CSharpMemberScope("record-decl", {
44
+ owner: thisRecordSymbol
45
+ });
46
+ let typeParams;
47
+ if (props.typeParameters) {
48
+ const typeParamNames = new Array();
49
+ for (const entry of Object.entries(props.typeParameters)) {
50
+ typeParamNames.push(useCSharpNamePolicy().getName(entry[0], "type-parameter"));
51
+ // create a symbol for each type param so its
52
+ // refkey resolves to the type param's name
53
+ new CSharpOutputSymbol(entry[0], {
54
+ scope: thisRecordScope,
55
+ refkeys: entry[1]
56
+ });
57
+ }
58
+ typeParams = _$createIntrinsic("group", {
59
+ get children() {
60
+ return ["<", _$createComponent(core.For, {
61
+ each: typeParamNames,
62
+ comma: true,
63
+ line: true,
64
+ children: name => name
65
+ }), ">"];
66
+ }
67
+ });
68
+ }
69
+ const modifiers = computeModifiersPrefix([getAccessModifier(props), getRecordModifiers(props)]);
70
+ return _$createComponent(core.Declaration, {
71
+ symbol: thisRecordSymbol,
72
+ get children() {
73
+ return [_$createComponent(DocWhen, {
74
+ get doc() {
75
+ return props.doc;
76
+ }
77
+ }), modifiers, "record ", _$createComponent(Name, {}), typeParams, _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
78
+ newline: true,
79
+ get children() {
80
+ return _$createComponent(core.Scope, {
81
+ value: thisRecordScope,
82
+ get children() {
83
+ return props.children;
84
+ }
85
+ });
86
+ }
87
+ }) : ";")];
88
+ }
89
+ });
90
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declaration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/record/declaration.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,94 @@
1
+ import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { describe, expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { Property } from "../property/property.js";
5
+ import { RecordDeclaration } from "./declaration.js";
6
+ it("declares class with no members", () => {
7
+ expect(_$createComponent(TestNamespace, {
8
+ get children() {
9
+ return _$createComponent(RecordDeclaration, {
10
+ name: "TestRecord"
11
+ });
12
+ }
13
+ })).toRenderTo(`
14
+ record TestRecord;
15
+ `);
16
+ });
17
+ describe("modifiers", () => {
18
+ it.each(["public", "private", "internal"])("%s", mod => {
19
+ expect(_$createComponent(TestNamespace, {
20
+ get children() {
21
+ return _$createComponent(RecordDeclaration, _$mergeProps({
22
+ [mod]: true
23
+ }, {
24
+ name: "TestRecord"
25
+ }));
26
+ }
27
+ })).toRenderTo(`
28
+ ${mod} record TestRecord;
29
+ `);
30
+ });
31
+ it.each(["partial"])("%s", mod => {
32
+ expect(_$createComponent(TestNamespace, {
33
+ get children() {
34
+ return _$createComponent(RecordDeclaration, _$mergeProps({
35
+ [mod]: true
36
+ }, {
37
+ name: "TestRecord"
38
+ }));
39
+ }
40
+ })).toRenderTo(`
41
+ ${mod} record TestRecord;
42
+ `);
43
+ });
44
+ it("combines modifiers", () => {
45
+ expect(_$createComponent(TestNamespace, {
46
+ get children() {
47
+ return _$createComponent(RecordDeclaration, {
48
+ "public": true,
49
+ partial: true,
50
+ name: "TestRecord"
51
+ });
52
+ }
53
+ })).toRenderTo(`
54
+ public partial record TestRecord;
55
+ `);
56
+ });
57
+ });
58
+ it("specify doc comment", () => {
59
+ expect(_$createComponent(TestNamespace, {
60
+ get children() {
61
+ return _$createComponent(RecordDeclaration, {
62
+ name: "TestRecord",
63
+ doc: "This is a test"
64
+ });
65
+ }
66
+ })).toRenderTo(`
67
+ /// This is a test
68
+ record TestRecord;
69
+ `);
70
+ });
71
+ it("specify class property inside", () => {
72
+ expect(_$createComponent(TestNamespace, {
73
+ get children() {
74
+ return _$createComponent(RecordDeclaration, {
75
+ name: "TestRecord",
76
+ doc: "This is a test",
77
+ get children() {
78
+ return _$createComponent(Property, {
79
+ name: "Prop",
80
+ get: true,
81
+ set: true,
82
+ type: "string"
83
+ });
84
+ }
85
+ });
86
+ }
87
+ })).toRenderTo(`
88
+ /// This is a test
89
+ record TestRecord
90
+ {
91
+ string Prop { get; set; }
92
+ }
93
+ `);
94
+ });
@@ -1,10 +1,10 @@
1
1
  import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
- export declare const Class: core.StcSignature<base.ClassProps>;
3
+ export declare const ClassDeclaration: core.StcSignature<base.ClassDeclarationProps>;
4
4
  export declare const ClassConstructor: core.StcSignature<base.ClassConstructorProps>;
5
5
  export declare const ClassMember: core.StcSignature<base.ClassMemberProps>;
6
6
  export declare const ClassMethod: core.StcSignature<base.ClassMethodProps>;
7
- export declare const Enum: core.StcSignature<base.EnumProps>;
7
+ export declare const EnumDeclaration: core.StcSignature<base.EnumDeclarationProps>;
8
8
  export declare const EnumMember: core.StcSignature<base.EnumMemberProps>;
9
9
  export declare const Parameter: core.StcSignature<base.ParameterProps>;
10
10
  export declare const Parameters: core.StcSignature<base.ParametersProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,KAAK,oCAAuB,CAAC;AAC1C,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,IAAI,mCAAsB,CAAC;AACxC,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,eAAe,8CAAiC,CAAC;AAC9D,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
- export const Class = core.stc(base.Class);
3
+ export const ClassDeclaration = core.stc(base.ClassDeclaration);
4
4
  export const ClassConstructor = core.stc(base.ClassConstructor);
5
5
  export const ClassMember = core.stc(base.ClassMember);
6
6
  export const ClassMethod = core.stc(base.ClassMethod);
7
- export const Enum = core.stc(base.Enum);
7
+ export const EnumDeclaration = core.stc(base.EnumDeclaration);
8
8
  export const EnumMember = core.stc(base.EnumMember);
9
9
  export const Parameter = core.stc(base.Parameter);
10
10
  export const Parameters = core.stc(base.Parameters);
@@ -0,0 +1,8 @@
1
+ import { Children } from "@alloy-js/core";
2
+ import { TypeParameterProps } from "./type-parameter.jsx";
3
+ export interface TypeParameterConstraintsProps {
4
+ /** Parameters */
5
+ parameters: (TypeParameterProps | string)[];
6
+ }
7
+ export declare function TypeParameterConstraints(props: TypeParameterConstraintsProps): Children;
8
+ //# sourceMappingURL=type-parameter-constraints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameter-constraints.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter-constraints.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,MAAM,WAAW,6BAA6B;IAC5C,iBAAiB;IACjB,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,6BAA6B,GACnC,QAAQ,CAcV"}
@@ -0,0 +1,44 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { code, For, Indent } from "@alloy-js/core";
3
+ import { normalizeParameters } from "./type-parameters.js";
4
+ export function TypeParameterConstraints(props) {
5
+ const parameters = normalizeParameters(props.parameters);
6
+ if (!parameters.some(x => x.constraints)) {
7
+ return null;
8
+ }
9
+ return _$createIntrinsic("group", {
10
+ get children() {
11
+ return _$createComponent(Indent, {
12
+ line: true,
13
+ get children() {
14
+ return _$createComponent(For, {
15
+ each: parameters,
16
+ hardline: true,
17
+ children: param => _$createComponent(TypeParameterConstraint, param)
18
+ });
19
+ }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ function TypeParameterConstraint(props) {
25
+ const constraints = arrayify(props.constraints);
26
+ return ["where ", _$memo(() => code`${props.name} : `), _$createIntrinsic("group", {
27
+ get children() {
28
+ return _$createComponent(Indent, {
29
+ softline: true,
30
+ get children() {
31
+ return _$createComponent(For, {
32
+ each: constraints,
33
+ comma: true,
34
+ line: true,
35
+ children: constraint => code`${constraint}`
36
+ });
37
+ }
38
+ });
39
+ }
40
+ })];
41
+ }
42
+ function arrayify(value) {
43
+ return Array.isArray(value) ? value : [value];
44
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-parameter-constraints.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameter-constraints.test.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter-constraints.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,67 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { expect, it } from "vitest";
3
+ import { TypeParameterConstraints } from "./type-parameter-constraints.js";
4
+ it("renders nothing if there is no constraints", () => {
5
+ expect(_$createComponent(TypeParameterConstraints, {
6
+ parameters: ["A", "B"]
7
+ })).toRenderTo(``);
8
+ });
9
+ it("renders inline if there is only one", () => {
10
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
11
+ parameters: [{
12
+ name: "A",
13
+ constraints: "string"
14
+ }]
15
+ })]).toRenderTo(`
16
+ code() where A : string
17
+ `);
18
+ });
19
+ it("renders multiple constraints", () => {
20
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
21
+ parameters: [{
22
+ name: "A",
23
+ constraints: ["string", "int"]
24
+ }]
25
+ })]).toRenderTo(`
26
+ code() where A : string, int
27
+ `);
28
+ });
29
+ it("renders newline if constraint is very long", () => {
30
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
31
+ parameters: [{
32
+ name: "ThisIsQuiteALongName",
33
+ constraints: "VeryLongBuilderFactorySingletonThatShouldBeSplit"
34
+ }]
35
+ })]).toRenderTo(`
36
+ code()
37
+ where ThisIsQuiteALongName : VeryLongBuilderFactorySingletonThatShouldBeSplit
38
+ `);
39
+ });
40
+ it("renders multiple constraints on new lines if they are very long", () => {
41
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
42
+ parameters: [{
43
+ name: "A",
44
+ constraints: ["IVeryLongBuilderFactorySingletonThatShouldBeSplitA", "IVeryLongBuilderFactorySingletonThatShouldBeSplitB"]
45
+ }]
46
+ })]).toRenderTo(`
47
+ code()
48
+ where A :
49
+ IVeryLongBuilderFactorySingletonThatShouldBeSplitA,
50
+ IVeryLongBuilderFactorySingletonThatShouldBeSplitB
51
+ `);
52
+ });
53
+ it("declare type parameters using parameters", () => {
54
+ expect(["code()", _$createComponent(TypeParameterConstraints, {
55
+ parameters: [{
56
+ name: "A",
57
+ constraints: "string"
58
+ }, {
59
+ name: "B",
60
+ constraints: "string"
61
+ }]
62
+ })]).toRenderTo(`
63
+ code()
64
+ where A : string
65
+ where B : string
66
+ `);
67
+ });
@@ -0,0 +1,20 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ /**
3
+ * Information for a TypeScript generic type parameter.
4
+ */
5
+ export interface TypeParameterProps {
6
+ /**
7
+ * The name of the type parameter.
8
+ */
9
+ readonly name: string;
10
+ /**
11
+ * The parameter constraint
12
+ */
13
+ readonly constraints?: Children | Children[];
14
+ /**
15
+ * A refkey or array of refkeys for this type parameter.
16
+ */
17
+ readonly refkey?: Refkey | Refkey[];
18
+ }
19
+ export declare function TypeParameter(props: TypeParameterProps): Children;
20
+ //# sourceMappingURL=type-parameter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameter.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACrC;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAStD"}
@@ -0,0 +1,22 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { MemberDeclaration, refkey } from "@alloy-js/core";
3
+ import { useCSharpNamePolicy } from "../../name-policy.js";
4
+ import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
5
+ import { useCSharpScope } from "../../symbols/scopes.js";
6
+
7
+ /**
8
+ * Information for a TypeScript generic type parameter.
9
+ */
10
+
11
+ export function TypeParameter(props) {
12
+ const name = useCSharpNamePolicy().getName(props.name, "type-parameter");
13
+ const scope = useCSharpScope();
14
+ const symbol = new CSharpOutputSymbol(name, {
15
+ scope,
16
+ refkeys: props.refkey ?? refkey(props.name)
17
+ });
18
+ return _$createComponent(MemberDeclaration, {
19
+ symbol: symbol,
20
+ children: name
21
+ });
22
+ }
@@ -0,0 +1,17 @@
1
+ import { TypeParameterProps } from "./type-parameter.jsx";
2
+ export declare const typeParametersTag: unique symbol;
3
+ export interface TypeParametersProps {
4
+ /** Parameters */
5
+ parameters: (TypeParameterProps | string)[];
6
+ }
7
+ /**
8
+ * Represent type parameters
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * <A, B extends string>
13
+ * ```
14
+ */
15
+ export declare const TypeParameters: import("@alloy-js/core").Component<TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<TypeParametersProps>, "tag">>;
16
+ export declare function normalizeParameters(parameters: (TypeParameterProps | string)[]): TypeParameterProps[];
17
+ //# sourceMappingURL=type-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameters.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameters.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,eAAO,MAAM,iBAAiB,eAAuC,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0IAmB1B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,GAC1C,kBAAkB,EAAE,CAOtB"}
@@ -0,0 +1,54 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { For, Indent, taggedComponent } from "@alloy-js/core";
3
+ import { TypeParameter } from "./type-parameter.js";
4
+ export const typeParametersTag = Symbol.for("csharp.type-parameters");
5
+ /**
6
+ * Represent type parameters
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * <A, B extends string>
11
+ * ```
12
+ */
13
+ export const TypeParameters = taggedComponent(typeParametersTag, function TypeParameters(props) {
14
+ const typeParameters = normalizeParameters(props.parameters);
15
+ return ["<", _$createIntrinsic("group", {
16
+ get children() {
17
+ return _$createComponent(Indent, {
18
+ softline: true,
19
+ get children() {
20
+ return _$createComponent(For, {
21
+ each: typeParameters,
22
+ comma: true,
23
+ line: true,
24
+ children: param => _$createComponent(TypeParameter, param)
25
+ });
26
+ }
27
+ });
28
+ }
29
+ }), ">"];
30
+ });
31
+ export function normalizeParameters(parameters) {
32
+ return parameters.map(param => {
33
+ if (typeof param === "string") {
34
+ return {
35
+ name: param
36
+ };
37
+ }
38
+ return param;
39
+ });
40
+ }
41
+
42
+ // export function declareParameter(
43
+ // parameters: TypeParameterProps[],
44
+ // ): TypeParameterProps[] {
45
+ // return parameters.map((param) => {
46
+ // return {
47
+ // ...param,
48
+ // symbol: new CSharpOutputSymbol(entry[0], {
49
+ // scope: thisClassScope,
50
+ // refkeys: entry[1],
51
+ // }),
52
+ // };
53
+ // });
54
+ // }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-parameters.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-parameters.test.d.ts","sourceRoot":"","sources":["../../../../src/components/type-parameters/type-parameters.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,48 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { expect, it } from "vitest";
3
+ import { TestNamespace } from "../../../test/utils.js";
4
+ import { TypeParameters } from "./type-parameters.js";
5
+ it("render one", () => {
6
+ expect(_$createComponent(TestNamespace, {
7
+ get children() {
8
+ return _$createComponent(TypeParameters, {
9
+ parameters: ["A"]
10
+ });
11
+ }
12
+ })).toRenderTo(`<A>`);
13
+ });
14
+ it("render very long", () => {
15
+ expect(_$createComponent(TestNamespace, {
16
+ get children() {
17
+ return _$createComponent(TypeParameters, {
18
+ parameters: ["SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesA", "SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesB"]
19
+ });
20
+ }
21
+ })).toRenderTo(`
22
+ <
23
+ SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesA,
24
+ SomeVeryVeryLongParamThatMightGetSplitOverMultipleLinesB>
25
+ `);
26
+ });
27
+ it("declare type parameters using parameters names", () => {
28
+ expect(_$createComponent(TestNamespace, {
29
+ get children() {
30
+ return _$createComponent(TypeParameters, {
31
+ parameters: ["A", "B"]
32
+ });
33
+ }
34
+ })).toRenderTo(`<A, B>`);
35
+ });
36
+ it("declare type parameters using parameters", () => {
37
+ expect(_$createComponent(TestNamespace, {
38
+ get children() {
39
+ return _$createComponent(TypeParameters, {
40
+ parameters: [{
41
+ name: "A"
42
+ }, {
43
+ name: "B"
44
+ }]
45
+ });
46
+ }
47
+ })).toRenderTo(`<A, B>`);
48
+ });
@@ -0,0 +1,35 @@
1
+ import { Children, DeclarationProps, Refkey } from "@alloy-js/core";
2
+ /** Props for {@link VarDeclaration} component */
3
+ export interface VarDeclarationProps extends Omit<DeclarationProps, "nameKind"> {
4
+ /** Variable name */
5
+ name: string;
6
+ /** Type of the variable declaration. If not specified, defaults to "var" */
7
+ type?: Children;
8
+ /** Variable refkey */
9
+ refkey?: Refkey;
10
+ /** Variable value */
11
+ children?: Children;
12
+ }
13
+ /**
14
+ * Render a variable declaration
15
+ *
16
+ * @example with var
17
+ * ```tsx
18
+ * <VarDeclaration name="myVar">42</VarDeclaration>
19
+ * ```
20
+ * This will render:
21
+ * ```csharp
22
+ * var myVar = 42;
23
+ * ```
24
+ *
25
+ * @example with type
26
+ * ```tsx
27
+ * <VarDeclaration name="myVar" type="int">42</VarDeclaration>
28
+ * ```
29
+ * This will render:
30
+ * ```csharp
31
+ * int myVar = 42;
32
+ * ```
33
+ */
34
+ export declare function VarDeclaration(props: VarDeclarationProps): Children;
35
+ //# sourceMappingURL=declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/var/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAQ,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI1E,iDAAiD;AACjD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC;IAC1C,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YAQxD"}
@@ -0,0 +1,40 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Name } from "@alloy-js/core";
3
+ import { useCSharpNamePolicy } from "../../name-policy.js";
4
+ import { Declaration } from "../Declaration.js";
5
+
6
+ /** Props for {@link VarDeclaration} component */
7
+
8
+ /**
9
+ * Render a variable declaration
10
+ *
11
+ * @example with var
12
+ * ```tsx
13
+ * <VarDeclaration name="myVar">42</VarDeclaration>
14
+ * ```
15
+ * This will render:
16
+ * ```csharp
17
+ * var myVar = 42;
18
+ * ```
19
+ *
20
+ * @example with type
21
+ * ```tsx
22
+ * <VarDeclaration name="myVar" type="int">42</VarDeclaration>
23
+ * ```
24
+ * This will render:
25
+ * ```csharp
26
+ * int myVar = 42;
27
+ * ```
28
+ */
29
+ export function VarDeclaration(props) {
30
+ const name = useCSharpNamePolicy().getName(props.name, "variable");
31
+ return _$createComponent(Declaration, {
32
+ name: name,
33
+ get refkey() {
34
+ return props.refkey;
35
+ },
36
+ get children() {
37
+ return [_$memo(() => props.type ?? "var"), " ", _$createComponent(Name, {}), " = ", _$memo(() => props.children), ";"];
38
+ }
39
+ });
40
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=declaration.test.d.ts.map