@alloy-js/csharp 0.5.0 → 0.7.0
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/CHANGELOG.md +11 -0
- package/dist/src/components/Class.d.ts.map +1 -1
- package/dist/src/components/Class.js +26 -14
- package/dist/src/components/Class.js.map +1 -1
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +0 -1
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/Enum.d.ts.map +1 -1
- package/dist/src/components/Enum.js +6 -6
- package/dist/src/components/Enum.js.map +1 -1
- package/dist/src/components/Name.js +1 -1
- package/dist/src/components/Name.js.map +1 -1
- package/dist/src/components/Namespace.js +0 -1
- package/dist/src/components/Namespace.js.map +1 -1
- package/dist/src/components/Parameters.d.ts +1 -1
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +6 -4
- package/dist/src/components/Parameters.js.map +1 -1
- package/dist/src/components/ProjectDirectory.d.ts.map +1 -1
- package/dist/src/components/ProjectDirectory.js +1 -1
- package/dist/src/components/ProjectDirectory.js.map +1 -1
- package/dist/src/components/Reference.js +1 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +2 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +7 -9
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/UsingDirective.d.ts +2 -1
- package/dist/src/components/UsingDirective.d.ts.map +1 -1
- package/dist/src/components/UsingDirective.js +7 -7
- package/dist/src/components/UsingDirective.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +5 -5
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/Class.tsx +48 -42
- package/src/components/Declaration.tsx +1 -3
- package/src/components/Enum.tsx +15 -13
- package/src/components/Namespace.tsx +5 -5
- package/src/components/Parameters.tsx +9 -9
- package/src/components/ProjectDirectory.tsx +9 -7
- package/src/components/SourceFile.tsx +20 -12
- package/src/components/UsingDirective.tsx +8 -9
- package/temp/api.json +8 -20
- package/test/class.test.tsx +106 -38
- package/test/enum.test.tsx +19 -22
- package/test/namespace.test.tsx +6 -10
- package/test/projectdirectory.test.tsx +19 -12
- package/test/sourcefile.test.tsx +7 -8
- package/test/using.test.tsx +26 -14
- package/test/utils.tsx +2 -4
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/csharp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
|
-
"development": "./src/index.ts",
|
|
8
7
|
"import": "./dist/src/index.js"
|
|
9
8
|
},
|
|
10
9
|
"./stc": {
|
|
11
|
-
"development": "./src/components/stc/index.ts",
|
|
12
10
|
"import": "./dist/src/components/stc/index.js"
|
|
13
11
|
}
|
|
14
12
|
},
|
|
@@ -18,7 +16,7 @@
|
|
|
18
16
|
"dependencies": {
|
|
19
17
|
"change-case": "^5.4.4",
|
|
20
18
|
"pathe": "^1.1.2",
|
|
21
|
-
"@alloy-js/core": "~0.
|
|
19
|
+
"@alloy-js/core": "~0.7.0"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
22
|
"@babel/cli": "^7.24.7",
|
|
@@ -29,7 +27,7 @@
|
|
|
29
27
|
"concurrently": "^8.2.2",
|
|
30
28
|
"typescript": "^5.7.3",
|
|
31
29
|
"vitest": "^3.0.4",
|
|
32
|
-
"@alloy-js/babel-preset": "~0.
|
|
30
|
+
"@alloy-js/babel-preset": "~0.2.0"
|
|
33
31
|
},
|
|
34
32
|
"type": "module",
|
|
35
33
|
"scripts": {
|
package/src/components/Class.tsx
CHANGED
|
@@ -40,7 +40,7 @@ export function Class(props: ClassProps) {
|
|
|
40
40
|
"class-decl",
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
let typeParams:
|
|
43
|
+
let typeParams: core.Children;
|
|
44
44
|
if (props.typeParameters) {
|
|
45
45
|
const typeParamNames = new Array<string>();
|
|
46
46
|
for (const entry of Object.entries(props.typeParameters)) {
|
|
@@ -55,20 +55,29 @@ export function Class(props: ClassProps) {
|
|
|
55
55
|
refkey: entry[1],
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
typeParams =
|
|
58
|
+
typeParams = (
|
|
59
|
+
<group>
|
|
60
|
+
{"<"}
|
|
61
|
+
<core.For each={typeParamNames} comma line>
|
|
62
|
+
{(name) => name}
|
|
63
|
+
</core.For>
|
|
64
|
+
{">"}
|
|
65
|
+
</group>
|
|
66
|
+
);
|
|
59
67
|
}
|
|
60
68
|
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
</core.Declaration
|
|
69
|
+
return (
|
|
70
|
+
<core.Declaration symbol={thisClassSymbol}>
|
|
71
|
+
{getAccessModifier(props.accessModifier)}class <Name />
|
|
72
|
+
{typeParams}
|
|
73
|
+
{!props.children && ";"}
|
|
74
|
+
{props.children && (
|
|
75
|
+
<core.Block newline>
|
|
76
|
+
<core.Scope value={thisClassScope}>{props.children}</core.Scope>
|
|
77
|
+
</core.Block>
|
|
78
|
+
)}
|
|
79
|
+
</core.Declaration>
|
|
80
|
+
);
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
export interface ClassConstructorProps {
|
|
@@ -105,22 +114,18 @@ export function ClassConstructor(props: ClassConstructorProps) {
|
|
|
105
114
|
);
|
|
106
115
|
|
|
107
116
|
const accessModifier = getAccessModifier(props.accessModifier);
|
|
108
|
-
const params =
|
|
109
|
-
<Parameters parameters={props.parameters} />
|
|
110
|
-
: "";
|
|
117
|
+
const params =
|
|
118
|
+
props.parameters ? <Parameters parameters={props.parameters} /> : "";
|
|
111
119
|
|
|
112
120
|
// note that scope wraps the ctor decl so that the params get the correct scope
|
|
113
|
-
return
|
|
114
|
-
<core.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
{props.children}
|
|
119
|
-
{"}"}
|
|
120
|
-
</>
|
|
121
|
-
}
|
|
121
|
+
return (
|
|
122
|
+
<core.Declaration symbol={ctorSymbol}>
|
|
123
|
+
<core.Scope value={ctorDeclScope}>
|
|
124
|
+
{accessModifier}
|
|
125
|
+
<Name />({params})<core.Block newline>{props.children}</core.Block>
|
|
122
126
|
</core.Scope>
|
|
123
|
-
</core.Declaration
|
|
127
|
+
</core.Declaration>
|
|
128
|
+
);
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
// properties for creating a class member
|
|
@@ -151,9 +156,12 @@ export function ClassMember(props: ClassMemberProps) {
|
|
|
151
156
|
refkey: props.refkey ?? core.refkey(props.name),
|
|
152
157
|
});
|
|
153
158
|
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
return (
|
|
160
|
+
<core.Declaration symbol={memberSymbol}>
|
|
161
|
+
{getAccessModifier(props.accessModifier)}
|
|
162
|
+
{props.type} <Name />
|
|
163
|
+
</core.Declaration>
|
|
164
|
+
);
|
|
157
165
|
}
|
|
158
166
|
|
|
159
167
|
// properties for creating a method
|
|
@@ -190,21 +198,19 @@ export function ClassMethod(props: ClassMethodProps) {
|
|
|
190
198
|
|
|
191
199
|
const accessModifier = getAccessModifier(props.accessModifier);
|
|
192
200
|
const methodModifier = getMethodModifier(props.methodModifier);
|
|
193
|
-
const params =
|
|
194
|
-
<Parameters parameters={props.parameters} />
|
|
195
|
-
: "";
|
|
201
|
+
const params =
|
|
202
|
+
props.parameters ? <Parameters parameters={props.parameters} /> : "";
|
|
196
203
|
const returns = props.returns ?? "void";
|
|
197
204
|
|
|
198
205
|
// note that scope wraps the method decl so that the params get the correct scope
|
|
199
|
-
return
|
|
200
|
-
<core.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
</>
|
|
207
|
-
}
|
|
206
|
+
return (
|
|
207
|
+
<core.Declaration symbol={methodSymbol}>
|
|
208
|
+
<core.Scope value={methodScope}>
|
|
209
|
+
{accessModifier}
|
|
210
|
+
{methodModifier}
|
|
211
|
+
{returns} <Name />({params})
|
|
212
|
+
<core.Block newline>{props.children}</core.Block>
|
|
208
213
|
</core.Scope>
|
|
209
|
-
</core.Declaration
|
|
214
|
+
</core.Declaration>
|
|
215
|
+
);
|
|
210
216
|
}
|
|
@@ -11,7 +11,5 @@ export interface DeclarationProps {
|
|
|
11
11
|
// declares a symbol in the program (class, enum, interface etc)
|
|
12
12
|
export function Declaration(props: DeclarationProps) {
|
|
13
13
|
const sym = createCSharpSymbol(props);
|
|
14
|
-
return <core.Declaration symbol={sym}>
|
|
15
|
-
{props.children}
|
|
16
|
-
</core.Declaration>;
|
|
14
|
+
return <core.Declaration symbol={sym}>{props.children}</core.Declaration>;
|
|
17
15
|
}
|
package/src/components/Enum.tsx
CHANGED
|
@@ -33,17 +33,17 @@ export function Enum(props: EnumProps) {
|
|
|
33
33
|
"enum-decl",
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
return (
|
|
37
|
+
<core.Declaration symbol={thisEnumSymbol}>
|
|
38
|
+
{getAccessModifier(props.accessModifier)}enum <Name />
|
|
39
|
+
{!props.children && ";"}
|
|
40
|
+
{props.children && (
|
|
41
|
+
<core.Scope value={thisEnumScope}>
|
|
42
|
+
<core.Block newline>{props.children}</core.Block>
|
|
43
|
+
</core.Scope>
|
|
44
|
+
)}
|
|
45
|
+
</core.Declaration>
|
|
46
|
+
);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// properties for creating a C# enum member
|
|
@@ -68,7 +68,9 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
68
68
|
refkey: props.refkey ?? core.refkey(props.name),
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
return
|
|
71
|
+
return (
|
|
72
|
+
<core.Declaration symbol={thisEnumValueSymbol}>
|
|
72
73
|
<Name />
|
|
73
|
-
</core.Declaration
|
|
74
|
+
</core.Declaration>
|
|
75
|
+
);
|
|
74
76
|
}
|
|
@@ -31,9 +31,9 @@ export function Namespace(props: NamespaceProps) {
|
|
|
31
31
|
name: props.name,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
return (
|
|
35
|
+
<NamespaceContext.Provider value={namespaceCtx}>
|
|
36
|
+
<core.Scope value={scope}>{props.children}</core.Scope>
|
|
37
|
+
</NamespaceContext.Provider>
|
|
38
|
+
);
|
|
39
39
|
}
|
|
@@ -30,9 +30,11 @@ export function Parameter(props: ParameterProps) {
|
|
|
30
30
|
refkey: props.refkey ?? core.refkey(props.name),
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
return
|
|
33
|
+
return (
|
|
34
|
+
<core.Declaration symbol={memberSymbol}>
|
|
34
35
|
{props.type} <Name />
|
|
35
|
-
</core.Declaration
|
|
36
|
+
</core.Declaration>
|
|
37
|
+
);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface ParametersProps {
|
|
@@ -41,12 +43,10 @@ export interface ParametersProps {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
// a collection of parameters
|
|
44
|
-
export function Parameters(props: ParametersProps)
|
|
45
|
-
return
|
|
46
|
-
props.parameters,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
{ joiner: ", " },
|
|
46
|
+
export function Parameters(props: ParametersProps) {
|
|
47
|
+
return (
|
|
48
|
+
<core.For each={props.parameters} joiner={", "}>
|
|
49
|
+
{(param) => <Parameter {...param} />}
|
|
50
|
+
</core.For>
|
|
51
51
|
);
|
|
52
52
|
}
|
|
@@ -35,9 +35,10 @@ export function ProjectDirectory(props: ProjectDirectoryProps) {
|
|
|
35
35
|
props.targetFrameworkMoniker = "net8.0";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
return
|
|
39
|
-
<core.
|
|
40
|
-
|
|
38
|
+
return (
|
|
39
|
+
<core.SourceDirectory path={join(props.path, props.name)}>
|
|
40
|
+
<core.SourceFile path={props.name + ".csproj"} filetype="xml">
|
|
41
|
+
{core.code`
|
|
41
42
|
<Project Sdk="Microsoft.NET.Sdk">
|
|
42
43
|
<PropertyGroup>
|
|
43
44
|
<Version>${props.version}</Version>
|
|
@@ -46,9 +47,10 @@ export function ProjectDirectory(props: ProjectDirectoryProps) {
|
|
|
46
47
|
</PropertyGroup>
|
|
47
48
|
</Project>
|
|
48
49
|
`}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
</core.SourceFile>
|
|
51
|
+
<core.SourceDirectory path={props.srcDir}>
|
|
52
|
+
{props.children}
|
|
53
|
+
</core.SourceDirectory>
|
|
52
54
|
</core.SourceDirectory>
|
|
53
|
-
|
|
55
|
+
);
|
|
54
56
|
}
|
|
@@ -16,10 +16,13 @@ export function useSourceFile(): SourceFileContext | undefined {
|
|
|
16
16
|
return core.useContext(SourceFileContext) as SourceFileContext;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// properties fro creating a C# source file
|
|
20
19
|
export interface SourceFileProps {
|
|
20
|
+
/** Path of the source file */
|
|
21
21
|
path: string;
|
|
22
|
+
|
|
23
|
+
/** A list of namespaces to use */
|
|
22
24
|
using?: Array<string>;
|
|
25
|
+
|
|
23
26
|
children?: core.Children;
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -49,21 +52,26 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
49
52
|
addUsing,
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
return
|
|
55
|
+
return (
|
|
56
|
+
<core.SourceFile
|
|
57
|
+
path={props.path}
|
|
58
|
+
filetype="cs"
|
|
59
|
+
reference={Reference}
|
|
60
|
+
tabWidth={4}
|
|
61
|
+
>
|
|
53
62
|
<SourceFileContext.Provider value={sourceFileCtx}>
|
|
54
63
|
<core.Scope name={props.path} kind="source-file">
|
|
55
|
-
{using.length > 0
|
|
56
|
-
<>
|
|
57
|
-
<UsingDirective namespaces={using} />{"\n\n"}
|
|
58
|
-
</>
|
|
59
|
-
) : undefined}namespace {namespaceCtx.name}{!props.children && " {}\n"}{props.children &&
|
|
64
|
+
{using.length > 0 && (
|
|
60
65
|
<>
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
<UsingDirective namespaces={using} />
|
|
67
|
+
<hbr />
|
|
68
|
+
<hbr />
|
|
64
69
|
</>
|
|
65
|
-
}
|
|
70
|
+
)}
|
|
71
|
+
namespace {namespaceCtx.name}
|
|
72
|
+
<core.Block newline>{props.children}</core.Block>
|
|
66
73
|
</core.Scope>
|
|
67
74
|
</SourceFileContext.Provider>
|
|
68
|
-
</core.SourceFile
|
|
75
|
+
</core.SourceFile>
|
|
76
|
+
);
|
|
69
77
|
}
|
|
@@ -6,14 +6,13 @@ export interface UsingDirectiveProps {
|
|
|
6
6
|
|
|
7
7
|
// one ore more C# using directives
|
|
8
8
|
export function UsingDirective(props: UsingDirectiveProps) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return core.memo(() => {
|
|
12
|
-
props.namespaces.sort();
|
|
13
|
-
return core
|
|
14
|
-
.mapJoin(props.namespaces, (namespace) => {
|
|
15
|
-
return `using ${namespace};`;
|
|
16
|
-
})
|
|
17
|
-
.join("");
|
|
9
|
+
const sortedNamespaces = core.computed(() => {
|
|
10
|
+
return props.namespaces.sort();
|
|
18
11
|
});
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<core.For each={sortedNamespaces}>
|
|
15
|
+
{(namespace) => `using ${namespace};`}
|
|
16
|
+
</core.For>
|
|
17
|
+
);
|
|
19
18
|
}
|
package/temp/api.json
CHANGED
|
@@ -2540,21 +2540,8 @@
|
|
|
2540
2540
|
},
|
|
2541
2541
|
{
|
|
2542
2542
|
"kind": "Reference",
|
|
2543
|
-
"text": "
|
|
2544
|
-
"canonicalReference": "!
|
|
2545
|
-
},
|
|
2546
|
-
{
|
|
2547
|
-
"kind": "Content",
|
|
2548
|
-
"text": "<"
|
|
2549
|
-
},
|
|
2550
|
-
{
|
|
2551
|
-
"kind": "Reference",
|
|
2552
|
-
"text": "core.Child",
|
|
2553
|
-
"canonicalReference": "@alloy-js/core!Child:type"
|
|
2554
|
-
},
|
|
2555
|
-
{
|
|
2556
|
-
"kind": "Content",
|
|
2557
|
-
"text": " | string>"
|
|
2543
|
+
"text": "core.Children",
|
|
2544
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
2558
2545
|
},
|
|
2559
2546
|
{
|
|
2560
2547
|
"kind": "Content",
|
|
@@ -2564,7 +2551,7 @@
|
|
|
2564
2551
|
"fileUrlPath": "src/components/Parameters.tsx",
|
|
2565
2552
|
"returnTypeTokenRange": {
|
|
2566
2553
|
"startIndex": 3,
|
|
2567
|
-
"endIndex":
|
|
2554
|
+
"endIndex": 4
|
|
2568
2555
|
},
|
|
2569
2556
|
"releaseTag": "Public",
|
|
2570
2557
|
"overloadIndex": 1,
|
|
@@ -3189,7 +3176,7 @@
|
|
|
3189
3176
|
{
|
|
3190
3177
|
"kind": "PropertySignature",
|
|
3191
3178
|
"canonicalReference": "@alloy-js/csharp!SourceFileProps#path:member",
|
|
3192
|
-
"docComment": "",
|
|
3179
|
+
"docComment": "/**\n * Path of the source file\n */\n",
|
|
3193
3180
|
"excerptTokens": [
|
|
3194
3181
|
{
|
|
3195
3182
|
"kind": "Content",
|
|
@@ -3216,7 +3203,7 @@
|
|
|
3216
3203
|
{
|
|
3217
3204
|
"kind": "PropertySignature",
|
|
3218
3205
|
"canonicalReference": "@alloy-js/csharp!SourceFileProps#using:member",
|
|
3219
|
-
"docComment": "",
|
|
3206
|
+
"docComment": "/**\n * A list of namespaces to use\n */\n",
|
|
3220
3207
|
"excerptTokens": [
|
|
3221
3208
|
{
|
|
3222
3209
|
"kind": "Content",
|
|
@@ -3404,8 +3391,9 @@
|
|
|
3404
3391
|
"text": "): "
|
|
3405
3392
|
},
|
|
3406
3393
|
{
|
|
3407
|
-
"kind": "
|
|
3408
|
-
"text": "
|
|
3394
|
+
"kind": "Reference",
|
|
3395
|
+
"text": "core.Children",
|
|
3396
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
3409
3397
|
},
|
|
3410
3398
|
{
|
|
3411
3399
|
"kind": "Content",
|