@alloy-js/csharp 0.18.0-dev.23 → 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 (160) 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 -64
  4. package/dist/src/components/ClassMethod.d.ts +5 -26
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +9 -27
  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 -13
  16. package/dist/src/components/index.d.ts.map +1 -1
  17. package/dist/src/components/index.js +5 -14
  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 -54
  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 -13
  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 +715 -5284
  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 -74
  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/doc/comment.d.ts +0 -70
  63. package/dist/src/components/doc/comment.d.ts.map +0 -1
  64. package/dist/src/components/doc/comment.js +0 -88
  65. package/dist/src/components/doc/comment.test.d.ts +0 -2
  66. package/dist/src/components/doc/comment.test.d.ts.map +0 -1
  67. package/dist/src/components/doc/comment.test.js +0 -348
  68. package/dist/src/components/doc/from-markdown.d.ts +0 -6
  69. package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
  70. package/dist/src/components/doc/from-markdown.js +0 -58
  71. package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
  72. package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
  73. package/dist/src/components/doc/from-markdown.test.js +0 -83
  74. package/dist/src/components/interface/declaration.d.ts +0 -47
  75. package/dist/src/components/interface/declaration.d.ts.map +0 -1
  76. package/dist/src/components/interface/declaration.js +0 -77
  77. package/dist/src/components/interface/declaration.test.d.ts +0 -2
  78. package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
  79. package/dist/src/components/interface/declaration.test.js +0 -153
  80. package/dist/src/components/interface/method.d.ts +0 -32
  81. package/dist/src/components/interface/method.d.ts.map +0 -1
  82. package/dist/src/components/interface/method.js +0 -68
  83. package/dist/src/components/interface/method.test.d.ts +0 -2
  84. package/dist/src/components/interface/method.test.d.ts.map +0 -1
  85. package/dist/src/components/interface/method.test.js +0 -279
  86. package/dist/src/components/interface/property.d.ts +0 -38
  87. package/dist/src/components/interface/property.d.ts.map +0 -1
  88. package/dist/src/components/interface/property.js +0 -67
  89. package/dist/src/components/interface/property.test.d.ts +0 -2
  90. package/dist/src/components/interface/property.test.d.ts.map +0 -1
  91. package/dist/src/components/interface/property.test.js +0 -165
  92. package/dist/src/components/parameters/parameters.d.ts +0 -19
  93. package/dist/src/components/parameters/parameters.d.ts.map +0 -1
  94. package/dist/src/components/parameters/parameters.js +0 -43
  95. package/dist/src/components/property/property.d.ts +0 -62
  96. package/dist/src/components/property/property.d.ts.map +0 -1
  97. package/dist/src/components/property/property.js +0 -70
  98. package/dist/src/components/property/property.test.d.ts +0 -2
  99. package/dist/src/components/property/property.test.d.ts.map +0 -1
  100. package/dist/src/components/property/property.test.js +0 -218
  101. package/dist/src/components/record/declaration.d.ts +0 -35
  102. package/dist/src/components/record/declaration.d.ts.map +0 -1
  103. package/dist/src/components/record/declaration.js +0 -90
  104. package/dist/src/components/record/declaration.test.d.ts +0 -2
  105. package/dist/src/components/record/declaration.test.d.ts.map +0 -1
  106. package/dist/src/components/record/declaration.test.js +0 -94
  107. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
  108. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
  109. package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
  110. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
  111. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
  112. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
  113. package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
  114. package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
  115. package/dist/src/components/type-parameters/type-parameter.js +0 -22
  116. package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
  117. package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
  118. package/dist/src/components/type-parameters/type-parameters.js +0 -54
  119. package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
  120. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
  121. package/dist/src/components/type-parameters/type-parameters.test.js +0 -48
  122. package/dist/src/components/var/declaration.d.ts +0 -35
  123. package/dist/src/components/var/declaration.d.ts.map +0 -1
  124. package/dist/src/components/var/declaration.js +0 -40
  125. package/dist/src/components/var/declaration.test.d.ts +0 -2
  126. package/dist/src/components/var/declaration.test.d.ts.map +0 -1
  127. package/dist/src/components/var/declaration.test.js +0 -73
  128. package/dist/test/class-declaration.test.d.ts +0 -2
  129. package/dist/test/class-declaration.test.d.ts.map +0 -1
  130. package/dist/test/class-declaration.test.js +0 -463
  131. package/dist/test/project-directory.test.d.ts +0 -2
  132. package/dist/test/project-directory.test.d.ts.map +0 -1
  133. package/dist/test/vitest.setup.d.ts +0 -2
  134. package/dist/test/vitest.setup.d.ts.map +0 -1
  135. package/dist/test/vitest.setup.js +0 -1
  136. package/src/components/ClassDeclaration.tsx +0 -213
  137. package/src/components/doc/comment.test.tsx +0 -337
  138. package/src/components/doc/comment.tsx +0 -152
  139. package/src/components/doc/from-markdown.test.tsx +0 -103
  140. package/src/components/doc/from-markdown.tsx +0 -58
  141. package/src/components/interface/declaration.test.tsx +0 -143
  142. package/src/components/interface/declaration.tsx +0 -105
  143. package/src/components/interface/method.test.tsx +0 -278
  144. package/src/components/interface/method.tsx +0 -102
  145. package/src/components/interface/property.test.tsx +0 -144
  146. package/src/components/interface/property.tsx +0 -107
  147. package/src/components/parameters/parameters.tsx +0 -74
  148. package/src/components/property/property.test.tsx +0 -188
  149. package/src/components/property/property.tsx +0 -152
  150. package/src/components/record/declaration.test.tsx +0 -73
  151. package/src/components/record/declaration.tsx +0 -109
  152. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  153. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  154. package/src/components/type-parameters/type-parameter.tsx +0 -35
  155. package/src/components/type-parameters/type-parameters.test.tsx +0 -46
  156. package/src/components/type-parameters/type-parameters.tsx +0 -63
  157. package/src/components/var/declaration.test.tsx +0 -59
  158. package/src/components/var/declaration.tsx +0 -47
  159. package/test/class-declaration.test.tsx +0 -418
  160. package/test/vitest.setup.ts +0 -1
@@ -1,47 +0,0 @@
1
- import * as core from "@alloy-js/core";
2
- import { AccessModifiers } from "../../modifiers.js";
3
- import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
4
- export interface InterfaceModifiers {
5
- readonly partial?: boolean;
6
- }
7
- export interface InterfaceDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, InterfaceModifiers {
8
- name: string;
9
- /** Doc comment */
10
- doc?: core.Children;
11
- refkey?: core.Refkey;
12
- /**
13
- * Type parameters for the interface
14
- *
15
- * @example
16
- * ```tsx
17
- * <InterfaceDeclaration name="IList" typeParameters={["T"]} />
18
- * ```
19
- * This will produce:
20
- * ```csharp
21
- * public interface IList<T>
22
- * ```
23
- */
24
- typeParameters?: (TypeParameterProps | string)[];
25
- }
26
- /**
27
- * CSharp interface declaration.
28
- * @example
29
- * ```tsx
30
- * <InterfaceDeclaration public name="IMyInterface">
31
- * <InterfaceMember public name="MyProperty" type="int" />
32
- * <InterfaceMethod public name="MyMethod" returnType="void">
33
- * <Parameter name="value" type="int" />
34
- * </InterfaceMethod>
35
- * </InterfaceDeclaration>
36
- * ```
37
- * This will produce:
38
- * ```csharp
39
- * public interface MyIface
40
- * {
41
- * public int MyProperty { get; set; }
42
- * public void MyMethod(int value);
43
- * }
44
- * ```
45
- */
46
- export declare function InterfaceDeclaration(props: InterfaceDeclarationProps): core.Children;
47
- //# sourceMappingURL=declaration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAKD,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,kBAAkB;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,iBAoCpE"}
@@ -1,77 +0,0 @@
1
- import { createComponent as _$createComponent, 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
- import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
10
- import { TypeParameters } from "../type-parameters/type-parameters.js";
11
- const getInterfaceModifiers = makeModifiers(["partial"]);
12
-
13
- // properties for creating a class
14
-
15
- /**
16
- * CSharp interface declaration.
17
- * @example
18
- * ```tsx
19
- * <InterfaceDeclaration public name="IMyInterface">
20
- * <InterfaceMember public name="MyProperty" type="int" />
21
- * <InterfaceMethod public name="MyMethod" returnType="void">
22
- * <Parameter name="value" type="int" />
23
- * </InterfaceMethod>
24
- * </InterfaceDeclaration>
25
- * ```
26
- * This will produce:
27
- * ```csharp
28
- * public interface MyIface
29
- * {
30
- * public int MyProperty { get; set; }
31
- * public void MyMethod(int value);
32
- * }
33
- * ```
34
- */
35
- export function InterfaceDeclaration(props) {
36
- const name = useCSharpNamePolicy().getName(props.name, "interface");
37
- const thisInterfaceSymbol = new CSharpOutputSymbol(name, {
38
- refkeys: props.refkey
39
- });
40
-
41
- // this creates a new scope for the interface definition.
42
- // members will automatically "inherit" this scope so
43
- // that refkeys to them will produce the fully-qualified
44
- // name e.g. Foo.Bar.
45
- const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
46
- owner: thisInterfaceSymbol
47
- });
48
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getInterfaceModifiers(props)]);
49
- return _$createComponent(core.Declaration, {
50
- symbol: thisInterfaceSymbol,
51
- get children() {
52
- return [_$createComponent(DocWhen, {
53
- get doc() {
54
- return props.doc;
55
- }
56
- }), modifiers, "interface ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
57
- get parameters() {
58
- return props.typeParameters;
59
- }
60
- })), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
61
- get parameters() {
62
- return props.typeParameters;
63
- }
64
- })), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
65
- newline: true,
66
- get children() {
67
- return _$createComponent(core.Scope, {
68
- value: thisInterfaceScope,
69
- get children() {
70
- return props.children;
71
- }
72
- });
73
- }
74
- }) : ";")];
75
- }
76
- });
77
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=declaration.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.test.tsx"],"names":[],"mappings":""}
@@ -1,153 +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 { SourceFile } from "../SourceFile.js";
6
- import { InterfaceDeclaration } from "./declaration.js";
7
- import { InterfaceProperty } from "./property.js";
8
- it("declares class with no members", () => {
9
- expect(_$createComponent(TestNamespace, {
10
- get children() {
11
- return _$createComponent(InterfaceDeclaration, {
12
- name: "TestInterface"
13
- });
14
- }
15
- })).toRenderTo(`
16
- interface TestInterface;
17
- `);
18
- });
19
- describe("modifiers", () => {
20
- it.each(["public", "private", "internal"])("%s", mod => {
21
- expect(_$createComponent(TestNamespace, {
22
- get children() {
23
- return _$createComponent(InterfaceDeclaration, _$mergeProps({
24
- [mod]: true
25
- }, {
26
- name: "TestInterface"
27
- }));
28
- }
29
- })).toRenderTo(`
30
- ${mod} interface TestInterface;
31
- `);
32
- });
33
- it.each(["partial"])("%s", mod => {
34
- expect(_$createComponent(TestNamespace, {
35
- get children() {
36
- return _$createComponent(InterfaceDeclaration, _$mergeProps({
37
- [mod]: true
38
- }, {
39
- name: "TestInterface"
40
- }));
41
- }
42
- })).toRenderTo(`
43
- ${mod} interface TestInterface;
44
- `);
45
- });
46
- it("combines modifiers", () => {
47
- expect(_$createComponent(TestNamespace, {
48
- get children() {
49
- return _$createComponent(InterfaceDeclaration, {
50
- "public": true,
51
- partial: true,
52
- name: "TestInterface"
53
- });
54
- }
55
- })).toRenderTo(`
56
- public partial interface TestInterface;
57
- `);
58
- });
59
- });
60
- it("specify doc comment", () => {
61
- expect(_$createComponent(TestNamespace, {
62
- get children() {
63
- return _$createComponent(InterfaceDeclaration, {
64
- name: "TestInterface",
65
- doc: "This is a test"
66
- });
67
- }
68
- })).toRenderTo(`
69
- /// This is a test
70
- interface TestInterface;
71
- `);
72
- });
73
- describe("with type parameters", () => {
74
- it("reference parameters", () => {
75
- const typeParameters = [{
76
- name: "T",
77
- refkey: refkey()
78
- }, {
79
- name: "U",
80
- refkey: refkey()
81
- }];
82
- expect(_$createComponent(TestNamespace, {
83
- get children() {
84
- return _$createComponent(SourceFile, {
85
- path: "Test.cs",
86
- get children() {
87
- return _$createComponent(InterfaceDeclaration, {
88
- "public": true,
89
- name: "Test",
90
- typeParameters: typeParameters,
91
- get children() {
92
- return _$createComponent(List, {
93
- get children() {
94
- return [_$createComponent(InterfaceProperty, {
95
- name: "PropA",
96
- get type() {
97
- return typeParameters[0].refkey;
98
- },
99
- get: true,
100
- set: true
101
- }), _$createComponent(InterfaceProperty, {
102
- name: "PropB",
103
- get type() {
104
- return typeParameters[1].refkey;
105
- },
106
- get: true,
107
- set: true
108
- })];
109
- }
110
- });
111
- }
112
- });
113
- }
114
- });
115
- }
116
- })).toRenderTo(`
117
- namespace TestCode
118
- {
119
- public interface Test<T, U>
120
- {
121
- T PropA { get; set; }
122
- U PropB { get; set; }
123
- }
124
- }
125
- `);
126
- });
127
- it("defines with constraints", () => {
128
- const typeParameters = [{
129
- name: "T",
130
- constraints: "IFoo"
131
- }, {
132
- name: "U",
133
- constraints: "IBar"
134
- }];
135
- expect(_$createComponent(TestNamespace, {
136
- get children() {
137
- return _$createComponent(InterfaceDeclaration, {
138
- "public": true,
139
- name: "Test",
140
- typeParameters: typeParameters,
141
- children: "// Body"
142
- });
143
- }
144
- })).toRenderTo(`
145
- public interface Test<T, U>
146
- where T : IFoo
147
- where U : IBar
148
- {
149
- // Body
150
- }
151
- `);
152
- });
153
- });
@@ -1,32 +0,0 @@
1
- import { Children, Refkey } from "@alloy-js/core";
2
- import { AccessModifiers } from "../../modifiers.js";
3
- import { ParameterProps } from "../parameters/parameters.jsx";
4
- import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
5
- /** Method modifiers. Can only be one. */
6
- export interface InterfaceMethodModifiers {
7
- readonly new?: boolean;
8
- }
9
- export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodModifiers {
10
- name: string;
11
- refkey?: Refkey;
12
- children?: Children;
13
- parameters?: Array<ParameterProps>;
14
- /**
15
- * Type parameters for the method
16
- *
17
- * @example
18
- * ```tsx
19
- * <InterfaceMethod name="Test" typeParameters={["T"]} />
20
- * ```
21
- * This will produce:
22
- * ```csharp
23
- * public void Test<T>()
24
- * ```
25
- */
26
- typeParameters?: (TypeParameterProps | string)[];
27
- returns?: Children;
28
- /** Doc comment */
29
- doc?: Children;
30
- }
31
- export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
32
- //# 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;AAK5B,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;CAChB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA2C1D"}
@@ -1,68 +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 { DocWhen } from "../doc/comment.js";
8
- import { Parameters } from "../parameters/parameters.js";
9
- import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
10
- import { TypeParameters } from "../type-parameters/type-parameters.js";
11
-
12
- /** Method modifiers. Can only be one. */
13
-
14
- const getMethodModifier = makeModifiers(["new"]);
15
-
16
- // properties for creating a method
17
-
18
- // a C# interface method
19
- export function InterfaceMethod(props) {
20
- const name = useCSharpNamePolicy().getName(props.name, "class-method");
21
- const scope = useCSharpScope();
22
- if (scope.kind !== "member" || scope.name !== "interface-decl") {
23
- throw new Error("can't define an interface method outside of an interface scope");
24
- }
25
- const methodSymbol = new CSharpOutputSymbol(name, {
26
- scope,
27
- refkeys: props.refkey ?? refkey(props.name)
28
- });
29
-
30
- // scope for method declaration
31
- const methodScope = new CSharpMemberScope("method-decl", {
32
- owner: methodSymbol
33
- });
34
- const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
35
- // note that scope wraps the method decl so that the params get the correct scope
36
- return _$createComponent(MemberDeclaration, {
37
- symbol: methodSymbol,
38
- get children() {
39
- return _$createComponent(Scope, {
40
- value: methodScope,
41
- get children() {
42
- return [_$createComponent(DocWhen, {
43
- get doc() {
44
- return props.doc;
45
- }
46
- }), modifiers, _$memo(() => props.returns ?? "void"), " ", name, _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
47
- get parameters() {
48
- return props.typeParameters;
49
- }
50
- })), _$createComponent(Parameters, {
51
- get parameters() {
52
- return props.parameters;
53
- }
54
- }), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
55
- get parameters() {
56
- return props.typeParameters;
57
- }
58
- })), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
59
- newline: true,
60
- get children() {
61
- return props.children;
62
- }
63
- }) : ";")];
64
- }
65
- });
66
- }
67
- });
68
- }
@@ -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,279 +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 { SourceFile } from "../SourceFile.js";
6
- import { InterfaceDeclaration } from "./declaration.js";
7
- import { InterfaceMethod } from "./method.js";
8
- const Wrapper = props => _$createComponent(TestNamespace, {
9
- get children() {
10
- return _$createComponent(InterfaceDeclaration, {
11
- "public": true,
12
- name: "TestInterface",
13
- get children() {
14
- return props.children;
15
- }
16
- });
17
- }
18
- });
19
- describe("modifiers", () => {
20
- describe("access modifiers", () => {
21
- it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
22
- expect(_$createComponent(Wrapper, {
23
- get children() {
24
- return _$createComponent(InterfaceMethod, _$mergeProps({
25
- [accessModifier]: true
26
- }, {
27
- name: "MethodOne"
28
- }));
29
- }
30
- })).toRenderTo(`
31
- public interface TestInterface
32
- {
33
- ${accessModifier} void MethodOne();
34
- }
35
- `);
36
- });
37
- });
38
- describe("method modifiers", () => {
39
- it.each(["new"])("%s", methodModifier => {
40
- expect(_$createComponent(Wrapper, {
41
- get children() {
42
- return _$createComponent(InterfaceMethod, _$mergeProps({
43
- [methodModifier]: true
44
- }, {
45
- name: "MethodOne"
46
- }));
47
- }
48
- })).toRenderTo(`
49
- public interface TestInterface
50
- {
51
- ${methodModifier} void MethodOne();
52
- }
53
- `);
54
- });
55
- });
56
- it("combine modifiers", () => {
57
- expect(_$createComponent(Wrapper, {
58
- get children() {
59
- return _$createComponent(InterfaceMethod, {
60
- returns: "Task",
61
- "public": true,
62
- "new": true,
63
- name: "MethodOne"
64
- });
65
- }
66
- })).toRenderTo(`
67
- public interface TestInterface
68
- {
69
- public new Task MethodOne();
70
- }
71
- `);
72
- });
73
- });
74
- it("applies PascalCase naming policy", () => {
75
- expect(_$createComponent(Wrapper, {
76
- get children() {
77
- return _$createComponent(InterfaceMethod, {
78
- name: "method_one"
79
- });
80
- }
81
- })).toRenderTo(`
82
- public interface TestInterface
83
- {
84
- void MethodOne();
85
- }
86
- `);
87
- });
88
- it("defines params and return type", () => {
89
- const params = [{
90
- name: "intParam",
91
- type: "int"
92
- }, {
93
- name: "stringParam",
94
- type: "string"
95
- }];
96
- const res = _$createComponent(Wrapper, {
97
- get children() {
98
- return _$createComponent(InterfaceMethod, {
99
- "public": true,
100
- name: "MethodOne",
101
- parameters: params,
102
- returns: "string"
103
- });
104
- }
105
- });
106
- expect(res).toRenderTo(`
107
- public interface TestInterface
108
- {
109
- public string MethodOne(int intParam, string stringParam);
110
- }
111
- `);
112
- });
113
- it("defines optional param", () => {
114
- const res = _$createComponent(Wrapper, {
115
- get children() {
116
- return _$createComponent(InterfaceMethod, {
117
- "public": true,
118
- name: "MethodOne",
119
- parameters: [{
120
- name: "intParam",
121
- type: "int",
122
- optional: true
123
- }],
124
- returns: "string"
125
- });
126
- }
127
- });
128
- expect(res).toRenderTo(`
129
- public interface TestInterface
130
- {
131
- public string MethodOne(int? intParam);
132
- }
133
- `);
134
- });
135
- it("defines optional param with default", () => {
136
- const res = _$createComponent(Wrapper, {
137
- get children() {
138
- return _$createComponent(InterfaceMethod, {
139
- "public": true,
140
- name: "MethodOne",
141
- parameters: [{
142
- name: "intParam",
143
- type: "int",
144
- default: 12
145
- }],
146
- returns: "string"
147
- });
148
- }
149
- });
150
- expect(res).toRenderTo(`
151
- public interface TestInterface
152
- {
153
- public string MethodOne(int intParam = 12);
154
- }
155
- `);
156
- });
157
- it("specify doc comment", () => {
158
- expect(_$createComponent(TestNamespace, {
159
- get children() {
160
- return _$createComponent(InterfaceDeclaration, {
161
- name: "Test",
162
- get children() {
163
- return _$createComponent(InterfaceMethod, {
164
- name: "Method",
165
- doc: "This is a test"
166
- });
167
- }
168
- });
169
- }
170
- })).toRenderTo(`
171
- interface Test
172
- {
173
- /// This is a test
174
- void Method();
175
- }
176
- `);
177
- });
178
- describe("with type parameters", () => {
179
- it("reference parameters", () => {
180
- const typeParameters = [{
181
- name: "T",
182
- refkey: refkey()
183
- }, {
184
- name: "U",
185
- refkey: refkey()
186
- }];
187
- expect(_$createComponent(TestNamespace, {
188
- get children() {
189
- return _$createComponent(SourceFile, {
190
- path: "TestFile.cs",
191
- get children() {
192
- return _$createComponent(InterfaceDeclaration, {
193
- "public": true,
194
- name: "TestInterface",
195
- get children() {
196
- return _$createComponent(InterfaceMethod, {
197
- name: "Test",
198
- "public": true,
199
- typeParameters: typeParameters,
200
- get parameters() {
201
- return [{
202
- name: "paramA",
203
- type: typeParameters[0].refkey
204
- }];
205
- },
206
- get returns() {
207
- return typeParameters[0].refkey;
208
- }
209
- });
210
- }
211
- });
212
- }
213
- });
214
- }
215
- })).toRenderTo(`
216
- namespace TestCode
217
- {
218
- public interface TestInterface
219
- {
220
- public T Test<T, U>(T paramA);
221
- }
222
- }
223
- `);
224
- });
225
- it("defines with constraints", () => {
226
- const typeParameters = [{
227
- name: "T",
228
- constraints: "IFoo"
229
- }, {
230
- name: "U",
231
- constraints: "IBar"
232
- }];
233
- expect(_$createComponent(Wrapper, {
234
- get children() {
235
- return _$createComponent(InterfaceMethod, {
236
- "public": true,
237
- name: "Test",
238
- typeParameters: typeParameters,
239
- children: "// Body"
240
- });
241
- }
242
- })).toRenderTo(`
243
- public interface TestInterface
244
- {
245
- public void Test<T, U>()
246
- where T : IFoo
247
- where U : IBar
248
- {
249
- // Body
250
- }
251
- }
252
- `);
253
- });
254
- });
255
- describe("formatting", () => {
256
- it("Split parameters before type parameters", () => {
257
- expect(_$createComponent(Wrapper, {
258
- get children() {
259
- return _$createComponent(InterfaceMethod, {
260
- "public": true,
261
- name: "Handle",
262
- parameters: [{
263
- name: "message",
264
- type: "Some.Quite.Long.Type.That.Will.Split"
265
- }],
266
- typeParameters: ["T"],
267
- returns: "Some.Quite.Long.Type.That.Will.Split"
268
- });
269
- }
270
- })).toRenderTo(`
271
- public interface TestInterface
272
- {
273
- public Some.Quite.Long.Type.That.Will.Split Handle<T>(
274
- Some.Quite.Long.Type.That.Will.Split message
275
- );
276
- }
277
- `);
278
- });
279
- });