@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,233 +0,0 @@
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";
9
- import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
10
- import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
11
- 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
- ]);
33
-
34
- // properties for creating a class
35
- export interface ClassDeclarationProps
36
- extends Omit<core.DeclarationProps, "nameKind">,
37
- AccessModifiers,
38
- ClassModifiers {
39
- name: string;
40
- /** Doc comment */
41
- doc?: core.Children;
42
- 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;
81
- }
82
-
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) {
108
- const name = useCSharpNamePolicy().getName(props.name!, "class");
109
-
110
- const thisClassSymbol = new CSharpOutputSymbol(name, {
111
- refkeys: props.refkey,
112
- });
113
-
114
- // this creates a new scope for the class definition.
115
- // members will automatically "inherit" this scope so
116
- // that refkeys to them will produce the fully-qualified
117
- // name e.g. Foo.Bar.
118
- const thisClassScope = new CSharpMemberScope("class-decl", {
119
- owner: thisClassSymbol,
120
- });
121
-
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
- ]);
132
- return (
133
- <core.Declaration symbol={thisClassSymbol}>
134
- <DocWhen doc={props.doc} />
135
- <AttributeList attributes={props.attributes} endline />
136
- {modifiers}class <Name />
137
- {props.typeParameters && (
138
- <TypeParameters parameters={props.typeParameters} />
139
- )}
140
- {base}
141
- {props.typeParameters && (
142
- <TypeParameterConstraints parameters={props.typeParameters} />
143
- )}
144
- {!props.children && ";"}
145
- {props.children && (
146
- <core.Block newline>
147
- <core.Scope value={thisClassScope}>{props.children}</core.Scope>
148
- </core.Block>
149
- )}
150
- </core.Declaration>
151
- );
152
- }
153
-
154
- export interface ClassConstructorProps extends AccessModifiers {
155
- parameters?: Array<ParameterProps>;
156
- refkey?: core.Refkey;
157
- symbol?: core.OutputSymbol;
158
- children?: core.Children;
159
- }
160
-
161
- // a C# class constructor
162
- export function ClassConstructor(props: ClassConstructorProps) {
163
- const scope = useCSharpScope();
164
- if (scope.kind !== "member" || scope.name !== "class-decl") {
165
- throw new Error(
166
- "can't define a class constructor outside of a class-decl scope",
167
- );
168
- }
169
-
170
- // fetch the class name from the scope
171
- const name = useCSharpNamePolicy().getName(scope.owner!.name, "class-method");
172
- const ctorSymbol = new CSharpOutputSymbol(name, {
173
- scope,
174
- refkeys: props.refkey ?? core.refkey(name),
175
- });
176
-
177
- // scope for ctor declaration
178
- const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
179
- owner: ctorSymbol,
180
- });
181
-
182
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
183
-
184
- // note that scope wraps the ctor decl so that the params get the correct scope
185
- return (
186
- <core.Declaration symbol={ctorSymbol}>
187
- <core.Scope value={ctorDeclScope}>
188
- {modifiers}
189
- <Name />
190
- <Parameters parameters={props.parameters} />
191
- <core.Block newline>{props.children}</core.Block>
192
- </core.Scope>
193
- </core.Declaration>
194
- );
195
- }
196
-
197
- // properties for creating a class member
198
- export interface ClassMemberProps extends AccessModifiers {
199
- name: string;
200
- type: core.Children;
201
- refkey?: core.Refkey;
202
- /** Doc comment */
203
- doc?: core.Children;
204
- }
205
-
206
- // a C# class member (i.e. a field within a class like "private int count")
207
- export function ClassMember(props: ClassMemberProps) {
208
- let nameElement: CSharpElements = "class-member-private";
209
- if (props.public) {
210
- nameElement = "class-member-public";
211
- }
212
- const name = useCSharpNamePolicy().getName(props.name, nameElement);
213
- const scope = useCSharpScope();
214
- if (scope.kind !== "member" || scope.name !== "class-decl") {
215
- throw new Error(
216
- "can't define a class member outside of a class-decl scope",
217
- );
218
- }
219
-
220
- const memberSymbol = new CSharpOutputSymbol(name, {
221
- scope,
222
- refkeys: props.refkey ?? core.refkey(props.name),
223
- });
224
-
225
- const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
226
- return (
227
- <core.Declaration symbol={memberSymbol}>
228
- <DocWhen doc={props.doc} />
229
- {modifiers}
230
- {props.type} <Name />
231
- </core.Declaration>
232
- );
233
- }
@@ -1,61 +0,0 @@
1
- import { expect, it } from "vitest";
2
- import { Attribute, AttributeList } from "./attributes.jsx";
3
-
4
- it("define attribute", () => {
5
- expect(<Attribute name="Test" />).toRenderTo(`
6
- [Test]
7
- `);
8
- });
9
-
10
- it("define attribute with single arg", () => {
11
- expect(<Attribute name="Test" args={[`"abc"`]} />).toRenderTo(`
12
- [Test("abc")]
13
- `);
14
- });
15
-
16
- it("define attribute with multiple arg", () => {
17
- expect(<Attribute name="Test" args={[`"abc"`, `"def"`]} />).toRenderTo(`
18
- [Test("abc", "def")]
19
- `);
20
- });
21
-
22
- it("define attribute list with Attribute components", () => {
23
- expect(
24
- <AttributeList
25
- attributes={[<Attribute name="TestA" />, <Attribute name="TestB" />]}
26
- />,
27
- ).toRenderTo(`
28
- [TestA]
29
- [TestB]
30
- `);
31
- });
32
-
33
- it("define attribute list with attribute names", () => {
34
- expect(<AttributeList attributes={["TestA", "TestB"]} />).toRenderTo(`
35
- [TestA]
36
- [TestB]
37
- `);
38
- });
39
-
40
- it("define attribute list with attribute props", () => {
41
- expect(
42
- <AttributeList
43
- attributes={[{ name: "TestA" }, { name: "TestB", args: [`"test"`] }]}
44
- />,
45
- ).toRenderTo(`
46
- [TestA]
47
- [TestB("test")]
48
- `);
49
- });
50
-
51
- it("define attribute list with children", () => {
52
- expect(
53
- <AttributeList>
54
- <Attribute name="TestA" />
55
- <Attribute name="TestB" />
56
- </AttributeList>,
57
- ).toRenderTo(`
58
- [TestA]
59
- [TestB]
60
- `);
61
- });
@@ -1,100 +0,0 @@
1
- import {
2
- Children,
3
- findKeyedChildren,
4
- For,
5
- Indent,
6
- taggedComponent,
7
- } from "@alloy-js/core";
8
-
9
- export interface AttributeItem {
10
- name: string;
11
- args?: string[];
12
- }
13
-
14
- export type AttributesProp = Array<string | AttributeProps | Children>;
15
-
16
- export interface AttributeListProps {
17
- /** If the attribute list should finish with a hard line if there is any attribute */
18
- endline?: boolean;
19
- attributes?: AttributesProp;
20
- children?: Children[];
21
- }
22
-
23
- /**
24
- * Render each attributes in a new line.
25
- */
26
- export function AttributeList(props: AttributeListProps) {
27
- const attributes =
28
- props.attributes ??
29
- (props.children && findKeyedChildren(props.children, Attribute.tag));
30
-
31
- if (!attributes) {
32
- return null;
33
- }
34
-
35
- return (
36
- <>
37
- <For each={attributes} line>
38
- {(arg) => renderAttribute(arg)}
39
- </For>
40
- {props.endline && attributes.length > 0 && <hbr />}
41
- </>
42
- );
43
- }
44
-
45
- function renderAttribute(attr: string | AttributeProps | Children): Children {
46
- if (typeof attr === "string") {
47
- return <Attribute name={attr} />;
48
- } else if (typeof attr === "object" && attr && "name" in attr) {
49
- return <Attribute {...attr} />;
50
- } else {
51
- return attr;
52
- }
53
- }
54
-
55
- export interface AttributeProps {
56
- /** Attribute name */
57
- name: Children;
58
-
59
- /** Argument */
60
- args?: Children[];
61
- }
62
-
63
- const AttributeTag = Symbol("AttributeTag");
64
- /**
65
- * Render a csharp attribute.
66
- *
67
- * @example
68
- * ```tsx
69
- * <Attribute name="Test" /><hbr/>
70
- * <Attribute name="Test" args={["arg1", "arg2"]} />
71
- * ```
72
- *
73
- * will render:
74
- * ```csharp
75
- * [Test]
76
- * [Test("arg1", "arg2")]
77
- * ```
78
- */
79
- export const Attribute = taggedComponent(
80
- AttributeTag,
81
- (props: AttributeProps) => {
82
- return (
83
- <group>
84
- [{props.name}
85
- {props.args && props.args.length > 0 && (
86
- <>
87
- (
88
- <Indent softline>
89
- <For each={props.args ?? []} comma line>
90
- {(arg) => arg}
91
- </For>
92
- </Indent>
93
- )
94
- </>
95
- )}
96
- ]
97
- </group>
98
- );
99
- },
100
- );