@alloy-js/csharp 0.21.0-dev.0 → 0.21.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.
Files changed (139) hide show
  1. package/dist/src/components/enum/declaration.d.ts +2 -2
  2. package/dist/src/components/enum/declaration.d.ts.map +1 -1
  3. package/dist/src/components/enum/declaration.js +3 -3
  4. package/dist/src/components/enum/declaration.js.map +1 -1
  5. package/dist/src/components/enum/declaration.test.js +15 -1
  6. package/dist/src/components/enum/declaration.test.js.map +1 -1
  7. package/dist/src/components/enum/member.d.ts +2 -2
  8. package/dist/src/components/enum/member.d.ts.map +1 -1
  9. package/dist/src/components/enum/member.js +3 -3
  10. package/dist/src/components/enum/member.js.map +1 -1
  11. package/dist/src/components/enum/member.test.js +24 -1
  12. package/dist/src/components/enum/member.test.js.map +1 -1
  13. package/dist/src/components/field/field.d.ts +2 -2
  14. package/dist/src/components/field/field.d.ts.map +1 -1
  15. package/dist/src/components/field/field.js.map +1 -1
  16. package/dist/src/components/field/field.test.js +19 -1
  17. package/dist/src/components/field/field.test.js.map +1 -1
  18. package/dist/src/components/index.d.ts +1 -1
  19. package/dist/src/components/index.d.ts.map +1 -1
  20. package/dist/src/components/index.js +1 -1
  21. package/dist/src/components/index.js.map +1 -1
  22. package/dist/src/components/interface/declaration.d.ts +1 -1
  23. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  24. package/dist/src/components/interface/declaration.js +3 -3
  25. package/dist/src/components/interface/declaration.js.map +1 -1
  26. package/dist/src/components/interface/declaration.test.js +14 -1
  27. package/dist/src/components/interface/declaration.test.js.map +1 -1
  28. package/dist/src/components/interface/method.d.ts +2 -2
  29. package/dist/src/components/interface/method.d.ts.map +1 -1
  30. package/dist/src/components/interface/method.js.map +1 -1
  31. package/dist/src/components/interface/method.test.js +17 -1
  32. package/dist/src/components/interface/method.test.js.map +1 -1
  33. package/dist/src/components/interface/property.d.ts +2 -2
  34. package/dist/src/components/interface/property.d.ts.map +1 -1
  35. package/dist/src/components/interface/property.js.map +1 -1
  36. package/dist/src/components/interface/property.test.js +19 -0
  37. package/dist/src/components/interface/property.test.js.map +1 -1
  38. package/dist/src/components/namespace.d.ts +3 -1
  39. package/dist/src/components/namespace.d.ts.map +1 -1
  40. package/dist/src/components/namespace.js +3 -1
  41. package/dist/src/components/namespace.js.map +1 -1
  42. package/dist/src/components/namespace.ref.test.js +41 -9
  43. package/dist/src/components/namespace.ref.test.js.map +1 -1
  44. package/dist/src/components/namespace.test.js +14 -0
  45. package/dist/src/components/namespace.test.js.map +1 -1
  46. package/dist/src/components/record/declaration.d.ts +1 -1
  47. package/dist/src/components/record/declaration.d.ts.map +1 -1
  48. package/dist/src/components/record/declaration.js +3 -4
  49. package/dist/src/components/record/declaration.js.map +1 -1
  50. package/dist/src/components/record/declaration.test.js +14 -1
  51. package/dist/src/components/record/declaration.test.js.map +1 -1
  52. package/dist/src/components/source-file/source-file.js +2 -2
  53. package/dist/src/components/source-file/source-file.js.map +1 -1
  54. package/dist/src/components/source-file/using.test.d.ts.map +1 -0
  55. package/dist/{test → src/components/source-file}/using.test.js +30 -49
  56. package/dist/src/components/source-file/using.test.js.map +1 -0
  57. package/dist/src/components/stc/index.d.ts +1 -1
  58. package/dist/src/components/stc/index.d.ts.map +1 -1
  59. package/dist/src/components/stc/index.js +1 -1
  60. package/dist/src/components/stc/index.js.map +1 -1
  61. package/dist/src/components/struct/declaration.d.ts +1 -1
  62. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  63. package/dist/src/components/struct/declaration.js +3 -3
  64. package/dist/src/components/struct/declaration.js.map +1 -1
  65. package/dist/src/components/struct/declaration.test.js +14 -1
  66. package/dist/src/components/struct/declaration.test.js.map +1 -1
  67. package/dist/src/components/type-parameters/type-parameter.d.ts +2 -2
  68. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  69. package/dist/src/components/type-parameters/type-parameter.js.map +1 -1
  70. package/dist/src/components/type-parameters/type-parameters.test.js +14 -0
  71. package/dist/src/components/type-parameters/type-parameters.test.js.map +1 -1
  72. package/dist/src/components/using/using.d.ts +28 -0
  73. package/dist/src/components/using/using.d.ts.map +1 -0
  74. package/dist/src/components/using/using.js +37 -0
  75. package/dist/src/components/using/using.js.map +1 -0
  76. package/dist/src/components/using/using.test.d.ts +2 -0
  77. package/dist/src/components/using/using.test.d.ts.map +1 -0
  78. package/dist/src/components/using/using.test.js +19 -0
  79. package/dist/src/components/using/using.test.js.map +1 -0
  80. package/dist/src/components/var/declaration.d.ts +2 -2
  81. package/dist/src/components/var/declaration.d.ts.map +1 -1
  82. package/dist/src/components/var/declaration.js.map +1 -1
  83. package/dist/src/components/var/declaration.test.js +22 -1
  84. package/dist/src/components/var/declaration.test.js.map +1 -1
  85. package/dist/src/name-policy.d.ts +1 -1
  86. package/dist/src/name-policy.d.ts.map +1 -1
  87. package/dist/src/name-policy.js +1 -0
  88. package/dist/src/name-policy.js.map +1 -1
  89. package/dist/src/symbols/factories.d.ts +1 -1
  90. package/dist/src/symbols/factories.d.ts.map +1 -1
  91. package/dist/src/symbols/factories.js +6 -4
  92. package/dist/src/symbols/factories.js.map +1 -1
  93. package/dist/src/symbols/namespace.d.ts +2 -2
  94. package/dist/src/symbols/namespace.d.ts.map +1 -1
  95. package/dist/src/symbols/namespace.js.map +1 -1
  96. package/dist/tsconfig.tsbuildinfo +1 -1
  97. package/package.json +2 -2
  98. package/src/components/enum/declaration.test.tsx +14 -1
  99. package/src/components/enum/declaration.tsx +4 -3
  100. package/src/components/enum/member.test.tsx +22 -1
  101. package/src/components/enum/member.tsx +4 -4
  102. package/src/components/field/field.test.tsx +14 -1
  103. package/src/components/field/field.tsx +2 -2
  104. package/src/components/index.ts +1 -1
  105. package/src/components/interface/declaration.test.tsx +11 -1
  106. package/src/components/interface/declaration.tsx +3 -4
  107. package/src/components/interface/method.test.tsx +14 -1
  108. package/src/components/interface/method.tsx +2 -1
  109. package/src/components/interface/property.test.tsx +13 -0
  110. package/src/components/interface/property.tsx +2 -1
  111. package/src/components/namespace.ref.test.tsx +33 -8
  112. package/src/components/namespace.test.tsx +13 -0
  113. package/src/components/namespace.tsx +6 -3
  114. package/src/components/record/declaration.test.tsx +11 -1
  115. package/src/components/record/declaration.tsx +3 -4
  116. package/src/components/source-file/source-file.tsx +2 -2
  117. package/src/components/source-file/using.test.tsx +94 -0
  118. package/src/components/stc/index.ts +1 -1
  119. package/src/components/struct/declaration.test.tsx +11 -1
  120. package/src/components/struct/declaration.tsx +3 -4
  121. package/src/components/type-parameters/type-parameter.tsx +2 -1
  122. package/src/components/type-parameters/type-parameters.test.tsx +9 -0
  123. package/src/components/using/using.test.tsx +15 -0
  124. package/src/components/using/using.tsx +52 -0
  125. package/src/components/var/declaration.test.tsx +16 -1
  126. package/src/components/var/declaration.tsx +2 -1
  127. package/src/name-policy.ts +3 -1
  128. package/src/symbols/factories.ts +12 -4
  129. package/src/symbols/namespace.ts +2 -2
  130. package/temp/api.json +266 -48
  131. package/dist/src/components/UsingDirective.d.ts +0 -10
  132. package/dist/src/components/UsingDirective.d.ts.map +0 -1
  133. package/dist/src/components/UsingDirective.js +0 -15
  134. package/dist/src/components/UsingDirective.js.map +0 -1
  135. package/dist/test/using.test.d.ts.map +0 -1
  136. package/dist/test/using.test.js.map +0 -1
  137. package/src/components/UsingDirective.tsx +0 -28
  138. package/test/using.test.tsx +0 -118
  139. /package/dist/{test → src/components/source-file}/using.test.d.ts +0 -0
@@ -1,4 +1,5 @@
1
- import { toSourceText } from "#test/utils.jsx";
1
+ import { TestNamespace, toSourceText } from "#test/utils.jsx";
2
+ import { namekey } from "@alloy-js/core";
2
3
  import { d } from "@alloy-js/core/testing";
3
4
  import { expect, it } from "vitest";
4
5
  import { EnumDeclaration } from "./declaration.jsx";
@@ -32,3 +33,15 @@ it("applies naming policy to enum and members", () => {
32
33
  }
33
34
  `);
34
35
  });
36
+
37
+ it("takes a namekey", () => {
38
+ const key = namekey("my-enum");
39
+ const tree = (
40
+ <TestNamespace>
41
+ <EnumDeclaration name={key} />
42
+ </TestNamespace>
43
+ );
44
+ expect(tree).toRenderTo(`
45
+ enum MyEnum;
46
+ `);
47
+ });
@@ -3,6 +3,7 @@ import {
3
3
  Children,
4
4
  Declaration,
5
5
  MemberScope,
6
+ Namekey,
6
7
  Refkey,
7
8
  } from "@alloy-js/core";
8
9
  import {
@@ -17,7 +18,7 @@ import { Name } from "../Name.jsx";
17
18
 
18
19
  // properties for creating an enum
19
20
  export interface EnumDeclarationProps extends AccessModifiers {
20
- name: string;
21
+ name: string | Namekey;
21
22
  refkey?: Refkey | Refkey[];
22
23
  children?: Children;
23
24
  }
@@ -43,9 +44,9 @@ export interface EnumDeclarationProps extends AccessModifiers {
43
44
  * ```
44
45
  */
45
46
  export function EnumDeclaration(props: EnumDeclarationProps) {
46
- const name = useCSharpNamePolicy().getName(props.name!, "enum");
47
- const symbol = createNamedTypeSymbol(name, "enum", {
47
+ const symbol = createNamedTypeSymbol(props.name, "enum", {
48
48
  refkeys: props.refkey,
49
+ namePolicy: useCSharpNamePolicy().for("enum"),
49
50
  });
50
51
  const scope = createNamedTypeScope(symbol);
51
52
 
@@ -1,4 +1,5 @@
1
- import { toSourceText } from "#test/utils.jsx";
1
+ import { TestNamespace, toSourceText } from "#test/utils.jsx";
2
+ import { namekey } from "@alloy-js/core";
2
3
  import { d } from "@alloy-js/core/testing";
3
4
  import { expect, it } from "vitest";
4
5
  import { EnumDeclaration } from "./declaration.jsx";
@@ -22,3 +23,23 @@ it("declares enum with members", () => {
22
23
  }
23
24
  `);
24
25
  });
26
+
27
+ it("takes a namekey", () => {
28
+ const memberKey = namekey("MyMember");
29
+ const tree = (
30
+ <TestNamespace>
31
+ <EnumDeclaration name="Foo">
32
+ <EnumMember name={memberKey} />
33
+ </EnumDeclaration>
34
+ <hbr />
35
+ {memberKey};
36
+ </TestNamespace>
37
+ );
38
+ expect(tree).toRenderTo(`
39
+ enum Foo
40
+ {
41
+ MyMember
42
+ }
43
+ Foo.MyMember;
44
+ `);
45
+ });
@@ -1,11 +1,11 @@
1
- import { MemberDeclaration, MemberName, Refkey } from "@alloy-js/core";
1
+ import { MemberDeclaration, MemberName, Namekey, Refkey } from "@alloy-js/core";
2
2
  import { useCSharpNamePolicy } from "../../name-policy.js";
3
3
  import { useNamedTypeScope } from "../../scopes/contexts.js";
4
4
  import { CSharpSymbol } from "../../symbols/csharp.js";
5
5
 
6
6
  // properties for creating a C# enum member
7
7
  export interface EnumMemberProps {
8
- name: string;
8
+ name: string | Namekey;
9
9
  refkey?: Refkey;
10
10
  }
11
11
 
@@ -23,9 +23,9 @@ export function EnumMember(props: EnumMemberProps) {
23
23
  throw new Error("EnumMember must be used within an EnumDeclaration.");
24
24
  }
25
25
 
26
- const name = useCSharpNamePolicy().getName(props.name, "enum-member");
27
- const thisEnumValueSymbol = new CSharpSymbol(name, symbol.members, {
26
+ const thisEnumValueSymbol = new CSharpSymbol(props.name, symbol.members, {
28
27
  refkeys: props.refkey,
28
+ namePolicy: useCSharpNamePolicy().for("enum-member"),
29
29
  });
30
30
 
31
31
  return (
@@ -1,4 +1,4 @@
1
- import { List } from "@alloy-js/core";
1
+ import { List, namekey } from "@alloy-js/core";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { ClassDeclaration } from "../class/declaration.jsx";
@@ -30,6 +30,19 @@ it("declares multiple fields", () => {
30
30
  `);
31
31
  });
32
32
 
33
+ it("takes a namekey", () => {
34
+ expect(
35
+ <Wrapper>
36
+ <Field name={namekey("my-field")} type="string" public />
37
+ </Wrapper>,
38
+ ).toRenderTo(`
39
+ public class TestClass
40
+ {
41
+ public string MyField;
42
+ }
43
+ `);
44
+ });
45
+
33
46
  describe("modifiers", () => {
34
47
  describe("access modifiers", () => {
35
48
  it.each(["public", "private", "protected", "internal"] as const)(
@@ -1,4 +1,4 @@
1
- import { Children, Declaration, Name, Refkey } from "@alloy-js/core";
1
+ import { Children, Declaration, Name, Namekey, Refkey } from "@alloy-js/core";
2
2
  import {
3
3
  AccessModifiers,
4
4
  computeModifiersPrefix,
@@ -28,7 +28,7 @@ const getModifiers = makeModifiers<FieldModifiers>([
28
28
  ]);
29
29
 
30
30
  export interface FieldProps extends AccessModifiers, FieldModifiers {
31
- name: string;
31
+ name: string | Namekey;
32
32
  type: Children;
33
33
  refkey?: Refkey;
34
34
  /** Doc comment */
@@ -24,5 +24,5 @@ export * from "./Reference.js";
24
24
  export * from "./source-file/source-file.jsx";
25
25
  export * from "./struct/declaration.jsx";
26
26
  export type { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
27
- export * from "./UsingDirective.js";
27
+ export * from "./using/using.jsx";
28
28
  export * from "./var/declaration.jsx";
@@ -1,4 +1,4 @@
1
- import { List, refkey } from "@alloy-js/core";
1
+ import { List, namekey, refkey } from "@alloy-js/core";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { Attribute } from "../attributes/attributes.jsx";
@@ -59,6 +59,16 @@ it("specify doc comment", () => {
59
59
  `);
60
60
  });
61
61
 
62
+ it("takes a namekey", () => {
63
+ expect(
64
+ <TestNamespace>
65
+ <InterfaceDeclaration name={namekey("my-interface")} />
66
+ </TestNamespace>,
67
+ ).toRenderTo(`
68
+ interface MyInterface;
69
+ `);
70
+ });
71
+
62
72
  describe("with type parameters", () => {
63
73
  it("reference parameters", () => {
64
74
  const typeParameters: TypeParameterProps[] = [
@@ -26,7 +26,7 @@ export interface InterfaceDeclarationProps
26
26
  extends Omit<core.DeclarationProps, "nameKind">,
27
27
  AccessModifiers,
28
28
  InterfaceModifiers {
29
- name: string;
29
+ name: string | core.Namekey;
30
30
 
31
31
  /** Doc comment */
32
32
  doc?: core.Children;
@@ -86,10 +86,9 @@ export interface InterfaceDeclarationProps
86
86
  * ```
87
87
  */
88
88
  export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
89
- const name = useCSharpNamePolicy().getName(props.name!, "interface");
90
-
91
- const symbol = createNamedTypeSymbol(name, "interface", {
89
+ const symbol = createNamedTypeSymbol(props.name!, "interface", {
92
90
  refkeys: props.refkey,
91
+ namePolicy: useCSharpNamePolicy().for("interface"),
93
92
  });
94
93
 
95
94
  // this creates a new scope for the interface definition.
@@ -1,4 +1,4 @@
1
- import { refkey } from "@alloy-js/core";
1
+ import { namekey, refkey } from "@alloy-js/core";
2
2
  import { Children } from "@alloy-js/core/jsx-runtime";
3
3
  import { describe, expect, it } from "vitest";
4
4
  import { TestNamespace } from "../../../test/utils.jsx";
@@ -188,6 +188,19 @@ it("specify attributes", () => {
188
188
  `);
189
189
  });
190
190
 
191
+ it("takes a namekey", () => {
192
+ expect(
193
+ <Wrapper>
194
+ <InterfaceMethod name={namekey("my-method")} />
195
+ </Wrapper>,
196
+ ).toRenderTo(`
197
+ public interface TestInterface
198
+ {
199
+ void MyMethod();
200
+ }
201
+ `);
202
+ });
203
+
191
204
  describe("with type parameters", () => {
192
205
  it("reference parameters", () => {
193
206
  const typeParameters: TypeParameterProps[] = [
@@ -3,6 +3,7 @@ import {
3
3
  Children,
4
4
  MemberDeclaration,
5
5
  MemberName,
6
+ Namekey,
6
7
  Refkey,
7
8
  Scope,
8
9
  } from "@alloy-js/core";
@@ -32,7 +33,7 @@ const getMethodModifier = makeModifiers<InterfaceMethodModifiers>(["new"]);
32
33
  export interface InterfaceMethodProps
33
34
  extends AccessModifiers,
34
35
  InterfaceMethodModifiers {
35
- name: string;
36
+ name: string | Namekey;
36
37
  refkey?: Refkey;
37
38
  children?: Children;
38
39
  parameters?: Array<ParameterProps>;
@@ -1,5 +1,6 @@
1
1
  import { Children } from "@alloy-js/core/jsx-runtime";
2
2
  import { describe, expect, it } from "vitest";
3
+ import { namekey } from "../../../../core/src/refkey.js";
3
4
  import { TestNamespace } from "../../../test/utils.jsx";
4
5
  import { Attribute } from "../attributes/attributes.jsx";
5
6
  import { InterfaceDeclaration } from "./declaration.jsx";
@@ -144,6 +145,18 @@ it("specify doc comment", () => {
144
145
  `);
145
146
  });
146
147
 
148
+ it("takes a namekey", () => {
149
+ expect(
150
+ <Wrapper>
151
+ <InterfaceProperty name={namekey("my-property")} type="string" get />
152
+ </Wrapper>,
153
+ ).toRenderTo(`
154
+ public interface TestInterface
155
+ {
156
+ string MyProperty { get; }
157
+ }
158
+ `);
159
+ });
147
160
  it("specify attributes", () => {
148
161
  expect(
149
162
  <Wrapper>
@@ -4,6 +4,7 @@ import {
4
4
  List,
5
5
  MemberDeclaration,
6
6
  MemberName,
7
+ Namekey,
7
8
  Refkey,
8
9
  } from "@alloy-js/core";
9
10
  import {
@@ -27,7 +28,7 @@ const getModifiers = makeModifiers<InterfacePropertyModifiers>(["new"]);
27
28
  export interface InterfacePropertyProps
28
29
  extends AccessModifiers,
29
30
  InterfacePropertyModifiers {
30
- name: string;
31
+ name: string | Namekey;
31
32
  refkey?: Refkey;
32
33
 
33
34
  /** Property type */
@@ -1,5 +1,4 @@
1
- import { Output, refkey } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
1
+ import { List, memberRefkey, namekey, Output, refkey } from "@alloy-js/core";
3
2
  import { expect, it } from "vitest";
4
3
  import { ClassDeclaration } from "./class/declaration.jsx";
5
4
  import { Namespace } from "./namespace.jsx";
@@ -20,7 +19,7 @@ it("references types in the same namespace", () => {
20
19
  </Output>
21
20
  );
22
21
 
23
- expect(tree).toRenderTo(d`
22
+ expect(tree).toRenderTo(`
24
23
  namespace Test;
25
24
 
26
25
  class TestClass;
@@ -43,7 +42,7 @@ it("references types in a parent namespace", () => {
43
42
  </Output>
44
43
  );
45
44
 
46
- expect(tree).toRenderTo(d`
45
+ expect(tree).toRenderTo(`
47
46
  namespace Test {
48
47
  class TestClass;
49
48
  namespace Nested {
@@ -69,7 +68,7 @@ it("references types in a child namespace", () => {
69
68
  </Output>
70
69
  );
71
70
 
72
- expect(tree).toRenderTo(d`
71
+ expect(tree).toRenderTo(`
73
72
  namespace Test {
74
73
  Nested.TestClass;
75
74
  namespace Nested {
@@ -94,7 +93,7 @@ it("references types in a different top-level namespace declared in the same fil
94
93
  </Output>
95
94
  );
96
95
 
97
- expect(tree).toRenderTo(d`
96
+ expect(tree).toRenderTo(`
98
97
  using TestCode2;
99
98
 
100
99
  namespace TestCode1 {
@@ -123,17 +122,43 @@ it("references types in a different top-level namespace declared in a different
123
122
  );
124
123
 
125
124
  expect(tree).toRenderTo({
126
- "test.cs": d`
125
+ "test.cs": `
127
126
  using TestCode2;
128
127
 
129
128
  namespace TestCode1 {
130
129
  TestClass;
131
130
  }
132
131
  `,
133
- "other.cs": d`
132
+ "other.cs": `
134
133
  namespace TestCode2 {
135
134
  class TestClass;
136
135
  }
137
136
  `,
138
137
  });
139
138
  });
139
+
140
+ it("can be referenced by refkey", () => {
141
+ const classRef = namekey("TestClass");
142
+ const nsRef = namekey("TestCode2");
143
+ const tree = (
144
+ <Output>
145
+ <SourceFile path="other.cs">
146
+ <List>
147
+ <Namespace name={nsRef}>
148
+ <ClassDeclaration name={classRef} />
149
+ </Namespace>
150
+ <>{memberRefkey(nsRef, classRef)};</>
151
+ </List>
152
+ </SourceFile>
153
+ </Output>
154
+ );
155
+
156
+ expect(tree).toRenderTo(`
157
+ using TestCode2;
158
+
159
+ namespace TestCode2 {
160
+ class TestClass;
161
+ }
162
+ TestClass;
163
+ `);
164
+ });
@@ -1,3 +1,4 @@
1
+ import { TestNamespace } from "#test/utils.jsx";
1
2
  import { Output } from "@alloy-js/core";
2
3
  import { d } from "@alloy-js/core/testing";
3
4
  import { expect, it } from "vitest";
@@ -50,3 +51,15 @@ it("defines multiple namespaces and source files with unique content", () => {
50
51
  `,
51
52
  });
52
53
  });
54
+
55
+ it("uses a name policy", () => {
56
+ expect(
57
+ <TestNamespace>
58
+ <Namespace name="my-namespace" />
59
+ </TestNamespace>,
60
+ ).toRenderTo(`
61
+ namespace MyNamespace {
62
+
63
+ }
64
+ `);
65
+ });
@@ -1,4 +1,4 @@
1
- import { Block } from "@alloy-js/core";
1
+ import { Block, Namekey, Refkey } from "@alloy-js/core";
2
2
  import { Children } from "@alloy-js/core/jsx-runtime";
3
3
  import { NamespaceContext } from "../contexts/namespace.js";
4
4
  import { useSourceFileScope } from "../scopes/source-file.js";
@@ -6,12 +6,15 @@ import { createNamespaceSymbol } from "../symbols/factories.js";
6
6
  import { NamespaceScope } from "./namespace-scopes.jsx";
7
7
 
8
8
  export interface NamespaceProps {
9
- name: string;
9
+ name: string | Namekey;
10
+ refkey?: Refkey | Refkey[];
10
11
  children?: Children;
11
12
  }
12
13
 
13
14
  export function Namespace(props: NamespaceProps) {
14
- const namespaceSymbol = createNamespaceSymbol(props.name);
15
+ const namespaceSymbol = createNamespaceSymbol(props.name, {
16
+ refkeys: props.refkey,
17
+ });
15
18
  const sfScope = useSourceFileScope();
16
19
 
17
20
  if (!sfScope) {
@@ -1,4 +1,4 @@
1
- import { Children, code, refkey } from "@alloy-js/core";
1
+ import { Children, code, namekey, refkey } from "@alloy-js/core";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { Property } from "../property/property.jsx";
@@ -19,6 +19,16 @@ it("declares record with no members", () => {
19
19
  `);
20
20
  });
21
21
 
22
+ it("takes a namekey", () => {
23
+ expect(
24
+ <TestNamespace>
25
+ <RecordDeclaration name={namekey("my-record")} />
26
+ </TestNamespace>,
27
+ ).toRenderTo(`
28
+ record MyRecord;
29
+ `);
30
+ });
31
+
22
32
  describe("modifiers", () => {
23
33
  it.each(["public", "private", "internal"])("%s", (mod) => {
24
34
  expect(
@@ -26,7 +26,7 @@ export interface RecordDeclarationProps
26
26
  extends Omit<core.DeclarationProps, "nameKind">,
27
27
  AccessModifiers,
28
28
  RecordModifiers {
29
- name: string;
29
+ name: string | core.Namekey;
30
30
 
31
31
  /** Doc comment */
32
32
  doc?: core.Children;
@@ -73,12 +73,11 @@ export interface RecordDeclarationProps
73
73
  * ```
74
74
  */
75
75
  export function RecordDeclaration(props: RecordDeclarationProps) {
76
- const name = useCSharpNamePolicy().getName(props.name!, "record");
77
-
78
76
  // records don't have their own type kind but instead use class or struct
79
77
  // depending on what kind of record we have.
80
- const thisRecordSymbol = createNamedTypeSymbol(name, "record", {
78
+ const thisRecordSymbol = createNamedTypeSymbol(props.name, "record", {
81
79
  refkeys: props.refkey,
80
+ namePolicy: useCSharpNamePolicy().for("record"),
82
81
  });
83
82
 
84
83
  const thisRecordScope = createClassScope(thisRecordSymbol);
@@ -1,6 +1,6 @@
1
1
  import { NamespaceScopes } from "#components/namespace-scopes.jsx";
2
2
  import { Reference } from "#components/Reference.jsx";
3
- import { UsingDirective } from "#components/UsingDirective.jsx";
3
+ import { Usings } from "#components/using/using.jsx";
4
4
  import {
5
5
  Block,
6
6
  Children,
@@ -70,7 +70,7 @@ export function SourceFile(props: SourceFileProps) {
70
70
  {(sourceFileScope.usings.size > 0 ||
71
71
  (props.using && props.using.length > 0)) && (
72
72
  <>
73
- <UsingDirective namespaces={usings.value} />
73
+ <Usings namespaces={usings.value} />
74
74
  <hbr />
75
75
  <hbr />
76
76
  </>
@@ -0,0 +1,94 @@
1
+ import { ClassDeclaration } from "#components/class/declaration.jsx";
2
+ import { EnumDeclaration } from "#components/enum/declaration.jsx";
3
+ import { EnumMember } from "#components/enum/member.jsx";
4
+ import { Method } from "#components/method/method.jsx";
5
+ import { Namespace } from "#components/namespace.jsx";
6
+ import { SourceFile } from "#components/source-file/source-file.jsx";
7
+ import { Output, refkey } from "@alloy-js/core";
8
+ import * as coretest from "@alloy-js/core/testing";
9
+ import { expect, it } from "vitest";
10
+ import { createCSharpNamePolicy } from "../../name-policy.js";
11
+
12
+ it("using on source file are placed above file namespace statement", () => {
13
+ expect(
14
+ <Output>
15
+ <Namespace name="TestCode">
16
+ <SourceFile path="Test1.cs" using={["Foo"]} />
17
+ </Namespace>
18
+ </Output>,
19
+ ).toRenderTo(`
20
+ using Foo;
21
+
22
+ namespace TestCode;
23
+
24
+
25
+ `);
26
+ });
27
+
28
+ it("adds using statement across namespaces", () => {
29
+ const inputTypeRefkey = refkey();
30
+ const outputTypeRefkey = refkey();
31
+ const twoValRefkey = refkey();
32
+
33
+ const params = [
34
+ {
35
+ name: "BodyParam",
36
+ type: inputTypeRefkey,
37
+ },
38
+ ];
39
+
40
+ expect(
41
+ <Output namePolicy={createCSharpNamePolicy()}>
42
+ <Namespace name="Models">
43
+ <SourceFile path="Models.cs">
44
+ <ClassDeclaration public name="Input" refkey={inputTypeRefkey} />
45
+ <hbr />
46
+ <ClassDeclaration public name="Output" refkey={outputTypeRefkey} />
47
+ <hbr />
48
+ <EnumDeclaration public name="TestEnum">
49
+ <EnumMember name="One" />,<hbr />
50
+ <EnumMember name="Two" refkey={twoValRefkey} />
51
+ </EnumDeclaration>
52
+ </SourceFile>
53
+ </Namespace>
54
+ <Namespace name="Client">
55
+ <SourceFile path="Client.cs" using={["System"]}>
56
+ <ClassDeclaration public name="Client">
57
+ <Method
58
+ public
59
+ name="MethodOne"
60
+ parameters={params}
61
+ returns={outputTypeRefkey}
62
+ />
63
+ </ClassDeclaration>
64
+ <hbr />
65
+ {twoValRefkey};
66
+ </SourceFile>
67
+ </Namespace>
68
+ </Output>,
69
+ ).toRenderTo({
70
+ "Models.cs": coretest.d`
71
+ namespace Models;
72
+
73
+ public class Input;
74
+ public class Output;
75
+ public enum TestEnum
76
+ {
77
+ One,
78
+ Two
79
+ }
80
+ `,
81
+ "Client.cs": coretest.d`
82
+ using Models;
83
+ using System;
84
+
85
+ namespace Client;
86
+
87
+ public class Client
88
+ {
89
+ public Output MethodOne(Input bodyParam) {}
90
+ }
91
+ TestEnum.Two;
92
+ `,
93
+ });
94
+ });
@@ -10,5 +10,5 @@ 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);
12
12
  export const ProjectDirectory = core.stc(base.ProjectDirectory);
13
- export const UsingDirective = core.stc(base.UsingDirective);
13
+ export const UsingDirective = core.stc(base.Usings);
14
14
  export const StructDeclaration = core.stc(base.StructDeclaration);
@@ -1,4 +1,4 @@
1
- import { List, refkey } from "@alloy-js/core";
1
+ import { List, namekey, refkey } from "@alloy-js/core";
2
2
  import { describe, expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { Attribute } from "../attributes/attributes.jsx";
@@ -19,6 +19,16 @@ it("declares struct with no members", () => {
19
19
  `);
20
20
  });
21
21
 
22
+ it("takes a namekey", () => {
23
+ expect(
24
+ <TestNamespace>
25
+ <StructDeclaration name={namekey("my-struct")} />
26
+ </TestNamespace>,
27
+ ).toRenderTo(`
28
+ struct MyStruct;
29
+ `);
30
+ });
31
+
22
32
  describe("modifiers", () => {
23
33
  it.each(["public", "private", "internal"])("%s", (mod) => {
24
34
  expect(
@@ -35,7 +35,7 @@ export interface StructDeclarationProps
35
35
  extends Omit<core.DeclarationProps, "nameKind">,
36
36
  AccessModifiers,
37
37
  StructModifiers {
38
- name: string;
38
+ name: string | core.Namekey;
39
39
 
40
40
  /** Doc comment */
41
41
  doc?: core.Children;
@@ -98,10 +98,9 @@ export interface StructDeclarationProps
98
98
  * ```
99
99
  */
100
100
  export function StructDeclaration(props: StructDeclarationProps) {
101
- const name = useCSharpNamePolicy().getName(props.name!, "struct");
102
-
103
- const thisStructSymbol = createNamedTypeSymbol(name, "struct", {
101
+ const thisStructSymbol = createNamedTypeSymbol(props.name, "struct", {
104
102
  refkeys: props.refkey,
103
+ namePolicy: useCSharpNamePolicy().for("struct"),
105
104
  });
106
105
 
107
106
  const thisStructScope = createNamedTypeScope(thisStructSymbol);
@@ -2,6 +2,7 @@ import {
2
2
  Children,
3
3
  MemberDeclaration,
4
4
  MemberName,
5
+ Namekey,
5
6
  Refkey,
6
7
  } from "@alloy-js/core";
7
8
  import { createTypeParameterSymbol } from "../../symbols/factories.js";
@@ -13,7 +14,7 @@ export interface TypeParameterProps {
13
14
  /**
14
15
  * The name of the type parameter.
15
16
  */
16
- readonly name: string;
17
+ readonly name: string | Namekey;
17
18
 
18
19
  /**
19
20
  * The parameter constraint
@@ -1,3 +1,4 @@
1
+ import { namekey } from "@alloy-js/core";
1
2
  import { expect, it } from "vitest";
2
3
  import { TestNamespace } from "../../../test/utils.jsx";
3
4
  import { TypeParameters } from "./type-parameters.jsx";
@@ -44,3 +45,11 @@ it("declare type parameters using parameters", () => {
44
45
  </TestNamespace>,
45
46
  ).toRenderTo(`<A, B>`);
46
47
  });
48
+
49
+ it("takes a namekey", () => {
50
+ expect(
51
+ <TestNamespace>
52
+ <TypeParameters parameters={[{ name: namekey("my-param") }]} />
53
+ </TestNamespace>,
54
+ ).toRenderTo(`<MyParam>`);
55
+ });