@alloy-js/csharp 0.21.0-dev.1 → 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 (103) 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/interface/declaration.d.ts +1 -1
  19. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  20. package/dist/src/components/interface/declaration.js +3 -3
  21. package/dist/src/components/interface/declaration.js.map +1 -1
  22. package/dist/src/components/interface/declaration.test.js +14 -1
  23. package/dist/src/components/interface/declaration.test.js.map +1 -1
  24. package/dist/src/components/interface/method.d.ts +2 -2
  25. package/dist/src/components/interface/method.d.ts.map +1 -1
  26. package/dist/src/components/interface/method.js.map +1 -1
  27. package/dist/src/components/interface/method.test.js +17 -1
  28. package/dist/src/components/interface/method.test.js.map +1 -1
  29. package/dist/src/components/interface/property.d.ts +2 -2
  30. package/dist/src/components/interface/property.d.ts.map +1 -1
  31. package/dist/src/components/interface/property.js.map +1 -1
  32. package/dist/src/components/interface/property.test.js +19 -0
  33. package/dist/src/components/interface/property.test.js.map +1 -1
  34. package/dist/src/components/namespace.d.ts +3 -1
  35. package/dist/src/components/namespace.d.ts.map +1 -1
  36. package/dist/src/components/namespace.js +3 -1
  37. package/dist/src/components/namespace.js.map +1 -1
  38. package/dist/src/components/namespace.ref.test.js +41 -9
  39. package/dist/src/components/namespace.ref.test.js.map +1 -1
  40. package/dist/src/components/namespace.test.js +14 -0
  41. package/dist/src/components/namespace.test.js.map +1 -1
  42. package/dist/src/components/record/declaration.d.ts +1 -1
  43. package/dist/src/components/record/declaration.d.ts.map +1 -1
  44. package/dist/src/components/record/declaration.js +3 -4
  45. package/dist/src/components/record/declaration.js.map +1 -1
  46. package/dist/src/components/record/declaration.test.js +14 -1
  47. package/dist/src/components/record/declaration.test.js.map +1 -1
  48. package/dist/src/components/struct/declaration.d.ts +1 -1
  49. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  50. package/dist/src/components/struct/declaration.js +3 -3
  51. package/dist/src/components/struct/declaration.js.map +1 -1
  52. package/dist/src/components/struct/declaration.test.js +14 -1
  53. package/dist/src/components/struct/declaration.test.js.map +1 -1
  54. package/dist/src/components/type-parameters/type-parameter.d.ts +2 -2
  55. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  56. package/dist/src/components/type-parameters/type-parameter.js.map +1 -1
  57. package/dist/src/components/type-parameters/type-parameters.test.js +14 -0
  58. package/dist/src/components/type-parameters/type-parameters.test.js.map +1 -1
  59. package/dist/src/components/var/declaration.d.ts +2 -2
  60. package/dist/src/components/var/declaration.d.ts.map +1 -1
  61. package/dist/src/components/var/declaration.js.map +1 -1
  62. package/dist/src/components/var/declaration.test.js +22 -1
  63. package/dist/src/components/var/declaration.test.js.map +1 -1
  64. package/dist/src/name-policy.d.ts +1 -1
  65. package/dist/src/name-policy.d.ts.map +1 -1
  66. package/dist/src/name-policy.js +1 -0
  67. package/dist/src/name-policy.js.map +1 -1
  68. package/dist/src/symbols/factories.d.ts +1 -1
  69. package/dist/src/symbols/factories.d.ts.map +1 -1
  70. package/dist/src/symbols/factories.js +6 -4
  71. package/dist/src/symbols/factories.js.map +1 -1
  72. package/dist/src/symbols/namespace.d.ts +2 -2
  73. package/dist/src/symbols/namespace.d.ts.map +1 -1
  74. package/dist/src/symbols/namespace.js.map +1 -1
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +2 -2
  77. package/src/components/enum/declaration.test.tsx +14 -1
  78. package/src/components/enum/declaration.tsx +4 -3
  79. package/src/components/enum/member.test.tsx +22 -1
  80. package/src/components/enum/member.tsx +4 -4
  81. package/src/components/field/field.test.tsx +14 -1
  82. package/src/components/field/field.tsx +2 -2
  83. package/src/components/interface/declaration.test.tsx +11 -1
  84. package/src/components/interface/declaration.tsx +3 -4
  85. package/src/components/interface/method.test.tsx +14 -1
  86. package/src/components/interface/method.tsx +2 -1
  87. package/src/components/interface/property.test.tsx +13 -0
  88. package/src/components/interface/property.tsx +2 -1
  89. package/src/components/namespace.ref.test.tsx +33 -8
  90. package/src/components/namespace.test.tsx +13 -0
  91. package/src/components/namespace.tsx +6 -3
  92. package/src/components/record/declaration.test.tsx +11 -1
  93. package/src/components/record/declaration.tsx +3 -4
  94. package/src/components/struct/declaration.test.tsx +11 -1
  95. package/src/components/struct/declaration.tsx +3 -4
  96. package/src/components/type-parameters/type-parameter.tsx +2 -1
  97. package/src/components/type-parameters/type-parameters.test.tsx +9 -0
  98. package/src/components/var/declaration.test.tsx +16 -1
  99. package/src/components/var/declaration.tsx +2 -1
  100. package/src/name-policy.ts +3 -1
  101. package/src/symbols/factories.ts +12 -4
  102. package/src/symbols/namespace.ts +2 -2
  103. package/temp/api.json +156 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/csharp",
3
- "version": "0.21.0-dev.1",
3
+ "version": "0.21.0-dev.2",
4
4
  "description": "Alloy components for CSharp language.",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,7 @@
20
20
  "author": "jhendrix@microsoft.com",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.0",
23
+ "@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.1",
24
24
  "change-case": "^5.4.4",
25
25
  "marked": "^16.1.1",
26
26
  "pathe": "^2.0.3"
@@ -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 */
@@ -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,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
+ });
@@ -1,4 +1,4 @@
1
- import { List, refkey } from "@alloy-js/core";
1
+ import { List, namekey, refkey } from "@alloy-js/core";
2
2
  import { expect, it } from "vitest";
3
3
  import { TestNamespace } from "../../../test/utils.jsx";
4
4
  import { VarDeclaration } from "./declaration.jsx";
@@ -51,3 +51,18 @@ it("links refkey", () => {
51
51
  var testVar2 = testVar;
52
52
  `);
53
53
  });
54
+
55
+ it("links namekey", () => {
56
+ const key = namekey("test-var");
57
+ expect(
58
+ <TestNamespace>
59
+ <List>
60
+ <VarDeclaration name={key}>42</VarDeclaration>
61
+ <VarDeclaration name="testVar2">{key}</VarDeclaration>
62
+ </List>
63
+ </TestNamespace>,
64
+ ).toRenderTo(`
65
+ var testVar = 42;
66
+ var testVar2 = testVar;
67
+ `);
68
+ });
@@ -3,6 +3,7 @@ import {
3
3
  Declaration,
4
4
  DeclarationProps,
5
5
  Name,
6
+ Namekey,
6
7
  Refkey,
7
8
  } from "@alloy-js/core";
8
9
  import { createVariableSymbol } from "../../symbols/factories.js";
@@ -11,7 +12,7 @@ import { createVariableSymbol } from "../../symbols/factories.js";
11
12
  export interface VarDeclarationProps
12
13
  extends Omit<DeclarationProps, "nameKind"> {
13
14
  /** Variable name */
14
- name: string;
15
+ name: string | Namekey;
15
16
  /** Type of the variable declaration. If not specified, defaults to "var" */
16
17
  type?: Children;
17
18
  /** Variable refkey */
@@ -17,7 +17,8 @@ export type CSharpElements =
17
17
  | "class-method"
18
18
  | "class-property"
19
19
  | "parameter"
20
- | "type-parameter";
20
+ | "type-parameter"
21
+ | "namespace";
21
22
 
22
23
  // creates the C# naming policy
23
24
  export function createCSharpNamePolicy(): core.NamePolicy<CSharpElements> {
@@ -33,6 +34,7 @@ export function createCSharpNamePolicy(): core.NamePolicy<CSharpElements> {
33
34
  case "class-method":
34
35
  case "type-parameter":
35
36
  case "class-property":
37
+ case "namespace":
36
38
  return changecase.pascalCase(name);
37
39
  case "constant":
38
40
  return changecase.constantCase(name);
@@ -118,13 +118,21 @@ export function createNamedTypeSymbol(
118
118
  );
119
119
  }
120
120
 
121
- export function createNamespaceSymbol(name: string) {
121
+ export function createNamespaceSymbol(
122
+ name: string | Namekey,
123
+ options: CSharpSymbolOptions = {},
124
+ ) {
122
125
  const scope = useEnclosingNamespaceScope();
123
126
  const nsSymbol = scope?.ownerSymbol ?? getGlobalNamespace(useBinder());
124
- if (nsSymbol.members.symbolNames.has(name)) {
125
- return nsSymbol.members.symbolNames.get(name)! as NamespaceSymbol;
127
+ const namePolicy =
128
+ options.namePolicy ?? useCSharpNamePolicy().for("namespace");
129
+ const expectedName = namePolicy(typeof name === "string" ? name : name.name);
130
+ if (nsSymbol.members.symbolNames.has(expectedName)) {
131
+ return nsSymbol.members.symbolNames.get(expectedName)! as NamespaceSymbol;
126
132
  }
127
- return withCleanup(new NamespaceSymbol(name, nsSymbol));
133
+ return withCleanup(
134
+ new NamespaceSymbol(name, nsSymbol, withNamePolicy(options, "namespace")),
135
+ );
128
136
  }
129
137
 
130
138
  export interface CreateMethodSymbolOptions extends CSharpSymbolOptions {
@@ -1,4 +1,4 @@
1
- import { OutputSymbolOptions } from "@alloy-js/core";
1
+ import { Namekey, OutputSymbolOptions } from "@alloy-js/core";
2
2
  import { NamedTypeSymbol } from "./named-type.js";
3
3
 
4
4
  export interface NamespaceSymbolOptions extends OutputSymbolOptions {
@@ -11,7 +11,7 @@ export interface NamespaceSymbolOptions extends OutputSymbolOptions {
11
11
  export class NamespaceSymbol extends NamedTypeSymbol {
12
12
  public readonly symbolKind = "namespace";
13
13
  constructor(
14
- name: string,
14
+ name: string | Namekey,
15
15
  parentNamespace?: NamespaceSymbol,
16
16
  options?: NamespaceSymbolOptions,
17
17
  ) {