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

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 (166) hide show
  1. package/dist/src/components/Class.d.ts +23 -0
  2. package/dist/src/components/Class.d.ts.map +1 -0
  3. package/dist/src/components/{ClassDeclaration.js → Class.js} +37 -67
  4. package/dist/src/components/ClassMethod.d.ts +3 -44
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +8 -32
  7. package/dist/src/components/Enum.d.ts +14 -0
  8. package/dist/src/components/Enum.d.ts.map +1 -0
  9. package/dist/src/components/{EnumDeclaration.js → Enum.js} +2 -21
  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 +9 -2
  22. package/dist/src/modifiers.d.ts.map +1 -1
  23. package/dist/src/modifiers.js +9 -6
  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 +2 -23
  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-declaration.test.js → class.test.js} +51 -234
  31. package/dist/test/enum.test.js +6 -6
  32. package/dist/test/namespace.test.js +4 -4
  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} +4 -4
  36. package/dist/test/sourcefile.test.js +2 -2
  37. package/dist/test/using.test.js +4 -4
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +3 -4
  40. package/src/components/{ClassDeclaration.tsx → Class.tsx} +38 -116
  41. package/src/components/ClassMethod.tsx +7 -70
  42. package/src/components/{EnumDeclaration.tsx → Enum.tsx} +3 -22
  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 +30 -16
  48. package/src/name-policy.ts +0 -5
  49. package/temp/api.json +1194 -6218
  50. package/test/class-method.test.tsx +3 -19
  51. package/test/class.test.tsx +257 -0
  52. package/test/enum.test.tsx +11 -13
  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 +6 -14
  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/project-directory.test.d.ts +0 -2
  137. package/dist/test/project-directory.test.d.ts.map +0 -1
  138. package/dist/test/vitest.setup.d.ts +0 -2
  139. package/dist/test/vitest.setup.d.ts.map +0 -1
  140. package/dist/test/vitest.setup.js +0 -1
  141. package/src/components/attributes/attributes.test.tsx +0 -61
  142. package/src/components/attributes/attributes.tsx +0 -100
  143. package/src/components/doc/comment.test.tsx +0 -337
  144. package/src/components/doc/comment.tsx +0 -152
  145. package/src/components/doc/from-markdown.test.tsx +0 -103
  146. package/src/components/doc/from-markdown.tsx +0 -58
  147. package/src/components/interface/declaration.test.tsx +0 -158
  148. package/src/components/interface/declaration.tsx +0 -125
  149. package/src/components/interface/method.test.tsx +0 -293
  150. package/src/components/interface/method.tsx +0 -122
  151. package/src/components/interface/property.test.tsx +0 -165
  152. package/src/components/interface/property.tsx +0 -127
  153. package/src/components/parameters/parameters.tsx +0 -74
  154. package/src/components/property/property.test.tsx +0 -209
  155. package/src/components/property/property.tsx +0 -172
  156. package/src/components/record/declaration.test.tsx +0 -73
  157. package/src/components/record/declaration.tsx +0 -109
  158. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  159. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  160. package/src/components/type-parameters/type-parameter.tsx +0 -35
  161. package/src/components/type-parameters/type-parameters.test.tsx +0 -46
  162. package/src/components/type-parameters/type-parameters.tsx +0 -63
  163. package/src/components/var/declaration.test.tsx +0 -59
  164. package/src/components/var/declaration.tsx +0 -47
  165. package/test/class-declaration.test.tsx +0 -430
  166. package/test/vitest.setup.ts +0 -1
@@ -1,110 +1,26 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { join } from "@alloy-js/core";
3
2
  import {
4
3
  AccessModifiers,
5
4
  computeModifiersPrefix,
6
5
  getAccessModifier,
7
- makeModifiers,
8
6
  } from "../modifiers.js";
9
7
  import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
10
8
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
11
9
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
12
- import { AttributeList, AttributesProp } from "./attributes/attributes.jsx";
13
- import { DocWhen } from "./doc/comment.jsx";
14
- import { Name } from "./Name.jsx";
15
- import { ParameterProps, Parameters } from "./parameters/parameters.jsx";
16
- import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
17
- import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
18
- import { TypeParameters } from "./type-parameters/type-parameters.jsx";
19
-
20
- export interface ClassModifiers {
21
- readonly abstract?: boolean;
22
- readonly partial?: boolean;
23
- readonly sealed?: boolean;
24
- readonly static?: boolean;
25
- }
26
-
27
- const getClassModifiers = makeModifiers<ClassModifiers>([
28
- "abstract",
29
- "partial",
30
- "sealed",
31
- "static",
32
- ]);
10
+ import { Name } from "./Name.js";
11
+ import { ParameterProps, Parameters } from "./Parameters.js";
33
12
 
34
13
  // properties for creating a class
35
- export interface ClassDeclarationProps
14
+ export interface ClassProps
36
15
  extends Omit<core.DeclarationProps, "nameKind">,
37
- AccessModifiers,
38
- ClassModifiers {
16
+ AccessModifiers {
39
17
  name: string;
40
- /** Doc comment */
41
- doc?: core.Children;
42
18
  refkey?: core.Refkey;
43
-
44
- /**
45
- * Type parameters for the class
46
- *
47
- * @example
48
- * ```tsx
49
- * <ClassDeclaration name="MyClass" typeParameters={["T"]} />
50
- * ```
51
- * This will produce:
52
- * ```csharp
53
- * public class MyClass<T>
54
- * ```
55
- */
56
- typeParameters?: (string | TypeParameterProps)[];
57
-
58
- /** Base class that this class extends */
59
- baseType?: core.Children;
60
-
61
- /** Interfaces this class implements */
62
- interfaceTypes?: core.Children[];
63
-
64
- /**
65
- * Define attributes to attach
66
- * @example
67
- * ```tsx
68
- * <ClassDeclaration name="MyClass" attributes={[
69
- * <Attribute name="Test" />
70
- * <Attribute name="Test2" args={["arg1", "arg2"]} />
71
- * ]}>
72
- * ```
73
- * This will produce:
74
- * ```csharp
75
- * [Test]
76
- * [Test2("arg1", "arg2")]
77
- * public class MyClass
78
- * ```
79
- */
80
- attributes?: AttributesProp;
19
+ typeParameters?: Record<string, core.Refkey>;
81
20
  }
82
21
 
83
- /**
84
- * CSharp class declaration.
85
- * @example
86
- * ```tsx
87
- * <ClassDeclaration public name="MyClass">
88
- * <ClassMember public name="MyField" type="int" />
89
- * <ClassConstructor>
90
- * <Parameter name="value" type="int" />
91
- * this.MyField = value;
92
- * </ClassConstructor>
93
- * </ClassDeclaration>
94
- * ```
95
- * This will produce:
96
- * ```csharp
97
- * public class MyClass
98
- * {
99
- * public int MyField;
100
- * public MyClass(int value)
101
- * {
102
- * this.MyField = value;
103
- * }
104
- * }
105
- * ```
106
- */
107
- export function ClassDeclaration(props: ClassDeclarationProps) {
22
+ // a C# class declaration
23
+ export function Class(props: ClassProps) {
108
24
  const name = useCSharpNamePolicy().getName(props.name!, "class");
109
25
 
110
26
  const thisClassSymbol = new CSharpOutputSymbol(name, {
@@ -119,28 +35,36 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
119
35
  owner: thisClassSymbol,
120
36
  });
121
37
 
122
- const bases = [
123
- ...(props.baseType ? [props.baseType] : []),
124
- ...(props.interfaceTypes || []),
125
- ];
126
- const base =
127
- bases.length > 0 ? <> : {join(bases, { joiner: ", " })}</> : null;
128
- const modifiers = computeModifiersPrefix([
129
- getAccessModifier(props),
130
- getClassModifiers(props),
131
- ]);
38
+ let typeParams: core.Children;
39
+ if (props.typeParameters) {
40
+ const typeParamNames = new Array<string>();
41
+ for (const entry of Object.entries(props.typeParameters)) {
42
+ typeParamNames.push(
43
+ useCSharpNamePolicy().getName(entry[0], "type-parameter"),
44
+ );
45
+ // create a symbol for each type param so its
46
+ // refkey resolves to the type param's name
47
+ new CSharpOutputSymbol(entry[0], {
48
+ scope: thisClassScope,
49
+ refkeys: entry[1],
50
+ });
51
+ }
52
+ typeParams = (
53
+ <group>
54
+ {"<"}
55
+ <core.For each={typeParamNames} comma line>
56
+ {(name) => name}
57
+ </core.For>
58
+ {">"}
59
+ </group>
60
+ );
61
+ }
62
+
63
+ const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
132
64
  return (
133
65
  <core.Declaration symbol={thisClassSymbol}>
134
- <DocWhen doc={props.doc} />
135
- <AttributeList attributes={props.attributes} endline />
136
66
  {modifiers}class <Name />
137
- {props.typeParameters && (
138
- <TypeParameters parameters={props.typeParameters} />
139
- )}
140
- {base}
141
- {props.typeParameters && (
142
- <TypeParameterConstraints parameters={props.typeParameters} />
143
- )}
67
+ {typeParams}
144
68
  {!props.children && ";"}
145
69
  {props.children && (
146
70
  <core.Block newline>
@@ -181,14 +105,15 @@ export function ClassConstructor(props: ClassConstructorProps) {
181
105
 
182
106
  const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
183
107
 
108
+ const params =
109
+ props.parameters ? <Parameters parameters={props.parameters} /> : "";
110
+
184
111
  // note that scope wraps the ctor decl so that the params get the correct scope
185
112
  return (
186
113
  <core.Declaration symbol={ctorSymbol}>
187
114
  <core.Scope value={ctorDeclScope}>
188
115
  {modifiers}
189
- <Name />
190
- <Parameters parameters={props.parameters} />
191
- <core.Block newline>{props.children}</core.Block>
116
+ <Name />({params})<core.Block newline>{props.children}</core.Block>
192
117
  </core.Scope>
193
118
  </core.Declaration>
194
119
  );
@@ -199,8 +124,6 @@ export interface ClassMemberProps extends AccessModifiers {
199
124
  name: string;
200
125
  type: core.Children;
201
126
  refkey?: core.Refkey;
202
- /** Doc comment */
203
- doc?: core.Children;
204
127
  }
205
128
 
206
129
  // a C# class member (i.e. a field within a class like "private int count")
@@ -225,7 +148,6 @@ export function ClassMember(props: ClassMemberProps) {
225
148
  const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
226
149
  return (
227
150
  <core.Declaration symbol={memberSymbol}>
228
- <DocWhen doc={props.doc} />
229
151
  {modifiers}
230
152
  {props.type} <Name />
231
153
  </core.Declaration>
@@ -11,37 +11,16 @@ import {
11
11
  computeModifiersPrefix,
12
12
  getAccessModifier,
13
13
  getAsyncModifier,
14
- makeModifiers,
14
+ getMethodModifier,
15
+ MethodModifiers,
15
16
  } from "../modifiers.js";
16
17
  import { useCSharpNamePolicy } from "../name-policy.js";
17
18
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
18
19
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
19
- import { AttributeList, AttributesProp } from "./attributes/attributes.jsx";
20
- import { DocWhen } from "./doc/comment.jsx";
21
- import { ParameterProps, Parameters } from "./parameters/parameters.jsx";
22
- import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
23
- import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
24
- import { TypeParameters } from "./type-parameters/type-parameters.jsx";
25
-
26
- /** Method modifiers. Can only be one. */
27
- export interface ClassMethodModifiers {
28
- readonly abstract?: boolean;
29
- readonly sealed?: boolean;
30
- readonly static?: boolean;
31
- readonly virtual?: boolean;
32
- }
33
-
34
- const getMethodModifier = makeModifiers<ClassMethodModifiers>([
35
- "abstract",
36
- "sealed",
37
- "static",
38
- "virtual",
39
- ]);
20
+ import { ParameterProps, Parameters } from "./Parameters.jsx";
40
21
 
41
22
  // properties for creating a method
42
- export interface ClassMethodProps
43
- extends AccessModifiers,
44
- ClassMethodModifiers {
23
+ export interface ClassMethodProps extends AccessModifiers, MethodModifiers {
45
24
  name: string;
46
25
  refkey?: Refkey;
47
26
  children?: Children;
@@ -52,41 +31,6 @@ export interface ClassMethodProps
52
31
  * If true, the method will be declared as an async method.
53
32
  */
54
33
  async?: boolean;
55
-
56
- /** Doc comment */
57
- doc?: Children;
58
-
59
- /**
60
- * Type parameters for the method
61
- *
62
- * @example
63
- * ```tsx
64
- * <InterfaceMethod name="Test" typeParameters={["T"]} />
65
- * ```
66
- * This will produce:
67
- * ```csharp
68
- * public void Test<T>()
69
- * ```
70
- */
71
- typeParameters?: (TypeParameterProps | string)[];
72
-
73
- /**
74
- * Define attributes to attach
75
- * @example
76
- * ```tsx
77
- * <ClassMethod name="MyMethod" attributes={[
78
- * <Attribute name="Test" />
79
- * <Attribute name="Test2" args={["arg1", "arg2"]} />
80
- * ]} />
81
- * ```
82
- * This will produce:
83
- * ```csharp
84
- * [Test]
85
- * [Test2("arg1", "arg2")]
86
- * public void MyMethod() { }
87
- * ```
88
- */
89
- attributes?: AttributesProp;
90
34
  }
91
35
 
92
36
  // a C# class method
@@ -107,6 +51,8 @@ export function ClassMethod(props: ClassMethodProps) {
107
51
  owner: methodSymbol,
108
52
  });
109
53
 
54
+ const params =
55
+ props.parameters ? <Parameters parameters={props.parameters} /> : "";
110
56
  const returns = props.returns ?? (props.async ? "Task" : "void");
111
57
 
112
58
  const modifiers = computeModifiersPrefix([
@@ -118,17 +64,8 @@ export function ClassMethod(props: ClassMethodProps) {
118
64
  return (
119
65
  <MemberDeclaration symbol={methodSymbol}>
120
66
  <Scope value={methodScope}>
121
- <DocWhen doc={props.doc} />
122
- <AttributeList attributes={props.attributes} endline />
123
67
  {modifiers}
124
- {returns} {name}
125
- {props.typeParameters && (
126
- <TypeParameters parameters={props.typeParameters} />
127
- )}
128
- <Parameters parameters={props.parameters} />
129
- {props.typeParameters && (
130
- <TypeParameterConstraints parameters={props.typeParameters} />
131
- )}
68
+ {returns} {name}({params})
132
69
  {props.abstract ? ";" : <Block newline>{props.children}</Block>}
133
70
  </Scope>
134
71
  </MemberDeclaration>
@@ -10,33 +10,14 @@ import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
10
10
  import { Name } from "./Name.jsx";
11
11
 
12
12
  // properties for creating an enum
13
- export interface EnumDeclarationProps extends AccessModifiers {
13
+ export interface EnumProps extends AccessModifiers {
14
14
  name: string;
15
15
  refkey?: core.Refkey;
16
16
  children?: core.Children;
17
17
  }
18
18
 
19
- /**
20
- * A C# enum declaration
21
- * @example
22
- * ```tsx
23
- * <EnumDeclaration public name="Color">
24
- * <EnumMember name="Red" />
25
- * <EnumMember name="Green" />
26
- * <EnumMember name="Blue" />
27
- * </EnumDeclaration>
28
- * ```
29
- * This will produce:
30
- * ```csharp
31
- * public enum Color
32
- * {
33
- * Red,
34
- * Green,
35
- * Blue
36
- * }
37
- * ```
38
- */
39
- export function EnumDeclaration(props: EnumDeclarationProps) {
19
+ // a C# enum declaration
20
+ export function Enum(props: EnumProps) {
40
21
  const name = useCSharpNamePolicy().getName(props.name!, "enum");
41
22
  const scope = useCSharpScope();
42
23
 
@@ -0,0 +1,51 @@
1
+ import * as core from "@alloy-js/core";
2
+ import { useCSharpNamePolicy } from "../name-policy.js";
3
+ import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
4
+ import { useCSharpScope } from "../symbols/scopes.js";
5
+ import { Name } from "./Name.js";
6
+
7
+ export interface ParameterProps {
8
+ name: string;
9
+ type: core.Children;
10
+ refkey?: core.Refkey;
11
+ symbol?: core.OutputSymbol;
12
+ }
13
+
14
+ // a constructor/method parameter
15
+ export function Parameter(props: ParameterProps) {
16
+ const name = useCSharpNamePolicy().getName(props.name, "parameter");
17
+ const scope = useCSharpScope();
18
+ if (
19
+ scope.kind !== "member" ||
20
+ (scope.name !== "constructor-decl" && scope.name !== "method-decl")
21
+ ) {
22
+ throw new Error(
23
+ "can't define a parameter outside of a constructor-decl or method-decl scope",
24
+ );
25
+ }
26
+
27
+ const memberSymbol = new CSharpOutputSymbol(name, {
28
+ scope,
29
+ refkeys: props.refkey ?? core.refkey(props.name),
30
+ });
31
+
32
+ return (
33
+ <core.Declaration symbol={memberSymbol}>
34
+ {props.type} <Name />
35
+ </core.Declaration>
36
+ );
37
+ }
38
+
39
+ export interface ParametersProps {
40
+ // param name and type
41
+ parameters: Array<ParameterProps>;
42
+ }
43
+
44
+ // a collection of parameters
45
+ export function Parameters(props: ParametersProps) {
46
+ return (
47
+ <core.For each={props.parameters} joiner={", "}>
48
+ {(param) => <Parameter {...param} />}
49
+ </core.For>
50
+ );
51
+ }
@@ -58,7 +58,6 @@ export function SourceFile(props: SourceFileProps) {
58
58
  filetype="cs"
59
59
  reference={Reference}
60
60
  tabWidth={4}
61
- printWidth={120}
62
61
  >
63
62
  <SourceFileContext.Provider value={sourceFileCtx}>
64
63
  <core.Scope name={props.path} kind="source-file">
@@ -1,21 +1,11 @@
1
- export * from "./attributes/attributes.jsx";
2
- export * from "./ClassDeclaration.jsx";
3
- export * from "./ClassMethod.jsx";
1
+ export * from "./Class.js";
2
+ export { ClassMethod, type ClassMethodProps } from "./ClassMethod.jsx";
4
3
  export * from "./Declaration.js";
5
- export * from "./doc/comment.jsx";
6
- export * from "./doc/from-markdown.jsx";
7
- export * from "./EnumDeclaration.jsx";
8
- export * from "./interface/declaration.js";
9
- export * from "./interface/method.js";
10
- export * from "./interface/property.js";
4
+ export * from "./Enum.js";
11
5
  export * from "./Name.js";
12
6
  export * from "./Namespace.js";
13
- export * from "./parameters/parameters.jsx";
7
+ export * from "./Parameters.js";
14
8
  export * from "./ProjectDirectory.js";
15
- export * from "./property/property.jsx";
16
- export * from "./record/declaration.js";
17
9
  export * from "./Reference.js";
18
10
  export * from "./SourceFile.js";
19
- export type { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
20
11
  export * from "./UsingDirective.js";
21
- export * from "./var/declaration.jsx";
@@ -1,11 +1,11 @@
1
1
  import * as core from "@alloy-js/core";
2
2
  import * as base from "../index.js";
3
3
 
4
- export const ClassDeclaration = core.stc(base.ClassDeclaration);
4
+ export const Class = core.stc(base.Class);
5
5
  export const ClassConstructor = core.stc(base.ClassConstructor);
6
6
  export const ClassMember = core.stc(base.ClassMember);
7
7
  export const ClassMethod = core.stc(base.ClassMethod);
8
- export const EnumDeclaration = core.stc(base.EnumDeclaration);
8
+ export const Enum = core.stc(base.Enum);
9
9
  export const EnumMember = core.stc(base.EnumMember);
10
10
  export const Parameter = core.stc(base.Parameter);
11
11
  export const Parameters = core.stc(base.Parameters);
package/src/modifiers.ts CHANGED
@@ -10,13 +10,36 @@ export interface AccessModifiers {
10
10
  readonly file?: boolean;
11
11
  }
12
12
 
13
- export const getAccessModifier = makeModifiers<AccessModifiers>([
14
- "public",
15
- "protected",
16
- "private",
17
- "internal",
18
- "file",
19
- ]);
13
+ export function getAccessModifier(data: AccessModifiers): string {
14
+ return [
15
+ data.public && "public",
16
+ data.protected && "protected",
17
+ data.private && "private",
18
+ data.internal && "internal",
19
+ data.file && "file",
20
+ ]
21
+ .filter((x) => x)
22
+ .join(" ");
23
+ }
24
+
25
+ /** Method modifiers. Can only be one. */
26
+ export interface MethodModifiers {
27
+ readonly abstract?: boolean;
28
+ readonly sealed?: boolean;
29
+ readonly static?: boolean;
30
+ readonly virtual?: boolean;
31
+ }
32
+
33
+ export function getMethodModifier(data: MethodModifiers): string {
34
+ return [
35
+ data.abstract && "abstract",
36
+ data.sealed && "sealed",
37
+ data.static && "static",
38
+ data.virtual && "virtual",
39
+ ]
40
+ .filter((x) => x)
41
+ .join(" ");
42
+ }
20
43
 
21
44
  export function getAsyncModifier(async?: boolean): string {
22
45
  return async ? "async" : "";
@@ -29,12 +52,3 @@ export function computeModifiersPrefix(
29
52
  const resolved = modifiers.filter((x) => x);
30
53
  return resolved.length > 0 ? resolved.join(" ") + " " : "";
31
54
  }
32
-
33
- export function makeModifiers<T>(obj: Array<keyof T>) {
34
- return (data: T) => {
35
- return obj
36
- .map((key) => (data[key] ? key : undefined))
37
- .filter((x) => x)
38
- .join(" ");
39
- };
40
- }
@@ -5,16 +5,13 @@ import * as changecase from "change-case";
5
5
  export type CSharpElements =
6
6
  | "class"
7
7
  | "constant"
8
- | "variable"
9
8
  | "enum"
10
9
  | "enum-member"
11
10
  | "function"
12
11
  | "interface"
13
- | "record"
14
12
  | "class-member-private"
15
13
  | "class-member-public"
16
14
  | "class-method"
17
- | "class-property"
18
15
  | "parameter"
19
16
  | "type-parameter";
20
17
 
@@ -26,11 +23,9 @@ export function createCSharpNamePolicy(): core.NamePolicy<CSharpElements> {
26
23
  case "enum":
27
24
  case "enum-member":
28
25
  case "interface":
29
- case "record":
30
26
  case "class-member-public":
31
27
  case "class-method":
32
28
  case "type-parameter":
33
- case "class-property":
34
29
  return changecase.pascalCase(name);
35
30
  case "constant":
36
31
  return changecase.constantCase(name);