@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.
- package/dist/src/components/Class.d.ts +23 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/{ClassDeclaration.js → Class.js} +37 -67
- package/dist/src/components/ClassMethod.d.ts +3 -44
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +8 -32
- package/dist/src/components/Enum.d.ts +14 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/{EnumDeclaration.js → Enum.js} +2 -21
- package/dist/src/components/Parameters.d.ts +13 -0
- package/dist/src/components/Parameters.d.ts.map +1 -0
- package/dist/src/components/Parameters.js +34 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +0 -1
- package/dist/src/components/index.d.ts +4 -14
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +5 -15
- 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 +9 -2
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +9 -6
- 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 +2 -23
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/{class-declaration.test.js → class.test.js} +51 -234
- package/dist/test/enum.test.js +6 -6
- package/dist/test/namespace.test.js +4 -4
- 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} +4 -4
- package/dist/test/sourcefile.test.js +2 -2
- package/dist/test/using.test.js +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/src/components/{ClassDeclaration.tsx → Class.tsx} +38 -116
- package/src/components/ClassMethod.tsx +7 -70
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +3 -22
- package/src/components/Parameters.tsx +51 -0
- package/src/components/SourceFile.tsx +0 -1
- package/src/components/index.ts +4 -14
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +30 -16
- package/src/name-policy.ts +0 -5
- package/temp/api.json +1194 -6218
- package/test/class-method.test.tsx +3 -19
- package/test/class.test.tsx +257 -0
- package/test/enum.test.tsx +11 -13
- 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 +6 -14
- package/vitest.config.ts +0 -3
- package/dist/src/components/ClassDeclaration.d.ts +0 -92
- 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/attributes/attributes.d.ts +0 -39
- package/dist/src/components/attributes/attributes.d.ts.map +0 -1
- package/dist/src/components/attributes/attributes.js +0 -62
- package/dist/src/components/attributes/attributes.test.d.ts +0 -2
- package/dist/src/components/attributes/attributes.test.d.ts.map +0 -1
- package/dist/src/components/attributes/attributes.test.js +0 -75
- 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 -65
- package/dist/src/components/interface/declaration.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.js +0 -83
- 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 -171
- package/dist/src/components/interface/method.d.ts +0 -50
- package/dist/src/components/interface/method.d.ts.map +0 -1
- package/dist/src/components/interface/method.js +0 -74
- 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 -300
- package/dist/src/components/interface/property.d.ts +0 -56
- package/dist/src/components/interface/property.d.ts.map +0 -1
- package/dist/src/components/interface/property.js +0 -73
- 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 -189
- package/dist/src/components/parameters/parameters.d.ts +0 -19
- package/dist/src/components/parameters/parameters.d.ts.map +0 -1
- package/dist/src/components/parameters/parameters.js +0 -43
- package/dist/src/components/property/property.d.ts +0 -80
- package/dist/src/components/property/property.d.ts.map +0 -1
- package/dist/src/components/property/property.js +0 -76
- 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 -242
- 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 -54
- 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 -48
- 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/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/attributes/attributes.test.tsx +0 -61
- package/src/components/attributes/attributes.tsx +0 -100
- 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 -158
- package/src/components/interface/declaration.tsx +0 -125
- package/src/components/interface/method.test.tsx +0 -293
- package/src/components/interface/method.tsx +0 -122
- package/src/components/interface/property.test.tsx +0 -165
- package/src/components/interface/property.tsx +0 -127
- package/src/components/parameters/parameters.tsx +0 -74
- package/src/components/property/property.test.tsx +0 -209
- package/src/components/property/property.tsx +0 -172
- 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 -46
- package/src/components/type-parameters/type-parameters.tsx +0 -63
- package/src/components/var/declaration.test.tsx +0 -59
- package/src/components/var/declaration.tsx +0 -47
- package/test/class-declaration.test.tsx +0 -430
- 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 {
|
|
13
|
-
import {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
{
|
|
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
|
-
|
|
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 {
|
|
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
|
|
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
|
-
|
|
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
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export
|
|
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 "./
|
|
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 "./
|
|
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
|
|
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
|
@@ -10,13 +10,36 @@ export interface AccessModifiers {
|
|
|
10
10
|
readonly file?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
}
|
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);
|