@alloy-js/csharp 0.21.0-dev.1 → 0.21.0-dev.3

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 (131) 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.ref.test.js +1 -1
  6. package/dist/src/components/enum/declaration.test.js +15 -1
  7. package/dist/src/components/enum/declaration.test.js.map +1 -1
  8. package/dist/src/components/enum/member.d.ts +2 -2
  9. package/dist/src/components/enum/member.d.ts.map +1 -1
  10. package/dist/src/components/enum/member.js +3 -3
  11. package/dist/src/components/enum/member.js.map +1 -1
  12. package/dist/src/components/enum/member.test.js +24 -1
  13. package/dist/src/components/enum/member.test.js.map +1 -1
  14. package/dist/src/components/field/field.d.ts +2 -2
  15. package/dist/src/components/field/field.d.ts.map +1 -1
  16. package/dist/src/components/field/field.js.map +1 -1
  17. package/dist/src/components/field/field.test.js +19 -1
  18. package/dist/src/components/field/field.test.js.map +1 -1
  19. package/dist/src/components/index.d.ts +1 -1
  20. package/dist/src/components/index.d.ts.map +1 -1
  21. package/dist/src/components/index.js +1 -2
  22. package/dist/src/components/index.js.map +1 -1
  23. package/dist/src/components/interface/declaration.d.ts +1 -1
  24. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  25. package/dist/src/components/interface/declaration.js +3 -3
  26. package/dist/src/components/interface/declaration.js.map +1 -1
  27. package/dist/src/components/interface/declaration.test.js +14 -1
  28. package/dist/src/components/interface/declaration.test.js.map +1 -1
  29. package/dist/src/components/interface/method.d.ts +2 -2
  30. package/dist/src/components/interface/method.d.ts.map +1 -1
  31. package/dist/src/components/interface/method.js.map +1 -1
  32. package/dist/src/components/interface/method.test.js +17 -1
  33. package/dist/src/components/interface/method.test.js.map +1 -1
  34. package/dist/src/components/interface/property.d.ts +2 -2
  35. package/dist/src/components/interface/property.d.ts.map +1 -1
  36. package/dist/src/components/interface/property.js.map +1 -1
  37. package/dist/src/components/interface/property.test.js +19 -0
  38. package/dist/src/components/interface/property.test.js.map +1 -1
  39. package/dist/src/components/namespace/namespace-name.d.ts +10 -0
  40. package/dist/src/components/namespace/namespace-name.d.ts.map +1 -0
  41. package/dist/src/components/namespace/namespace-name.js +20 -0
  42. package/dist/src/components/namespace/namespace-name.js.map +1 -0
  43. package/dist/src/components/{namespace.d.ts → namespace/namespace.d.ts} +3 -1
  44. package/dist/src/components/namespace/namespace.d.ts.map +1 -0
  45. package/dist/src/components/{namespace.js → namespace/namespace.js} +12 -13
  46. package/dist/src/components/namespace/namespace.js.map +1 -0
  47. package/dist/src/components/namespace/namespace.test.d.ts.map +1 -0
  48. package/dist/src/components/namespace/namespace.test.js +207 -0
  49. package/dist/src/components/namespace/namespace.test.js.map +1 -0
  50. package/dist/src/components/namespace.ref.test.js +42 -10
  51. package/dist/src/components/namespace.ref.test.js.map +1 -1
  52. package/dist/src/components/record/declaration.d.ts +1 -1
  53. package/dist/src/components/record/declaration.d.ts.map +1 -1
  54. package/dist/src/components/record/declaration.js +3 -4
  55. package/dist/src/components/record/declaration.js.map +1 -1
  56. package/dist/src/components/record/declaration.test.js +14 -1
  57. package/dist/src/components/record/declaration.test.js.map +1 -1
  58. package/dist/src/components/source-file/source-file.d.ts.map +1 -1
  59. package/dist/src/components/source-file/source-file.js +4 -2
  60. package/dist/src/components/source-file/source-file.js.map +1 -1
  61. package/dist/src/components/source-file/source-file.test.js +1 -1
  62. package/dist/src/components/source-file/using.test.js +1 -1
  63. package/dist/src/components/struct/declaration.d.ts +1 -1
  64. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  65. package/dist/src/components/struct/declaration.js +3 -3
  66. package/dist/src/components/struct/declaration.js.map +1 -1
  67. package/dist/src/components/struct/declaration.test.js +14 -1
  68. package/dist/src/components/struct/declaration.test.js.map +1 -1
  69. package/dist/src/components/type-parameters/type-parameter.d.ts +2 -2
  70. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  71. package/dist/src/components/type-parameters/type-parameter.js.map +1 -1
  72. package/dist/src/components/type-parameters/type-parameters.test.js +14 -0
  73. package/dist/src/components/type-parameters/type-parameters.test.js.map +1 -1
  74. package/dist/src/components/var/declaration.d.ts +2 -2
  75. package/dist/src/components/var/declaration.d.ts.map +1 -1
  76. package/dist/src/components/var/declaration.js.map +1 -1
  77. package/dist/src/components/var/declaration.test.js +22 -1
  78. package/dist/src/components/var/declaration.test.js.map +1 -1
  79. package/dist/src/name-policy.d.ts +1 -1
  80. package/dist/src/name-policy.d.ts.map +1 -1
  81. package/dist/src/name-policy.js +1 -0
  82. package/dist/src/name-policy.js.map +1 -1
  83. package/dist/src/symbols/factories.d.ts +1 -1
  84. package/dist/src/symbols/factories.d.ts.map +1 -1
  85. package/dist/src/symbols/factories.js +27 -7
  86. package/dist/src/symbols/factories.js.map +1 -1
  87. package/dist/src/symbols/namespace.d.ts +2 -2
  88. package/dist/src/symbols/namespace.d.ts.map +1 -1
  89. package/dist/src/symbols/namespace.js.map +1 -1
  90. package/dist/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +2 -2
  92. package/src/components/enum/declaration.ref.test.tsx +1 -1
  93. package/src/components/enum/declaration.test.tsx +14 -1
  94. package/src/components/enum/declaration.tsx +4 -3
  95. package/src/components/enum/member.test.tsx +22 -1
  96. package/src/components/enum/member.tsx +4 -4
  97. package/src/components/field/field.test.tsx +14 -1
  98. package/src/components/field/field.tsx +2 -2
  99. package/src/components/index.ts +1 -1
  100. package/src/components/interface/declaration.test.tsx +11 -1
  101. package/src/components/interface/declaration.tsx +3 -4
  102. package/src/components/interface/method.test.tsx +14 -1
  103. package/src/components/interface/method.tsx +2 -1
  104. package/src/components/interface/property.test.tsx +13 -0
  105. package/src/components/interface/property.tsx +2 -1
  106. package/src/components/namespace/namespace-name.tsx +31 -0
  107. package/src/components/namespace/namespace.test.tsx +145 -0
  108. package/src/components/{namespace.tsx → namespace/namespace.tsx} +12 -15
  109. package/src/components/namespace.ref.test.tsx +34 -9
  110. package/src/components/record/declaration.test.tsx +11 -1
  111. package/src/components/record/declaration.tsx +3 -4
  112. package/src/components/source-file/source-file.test.tsx +1 -1
  113. package/src/components/source-file/source-file.tsx +2 -2
  114. package/src/components/source-file/using.test.tsx +1 -1
  115. package/src/components/struct/declaration.test.tsx +11 -1
  116. package/src/components/struct/declaration.tsx +3 -4
  117. package/src/components/type-parameters/type-parameter.tsx +2 -1
  118. package/src/components/type-parameters/type-parameters.test.tsx +9 -0
  119. package/src/components/var/declaration.test.tsx +16 -1
  120. package/src/components/var/declaration.tsx +2 -1
  121. package/src/name-policy.ts +3 -1
  122. package/src/symbols/factories.ts +47 -10
  123. package/src/symbols/namespace.ts +2 -2
  124. package/temp/api.json +184 -35
  125. package/dist/src/components/namespace.d.ts.map +0 -1
  126. package/dist/src/components/namespace.js.map +0 -1
  127. package/dist/src/components/namespace.test.d.ts.map +0 -1
  128. package/dist/src/components/namespace.test.js +0 -79
  129. package/dist/src/components/namespace.test.js.map +0 -1
  130. package/src/components/namespace.test.tsx +0 -52
  131. /package/dist/src/components/{namespace.test.d.ts → namespace/namespace.test.d.ts} +0 -0
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.3",
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,4 @@
1
- import { Namespace } from "#components/namespace.jsx";
1
+ import { Namespace } from "#components/namespace/namespace.jsx";
2
2
  import { SourceFile } from "#components/source-file/source-file.jsx";
3
3
  import { Output, refkey } from "@alloy-js/core";
4
4
  import { d } from "@alloy-js/core/testing";
@@ -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 */
@@ -15,7 +15,7 @@ export * from "./lexical-scope.jsx";
15
15
  export * from "./method-scope.jsx";
16
16
  export * from "./method/method.jsx";
17
17
  export * from "./Name.js";
18
- export * from "./namespace.js";
18
+ export { Namespace, type NamespaceProps } from "./namespace/namespace.jsx";
19
19
  export * from "./parameters/parameters.jsx";
20
20
  export * from "./ProjectDirectory.js";
21
21
  export * from "./property/property.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 */
@@ -0,0 +1,31 @@
1
+ import { useNamespaceContext } from "../../contexts/namespace.js";
2
+ import { NamespaceSymbol } from "../../symbols/namespace.js";
3
+
4
+ /** @internal */
5
+ export interface NamespaceNameProps {
6
+ symbol: NamespaceSymbol;
7
+
8
+ /** If it should print relative to the parent context */
9
+ relative?: boolean;
10
+ }
11
+
12
+ /** @internal */
13
+ export function NamespaceName(props: NamespaceNameProps) {
14
+ const names = [props.symbol.name];
15
+ const parent = props.relative ? useNamespaceContext()?.symbol : undefined;
16
+
17
+ let current = props.symbol.ownerSymbol;
18
+ while (current) {
19
+ if (
20
+ current === parent ||
21
+ !(current instanceof NamespaceSymbol) ||
22
+ current.isGlobal
23
+ ) {
24
+ break;
25
+ }
26
+ names.unshift(current.name);
27
+ current = current.ownerSymbol;
28
+ }
29
+
30
+ return names.join(".");
31
+ }
@@ -0,0 +1,145 @@
1
+ import { TestNamespace } from "#test/utils.jsx";
2
+ import { Output } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { expect, it } from "vitest";
5
+ import { ClassDeclaration } from "../class/declaration.jsx";
6
+ import { SourceFile } from "../source-file/source-file.jsx";
7
+ import { Namespace } from "./namespace.jsx";
8
+
9
+ it("defines multiple namespaces and source files with unique content", () => {
10
+ const tree = (
11
+ <Output>
12
+ <Namespace name="Namespace1">
13
+ <SourceFile path="Model1.cs">
14
+ <ClassDeclaration public name="Model1" />
15
+ </SourceFile>
16
+ <SourceFile path="Model2.cs">
17
+ <ClassDeclaration public name="Model2" />
18
+ </SourceFile>
19
+ </Namespace>
20
+ <Namespace name="Namespace2">
21
+ <SourceFile path="Model3.cs">
22
+ <ClassDeclaration public name="Model3" />
23
+ </SourceFile>
24
+ <SourceFile path="Model4.cs">
25
+ <ClassDeclaration public name="Model4" />
26
+ </SourceFile>
27
+ </Namespace>
28
+ </Output>
29
+ );
30
+
31
+ expect(tree).toRenderTo({
32
+ "Model1.cs": d`
33
+ namespace Namespace1;
34
+
35
+ public class Model1;
36
+ `,
37
+ "Model2.cs": d`
38
+ namespace Namespace1;
39
+
40
+ public class Model2;
41
+ `,
42
+ "Model3.cs": d`
43
+ namespace Namespace2;
44
+
45
+ public class Model3;
46
+ `,
47
+ "Model4.cs": d`
48
+ namespace Namespace2;
49
+
50
+ public class Model4;
51
+ `,
52
+ });
53
+ });
54
+
55
+ it("nest namespaces", () => {
56
+ const tree = (
57
+ <Output>
58
+ <Namespace name={["Namespace1"]}>
59
+ <Namespace name={["Namespace2"]}>
60
+ <SourceFile path="Model1.cs">
61
+ <ClassDeclaration public name="Model1" />
62
+ </SourceFile>
63
+ </Namespace>
64
+ </Namespace>
65
+ </Output>
66
+ );
67
+
68
+ expect(tree).toRenderTo(`
69
+ namespace Namespace1.Namespace2;
70
+
71
+ public class Model1;
72
+ `);
73
+ });
74
+
75
+ it("define nested namespace directly with array", () => {
76
+ const tree = (
77
+ <Output>
78
+ <Namespace name={["Namespace1", "Namespace2"]}>
79
+ <SourceFile path="Model1.cs">
80
+ <ClassDeclaration public name="Model1" />
81
+ </SourceFile>
82
+ </Namespace>
83
+ </Output>
84
+ );
85
+
86
+ expect(tree).toRenderTo(`
87
+ namespace Namespace1.Namespace2;
88
+
89
+ public class Model1;
90
+ `);
91
+ });
92
+
93
+ it("define nested namespace directly as dotted notation", () => {
94
+ const tree = (
95
+ <Output>
96
+ <Namespace name="Namespace1.Namespace2">
97
+ <SourceFile path="Model1.cs">
98
+ <ClassDeclaration public name="Model1" />
99
+ </SourceFile>
100
+ </Namespace>
101
+ </Output>
102
+ );
103
+
104
+ expect(tree).toRenderTo({
105
+ "Model1.cs": d`
106
+ namespace Namespace1.Namespace2;
107
+
108
+ public class Model1;
109
+ `,
110
+ });
111
+ });
112
+
113
+ it("uses a name policy", () => {
114
+ expect(
115
+ <TestNamespace>
116
+ <Namespace name="my-namespace" />
117
+ </TestNamespace>,
118
+ ).toRenderTo(`
119
+ namespace MyNamespace {
120
+
121
+ }
122
+ `);
123
+ });
124
+
125
+ it("define nested namespace in sourcefile", () => {
126
+ const tree = (
127
+ <Output>
128
+ <Namespace name="Base">
129
+ <SourceFile path="Model1.cs">
130
+ <Namespace name="Namespace1.Namespace2">
131
+ <ClassDeclaration public name="Model1" />
132
+ </Namespace>
133
+ </SourceFile>
134
+ </Namespace>
135
+ </Output>
136
+ );
137
+
138
+ expect(tree).toRenderTo(`
139
+ namespace Base {
140
+ namespace Namespace1.Namespace2 {
141
+ public class Model1;
142
+ }
143
+ }
144
+ `);
145
+ });
@@ -1,17 +1,21 @@
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
- import { NamespaceContext } from "../contexts/namespace.js";
4
- import { useSourceFileScope } from "../scopes/source-file.js";
5
- import { createNamespaceSymbol } from "../symbols/factories.js";
6
- import { NamespaceScope } from "./namespace-scopes.jsx";
3
+ import { NamespaceContext } from "../../contexts/namespace.js";
4
+ import { useSourceFileScope } from "../../scopes/source-file.js";
5
+ import { createNamespaceSymbol } from "../../symbols/factories.js";
6
+ import { NamespaceScope } from "../namespace-scopes.jsx";
7
+ import { NamespaceName } from "./namespace-name.jsx";
7
8
 
8
9
  export interface NamespaceProps {
9
- name: string;
10
+ name: string | Namekey | (string | Namekey)[];
11
+ refkey?: Refkey | Refkey[];
10
12
  children?: Children;
11
13
  }
12
14
 
13
15
  export function Namespace(props: NamespaceProps) {
14
- const namespaceSymbol = createNamespaceSymbol(props.name);
16
+ const namespaceSymbol = createNamespaceSymbol(props.name, {
17
+ refkeys: props.refkey,
18
+ });
15
19
  const sfScope = useSourceFileScope();
16
20
 
17
21
  if (!sfScope) {
@@ -24,7 +28,7 @@ export function Namespace(props: NamespaceProps) {
24
28
  sfScope.hasBlockNamespace = true;
25
29
  return (
26
30
  <>
27
- namespace {namespaceSymbol.name}{" "}
31
+ namespace <NamespaceName symbol={namespaceSymbol} relative />{" "}
28
32
  <Block>
29
33
  <NamespaceContext.Provider value={{ symbol: namespaceSymbol }}>
30
34
  <NamespaceScope symbol={namespaceSymbol}>
@@ -36,10 +40,3 @@ export function Namespace(props: NamespaceProps) {
36
40
  );
37
41
  }
38
42
  }
39
-
40
- /*
41
- const scope = createCSharpNamespaceScope(namespaceSymbol);
42
-
43
- return <Scope value={scope}>{props.children}</Scope>;
44
- }
45
- */
@@ -1,8 +1,7 @@
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
- import { Namespace } from "./namespace.jsx";
4
+ import { Namespace } from "./namespace/namespace.jsx";
6
5
  import { SourceFile } from "./source-file/source-file.jsx";
7
6
 
8
7
  it("references types in the same namespace", () => {
@@ -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,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(