@alloy-js/csharp 0.18.0-dev.18 → 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.
- package/dist/src/components/Class.d.ts +26 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/{ClassDeclaration.js → Class.js} +32 -59
- package/dist/src/components/ClassMethod.d.ts +4 -25
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +3 -22
- package/dist/src/components/Enum.d.ts +15 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
- package/dist/src/components/Parameters.d.ts +1 -6
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +2 -3
- package/dist/src/components/index.d.ts +3 -12
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +4 -13
- package/dist/src/components/stc/index.d.ts +2 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/modifiers.d.ts +4 -10
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +32 -9
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +0 -2
- package/dist/test/class-method.test.js +14 -37
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/class.test.js +298 -0
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/projectdirectory.test.d.ts +2 -0
- package/dist/test/projectdirectory.test.d.ts.map +1 -0
- package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/src/components/{ClassDeclaration.tsx → Class.tsx} +43 -108
- package/src/components/ClassMethod.tsx +12 -53
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
- package/src/components/Parameters.tsx +3 -10
- package/src/components/index.ts +3 -12
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +42 -25
- package/src/name-policy.ts +0 -5
- package/temp/api.json +714 -5256
- package/test/class-method.test.tsx +14 -24
- package/test/class.test.tsx +292 -0
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/vitest.config.ts +0 -3
- package/LICENSE +0 -7
- package/dist/src/components/ClassDeclaration.d.ts +0 -74
- package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.d.ts +0 -34
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/doc/comment.d.ts +0 -70
- package/dist/src/components/doc/comment.d.ts.map +0 -1
- package/dist/src/components/doc/comment.js +0 -88
- package/dist/src/components/doc/comment.test.d.ts +0 -2
- package/dist/src/components/doc/comment.test.d.ts.map +0 -1
- package/dist/src/components/doc/comment.test.js +0 -348
- package/dist/src/components/doc/from-markdown.d.ts +0 -6
- package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.js +0 -58
- package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
- package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.test.js +0 -83
- package/dist/src/components/interface/declaration.d.ts +0 -47
- package/dist/src/components/interface/declaration.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.js +0 -77
- package/dist/src/components/interface/declaration.test.d.ts +0 -2
- package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.test.js +0 -153
- package/dist/src/components/interface/method.d.ts +0 -32
- package/dist/src/components/interface/method.d.ts.map +0 -1
- package/dist/src/components/interface/method.js +0 -69
- package/dist/src/components/interface/method.test.d.ts +0 -2
- package/dist/src/components/interface/method.test.d.ts.map +0 -1
- package/dist/src/components/interface/method.test.js +0 -254
- package/dist/src/components/interface/property.d.ts +0 -38
- package/dist/src/components/interface/property.d.ts.map +0 -1
- package/dist/src/components/interface/property.js +0 -67
- package/dist/src/components/interface/property.test.d.ts +0 -2
- package/dist/src/components/interface/property.test.d.ts.map +0 -1
- package/dist/src/components/interface/property.test.js +0 -165
- package/dist/src/components/property/property.d.ts +0 -57
- package/dist/src/components/property/property.d.ts.map +0 -1
- package/dist/src/components/property/property.js +0 -70
- package/dist/src/components/property/property.test.d.ts +0 -2
- package/dist/src/components/property/property.test.d.ts.map +0 -1
- package/dist/src/components/property/property.test.js +0 -218
- package/dist/src/components/record/declaration.d.ts +0 -35
- package/dist/src/components/record/declaration.d.ts.map +0 -1
- package/dist/src/components/record/declaration.js +0 -90
- package/dist/src/components/record/declaration.test.d.ts +0 -2
- package/dist/src/components/record/declaration.test.d.ts.map +0 -1
- package/dist/src/components/record/declaration.test.js +0 -94
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
- package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter.js +0 -22
- package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.js +0 -65
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.test.js +0 -26
- package/dist/src/components/var/declaration.d.ts +0 -35
- package/dist/src/components/var/declaration.d.ts.map +0 -1
- package/dist/src/components/var/declaration.js +0 -40
- package/dist/src/components/var/declaration.test.d.ts +0 -2
- package/dist/src/components/var/declaration.test.d.ts.map +0 -1
- package/dist/src/components/var/declaration.test.js +0 -73
- package/dist/test/class-declaration.test.d.ts +0 -2
- package/dist/test/class-declaration.test.d.ts.map +0 -1
- package/dist/test/class-declaration.test.js +0 -463
- package/dist/test/project-directory.test.d.ts +0 -2
- package/dist/test/project-directory.test.d.ts.map +0 -1
- package/dist/test/vitest.setup.d.ts +0 -2
- package/dist/test/vitest.setup.d.ts.map +0 -1
- package/dist/test/vitest.setup.js +0 -1
- package/src/components/doc/comment.test.tsx +0 -337
- package/src/components/doc/comment.tsx +0 -152
- package/src/components/doc/from-markdown.test.tsx +0 -103
- package/src/components/doc/from-markdown.tsx +0 -58
- package/src/components/interface/declaration.test.tsx +0 -143
- package/src/components/interface/declaration.tsx +0 -105
- package/src/components/interface/method.test.tsx +0 -250
- package/src/components/interface/method.tsx +0 -105
- package/src/components/interface/property.test.tsx +0 -144
- package/src/components/interface/property.tsx +0 -107
- package/src/components/property/property.test.tsx +0 -187
- package/src/components/property/property.tsx +0 -146
- package/src/components/record/declaration.test.tsx +0 -73
- package/src/components/record/declaration.tsx +0 -109
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
- package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
- package/src/components/type-parameters/type-parameter.tsx +0 -35
- package/src/components/type-parameters/type-parameters.test.tsx +0 -19
- package/src/components/type-parameters/type-parameters.tsx +0 -72
- package/src/components/var/declaration.test.tsx +0 -59
- package/src/components/var/declaration.tsx +0 -47
- package/test/class-declaration.test.tsx +0 -418
- package/test/vitest.setup.ts +0 -1
|
@@ -1,91 +1,21 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import {
|
|
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.
|
|
13
|
-
import { ParameterProps, Parameters } from "./Parameters.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
116
|
-
{
|
|
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
|
|
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
|
|
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
|
-
{
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
10
|
+
AccessModifier,
|
|
11
11
|
computeModifiersPrefix,
|
|
12
12
|
getAccessModifier,
|
|
13
13
|
getAsyncModifier,
|
|
14
|
-
|
|
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}{
|
|
107
|
-
{props.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{name}({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
|
|
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
|
-
|
|
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
|
-
{
|
|
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
|
-
|
|
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
|
package/src/components/index.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export
|
|
1
|
+
export * from "./Class.js";
|
|
2
|
+
export { ClassMethod, type ClassMethodProps } from "./ClassMethod.jsx";
|
|
3
3
|
export * from "./Declaration.js";
|
|
4
|
-
export * from "./
|
|
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
|
|
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
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
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
|
}
|
package/src/name-policy.ts
CHANGED
|
@@ -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);
|