@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/src/components/Class.d.ts.map +1 -1
  3. package/dist/src/components/Class.js +26 -14
  4. package/dist/src/components/Class.js.map +1 -1
  5. package/dist/src/components/Declaration.d.ts.map +1 -1
  6. package/dist/src/components/Declaration.js +0 -1
  7. package/dist/src/components/Declaration.js.map +1 -1
  8. package/dist/src/components/Enum.d.ts.map +1 -1
  9. package/dist/src/components/Enum.js +6 -6
  10. package/dist/src/components/Enum.js.map +1 -1
  11. package/dist/src/components/Name.js +1 -1
  12. package/dist/src/components/Name.js.map +1 -1
  13. package/dist/src/components/Namespace.js +0 -1
  14. package/dist/src/components/Namespace.js.map +1 -1
  15. package/dist/src/components/Parameters.d.ts +1 -1
  16. package/dist/src/components/Parameters.d.ts.map +1 -1
  17. package/dist/src/components/Parameters.js +6 -4
  18. package/dist/src/components/Parameters.js.map +1 -1
  19. package/dist/src/components/ProjectDirectory.d.ts.map +1 -1
  20. package/dist/src/components/ProjectDirectory.js +1 -1
  21. package/dist/src/components/ProjectDirectory.js.map +1 -1
  22. package/dist/src/components/Reference.js +1 -1
  23. package/dist/src/components/Reference.js.map +1 -1
  24. package/dist/src/components/SourceFile.d.ts +2 -0
  25. package/dist/src/components/SourceFile.d.ts.map +1 -1
  26. package/dist/src/components/SourceFile.js +7 -9
  27. package/dist/src/components/SourceFile.js.map +1 -1
  28. package/dist/src/components/UsingDirective.d.ts +2 -1
  29. package/dist/src/components/UsingDirective.d.ts.map +1 -1
  30. package/dist/src/components/UsingDirective.js +7 -7
  31. package/dist/src/components/UsingDirective.js.map +1 -1
  32. package/dist/src/components/stc/index.d.ts +5 -5
  33. package/dist/test/utils.d.ts.map +1 -1
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +3 -5
  36. package/src/components/Class.tsx +48 -42
  37. package/src/components/Declaration.tsx +1 -3
  38. package/src/components/Enum.tsx +15 -13
  39. package/src/components/Namespace.tsx +5 -5
  40. package/src/components/Parameters.tsx +9 -9
  41. package/src/components/ProjectDirectory.tsx +9 -7
  42. package/src/components/SourceFile.tsx +20 -12
  43. package/src/components/UsingDirective.tsx +8 -9
  44. package/temp/api.json +8 -20
  45. package/test/class.test.tsx +106 -38
  46. package/test/enum.test.tsx +19 -22
  47. package/test/namespace.test.tsx +6 -10
  48. package/test/projectdirectory.test.tsx +19 -12
  49. package/test/sourcefile.test.tsx +7 -8
  50. package/test/using.test.tsx +26 -14
  51. 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.5.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.5.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.1.1"
30
+ "@alloy-js/babel-preset": "~0.2.0"
33
31
  },
34
32
  "type": "module",
35
33
  "scripts": {
@@ -40,7 +40,7 @@ export function Class(props: ClassProps) {
40
40
  "class-decl",
41
41
  );
42
42
 
43
- let typeParams: string | undefined;
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 = `<${typeParamNames.join(", ")}>`;
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 <core.Declaration symbol={thisClassSymbol}>
62
- {getAccessModifier(props.accessModifier)}class <Name />{typeParams}{!props.children && ";"}{props.children &&
63
- <>
64
- {"\n{"}
65
- <core.Scope value={thisClassScope}>
66
- {props.children}
67
- </core.Scope>
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 = props.parameters ?
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 <core.Declaration symbol={ctorSymbol}>
114
- <core.Scope value={ctorDeclScope}>
115
- {accessModifier}<Name />({params}){!props.children && " {}"}{props.children &&
116
- <>
117
- {"\n{"}
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 <core.Declaration symbol={memberSymbol}>
155
- {getAccessModifier(props.accessModifier)}{props.type} <Name />;
156
- </core.Declaration>;
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 = props.parameters ?
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 <core.Declaration symbol={methodSymbol}>
200
- <core.Scope value={methodScope}>
201
- {accessModifier}{methodModifier}{returns} <Name />({params}){!props.children && " {}"}{props.children &&
202
- <>
203
- {"\n{"}
204
- {props.children}
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
  }
@@ -33,17 +33,17 @@ export function Enum(props: EnumProps) {
33
33
  "enum-decl",
34
34
  );
35
35
 
36
- return <core.Declaration symbol={thisEnumSymbol}>
37
- {getAccessModifier(props.accessModifier)}enum <Name />{!props.children && ";"}{props.children &&
38
- <>
39
- {"\n{"}
40
- <core.Scope value={thisEnumScope}>
41
- {props.children}
42
- </core.Scope>
43
- {"}"}
44
- </>
45
- }
46
- </core.Declaration>;
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 <core.Declaration symbol={thisEnumValueSymbol}>
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 <NamespaceContext.Provider value={namespaceCtx}>
35
- <core.Scope value={scope}>
36
- {props.children}
37
- </core.Scope>
38
- </NamespaceContext.Provider>;
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 <core.Declaration symbol={memberSymbol}>
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): Array<core.Child | string> {
45
- return core.mapJoin(
46
- props.parameters,
47
- (param) => {
48
- return <Parameter {...param} />;
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 <core.SourceDirectory path={join(props.path, props.name)}>
39
- <core.SourceFile path={props.name+".csproj"} filetype="xml">
40
- {core.code`
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
- </core.SourceFile>
50
- <core.SourceDirectory path={props.srcDir}>
51
- {props.children}
50
+ </core.SourceFile>
51
+ <core.SourceDirectory path={props.srcDir}>
52
+ {props.children}
53
+ </core.SourceDirectory>
52
54
  </core.SourceDirectory>
53
- </core.SourceDirectory>;
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 <core.SourceFile path={props.path} filetype="cs" reference={Reference} indent=" ">
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
- {"\n{"}
62
- {props.children}
63
- {"}\n"}
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
- // we need core.memo here so that the contents are in a reactive context.
10
- // the values for namespaces are reactive thus we need to observe any changes.
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": "Array",
2544
- "canonicalReference": "!Array:interface"
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": 7
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": "Content",
3408
- "text": "() => string"
3394
+ "kind": "Reference",
3395
+ "text": "core.Children",
3396
+ "canonicalReference": "@alloy-js/core!Children:type"
3409
3397
  },
3410
3398
  {
3411
3399
  "kind": "Content",