@alloy-js/csharp 0.18.0-dev.24 → 0.18.0-dev.3

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 (168) hide show
  1. package/dist/src/components/Class.d.ts +26 -0
  2. package/dist/src/components/Class.d.ts.map +1 -0
  3. package/dist/src/components/{ClassDeclaration.js → Class.js} +38 -70
  4. package/dist/src/components/ClassMethod.d.ts +5 -44
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +9 -33
  7. package/dist/src/components/Enum.d.ts +15 -0
  8. package/dist/src/components/Enum.d.ts.map +1 -0
  9. package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
  10. package/dist/src/components/Parameters.d.ts +13 -0
  11. package/dist/src/components/Parameters.d.ts.map +1 -0
  12. package/dist/src/components/Parameters.js +34 -0
  13. package/dist/src/components/SourceFile.d.ts.map +1 -1
  14. package/dist/src/components/SourceFile.js +0 -1
  15. package/dist/src/components/index.d.ts +4 -14
  16. package/dist/src/components/index.d.ts.map +1 -1
  17. package/dist/src/components/index.js +5 -15
  18. package/dist/src/components/stc/index.d.ts +2 -2
  19. package/dist/src/components/stc/index.d.ts.map +1 -1
  20. package/dist/src/components/stc/index.js +2 -2
  21. package/dist/src/modifiers.d.ts +4 -10
  22. package/dist/src/modifiers.d.ts.map +1 -1
  23. package/dist/src/modifiers.js +32 -9
  24. package/dist/src/name-policy.d.ts +1 -1
  25. package/dist/src/name-policy.d.ts.map +1 -1
  26. package/dist/src/name-policy.js +0 -2
  27. package/dist/test/class-method.test.js +14 -37
  28. package/dist/test/class.test.d.ts +2 -0
  29. package/dist/test/class.test.d.ts.map +1 -0
  30. package/dist/test/class.test.js +298 -0
  31. package/dist/test/enum.test.js +12 -12
  32. package/dist/test/namespace.test.js +8 -8
  33. package/dist/test/projectdirectory.test.d.ts +2 -0
  34. package/dist/test/projectdirectory.test.d.ts.map +1 -0
  35. package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
  36. package/dist/test/sourcefile.test.js +4 -4
  37. package/dist/test/using.test.js +9 -9
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +3 -4
  40. package/src/components/Class.tsx +149 -0
  41. package/src/components/ClassMethod.tsx +15 -74
  42. package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
  43. package/src/components/Parameters.tsx +51 -0
  44. package/src/components/SourceFile.tsx +0 -1
  45. package/src/components/index.ts +4 -14
  46. package/src/components/stc/index.ts +2 -2
  47. package/src/modifiers.ts +42 -25
  48. package/src/name-policy.ts +0 -5
  49. package/temp/api.json +1298 -6463
  50. package/test/class-method.test.tsx +14 -24
  51. package/test/class.test.tsx +292 -0
  52. package/test/enum.test.tsx +11 -11
  53. package/test/namespace.test.tsx +4 -4
  54. package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
  55. package/test/sourcefile.test.tsx +2 -2
  56. package/test/using.test.tsx +9 -9
  57. package/vitest.config.ts +0 -3
  58. package/dist/src/components/ClassDeclaration.d.ts +0 -92
  59. package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
  60. package/dist/src/components/EnumDeclaration.d.ts +0 -34
  61. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  62. package/dist/src/components/attributes/attributes.d.ts +0 -39
  63. package/dist/src/components/attributes/attributes.d.ts.map +0 -1
  64. package/dist/src/components/attributes/attributes.js +0 -62
  65. package/dist/src/components/attributes/attributes.test.d.ts +0 -2
  66. package/dist/src/components/attributes/attributes.test.d.ts.map +0 -1
  67. package/dist/src/components/attributes/attributes.test.js +0 -75
  68. package/dist/src/components/doc/comment.d.ts +0 -70
  69. package/dist/src/components/doc/comment.d.ts.map +0 -1
  70. package/dist/src/components/doc/comment.js +0 -88
  71. package/dist/src/components/doc/comment.test.d.ts +0 -2
  72. package/dist/src/components/doc/comment.test.d.ts.map +0 -1
  73. package/dist/src/components/doc/comment.test.js +0 -348
  74. package/dist/src/components/doc/from-markdown.d.ts +0 -6
  75. package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
  76. package/dist/src/components/doc/from-markdown.js +0 -58
  77. package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
  78. package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
  79. package/dist/src/components/doc/from-markdown.test.js +0 -83
  80. package/dist/src/components/interface/declaration.d.ts +0 -65
  81. package/dist/src/components/interface/declaration.d.ts.map +0 -1
  82. package/dist/src/components/interface/declaration.js +0 -83
  83. package/dist/src/components/interface/declaration.test.d.ts +0 -2
  84. package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
  85. package/dist/src/components/interface/declaration.test.js +0 -171
  86. package/dist/src/components/interface/method.d.ts +0 -50
  87. package/dist/src/components/interface/method.d.ts.map +0 -1
  88. package/dist/src/components/interface/method.js +0 -74
  89. package/dist/src/components/interface/method.test.d.ts +0 -2
  90. package/dist/src/components/interface/method.test.d.ts.map +0 -1
  91. package/dist/src/components/interface/method.test.js +0 -300
  92. package/dist/src/components/interface/property.d.ts +0 -56
  93. package/dist/src/components/interface/property.d.ts.map +0 -1
  94. package/dist/src/components/interface/property.js +0 -73
  95. package/dist/src/components/interface/property.test.d.ts +0 -2
  96. package/dist/src/components/interface/property.test.d.ts.map +0 -1
  97. package/dist/src/components/interface/property.test.js +0 -189
  98. package/dist/src/components/parameters/parameters.d.ts +0 -19
  99. package/dist/src/components/parameters/parameters.d.ts.map +0 -1
  100. package/dist/src/components/parameters/parameters.js +0 -43
  101. package/dist/src/components/property/property.d.ts +0 -80
  102. package/dist/src/components/property/property.d.ts.map +0 -1
  103. package/dist/src/components/property/property.js +0 -76
  104. package/dist/src/components/property/property.test.d.ts +0 -2
  105. package/dist/src/components/property/property.test.d.ts.map +0 -1
  106. package/dist/src/components/property/property.test.js +0 -242
  107. package/dist/src/components/record/declaration.d.ts +0 -35
  108. package/dist/src/components/record/declaration.d.ts.map +0 -1
  109. package/dist/src/components/record/declaration.js +0 -90
  110. package/dist/src/components/record/declaration.test.d.ts +0 -2
  111. package/dist/src/components/record/declaration.test.d.ts.map +0 -1
  112. package/dist/src/components/record/declaration.test.js +0 -94
  113. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
  114. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
  115. package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
  116. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
  117. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
  118. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
  119. package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
  120. package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
  121. package/dist/src/components/type-parameters/type-parameter.js +0 -22
  122. package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
  123. package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
  124. package/dist/src/components/type-parameters/type-parameters.js +0 -54
  125. package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
  126. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
  127. package/dist/src/components/type-parameters/type-parameters.test.js +0 -48
  128. package/dist/src/components/var/declaration.d.ts +0 -35
  129. package/dist/src/components/var/declaration.d.ts.map +0 -1
  130. package/dist/src/components/var/declaration.js +0 -40
  131. package/dist/src/components/var/declaration.test.d.ts +0 -2
  132. package/dist/src/components/var/declaration.test.d.ts.map +0 -1
  133. package/dist/src/components/var/declaration.test.js +0 -73
  134. package/dist/test/class-declaration.test.d.ts +0 -2
  135. package/dist/test/class-declaration.test.d.ts.map +0 -1
  136. package/dist/test/class-declaration.test.js +0 -481
  137. package/dist/test/project-directory.test.d.ts +0 -2
  138. package/dist/test/project-directory.test.d.ts.map +0 -1
  139. package/dist/test/vitest.setup.d.ts +0 -2
  140. package/dist/test/vitest.setup.d.ts.map +0 -1
  141. package/dist/test/vitest.setup.js +0 -1
  142. package/src/components/ClassDeclaration.tsx +0 -233
  143. package/src/components/attributes/attributes.test.tsx +0 -61
  144. package/src/components/attributes/attributes.tsx +0 -100
  145. package/src/components/doc/comment.test.tsx +0 -337
  146. package/src/components/doc/comment.tsx +0 -152
  147. package/src/components/doc/from-markdown.test.tsx +0 -103
  148. package/src/components/doc/from-markdown.tsx +0 -58
  149. package/src/components/interface/declaration.test.tsx +0 -158
  150. package/src/components/interface/declaration.tsx +0 -125
  151. package/src/components/interface/method.test.tsx +0 -293
  152. package/src/components/interface/method.tsx +0 -122
  153. package/src/components/interface/property.test.tsx +0 -165
  154. package/src/components/interface/property.tsx +0 -127
  155. package/src/components/parameters/parameters.tsx +0 -74
  156. package/src/components/property/property.test.tsx +0 -209
  157. package/src/components/property/property.tsx +0 -172
  158. package/src/components/record/declaration.test.tsx +0 -73
  159. package/src/components/record/declaration.tsx +0 -109
  160. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  161. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  162. package/src/components/type-parameters/type-parameter.tsx +0 -35
  163. package/src/components/type-parameters/type-parameters.test.tsx +0 -46
  164. package/src/components/type-parameters/type-parameters.tsx +0 -63
  165. package/src/components/var/declaration.test.tsx +0 -59
  166. package/src/components/var/declaration.tsx +0 -47
  167. package/test/class-declaration.test.tsx +0 -430
  168. package/test/vitest.setup.ts +0 -1
@@ -1,171 +0,0 @@
1
- import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
- import { List, refkey } from "@alloy-js/core";
3
- import { describe, expect, it } from "vitest";
4
- import { TestNamespace } from "../../../test/utils.js";
5
- import { Attribute } from "../attributes/attributes.js";
6
- import { SourceFile } from "../SourceFile.js";
7
- import { InterfaceDeclaration } from "./declaration.js";
8
- import { InterfaceProperty } from "./property.js";
9
- it("declares class with no members", () => {
10
- expect(_$createComponent(TestNamespace, {
11
- get children() {
12
- return _$createComponent(InterfaceDeclaration, {
13
- name: "TestInterface"
14
- });
15
- }
16
- })).toRenderTo(`
17
- interface TestInterface;
18
- `);
19
- });
20
- describe("modifiers", () => {
21
- it.each(["public", "private", "internal"])("%s", mod => {
22
- expect(_$createComponent(TestNamespace, {
23
- get children() {
24
- return _$createComponent(InterfaceDeclaration, _$mergeProps({
25
- [mod]: true
26
- }, {
27
- name: "TestInterface"
28
- }));
29
- }
30
- })).toRenderTo(`
31
- ${mod} interface TestInterface;
32
- `);
33
- });
34
- it.each(["partial"])("%s", mod => {
35
- expect(_$createComponent(TestNamespace, {
36
- get children() {
37
- return _$createComponent(InterfaceDeclaration, _$mergeProps({
38
- [mod]: true
39
- }, {
40
- name: "TestInterface"
41
- }));
42
- }
43
- })).toRenderTo(`
44
- ${mod} interface TestInterface;
45
- `);
46
- });
47
- it("combines modifiers", () => {
48
- expect(_$createComponent(TestNamespace, {
49
- get children() {
50
- return _$createComponent(InterfaceDeclaration, {
51
- "public": true,
52
- partial: true,
53
- name: "TestInterface"
54
- });
55
- }
56
- })).toRenderTo(`
57
- public partial interface TestInterface;
58
- `);
59
- });
60
- });
61
- it("specify doc comment", () => {
62
- expect(_$createComponent(TestNamespace, {
63
- get children() {
64
- return _$createComponent(InterfaceDeclaration, {
65
- name: "TestInterface",
66
- doc: "This is a test"
67
- });
68
- }
69
- })).toRenderTo(`
70
- /// This is a test
71
- interface TestInterface;
72
- `);
73
- });
74
- describe("with type parameters", () => {
75
- it("reference parameters", () => {
76
- const typeParameters = [{
77
- name: "T",
78
- refkey: refkey()
79
- }, {
80
- name: "U",
81
- refkey: refkey()
82
- }];
83
- expect(_$createComponent(TestNamespace, {
84
- get children() {
85
- return _$createComponent(SourceFile, {
86
- path: "Test.cs",
87
- get children() {
88
- return _$createComponent(InterfaceDeclaration, {
89
- "public": true,
90
- name: "Test",
91
- typeParameters: typeParameters,
92
- get children() {
93
- return _$createComponent(List, {
94
- get children() {
95
- return [_$createComponent(InterfaceProperty, {
96
- name: "PropA",
97
- get type() {
98
- return typeParameters[0].refkey;
99
- },
100
- get: true,
101
- set: true
102
- }), _$createComponent(InterfaceProperty, {
103
- name: "PropB",
104
- get type() {
105
- return typeParameters[1].refkey;
106
- },
107
- get: true,
108
- set: true
109
- })];
110
- }
111
- });
112
- }
113
- });
114
- }
115
- });
116
- }
117
- })).toRenderTo(`
118
- namespace TestCode
119
- {
120
- public interface Test<T, U>
121
- {
122
- T PropA { get; set; }
123
- U PropB { get; set; }
124
- }
125
- }
126
- `);
127
- });
128
- it("defines with constraints", () => {
129
- const typeParameters = [{
130
- name: "T",
131
- constraints: "IFoo"
132
- }, {
133
- name: "U",
134
- constraints: "IBar"
135
- }];
136
- expect(_$createComponent(TestNamespace, {
137
- get children() {
138
- return _$createComponent(InterfaceDeclaration, {
139
- "public": true,
140
- name: "Test",
141
- typeParameters: typeParameters,
142
- children: "// Body"
143
- });
144
- }
145
- })).toRenderTo(`
146
- public interface Test<T, U>
147
- where T : IFoo
148
- where U : IBar
149
- {
150
- // Body
151
- }
152
- `);
153
- });
154
- });
155
- it("specify attributes", () => {
156
- expect(_$createComponent(TestNamespace, {
157
- get children() {
158
- return _$createComponent(InterfaceDeclaration, {
159
- name: "Test",
160
- get attributes() {
161
- return [_$createComponent(Attribute, {
162
- name: "Test"
163
- })];
164
- }
165
- });
166
- }
167
- })).toRenderTo(`
168
- [Test]
169
- interface Test;
170
- `);
171
- });
@@ -1,50 +0,0 @@
1
- import { Children, Refkey } from "@alloy-js/core";
2
- import { AccessModifiers } from "../../modifiers.js";
3
- import { AttributesProp } from "../attributes/attributes.jsx";
4
- import { ParameterProps } from "../parameters/parameters.jsx";
5
- import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
6
- /** Method modifiers. Can only be one. */
7
- export interface InterfaceMethodModifiers {
8
- readonly new?: boolean;
9
- }
10
- export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodModifiers {
11
- name: string;
12
- refkey?: Refkey;
13
- children?: Children;
14
- parameters?: Array<ParameterProps>;
15
- /**
16
- * Type parameters for the method
17
- *
18
- * @example
19
- * ```tsx
20
- * <InterfaceMethod name="Test" typeParameters={["T"]} />
21
- * ```
22
- * This will produce:
23
- * ```csharp
24
- * public void Test<T>()
25
- * ```
26
- */
27
- typeParameters?: (TypeParameterProps | string)[];
28
- returns?: Children;
29
- /** Doc comment */
30
- doc?: Children;
31
- /**
32
- * Define attributes to attach
33
- * @example
34
- * ```tsx
35
- * <InterfaceMethod name="MyMethod" attributes={[
36
- * <Attribute name="Test" />
37
- * <Attribute name="Test2" args={["arg1", "arg2"]} />
38
- * ]} />
39
- * ```
40
- * This will produce:
41
- * ```csharp
42
- * [Test]
43
- * [Test2("arg1", "arg2")]
44
- * void MyMethod();
45
- * ```
46
- */
47
- attributes?: AttributesProp;
48
- }
49
- export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
50
- //# sourceMappingURL=method.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,oBACf,SAAQ,eAAe,EACrB,wBAAwB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IACjD,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA4C1D"}
@@ -1,74 +0,0 @@
1
- import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
- import { Block, MemberDeclaration, refkey, Scope } 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, useCSharpScope } from "../../symbols/scopes.js";
7
- import { AttributeList } from "../attributes/attributes.js";
8
- import { DocWhen } from "../doc/comment.js";
9
- import { Parameters } from "../parameters/parameters.js";
10
- import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
11
- import { TypeParameters } from "../type-parameters/type-parameters.js";
12
-
13
- /** Method modifiers. Can only be one. */
14
-
15
- const getMethodModifier = makeModifiers(["new"]);
16
-
17
- // properties for creating a method
18
-
19
- // a C# interface method
20
- export function InterfaceMethod(props) {
21
- const name = useCSharpNamePolicy().getName(props.name, "class-method");
22
- const scope = useCSharpScope();
23
- if (scope.kind !== "member" || scope.name !== "interface-decl") {
24
- throw new Error("can't define an interface method outside of an interface scope");
25
- }
26
- const methodSymbol = new CSharpOutputSymbol(name, {
27
- scope,
28
- refkeys: props.refkey ?? refkey(props.name)
29
- });
30
-
31
- // scope for method declaration
32
- const methodScope = new CSharpMemberScope("method-decl", {
33
- owner: methodSymbol
34
- });
35
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
36
- // note that scope wraps the method decl so that the params get the correct scope
37
- return _$createComponent(MemberDeclaration, {
38
- symbol: methodSymbol,
39
- get children() {
40
- return _$createComponent(Scope, {
41
- value: methodScope,
42
- get children() {
43
- return [_$createComponent(DocWhen, {
44
- get doc() {
45
- return props.doc;
46
- }
47
- }), _$createComponent(AttributeList, {
48
- get attributes() {
49
- return props.attributes;
50
- },
51
- endline: true
52
- }), modifiers, _$memo(() => props.returns ?? "void"), " ", name, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
53
- get parameters() {
54
- return props.typeParameters;
55
- }
56
- })), _$createComponent(Parameters, {
57
- get parameters() {
58
- return props.parameters;
59
- }
60
- }), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
61
- get parameters() {
62
- return props.typeParameters;
63
- }
64
- })), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
65
- newline: true,
66
- get children() {
67
- return props.children;
68
- }
69
- }) : ";")];
70
- }
71
- });
72
- }
73
- });
74
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=method.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"method.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.test.tsx"],"names":[],"mappings":""}
@@ -1,300 +0,0 @@
1
- import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
- import { refkey } from "@alloy-js/core";
3
- import { describe, expect, it } from "vitest";
4
- import { TestNamespace } from "../../../test/utils.js";
5
- import { Attribute } from "../attributes/attributes.js";
6
- import { SourceFile } from "../SourceFile.js";
7
- import { InterfaceDeclaration } from "./declaration.js";
8
- import { InterfaceMethod } from "./method.js";
9
- const Wrapper = props => _$createComponent(TestNamespace, {
10
- get children() {
11
- return _$createComponent(InterfaceDeclaration, {
12
- "public": true,
13
- name: "TestInterface",
14
- get children() {
15
- return props.children;
16
- }
17
- });
18
- }
19
- });
20
- describe("modifiers", () => {
21
- describe("access modifiers", () => {
22
- it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
23
- expect(_$createComponent(Wrapper, {
24
- get children() {
25
- return _$createComponent(InterfaceMethod, _$mergeProps({
26
- [accessModifier]: true
27
- }, {
28
- name: "MethodOne"
29
- }));
30
- }
31
- })).toRenderTo(`
32
- public interface TestInterface
33
- {
34
- ${accessModifier} void MethodOne();
35
- }
36
- `);
37
- });
38
- });
39
- describe("method modifiers", () => {
40
- it.each(["new"])("%s", methodModifier => {
41
- expect(_$createComponent(Wrapper, {
42
- get children() {
43
- return _$createComponent(InterfaceMethod, _$mergeProps({
44
- [methodModifier]: true
45
- }, {
46
- name: "MethodOne"
47
- }));
48
- }
49
- })).toRenderTo(`
50
- public interface TestInterface
51
- {
52
- ${methodModifier} void MethodOne();
53
- }
54
- `);
55
- });
56
- });
57
- it("combine modifiers", () => {
58
- expect(_$createComponent(Wrapper, {
59
- get children() {
60
- return _$createComponent(InterfaceMethod, {
61
- returns: "Task",
62
- "public": true,
63
- "new": true,
64
- name: "MethodOne"
65
- });
66
- }
67
- })).toRenderTo(`
68
- public interface TestInterface
69
- {
70
- public new Task MethodOne();
71
- }
72
- `);
73
- });
74
- });
75
- it("applies PascalCase naming policy", () => {
76
- expect(_$createComponent(Wrapper, {
77
- get children() {
78
- return _$createComponent(InterfaceMethod, {
79
- name: "method_one"
80
- });
81
- }
82
- })).toRenderTo(`
83
- public interface TestInterface
84
- {
85
- void MethodOne();
86
- }
87
- `);
88
- });
89
- it("defines params and return type", () => {
90
- const params = [{
91
- name: "intParam",
92
- type: "int"
93
- }, {
94
- name: "stringParam",
95
- type: "string"
96
- }];
97
- const res = _$createComponent(Wrapper, {
98
- get children() {
99
- return _$createComponent(InterfaceMethod, {
100
- "public": true,
101
- name: "MethodOne",
102
- parameters: params,
103
- returns: "string"
104
- });
105
- }
106
- });
107
- expect(res).toRenderTo(`
108
- public interface TestInterface
109
- {
110
- public string MethodOne(int intParam, string stringParam);
111
- }
112
- `);
113
- });
114
- it("defines optional param", () => {
115
- const res = _$createComponent(Wrapper, {
116
- get children() {
117
- return _$createComponent(InterfaceMethod, {
118
- "public": true,
119
- name: "MethodOne",
120
- parameters: [{
121
- name: "intParam",
122
- type: "int",
123
- optional: true
124
- }],
125
- returns: "string"
126
- });
127
- }
128
- });
129
- expect(res).toRenderTo(`
130
- public interface TestInterface
131
- {
132
- public string MethodOne(int? intParam);
133
- }
134
- `);
135
- });
136
- it("defines optional param with default", () => {
137
- const res = _$createComponent(Wrapper, {
138
- get children() {
139
- return _$createComponent(InterfaceMethod, {
140
- "public": true,
141
- name: "MethodOne",
142
- parameters: [{
143
- name: "intParam",
144
- type: "int",
145
- default: 12
146
- }],
147
- returns: "string"
148
- });
149
- }
150
- });
151
- expect(res).toRenderTo(`
152
- public interface TestInterface
153
- {
154
- public string MethodOne(int intParam = 12);
155
- }
156
- `);
157
- });
158
- it("specify doc comment", () => {
159
- expect(_$createComponent(TestNamespace, {
160
- get children() {
161
- return _$createComponent(InterfaceDeclaration, {
162
- name: "Test",
163
- get children() {
164
- return _$createComponent(InterfaceMethod, {
165
- name: "Method",
166
- doc: "This is a test"
167
- });
168
- }
169
- });
170
- }
171
- })).toRenderTo(`
172
- interface Test
173
- {
174
- /// This is a test
175
- void Method();
176
- }
177
- `);
178
- });
179
- it("specify attributes", () => {
180
- expect(_$createComponent(Wrapper, {
181
- get children() {
182
- return _$createComponent(InterfaceMethod, {
183
- name: "Test",
184
- get attributes() {
185
- return [_$createComponent(Attribute, {
186
- name: "Test"
187
- })];
188
- }
189
- });
190
- }
191
- })).toRenderTo(`
192
- public interface TestInterface
193
- {
194
- [Test]
195
- void Test();
196
- }
197
- `);
198
- });
199
- describe("with type parameters", () => {
200
- it("reference parameters", () => {
201
- const typeParameters = [{
202
- name: "T",
203
- refkey: refkey()
204
- }, {
205
- name: "U",
206
- refkey: refkey()
207
- }];
208
- expect(_$createComponent(TestNamespace, {
209
- get children() {
210
- return _$createComponent(SourceFile, {
211
- path: "TestFile.cs",
212
- get children() {
213
- return _$createComponent(InterfaceDeclaration, {
214
- "public": true,
215
- name: "TestInterface",
216
- get children() {
217
- return _$createComponent(InterfaceMethod, {
218
- name: "Test",
219
- "public": true,
220
- typeParameters: typeParameters,
221
- get parameters() {
222
- return [{
223
- name: "paramA",
224
- type: typeParameters[0].refkey
225
- }];
226
- },
227
- get returns() {
228
- return typeParameters[0].refkey;
229
- }
230
- });
231
- }
232
- });
233
- }
234
- });
235
- }
236
- })).toRenderTo(`
237
- namespace TestCode
238
- {
239
- public interface TestInterface
240
- {
241
- public T Test<T, U>(T paramA);
242
- }
243
- }
244
- `);
245
- });
246
- it("defines with constraints", () => {
247
- const typeParameters = [{
248
- name: "T",
249
- constraints: "IFoo"
250
- }, {
251
- name: "U",
252
- constraints: "IBar"
253
- }];
254
- expect(_$createComponent(Wrapper, {
255
- get children() {
256
- return _$createComponent(InterfaceMethod, {
257
- "public": true,
258
- name: "Test",
259
- typeParameters: typeParameters,
260
- children: "// Body"
261
- });
262
- }
263
- })).toRenderTo(`
264
- public interface TestInterface
265
- {
266
- public void Test<T, U>()
267
- where T : IFoo
268
- where U : IBar
269
- {
270
- // Body
271
- }
272
- }
273
- `);
274
- });
275
- });
276
- describe("formatting", () => {
277
- it("Split parameters before type parameters", () => {
278
- expect(_$createComponent(Wrapper, {
279
- get children() {
280
- return _$createComponent(InterfaceMethod, {
281
- "public": true,
282
- name: "Handle",
283
- parameters: [{
284
- name: "message",
285
- type: "Some.Quite.Long.Type.That.Will.Split"
286
- }],
287
- typeParameters: ["T"],
288
- returns: "Some.Quite.Long.Type.That.Will.Split"
289
- });
290
- }
291
- })).toRenderTo(`
292
- public interface TestInterface
293
- {
294
- public Some.Quite.Long.Type.That.Will.Split Handle<T>(
295
- Some.Quite.Long.Type.That.Will.Split message
296
- );
297
- }
298
- `);
299
- });
300
- });
@@ -1,56 +0,0 @@
1
- import { Children, Refkey } from "@alloy-js/core";
2
- import { AccessModifiers } from "../../modifiers.js";
3
- import { AttributesProp } from "../attributes/attributes.jsx";
4
- /** Method modifiers. Can only be one. */
5
- export interface InterfacePropertyModifiers {
6
- readonly new?: boolean;
7
- }
8
- export interface InterfacePropertyProps extends AccessModifiers, InterfacePropertyModifiers {
9
- name: string;
10
- refkey?: Refkey;
11
- /** Property type */
12
- type: Children;
13
- /** If property should have a getter */
14
- get?: boolean;
15
- /** If property should have a setter */
16
- set?: boolean;
17
- /** Doc comment */
18
- doc?: Children;
19
- /**
20
- * Property initializer
21
- * @example `<ClassProperty name="My" get set nullable />`
22
- *
23
- * ```cs
24
- * int? My { get; set; };
25
- * ```
26
- */
27
- nullable?: boolean;
28
- /**
29
- * Define attributes to attach
30
- * @example
31
- * ```tsx
32
- * <InterfaceProperty name="MyProp" attributes={[
33
- * <Attribute name="Test" />
34
- * <Attribute name="Test2" args={["arg1", "arg2"]} />
35
- * ]} />
36
- * ```
37
- * This will produce:
38
- * ```csharp
39
- * [Test]
40
- * [Test2("arg1", "arg2")]
41
- * int MyProp { get; set; }
42
- * ```
43
- */
44
- attributes?: AttributesProp;
45
- }
46
- /**
47
- * Render a C# interface property.
48
- *
49
- * @example `<InterfaceProperty public name="My" get set />`
50
- *
51
- * ```cs
52
- * public int My { get; set; };
53
- * ```
54
- */
55
- export declare function InterfaceProperty(props: InterfacePropertyProps): Children;
56
- //# sourceMappingURL=property.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG7E,yCAAyC;AACzC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,sBACf,SAAQ,eAAe,EACrB,0BAA0B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,oBAAoB;IACpB,IAAI,EAAE,QAAQ,CAAC;IAEf,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,uCAAuC;IACvC,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,YAyC9D"}