@alloy-js/csharp 0.20.0-dev.2 → 0.20.0-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Declaration.d.ts +2 -2
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -13
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +5 -1
- package/dist/src/components/SourceFile.d.ts +8 -9
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +69 -45
- package/dist/src/components/UsingDirective.d.ts +5 -1
- package/dist/src/components/UsingDirective.d.ts.map +1 -1
- package/dist/src/components/UsingDirective.js +3 -1
- package/dist/src/components/class/declaration.d.ts +2 -2
- package/dist/src/components/class/declaration.d.ts.map +1 -1
- package/dist/src/components/class/declaration.js +19 -33
- package/dist/src/components/class/declaration.test.js +192 -193
- package/dist/src/components/constructor/constructor.d.ts.map +1 -1
- package/dist/src/components/constructor/constructor.js +11 -19
- package/dist/src/components/constructor/constructor.test.js +10 -19
- package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
- package/dist/src/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.js +54 -0
- package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
- package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.ref.test.js +120 -0
- package/dist/src/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.test.js +39 -0
- package/dist/src/components/enum/member.d.ts +7 -0
- package/dist/src/components/enum/member.d.ts.map +1 -0
- package/dist/src/components/enum/member.js +29 -0
- package/dist/src/components/enum/member.test.d.ts +2 -0
- package/dist/src/components/enum/member.test.d.ts.map +1 -0
- package/dist/src/components/enum/member.test.js +28 -0
- package/dist/src/components/field/field.d.ts.map +1 -1
- package/dist/src/components/field/field.js +9 -17
- package/dist/src/components/field/field.test.js +7 -7
- package/dist/src/components/index.d.ts +5 -2
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +5 -2
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +19 -21
- package/dist/src/components/interface/declaration.test.js +26 -35
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +7 -18
- package/dist/src/components/interface/method.test.js +38 -47
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +21 -39
- package/dist/src/components/interface/property.test.js +11 -11
- package/dist/src/components/lexical-scope.d.ts +8 -0
- package/dist/src/components/lexical-scope.d.ts.map +1 -0
- package/dist/src/components/lexical-scope.js +24 -0
- package/dist/src/components/method/method.d.ts +5 -2
- package/dist/src/components/method/method.d.ts.map +1 -1
- package/dist/src/components/method/method.js +7 -16
- package/dist/src/components/method/method.test.js +11 -11
- package/dist/src/components/method-scope.d.ts +8 -0
- package/dist/src/components/method-scope.d.ts.map +1 -0
- package/dist/src/components/method-scope.js +24 -0
- package/dist/src/components/namespace-scopes.d.ts +13 -0
- package/dist/src/components/namespace-scopes.d.ts.map +1 -0
- package/dist/src/components/namespace-scopes.js +44 -0
- package/dist/src/components/namespace.d.ts +7 -0
- package/dist/src/components/namespace.d.ts.map +1 -0
- package/dist/src/components/namespace.js +46 -0
- package/dist/src/components/namespace.ref.test.d.ts +2 -0
- package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
- package/dist/src/components/namespace.ref.test.js +181 -0
- package/dist/src/components/namespace.test.d.ts.map +1 -0
- package/dist/src/components/namespace.test.js +78 -0
- package/dist/src/components/parameters/parameters.d.ts +2 -2
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +12 -14
- package/dist/src/components/parameters/parameters.test.d.ts +2 -0
- package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.test.js +87 -0
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +21 -39
- package/dist/src/components/property/property.test.js +14 -14
- package/dist/src/components/record/declaration.d.ts +18 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +19 -13
- package/dist/src/components/record/declaration.test.js +50 -3
- package/dist/src/components/struct/declaration.d.ts.map +1 -1
- package/dist/src/components/struct/declaration.js +4 -6
- package/dist/src/components/struct/declaration.test.js +30 -39
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
- package/dist/src/components/type-parameters/type-parameter.js +7 -10
- package/dist/src/components/type-parameters/type-parameters.test.js +3 -3
- package/dist/src/components/var/declaration.d.ts.map +1 -1
- package/dist/src/components/var/declaration.js +6 -8
- package/dist/src/components/var/declaration.test.js +11 -20
- package/dist/src/contexts/global-namespace.d.ts +5 -0
- package/dist/src/contexts/global-namespace.d.ts.map +1 -0
- package/dist/src/contexts/global-namespace.js +24 -0
- package/dist/src/contexts/namespace.d.ts +8 -0
- package/dist/src/contexts/namespace.d.ts.map +1 -0
- package/dist/src/contexts/namespace.js +5 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/modifiers.d.ts +11 -0
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/scopes/class.d.ts +10 -0
- package/dist/src/scopes/class.d.ts.map +1 -0
- package/dist/src/scopes/class.js +10 -0
- package/dist/src/scopes/contexts.d.ts +9 -0
- package/dist/src/scopes/contexts.d.ts.map +1 -0
- package/dist/src/scopes/contexts.js +33 -0
- package/dist/src/scopes/csharp.d.ts +8 -0
- package/dist/src/scopes/csharp.d.ts.map +1 -0
- package/dist/src/scopes/csharp.js +11 -0
- package/dist/src/scopes/factories.d.ts +9 -0
- package/dist/src/scopes/factories.d.ts.map +1 -0
- package/dist/src/scopes/factories.js +23 -0
- package/dist/src/scopes/index.d.ts +10 -0
- package/dist/src/scopes/index.d.ts.map +1 -0
- package/dist/src/scopes/index.js +9 -0
- package/dist/src/scopes/lexical.d.ts +7 -0
- package/dist/src/scopes/lexical.d.ts.map +1 -0
- package/dist/src/scopes/lexical.js +7 -0
- package/dist/src/scopes/method.d.ts +9 -0
- package/dist/src/scopes/method.d.ts.map +1 -0
- package/dist/src/scopes/method.js +13 -0
- package/dist/src/scopes/named-type.d.ts +22 -0
- package/dist/src/scopes/named-type.d.ts.map +1 -0
- package/dist/src/scopes/named-type.js +32 -0
- package/dist/src/scopes/namespace.d.ts +11 -0
- package/dist/src/scopes/namespace.d.ts.map +1 -0
- package/dist/src/scopes/namespace.js +38 -0
- package/dist/src/scopes/source-file.d.ts +16 -0
- package/dist/src/scopes/source-file.d.ts.map +1 -0
- package/dist/src/scopes/source-file.js +43 -0
- package/dist/src/symbols/csharp.d.ts +76 -0
- package/dist/src/symbols/csharp.d.ts.map +1 -0
- package/dist/src/symbols/csharp.js +222 -0
- package/dist/src/symbols/factories.d.ts +25 -0
- package/dist/src/symbols/factories.d.ts.map +1 -0
- package/dist/src/symbols/factories.js +86 -0
- package/dist/src/symbols/index.d.ts +5 -2
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +6 -3
- package/dist/src/symbols/method.d.ts +13 -0
- package/dist/src/symbols/method.d.ts.map +1 -0
- package/dist/src/symbols/method.js +15 -0
- package/dist/src/symbols/named-type.d.ts +19 -0
- package/dist/src/symbols/named-type.d.ts.map +1 -0
- package/dist/src/symbols/named-type.js +30 -0
- package/dist/src/symbols/namespace.d.ts +22 -0
- package/dist/src/symbols/namespace.d.ts.map +1 -0
- package/dist/src/symbols/namespace.js +44 -0
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +36 -43
- package/dist/test/project-directory.test.js +12 -16
- package/dist/test/sourcefile.test.js +7 -19
- package/dist/test/using.test.js +18 -16
- package/dist/test/utils.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -4
- package/src/components/Declaration.tsx +3 -6
- package/src/components/Reference.tsx +3 -1
- package/src/components/SourceFile.tsx +68 -55
- package/src/components/UsingDirective.tsx +12 -2
- package/src/components/class/declaration.test.tsx +138 -143
- package/src/components/class/declaration.tsx +20 -33
- package/src/components/constructor/constructor.test.tsx +10 -16
- package/src/components/constructor/constructor.tsx +13 -32
- package/src/components/enum/declaration.ref.test.tsx +93 -0
- package/src/components/enum/declaration.test.tsx +34 -0
- package/src/components/enum/declaration.tsx +65 -0
- package/src/components/enum/member.test.tsx +24 -0
- package/src/components/enum/member.tsx +36 -0
- package/src/components/field/field.test.tsx +7 -7
- package/src/components/field/field.tsx +12 -22
- package/src/components/index.ts +5 -2
- package/src/components/interface/declaration.test.tsx +26 -32
- package/src/components/interface/declaration.tsx +16 -18
- package/src/components/interface/method.test.tsx +38 -44
- package/src/components/interface/method.tsx +7 -20
- package/src/components/interface/property.test.tsx +11 -11
- package/src/components/interface/property.tsx +15 -34
- package/src/components/lexical-scope.tsx +29 -0
- package/src/components/method/method.test.tsx +11 -11
- package/src/components/method/method.tsx +12 -23
- package/src/components/method-scope.tsx +27 -0
- package/src/components/namespace-scopes.tsx +44 -0
- package/src/components/namespace.ref.test.tsx +139 -0
- package/src/components/namespace.test.tsx +52 -0
- package/src/components/namespace.tsx +45 -0
- package/src/components/parameters/parameters.test.tsx +71 -0
- package/src/components/parameters/parameters.tsx +9 -21
- package/src/components/property/property.test.tsx +14 -14
- package/src/components/property/property.tsx +17 -41
- package/src/components/record/declaration.test.tsx +47 -3
- package/src/components/record/declaration.tsx +34 -11
- package/src/components/struct/declaration.test.tsx +16 -22
- package/src/components/struct/declaration.tsx +4 -6
- package/src/components/type-parameters/type-parameter.tsx +14 -11
- package/src/components/type-parameters/type-parameters.test.tsx +4 -4
- package/src/components/var/declaration.test.tsx +8 -14
- package/src/components/var/declaration.tsx +12 -6
- package/src/contexts/global-namespace.ts +29 -0
- package/src/contexts/namespace.ts +13 -0
- package/src/index.ts +1 -0
- package/src/modifiers.ts +14 -0
- package/src/scopes/class.ts +12 -0
- package/src/scopes/contexts.ts +45 -0
- package/src/scopes/csharp.ts +18 -0
- package/src/scopes/factories.ts +45 -0
- package/src/scopes/index.ts +9 -0
- package/src/scopes/lexical.ts +10 -0
- package/src/scopes/method.ts +22 -0
- package/src/scopes/named-type.ts +44 -0
- package/src/scopes/namespace.ts +59 -0
- package/src/scopes/source-file.ts +67 -0
- package/src/symbols/csharp.ts +307 -0
- package/src/symbols/factories.ts +199 -0
- package/src/symbols/index.ts +5 -2
- package/src/symbols/method.ts +26 -0
- package/src/symbols/named-type.ts +54 -0
- package/src/symbols/namespace.ts +62 -0
- package/src/symbols/reference.ts +47 -50
- package/temp/api.json +6152 -2151
- package/test/project-directory.test.tsx +12 -16
- package/test/sourcefile.test.tsx +7 -21
- package/test/using.test.tsx +18 -16
- package/test/utils.tsx +1 -1
- package/tsdoc-metadata.json +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.js +0 -85
- package/dist/src/components/Namespace.d.ts +0 -11
- package/dist/src/components/Namespace.d.ts.map +0 -1
- package/dist/src/components/Namespace.js +0 -33
- package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
- package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
- package/dist/src/symbols/csharp-output-symbol.js +0 -19
- package/dist/src/symbols/scopes.d.ts +0 -14
- package/dist/src/symbols/scopes.d.ts.map +0 -1
- package/dist/src/symbols/scopes.js +0 -31
- package/dist/test/enum.test.d.ts +0 -2
- package/dist/test/enum.test.d.ts.map +0 -1
- package/dist/test/enum.test.js +0 -178
- package/dist/test/namespace.test.d.ts.map +0 -1
- package/dist/test/namespace.test.js +0 -81
- package/src/components/EnumDeclaration.tsx +0 -99
- package/src/components/Namespace.tsx +0 -35
- package/src/symbols/csharp-output-symbol.ts +0 -22
- package/src/symbols/scopes.ts +0 -41
- package/test/enum.test.tsx +0 -149
- package/test/namespace.test.tsx +0 -55
- /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Scope } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { NamespaceContext } from "../contexts/namespace.js";
|
|
4
|
+
import { createCSharpNamespaceScope } from "../scopes/namespace.js";
|
|
5
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
6
|
+
|
|
7
|
+
export interface NamespaceScopProps {
|
|
8
|
+
symbol: NamespaceSymbol;
|
|
9
|
+
children: Children;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function NamespaceScope(props: NamespaceScopProps) {
|
|
13
|
+
const scope = createCSharpNamespaceScope(props.symbol);
|
|
14
|
+
return (
|
|
15
|
+
<NamespaceContext.Provider value={{ symbol: props.symbol }}>
|
|
16
|
+
<Scope value={scope}>{props.children}</Scope>
|
|
17
|
+
</NamespaceContext.Provider>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface NamespaceScopesProps {
|
|
22
|
+
symbol: NamespaceSymbol;
|
|
23
|
+
children: Children;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function NamespaceScopes(props: NamespaceScopesProps) {
|
|
27
|
+
function wrapWithScope(symbol: NamespaceSymbol, children: Children) {
|
|
28
|
+
const scopeChildren = (
|
|
29
|
+
<NamespaceScope symbol={symbol}>{children}</NamespaceScope>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (symbol.enclosingNamespace) {
|
|
33
|
+
return wrapWithScope(symbol.enclosingNamespace, scopeChildren);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return scopeChildren;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<NamespaceContext.Provider value={{ symbol: props.symbol }}>
|
|
41
|
+
{wrapWithScope(props.symbol, props.children)}
|
|
42
|
+
</NamespaceContext.Provider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Output, refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { ClassDeclaration } from "./class/declaration.jsx";
|
|
5
|
+
import { Namespace } from "./namespace.jsx";
|
|
6
|
+
import { SourceFile } from "./SourceFile.jsx";
|
|
7
|
+
|
|
8
|
+
it("references types in the same namespace", () => {
|
|
9
|
+
const classRef = refkey();
|
|
10
|
+
|
|
11
|
+
const tree = (
|
|
12
|
+
<Output>
|
|
13
|
+
<Namespace name="Test">
|
|
14
|
+
<SourceFile path="test.cs">
|
|
15
|
+
<ClassDeclaration name="TestClass" refkey={classRef} />
|
|
16
|
+
<hbr />
|
|
17
|
+
{classRef};
|
|
18
|
+
</SourceFile>
|
|
19
|
+
</Namespace>
|
|
20
|
+
</Output>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(tree).toRenderTo(d`
|
|
24
|
+
namespace Test;
|
|
25
|
+
|
|
26
|
+
class TestClass;
|
|
27
|
+
TestClass;
|
|
28
|
+
`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("references types in a parent namespace", () => {
|
|
32
|
+
const classRef = refkey();
|
|
33
|
+
|
|
34
|
+
const tree = (
|
|
35
|
+
<Output>
|
|
36
|
+
<Namespace name="Test">
|
|
37
|
+
<SourceFile path="test.cs">
|
|
38
|
+
<ClassDeclaration name="TestClass" refkey={classRef} />
|
|
39
|
+
<hbr />
|
|
40
|
+
<Namespace name="Nested">{classRef};</Namespace>
|
|
41
|
+
</SourceFile>
|
|
42
|
+
</Namespace>
|
|
43
|
+
</Output>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect(tree).toRenderTo(d`
|
|
47
|
+
namespace Test {
|
|
48
|
+
class TestClass;
|
|
49
|
+
namespace Nested {
|
|
50
|
+
TestClass;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("references types in a child namespace", () => {
|
|
57
|
+
const classRef = refkey();
|
|
58
|
+
|
|
59
|
+
const tree = (
|
|
60
|
+
<Output>
|
|
61
|
+
<Namespace name="Test">
|
|
62
|
+
<SourceFile path="test.cs">
|
|
63
|
+
{classRef};<hbr />
|
|
64
|
+
<Namespace name="Nested">
|
|
65
|
+
<ClassDeclaration name="TestClass" refkey={classRef} />
|
|
66
|
+
</Namespace>
|
|
67
|
+
</SourceFile>
|
|
68
|
+
</Namespace>
|
|
69
|
+
</Output>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(tree).toRenderTo(d`
|
|
73
|
+
namespace Test {
|
|
74
|
+
Nested.TestClass;
|
|
75
|
+
namespace Nested {
|
|
76
|
+
class TestClass;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("references types in a different top-level namespace declared in the same file", () => {
|
|
83
|
+
const classRef = refkey();
|
|
84
|
+
|
|
85
|
+
const tree = (
|
|
86
|
+
<Output>
|
|
87
|
+
<SourceFile path="test.cs">
|
|
88
|
+
<Namespace name="TestCode1">{classRef}</Namespace>
|
|
89
|
+
<hbr />
|
|
90
|
+
<Namespace name="TestCode2">
|
|
91
|
+
<ClassDeclaration name="TestClass" refkey={classRef} />
|
|
92
|
+
</Namespace>
|
|
93
|
+
</SourceFile>
|
|
94
|
+
</Output>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
expect(tree).toRenderTo(d`
|
|
98
|
+
using TestCode2;
|
|
99
|
+
|
|
100
|
+
namespace TestCode1 {
|
|
101
|
+
TestClass
|
|
102
|
+
}
|
|
103
|
+
namespace TestCode2 {
|
|
104
|
+
class TestClass;
|
|
105
|
+
}
|
|
106
|
+
`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("references types in a different top-level namespace declared in a different file", () => {
|
|
110
|
+
const classRef = refkey();
|
|
111
|
+
|
|
112
|
+
const tree = (
|
|
113
|
+
<Output>
|
|
114
|
+
<SourceFile path="test.cs">
|
|
115
|
+
<Namespace name="TestCode1">{classRef};</Namespace>
|
|
116
|
+
</SourceFile>
|
|
117
|
+
<SourceFile path="other.cs">
|
|
118
|
+
<Namespace name="TestCode2">
|
|
119
|
+
<ClassDeclaration name="TestClass" refkey={classRef} />
|
|
120
|
+
</Namespace>
|
|
121
|
+
</SourceFile>
|
|
122
|
+
</Output>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(tree).toRenderTo({
|
|
126
|
+
"test.cs": d`
|
|
127
|
+
using TestCode2;
|
|
128
|
+
|
|
129
|
+
namespace TestCode1 {
|
|
130
|
+
TestClass;
|
|
131
|
+
}
|
|
132
|
+
`,
|
|
133
|
+
"other.cs": d`
|
|
134
|
+
namespace TestCode2 {
|
|
135
|
+
class TestClass;
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Output } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { ClassDeclaration } from "./class/declaration.jsx";
|
|
5
|
+
import { Namespace } from "./namespace.jsx";
|
|
6
|
+
import { SourceFile } from "./SourceFile.jsx";
|
|
7
|
+
|
|
8
|
+
it("defines multiple namespaces and source files with unique content", () => {
|
|
9
|
+
const tree = (
|
|
10
|
+
<Output>
|
|
11
|
+
<Namespace name="Namespace1">
|
|
12
|
+
<SourceFile path="Model1.cs">
|
|
13
|
+
<ClassDeclaration public name="Model1" />
|
|
14
|
+
</SourceFile>
|
|
15
|
+
<SourceFile path="Model2.cs">
|
|
16
|
+
<ClassDeclaration public name="Model2" />
|
|
17
|
+
</SourceFile>
|
|
18
|
+
</Namespace>
|
|
19
|
+
<Namespace name="Namespace2">
|
|
20
|
+
<SourceFile path="Model3.cs">
|
|
21
|
+
<ClassDeclaration public name="Model3" />
|
|
22
|
+
</SourceFile>
|
|
23
|
+
<SourceFile path="Model4.cs">
|
|
24
|
+
<ClassDeclaration public name="Model4" />
|
|
25
|
+
</SourceFile>
|
|
26
|
+
</Namespace>
|
|
27
|
+
</Output>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
expect(tree).toRenderTo({
|
|
31
|
+
"Model1.cs": d`
|
|
32
|
+
namespace Namespace1;
|
|
33
|
+
|
|
34
|
+
public class Model1;
|
|
35
|
+
`,
|
|
36
|
+
"Model2.cs": d`
|
|
37
|
+
namespace Namespace1;
|
|
38
|
+
|
|
39
|
+
public class Model2;
|
|
40
|
+
`,
|
|
41
|
+
"Model3.cs": d`
|
|
42
|
+
namespace Namespace2;
|
|
43
|
+
|
|
44
|
+
public class Model3;
|
|
45
|
+
`,
|
|
46
|
+
"Model4.cs": d`
|
|
47
|
+
namespace Namespace2;
|
|
48
|
+
|
|
49
|
+
public class Model4;
|
|
50
|
+
`,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Block } from "@alloy-js/core";
|
|
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";
|
|
7
|
+
|
|
8
|
+
export interface NamespaceProps {
|
|
9
|
+
name: string;
|
|
10
|
+
children?: Children;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Namespace(props: NamespaceProps) {
|
|
14
|
+
const namespaceSymbol = createNamespaceSymbol(props.name);
|
|
15
|
+
const sfScope = useSourceFileScope();
|
|
16
|
+
|
|
17
|
+
if (!sfScope) {
|
|
18
|
+
return (
|
|
19
|
+
<NamespaceContext.Provider value={{ symbol: namespaceSymbol }}>
|
|
20
|
+
{props.children}
|
|
21
|
+
</NamespaceContext.Provider>
|
|
22
|
+
);
|
|
23
|
+
} else {
|
|
24
|
+
sfScope.hasBlockNamespace = true;
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
namespace {namespaceSymbol.name}{" "}
|
|
28
|
+
<Block>
|
|
29
|
+
<NamespaceContext.Provider value={{ symbol: namespaceSymbol }}>
|
|
30
|
+
<NamespaceScope symbol={namespaceSymbol}>
|
|
31
|
+
{props.children}
|
|
32
|
+
</NamespaceScope>
|
|
33
|
+
</NamespaceContext.Provider>
|
|
34
|
+
</Block>
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
const scope = createCSharpNamespaceScope(namespaceSymbol);
|
|
42
|
+
|
|
43
|
+
return <Scope value={scope}>{props.children}</Scope>;
|
|
44
|
+
}
|
|
45
|
+
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ClassDeclaration } from "#components/class/declaration.jsx";
|
|
2
|
+
import { Method } from "#components/method/method.jsx";
|
|
3
|
+
import { List, memberRefkey, namekey } from "@alloy-js/core";
|
|
4
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import { TestNamespace } from "../../../test/utils.jsx";
|
|
7
|
+
|
|
8
|
+
const Wrapper = (props: { children: Children }) => (
|
|
9
|
+
<TestNamespace>
|
|
10
|
+
<ClassDeclaration public name="TestClass">
|
|
11
|
+
{props.children}
|
|
12
|
+
</ClassDeclaration>
|
|
13
|
+
</TestNamespace>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
it("can be referenced", () => {
|
|
17
|
+
const param1Key = namekey("param1");
|
|
18
|
+
const param2Key = namekey("param2");
|
|
19
|
+
expect(
|
|
20
|
+
<Wrapper>
|
|
21
|
+
<Method
|
|
22
|
+
name="MethodOne"
|
|
23
|
+
parameters={[
|
|
24
|
+
{ name: param1Key, type: "T1" },
|
|
25
|
+
{ name: param2Key, type: "T2" },
|
|
26
|
+
]}
|
|
27
|
+
/>
|
|
28
|
+
</Wrapper>,
|
|
29
|
+
).toRenderTo(`
|
|
30
|
+
public class TestClass
|
|
31
|
+
{
|
|
32
|
+
void MethodOne(T1 param1, T2 param2) {}
|
|
33
|
+
}
|
|
34
|
+
`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("members can be referenced", () => {
|
|
38
|
+
const classKey = namekey("TestType");
|
|
39
|
+
const methodKey = namekey("TestMethod");
|
|
40
|
+
const param1Key = namekey("param1");
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
<TestNamespace>
|
|
44
|
+
<List>
|
|
45
|
+
<ClassDeclaration name={classKey}>
|
|
46
|
+
<Method name={methodKey} />
|
|
47
|
+
</ClassDeclaration>
|
|
48
|
+
<ClassDeclaration name="Test">
|
|
49
|
+
<Method
|
|
50
|
+
name="Test"
|
|
51
|
+
parameters={[{ name: param1Key, type: classKey }]}
|
|
52
|
+
>
|
|
53
|
+
return {memberRefkey(param1Key, methodKey)}();
|
|
54
|
+
</Method>
|
|
55
|
+
</ClassDeclaration>
|
|
56
|
+
</List>
|
|
57
|
+
</TestNamespace>,
|
|
58
|
+
).toRenderTo(`
|
|
59
|
+
class TestType
|
|
60
|
+
{
|
|
61
|
+
void TestMethod() {}
|
|
62
|
+
}
|
|
63
|
+
class Test
|
|
64
|
+
{
|
|
65
|
+
void Test(TestType param1)
|
|
66
|
+
{
|
|
67
|
+
return param1.TestMethod();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Children,
|
|
3
3
|
code,
|
|
4
|
+
createSymbolSlot,
|
|
4
5
|
Declaration,
|
|
5
6
|
For,
|
|
6
7
|
Indent,
|
|
8
|
+
Namekey,
|
|
7
9
|
OutputSymbol,
|
|
8
|
-
refkey,
|
|
9
10
|
Refkey,
|
|
10
11
|
} from "@alloy-js/core";
|
|
11
|
-
import {
|
|
12
|
-
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
13
|
-
import { useCSharpScope } from "../../symbols/scopes.js";
|
|
12
|
+
import { createParameterSymbol } from "../../symbols/factories.js";
|
|
14
13
|
import { Name } from "../Name.jsx";
|
|
15
14
|
|
|
16
15
|
export interface ParameterProps {
|
|
17
|
-
name: string;
|
|
16
|
+
name: string | Namekey;
|
|
18
17
|
type: Children;
|
|
19
18
|
/** If the parmaeter is optional(without default value) */
|
|
20
19
|
optional?: boolean;
|
|
@@ -26,27 +25,16 @@ export interface ParameterProps {
|
|
|
26
25
|
|
|
27
26
|
/** Define a parameter to be used in class or interface method. */
|
|
28
27
|
export function Parameter(props: ParameterProps) {
|
|
29
|
-
const
|
|
30
|
-
const scope = useCSharpScope();
|
|
31
|
-
if (
|
|
32
|
-
scope.kind !== "member" ||
|
|
33
|
-
(scope.name !== "constructor-decl" &&
|
|
34
|
-
scope.name !== "method-decl" &&
|
|
35
|
-
scope.name !== "class-decl")
|
|
36
|
-
) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
"can't define a parameter outside of a constructor-decl or method-decl scope",
|
|
39
|
-
);
|
|
40
|
-
}
|
|
28
|
+
const TypeSlot = createSymbolSlot();
|
|
41
29
|
|
|
42
|
-
const memberSymbol =
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
const memberSymbol = createParameterSymbol(props.name, {
|
|
31
|
+
refkeys: props.refkey,
|
|
32
|
+
type: TypeSlot.firstSymbol,
|
|
45
33
|
});
|
|
46
34
|
|
|
47
35
|
return (
|
|
48
36
|
<Declaration symbol={memberSymbol}>
|
|
49
|
-
{props.type}
|
|
37
|
+
<TypeSlot>{props.type}</TypeSlot>
|
|
50
38
|
{props.optional ? "?" : ""} <Name />
|
|
51
39
|
{props.default ? code` = ${props.default}` : ""}
|
|
52
40
|
</Declaration>
|
|
@@ -30,7 +30,7 @@ describe("modifiers", () => {
|
|
|
30
30
|
).toRenderTo(`
|
|
31
31
|
public class TestClass
|
|
32
32
|
{
|
|
33
|
-
|
|
33
|
+
${accessModifier} string TestProp { get; }
|
|
34
34
|
}
|
|
35
35
|
`);
|
|
36
36
|
},
|
|
@@ -61,7 +61,7 @@ describe("modifiers", () => {
|
|
|
61
61
|
).toRenderTo(`
|
|
62
62
|
public class TestClass
|
|
63
63
|
{
|
|
64
|
-
|
|
64
|
+
${methodModifier} string TestProp { get; }
|
|
65
65
|
}
|
|
66
66
|
`);
|
|
67
67
|
});
|
|
@@ -75,7 +75,7 @@ describe("modifiers", () => {
|
|
|
75
75
|
).toRenderTo(`
|
|
76
76
|
public class TestClass
|
|
77
77
|
{
|
|
78
|
-
|
|
78
|
+
public new string TestProp { get; }
|
|
79
79
|
}
|
|
80
80
|
`);
|
|
81
81
|
});
|
|
@@ -89,7 +89,7 @@ it("applies PascalCase naming policy", () => {
|
|
|
89
89
|
).toRenderTo(`
|
|
90
90
|
public class TestClass
|
|
91
91
|
{
|
|
92
|
-
|
|
92
|
+
string TestProp { get; }
|
|
93
93
|
}
|
|
94
94
|
`);
|
|
95
95
|
});
|
|
@@ -102,7 +102,7 @@ it("has getter only", () => {
|
|
|
102
102
|
).toRenderTo(`
|
|
103
103
|
public class TestClass
|
|
104
104
|
{
|
|
105
|
-
|
|
105
|
+
string TestProp { get; }
|
|
106
106
|
}
|
|
107
107
|
`);
|
|
108
108
|
});
|
|
@@ -115,7 +115,7 @@ it("has setter only", () => {
|
|
|
115
115
|
).toRenderTo(`
|
|
116
116
|
public class TestClass
|
|
117
117
|
{
|
|
118
|
-
|
|
118
|
+
string TestProp { set; }
|
|
119
119
|
}
|
|
120
120
|
`);
|
|
121
121
|
});
|
|
@@ -128,7 +128,7 @@ it("has getter and setter", () => {
|
|
|
128
128
|
).toRenderTo(`
|
|
129
129
|
public class TestClass
|
|
130
130
|
{
|
|
131
|
-
|
|
131
|
+
string TestProp { get; set; }
|
|
132
132
|
}
|
|
133
133
|
`);
|
|
134
134
|
});
|
|
@@ -141,7 +141,7 @@ it("has getter and init", () => {
|
|
|
141
141
|
).toRenderTo(`
|
|
142
142
|
public class TestClass
|
|
143
143
|
{
|
|
144
|
-
|
|
144
|
+
string TestProp { get; init; }
|
|
145
145
|
}
|
|
146
146
|
`);
|
|
147
147
|
});
|
|
@@ -156,8 +156,8 @@ it("specify doc comment", () => {
|
|
|
156
156
|
).toRenderTo(`
|
|
157
157
|
class Test
|
|
158
158
|
{
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
/// This is a test
|
|
160
|
+
string Method { get; set; }
|
|
161
161
|
}
|
|
162
162
|
`);
|
|
163
163
|
});
|
|
@@ -170,7 +170,7 @@ it("specify nullable property", () => {
|
|
|
170
170
|
).toRenderTo(`
|
|
171
171
|
public class TestClass
|
|
172
172
|
{
|
|
173
|
-
|
|
173
|
+
string? TestProp { get; set; }
|
|
174
174
|
}
|
|
175
175
|
`);
|
|
176
176
|
});
|
|
@@ -183,7 +183,7 @@ it("specify initializer", () => {
|
|
|
183
183
|
).toRenderTo(`
|
|
184
184
|
public class TestClass
|
|
185
185
|
{
|
|
186
|
-
|
|
186
|
+
string TestProp { get; set; } = "abc";
|
|
187
187
|
}
|
|
188
188
|
`);
|
|
189
189
|
});
|
|
@@ -202,8 +202,8 @@ it("specify attributes", () => {
|
|
|
202
202
|
).toRenderTo(`
|
|
203
203
|
public class TestClass
|
|
204
204
|
{
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
[Test]
|
|
206
|
+
int Test { get; set; }
|
|
207
207
|
}
|
|
208
208
|
`);
|
|
209
209
|
});
|
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
code,
|
|
5
5
|
List,
|
|
6
6
|
MemberDeclaration,
|
|
7
|
-
|
|
7
|
+
MemberName,
|
|
8
8
|
Refkey,
|
|
9
|
-
Scope,
|
|
10
9
|
} from "@alloy-js/core";
|
|
11
10
|
import {
|
|
12
11
|
AccessModifiers,
|
|
@@ -14,9 +13,7 @@ import {
|
|
|
14
13
|
getAccessModifier,
|
|
15
14
|
makeModifiers,
|
|
16
15
|
} from "../../modifiers.js";
|
|
17
|
-
import {
|
|
18
|
-
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
19
|
-
import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
16
|
+
import { createPropertySymbol } from "../../symbols/factories.js";
|
|
20
17
|
import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
|
|
21
18
|
import { DocWhen } from "../doc/comment.jsx";
|
|
22
19
|
|
|
@@ -118,27 +115,8 @@ export interface PropertyProps extends AccessModifiers, PropertyModifiers {
|
|
|
118
115
|
* ```
|
|
119
116
|
*/
|
|
120
117
|
export function Property(props: PropertyProps) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
scope.kind !== "member" ||
|
|
125
|
-
(scope.name !== "class-decl" &&
|
|
126
|
-
scope.name !== "record-decl" &&
|
|
127
|
-
scope.name !== "struct-decl")
|
|
128
|
-
) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
"can't define an interface method outside of an interface scope",
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const propertySymbol = new CSharpOutputSymbol(name, {
|
|
135
|
-
scope,
|
|
136
|
-
refkeys: props.refkey ?? refkey(props.name),
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// scope for property declaration
|
|
140
|
-
const propertyScope = new CSharpMemberScope("property-decl", {
|
|
141
|
-
owner: propertySymbol,
|
|
118
|
+
const propertySymbol = createPropertySymbol(props.name, {
|
|
119
|
+
refkeys: props.refkey,
|
|
142
120
|
});
|
|
143
121
|
|
|
144
122
|
const modifiers = computeModifiersPrefix([
|
|
@@ -154,21 +132,19 @@ export function Property(props: PropertyProps) {
|
|
|
154
132
|
// note that scope wraps the method decl so that the params get the correct scope
|
|
155
133
|
return (
|
|
156
134
|
<MemberDeclaration symbol={propertySymbol}>
|
|
157
|
-
<
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
<
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
{props.initializer && code` = ${props.initializer};`}
|
|
171
|
-
</Scope>
|
|
135
|
+
<DocWhen doc={props.doc} />
|
|
136
|
+
<AttributeList attributes={props.attributes} endline />
|
|
137
|
+
{modifiers}
|
|
138
|
+
{props.type}
|
|
139
|
+
{props.nullable && "?"} <MemberName />{" "}
|
|
140
|
+
<Block newline inline>
|
|
141
|
+
<List joiner=" ">
|
|
142
|
+
{props.get && "get;"}
|
|
143
|
+
{props.set && "set;"}
|
|
144
|
+
{props.init && "init;"}
|
|
145
|
+
</List>
|
|
146
|
+
</Block>
|
|
147
|
+
{props.initializer && code` = ${props.initializer};`}
|
|
172
148
|
</MemberDeclaration>
|
|
173
149
|
);
|
|
174
150
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { Children, code, refkey } from "@alloy-js/core";
|
|
1
2
|
import { describe, expect, it } from "vitest";
|
|
2
3
|
import { TestNamespace } from "../../../test/utils.jsx";
|
|
3
4
|
import { Property } from "../property/property.jsx";
|
|
4
5
|
import { RecordDeclaration } from "./declaration.jsx";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
// Remove Wrapper that added <SourceFile> because TestNamespace already does
|
|
8
|
+
function Wrapper({ children }: { children: Children }) {
|
|
9
|
+
return <TestNamespace>{children}</TestNamespace>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
it("declares record with no members", () => {
|
|
7
13
|
expect(
|
|
8
14
|
<TestNamespace>
|
|
9
15
|
<RecordDeclaration name="TestRecord" />
|
|
@@ -56,7 +62,7 @@ it("specify doc comment", () => {
|
|
|
56
62
|
`);
|
|
57
63
|
});
|
|
58
64
|
|
|
59
|
-
it("specify
|
|
65
|
+
it("specify record property inside", () => {
|
|
60
66
|
expect(
|
|
61
67
|
<TestNamespace>
|
|
62
68
|
<RecordDeclaration name="TestRecord" doc="This is a test">
|
|
@@ -67,7 +73,45 @@ it("specify class property inside", () => {
|
|
|
67
73
|
/// This is a test
|
|
68
74
|
record TestRecord
|
|
69
75
|
{
|
|
70
|
-
|
|
76
|
+
string Prop { get; set; }
|
|
71
77
|
}
|
|
72
78
|
`);
|
|
73
79
|
});
|
|
80
|
+
|
|
81
|
+
describe("constructor", () => {
|
|
82
|
+
it("declares primary constructor with args", () => {
|
|
83
|
+
const paramNameRefkey = refkey();
|
|
84
|
+
const paramSizeRefkey = refkey();
|
|
85
|
+
|
|
86
|
+
const ctorParams = [
|
|
87
|
+
{
|
|
88
|
+
name: "name",
|
|
89
|
+
type: "string",
|
|
90
|
+
refkey: paramNameRefkey,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "size",
|
|
94
|
+
type: "int",
|
|
95
|
+
refkey: paramSizeRefkey,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
expect(
|
|
100
|
+
<Wrapper>
|
|
101
|
+
<RecordDeclaration public name="Test" primaryConstructor={ctorParams}>
|
|
102
|
+
<Property
|
|
103
|
+
name="PrettyName"
|
|
104
|
+
type="string"
|
|
105
|
+
get
|
|
106
|
+
initializer={code`$"{${paramNameRefkey}} {${paramSizeRefkey}}"`}
|
|
107
|
+
/>
|
|
108
|
+
</RecordDeclaration>
|
|
109
|
+
</Wrapper>,
|
|
110
|
+
).toRenderTo(`
|
|
111
|
+
public record Test(string name, int size)
|
|
112
|
+
{
|
|
113
|
+
string PrettyName { get; } = $"{name} {size}";
|
|
114
|
+
}
|
|
115
|
+
`);
|
|
116
|
+
});
|
|
117
|
+
});
|