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

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 (153) 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} +32 -59
  4. package/dist/src/components/ClassMethod.d.ts +4 -25
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +3 -22
  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 +1 -6
  11. package/dist/src/components/Parameters.d.ts.map +1 -1
  12. package/dist/src/components/Parameters.js +2 -3
  13. package/dist/src/components/index.d.ts +3 -12
  14. package/dist/src/components/index.d.ts.map +1 -1
  15. package/dist/src/components/index.js +4 -13
  16. package/dist/src/components/stc/index.d.ts +2 -2
  17. package/dist/src/components/stc/index.d.ts.map +1 -1
  18. package/dist/src/components/stc/index.js +2 -2
  19. package/dist/src/modifiers.d.ts +4 -10
  20. package/dist/src/modifiers.d.ts.map +1 -1
  21. package/dist/src/modifiers.js +32 -9
  22. package/dist/src/name-policy.d.ts +1 -1
  23. package/dist/src/name-policy.d.ts.map +1 -1
  24. package/dist/src/name-policy.js +0 -2
  25. package/dist/test/class-method.test.js +14 -37
  26. package/dist/test/class.test.d.ts +2 -0
  27. package/dist/test/class.test.d.ts.map +1 -0
  28. package/dist/test/class.test.js +298 -0
  29. package/dist/test/enum.test.js +12 -12
  30. package/dist/test/namespace.test.js +8 -8
  31. package/dist/test/projectdirectory.test.d.ts +2 -0
  32. package/dist/test/projectdirectory.test.d.ts.map +1 -0
  33. package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
  34. package/dist/test/sourcefile.test.js +4 -4
  35. package/dist/test/using.test.js +9 -9
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +21 -21
  38. package/src/components/{ClassDeclaration.tsx → Class.tsx} +43 -108
  39. package/src/components/ClassMethod.tsx +12 -53
  40. package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
  41. package/src/components/Parameters.tsx +3 -10
  42. package/src/components/index.ts +3 -12
  43. package/src/components/stc/index.ts +2 -2
  44. package/src/modifiers.ts +42 -25
  45. package/src/name-policy.ts +0 -5
  46. package/temp/api.json +714 -5256
  47. package/test/class-method.test.tsx +14 -24
  48. package/test/class.test.tsx +292 -0
  49. package/test/enum.test.tsx +11 -11
  50. package/test/namespace.test.tsx +4 -4
  51. package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
  52. package/test/sourcefile.test.tsx +2 -2
  53. package/test/using.test.tsx +9 -9
  54. package/vitest.config.ts +0 -3
  55. package/LICENSE +0 -7
  56. package/dist/src/components/ClassDeclaration.d.ts +0 -74
  57. package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
  58. package/dist/src/components/EnumDeclaration.d.ts +0 -34
  59. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  60. package/dist/src/components/doc/comment.d.ts +0 -70
  61. package/dist/src/components/doc/comment.d.ts.map +0 -1
  62. package/dist/src/components/doc/comment.js +0 -88
  63. package/dist/src/components/doc/comment.test.d.ts +0 -2
  64. package/dist/src/components/doc/comment.test.d.ts.map +0 -1
  65. package/dist/src/components/doc/comment.test.js +0 -348
  66. package/dist/src/components/doc/from-markdown.d.ts +0 -6
  67. package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
  68. package/dist/src/components/doc/from-markdown.js +0 -58
  69. package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
  70. package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
  71. package/dist/src/components/doc/from-markdown.test.js +0 -83
  72. package/dist/src/components/interface/declaration.d.ts +0 -47
  73. package/dist/src/components/interface/declaration.d.ts.map +0 -1
  74. package/dist/src/components/interface/declaration.js +0 -77
  75. package/dist/src/components/interface/declaration.test.d.ts +0 -2
  76. package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
  77. package/dist/src/components/interface/declaration.test.js +0 -153
  78. package/dist/src/components/interface/method.d.ts +0 -32
  79. package/dist/src/components/interface/method.d.ts.map +0 -1
  80. package/dist/src/components/interface/method.js +0 -69
  81. package/dist/src/components/interface/method.test.d.ts +0 -2
  82. package/dist/src/components/interface/method.test.d.ts.map +0 -1
  83. package/dist/src/components/interface/method.test.js +0 -254
  84. package/dist/src/components/interface/property.d.ts +0 -38
  85. package/dist/src/components/interface/property.d.ts.map +0 -1
  86. package/dist/src/components/interface/property.js +0 -67
  87. package/dist/src/components/interface/property.test.d.ts +0 -2
  88. package/dist/src/components/interface/property.test.d.ts.map +0 -1
  89. package/dist/src/components/interface/property.test.js +0 -165
  90. package/dist/src/components/property/property.d.ts +0 -57
  91. package/dist/src/components/property/property.d.ts.map +0 -1
  92. package/dist/src/components/property/property.js +0 -70
  93. package/dist/src/components/property/property.test.d.ts +0 -2
  94. package/dist/src/components/property/property.test.d.ts.map +0 -1
  95. package/dist/src/components/property/property.test.js +0 -218
  96. package/dist/src/components/record/declaration.d.ts +0 -35
  97. package/dist/src/components/record/declaration.d.ts.map +0 -1
  98. package/dist/src/components/record/declaration.js +0 -90
  99. package/dist/src/components/record/declaration.test.d.ts +0 -2
  100. package/dist/src/components/record/declaration.test.d.ts.map +0 -1
  101. package/dist/src/components/record/declaration.test.js +0 -94
  102. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
  103. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
  104. package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
  105. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
  106. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
  107. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
  108. package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
  109. package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
  110. package/dist/src/components/type-parameters/type-parameter.js +0 -22
  111. package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
  112. package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
  113. package/dist/src/components/type-parameters/type-parameters.js +0 -65
  114. package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
  115. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
  116. package/dist/src/components/type-parameters/type-parameters.test.js +0 -26
  117. package/dist/src/components/var/declaration.d.ts +0 -35
  118. package/dist/src/components/var/declaration.d.ts.map +0 -1
  119. package/dist/src/components/var/declaration.js +0 -40
  120. package/dist/src/components/var/declaration.test.d.ts +0 -2
  121. package/dist/src/components/var/declaration.test.d.ts.map +0 -1
  122. package/dist/src/components/var/declaration.test.js +0 -73
  123. package/dist/test/class-declaration.test.d.ts +0 -2
  124. package/dist/test/class-declaration.test.d.ts.map +0 -1
  125. package/dist/test/class-declaration.test.js +0 -463
  126. package/dist/test/project-directory.test.d.ts +0 -2
  127. package/dist/test/project-directory.test.d.ts.map +0 -1
  128. package/dist/test/vitest.setup.d.ts +0 -2
  129. package/dist/test/vitest.setup.d.ts.map +0 -1
  130. package/dist/test/vitest.setup.js +0 -1
  131. package/src/components/doc/comment.test.tsx +0 -337
  132. package/src/components/doc/comment.tsx +0 -152
  133. package/src/components/doc/from-markdown.test.tsx +0 -103
  134. package/src/components/doc/from-markdown.tsx +0 -58
  135. package/src/components/interface/declaration.test.tsx +0 -143
  136. package/src/components/interface/declaration.tsx +0 -105
  137. package/src/components/interface/method.test.tsx +0 -250
  138. package/src/components/interface/method.tsx +0 -105
  139. package/src/components/interface/property.test.tsx +0 -144
  140. package/src/components/interface/property.tsx +0 -107
  141. package/src/components/property/property.test.tsx +0 -187
  142. package/src/components/property/property.tsx +0 -146
  143. package/src/components/record/declaration.test.tsx +0 -73
  144. package/src/components/record/declaration.tsx +0 -109
  145. package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
  146. package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
  147. package/src/components/type-parameters/type-parameter.tsx +0 -35
  148. package/src/components/type-parameters/type-parameters.test.tsx +0 -19
  149. package/src/components/type-parameters/type-parameters.tsx +0 -72
  150. package/src/components/var/declaration.test.tsx +0 -59
  151. package/src/components/var/declaration.tsx +0 -47
  152. package/test/class-declaration.test.tsx +0 -418
  153. package/test/vitest.setup.ts +0 -1
@@ -1,91 +1,21 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { join } from "@alloy-js/core";
3
- import {
4
- AccessModifiers,
5
- computeModifiersPrefix,
6
- getAccessModifier,
7
- makeModifiers,
8
- } from "../modifiers.js";
2
+ import { AccessModifier, getAccessModifier } from "../modifiers.js";
9
3
  import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
10
4
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
11
5
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
12
- import { Name } from "./Name.jsx";
13
- import { ParameterProps, Parameters } from "./Parameters.jsx";
14
- import { DocWhen } from "./doc/comment.jsx";
15
- import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
16
- import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
17
- import { TypeParameters } from "./type-parameters/type-parameters.jsx";
18
-
19
- export interface ClassModifiers {
20
- readonly abstract?: boolean;
21
- readonly partial?: boolean;
22
- readonly sealed?: boolean;
23
- readonly static?: boolean;
24
- }
25
-
26
- const getClassModifiers = makeModifiers<ClassModifiers>([
27
- "abstract",
28
- "partial",
29
- "sealed",
30
- "static",
31
- ]);
6
+ import { Name } from "./Name.js";
7
+ import { ParameterProps, Parameters } from "./Parameters.js";
32
8
 
33
9
  // properties for creating a class
34
- export interface ClassDeclarationProps
35
- extends Omit<core.DeclarationProps, "nameKind">,
36
- AccessModifiers,
37
- ClassModifiers {
10
+ export interface ClassProps extends Omit<core.DeclarationProps, "nameKind"> {
38
11
  name: string;
39
- /** Doc comment */
40
- doc?: core.Children;
41
12
  refkey?: core.Refkey;
42
-
43
- /**
44
- * Type parameters for the class
45
- *
46
- * @example
47
- * ```tsx
48
- * <ClassDeclaration name="MyClass" typeParameters={["T"]} />
49
- * ```
50
- * This will produce:
51
- * ```csharp
52
- * public class MyClass<T>
53
- * ```
54
- */
55
- typeParameters?: (string | TypeParameterProps)[];
56
-
57
- /** Base class that this class extends */
58
- baseType?: core.Children;
59
-
60
- /** Interfaces this class implements */
61
- interfaceTypes?: core.Children[];
13
+ accessModifier?: AccessModifier;
14
+ typeParameters?: Record<string, core.Refkey>;
62
15
  }
63
16
 
64
- /**
65
- * CSharp class declaration.
66
- * @example
67
- * ```tsx
68
- * <ClassDeclaration public name="MyClass">
69
- * <ClassMember public name="MyField" type="int" />
70
- * <ClassConstructor>
71
- * <Parameter name="value" type="int" />
72
- * this.MyField = value;
73
- * </ClassConstructor>
74
- * </ClassDeclaration>
75
- * ```
76
- * This will produce:
77
- * ```csharp
78
- * public class MyClass
79
- * {
80
- * public int MyField;
81
- * public MyClass(int value)
82
- * {
83
- * this.MyField = value;
84
- * }
85
- * }
86
- * ```
87
- */
88
- export function ClassDeclaration(props: ClassDeclarationProps) {
17
+ // a C# class declaration
18
+ export function Class(props: ClassProps) {
89
19
  const name = useCSharpNamePolicy().getName(props.name!, "class");
90
20
 
91
21
  const thisClassSymbol = new CSharpOutputSymbol(name, {
@@ -100,27 +30,35 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
100
30
  owner: thisClassSymbol,
101
31
  });
102
32
 
103
- const bases = [
104
- ...(props.baseType ? [props.baseType] : []),
105
- ...(props.interfaceTypes || []),
106
- ];
107
- const base =
108
- bases.length > 0 ? <> : {join(bases, { joiner: ", " })}</> : null;
109
- const modifiers = computeModifiersPrefix([
110
- getAccessModifier(props),
111
- getClassModifiers(props),
112
- ]);
33
+ let typeParams: core.Children;
34
+ if (props.typeParameters) {
35
+ const typeParamNames = new Array<string>();
36
+ for (const entry of Object.entries(props.typeParameters)) {
37
+ typeParamNames.push(
38
+ useCSharpNamePolicy().getName(entry[0], "type-parameter"),
39
+ );
40
+ // create a symbol for each type param so its
41
+ // refkey resolves to the type param's name
42
+ new CSharpOutputSymbol(entry[0], {
43
+ scope: thisClassScope,
44
+ refkeys: entry[1],
45
+ });
46
+ }
47
+ typeParams = (
48
+ <group>
49
+ {"<"}
50
+ <core.For each={typeParamNames} comma line>
51
+ {(name) => name}
52
+ </core.For>
53
+ {">"}
54
+ </group>
55
+ );
56
+ }
57
+
113
58
  return (
114
59
  <core.Declaration symbol={thisClassSymbol}>
115
- <DocWhen doc={props.doc} />
116
- {modifiers}class <Name />
117
- {props.typeParameters && (
118
- <TypeParameters parameters={props.typeParameters} />
119
- )}
120
- {base}
121
- {props.typeParameters && (
122
- <TypeParameterConstraints parameters={props.typeParameters} />
123
- )}
60
+ {getAccessModifier(props.accessModifier)}class <Name />
61
+ {typeParams}
124
62
  {!props.children && ";"}
125
63
  {props.children && (
126
64
  <core.Block newline>
@@ -131,7 +69,8 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
131
69
  );
132
70
  }
133
71
 
134
- export interface ClassConstructorProps extends AccessModifiers {
72
+ export interface ClassConstructorProps {
73
+ accessModifier?: AccessModifier;
135
74
  parameters?: Array<ParameterProps>;
136
75
  refkey?: core.Refkey;
137
76
  symbol?: core.OutputSymbol;
@@ -159,8 +98,7 @@ export function ClassConstructor(props: ClassConstructorProps) {
159
98
  owner: ctorSymbol,
160
99
  });
161
100
 
162
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
163
-
101
+ const accessModifier = getAccessModifier(props.accessModifier);
164
102
  const params =
165
103
  props.parameters ? <Parameters parameters={props.parameters} /> : "";
166
104
 
@@ -168,7 +106,7 @@ export function ClassConstructor(props: ClassConstructorProps) {
168
106
  return (
169
107
  <core.Declaration symbol={ctorSymbol}>
170
108
  <core.Scope value={ctorDeclScope}>
171
- {modifiers}
109
+ {accessModifier}
172
110
  <Name />({params})<core.Block newline>{props.children}</core.Block>
173
111
  </core.Scope>
174
112
  </core.Declaration>
@@ -176,18 +114,17 @@ export function ClassConstructor(props: ClassConstructorProps) {
176
114
  }
177
115
 
178
116
  // properties for creating a class member
179
- export interface ClassMemberProps extends AccessModifiers {
117
+ export interface ClassMemberProps {
180
118
  name: string;
181
119
  type: core.Children;
120
+ accessModifier?: AccessModifier;
182
121
  refkey?: core.Refkey;
183
- /** Doc comment */
184
- doc?: core.Children;
185
122
  }
186
123
 
187
124
  // a C# class member (i.e. a field within a class like "private int count")
188
125
  export function ClassMember(props: ClassMemberProps) {
189
126
  let nameElement: CSharpElements = "class-member-private";
190
- if (props.public) {
127
+ if (props.accessModifier === "public") {
191
128
  nameElement = "class-member-public";
192
129
  }
193
130
  const name = useCSharpNamePolicy().getName(props.name, nameElement);
@@ -203,11 +140,9 @@ export function ClassMember(props: ClassMemberProps) {
203
140
  refkeys: props.refkey ?? core.refkey(props.name),
204
141
  });
205
142
 
206
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
207
143
  return (
208
144
  <core.Declaration symbol={memberSymbol}>
209
- <DocWhen doc={props.doc} />
210
- {modifiers}
145
+ {getAccessModifier(props.accessModifier)}
211
146
  {props.type} <Name />
212
147
  </core.Declaration>
213
148
  );
@@ -7,43 +7,25 @@ import {
7
7
  Scope,
8
8
  } from "@alloy-js/core";
9
9
  import {
10
- AccessModifiers,
10
+ AccessModifier,
11
11
  computeModifiersPrefix,
12
12
  getAccessModifier,
13
13
  getAsyncModifier,
14
- makeModifiers,
14
+ getMethodModifier,
15
+ MethodModifier,
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
20
  import { ParameterProps, Parameters } from "./Parameters.jsx";
20
- import { DocWhen } from "./doc/comment.jsx";
21
- import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.jsx";
22
- import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
23
- import { TypeParameters } from "./type-parameters/type-parameters.jsx";
24
-
25
- /** Method modifiers. Can only be one. */
26
- export interface ClassMethodModifiers {
27
- readonly abstract?: boolean;
28
- readonly sealed?: boolean;
29
- readonly static?: boolean;
30
- readonly virtual?: boolean;
31
- }
32
-
33
- const getMethodModifier = makeModifiers<ClassMethodModifiers>([
34
- "abstract",
35
- "sealed",
36
- "static",
37
- "virtual",
38
- ]);
39
21
 
40
22
  // properties for creating a method
41
- export interface ClassMethodProps
42
- extends AccessModifiers,
43
- ClassMethodModifiers {
23
+ export interface ClassMethodProps {
44
24
  name: string;
45
25
  refkey?: Refkey;
46
26
  children?: Children;
27
+ accessModifier?: AccessModifier;
28
+ methodModifier?: MethodModifier;
47
29
  parameters?: Array<ParameterProps>;
48
30
  returns?: Children;
49
31
 
@@ -51,23 +33,6 @@ export interface ClassMethodProps
51
33
  * If true, the method will be declared as an async method.
52
34
  */
53
35
  async?: boolean;
54
-
55
- /** Doc comment */
56
- doc?: Children;
57
-
58
- /**
59
- * Type parameters for the method
60
- *
61
- * @example
62
- * ```tsx
63
- * <InterfaceMethod name="Test" typeParameters={["T"]} />
64
- * ```
65
- * This will produce:
66
- * ```csharp
67
- * public void Test<T>()
68
- * ```
69
- */
70
- typeParameters?: (TypeParameterProps | string)[];
71
36
  }
72
37
 
73
38
  // a C# class method
@@ -93,25 +58,19 @@ export function ClassMethod(props: ClassMethodProps) {
93
58
  const returns = props.returns ?? (props.async ? "Task" : "void");
94
59
 
95
60
  const modifiers = computeModifiersPrefix([
96
- getAccessModifier(props),
97
- getMethodModifier(props),
61
+ getAccessModifier(props.accessModifier),
62
+ getMethodModifier(props.methodModifier),
98
63
  getAsyncModifier(props.async),
99
64
  ]);
100
65
  // note that scope wraps the method decl so that the params get the correct scope
101
66
  return (
102
67
  <MemberDeclaration symbol={methodSymbol}>
103
68
  <Scope value={methodScope}>
104
- <DocWhen doc={props.doc} />
105
69
  {modifiers}
106
- {returns} {name}
107
- {props.typeParameters && (
108
- <TypeParameters parameters={props.typeParameters} />
109
- )}
110
- ({params})
111
- {props.typeParameters && (
112
- <TypeParameterConstraints parameters={props.typeParameters} />
113
- )}
114
- {props.abstract ? ";" : <Block newline>{props.children}</Block>}
70
+ {returns} {name}({params})
71
+ {props.methodModifier === "abstract" ?
72
+ ";"
73
+ : <Block newline>{props.children}</Block>}
115
74
  </Scope>
116
75
  </MemberDeclaration>
117
76
  );
@@ -1,42 +1,20 @@
1
1
  import * as core from "@alloy-js/core";
2
- import {
3
- AccessModifiers,
4
- computeModifiersPrefix,
5
- getAccessModifier,
6
- } from "../modifiers.js";
2
+ import { AccessModifier, getAccessModifier } from "../modifiers.js";
7
3
  import { useCSharpNamePolicy } from "../name-policy.js";
8
4
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
9
5
  import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
10
6
  import { Name } from "./Name.jsx";
11
7
 
12
8
  // properties for creating an enum
13
- export interface EnumDeclarationProps extends AccessModifiers {
9
+ export interface EnumProps {
14
10
  name: string;
15
11
  refkey?: core.Refkey;
16
12
  children?: core.Children;
13
+ accessModifier?: AccessModifier;
17
14
  }
18
15
 
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) {
16
+ // a C# enum declaration
17
+ export function Enum(props: EnumProps) {
40
18
  const name = useCSharpNamePolicy().getName(props.name!, "enum");
41
19
  const scope = useCSharpScope();
42
20
 
@@ -54,12 +32,10 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
54
32
  owner: thisEnumSymbol,
55
33
  });
56
34
 
57
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
58
-
59
35
  if (thisEnumScope.owner)
60
36
  return (
61
37
  <core.Declaration symbol={thisEnumSymbol}>
62
- {modifiers}enum <Name />
38
+ {getAccessModifier(props.accessModifier)}enum <Name />
63
39
  {!props.children && ";"}
64
40
  {props.children && (
65
41
  <core.Scope value={thisEnumScope}>
@@ -1,5 +1,4 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { code } from "@alloy-js/core";
3
2
  import { useCSharpNamePolicy } from "../name-policy.js";
4
3
  import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
5
4
  import { useCSharpScope } from "../symbols/scopes.js";
@@ -8,15 +7,11 @@ import { Name } from "./Name.js";
8
7
  export interface ParameterProps {
9
8
  name: string;
10
9
  type: core.Children;
11
- /** If the parmaeter is optional(without default value) */
12
- optional?: boolean;
13
- /** Default value for the parameter */
14
- default?: core.Children;
15
10
  refkey?: core.Refkey;
16
11
  symbol?: core.OutputSymbol;
17
12
  }
18
13
 
19
- /** Define a parameter to be used in class or interface method. */
14
+ // a constructor/method parameter
20
15
  export function Parameter(props: ParameterProps) {
21
16
  const name = useCSharpNamePolicy().getName(props.name, "parameter");
22
17
  const scope = useCSharpScope();
@@ -36,16 +31,14 @@ export function Parameter(props: ParameterProps) {
36
31
 
37
32
  return (
38
33
  <core.Declaration symbol={memberSymbol}>
39
- {props.type}
40
- {props.optional ? "?" : ""} <Name />
41
- {props.default ? code` = ${props.default}` : ""}
34
+ {props.type} <Name />
42
35
  </core.Declaration>
43
36
  );
44
37
  }
45
38
 
46
39
  export interface ParametersProps {
47
40
  // param name and type
48
- parameters: ParameterProps[];
41
+ parameters: Array<ParameterProps>;
49
42
  }
50
43
 
51
44
  // a collection of parameters
@@ -1,20 +1,11 @@
1
- export * from "./ClassDeclaration.jsx";
2
- export * from "./ClassMethod.jsx";
1
+ export * from "./Class.js";
2
+ export { ClassMethod, type ClassMethodProps } from "./ClassMethod.jsx";
3
3
  export * from "./Declaration.js";
4
- export * from "./doc/comment.jsx";
5
- export * from "./doc/from-markdown.jsx";
6
- export * from "./EnumDeclaration.jsx";
7
- export * from "./interface/declaration.js";
8
- export * from "./interface/method.js";
9
- export * from "./interface/property.js";
4
+ export * from "./Enum.js";
10
5
  export * from "./Name.js";
11
6
  export * from "./Namespace.js";
12
7
  export * from "./Parameters.js";
13
8
  export * from "./ProjectDirectory.js";
14
- export * from "./property/property.jsx";
15
- export * from "./record/declaration.js";
16
9
  export * from "./Reference.js";
17
10
  export * from "./SourceFile.js";
18
- export type { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
19
11
  export * from "./UsingDirective.js";
20
- 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
@@ -1,25 +1,51 @@
1
1
  // the possible C# access modifiers
2
2
  // https://learn.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
3
+ export type AccessModifier =
4
+ | "public"
5
+ | "protected"
6
+ | "private"
7
+ | "internal"
8
+ | "protected-internal"
9
+ | "private-protected"
10
+ | "file";
3
11
 
4
- /** Access modifiers. */
5
- export interface AccessModifiers {
6
- readonly public?: boolean;
7
- readonly protected?: boolean;
8
- readonly private?: boolean;
9
- readonly internal?: boolean;
10
- readonly file?: boolean;
12
+ // maps the above access modifier value to its C# syntax.
13
+ // note that the C# keyword includes a trailing space
14
+ const accessModifierLookup: Record<AccessModifier, string> = {
15
+ public: "public ",
16
+ protected: "protected ",
17
+ private: "private ",
18
+ internal: "internal ",
19
+ "protected-internal": "protected internal ",
20
+ "private-protected": "private protected ",
21
+ file: "file ",
22
+ };
23
+
24
+ // returns the C# syntax for the specified access modifier.
25
+ // if no access modifier is specified, the empty string is returned.
26
+ export function getAccessModifier(accessModifier?: AccessModifier): string {
27
+ return accessModifier ? accessModifierLookup[accessModifier] : "";
11
28
  }
12
29
 
13
- export const getAccessModifier = makeModifiers<AccessModifiers>([
14
- "public",
15
- "protected",
16
- "private",
17
- "internal",
18
- "file",
19
- ]);
30
+ export type MethodModifier = "abstract" | "sealed" | "static" | "virtual";
31
+
32
+ // maps the above method modifier value to its C# syntax.
33
+ // note that the C# keyword includes a trailing space
34
+ const methodModifierLookup: Record<MethodModifier, string> = {
35
+ abstract: "abstract ",
36
+ sealed: "sealed ",
37
+ static: "static ",
38
+ virtual: "virtual ",
39
+ };
40
+
41
+ // returns the C# syntax for the specified method modifier.
42
+ // if no method modifier is specified, the empty string is returned.
43
+ export function getMethodModifier(methodModifier?: MethodModifier): string {
44
+ return methodModifier ? methodModifierLookup[methodModifier] : "";
45
+ }
20
46
 
21
47
  export function getAsyncModifier(async?: boolean): string {
22
- return async ? "async" : "";
48
+ return async ? "async " : "";
23
49
  }
24
50
 
25
51
  /** Resolve the modifier prefix */
@@ -27,14 +53,5 @@ export function computeModifiersPrefix(
27
53
  modifiers: Array<string | undefined>,
28
54
  ): string {
29
55
  const resolved = modifiers.filter((x) => x);
30
- return resolved.length > 0 ? resolved.join(" ") + " " : "";
31
- }
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
- };
56
+ return resolved.length > 0 ? resolved.join("") : "";
40
57
  }
@@ -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);