@alloy-js/csharp 0.20.0-dev.3 → 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 +18 -32
- package/dist/src/components/class/declaration.test.js +171 -193
- package/dist/src/components/constructor/constructor.d.ts.map +1 -1
- package/dist/src/components/constructor/constructor.js +11 -16
- 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 -14
- 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 -15
- 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 -36
- 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 -13
- 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 -11
- 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 -36
- package/dist/src/components/property/property.test.js +14 -14
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +8 -12
- package/dist/src/components/record/declaration.test.js +6 -13
- 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 +6 -2
- 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 +120 -143
- package/src/components/class/declaration.tsx +19 -32
- package/src/components/constructor/constructor.test.tsx +10 -16
- package/src/components/constructor/constructor.tsx +13 -27
- 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 -14
- 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 -19
- package/src/components/interface/property.test.tsx +11 -11
- package/src/components/interface/property.tsx +15 -33
- package/src/components/lexical-scope.tsx +29 -0
- package/src/components/method/method.test.tsx +11 -11
- package/src/components/method/method.tsx +12 -18
- 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 -16
- package/src/components/property/property.test.tsx +14 -14
- package/src/components/property/property.tsx +17 -38
- package/src/components/record/declaration.test.tsx +5 -12
- package/src/components/record/declaration.tsx +10 -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 +6251 -2454
- 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/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.js +0 -82
- 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 -20
- package/dist/src/symbols/scopes.d.ts.map +0 -1
- package/dist/src/symbols/scopes.js +0 -42
- 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 -98
- package/src/components/Namespace.tsx +0 -35
- package/src/symbols/csharp-output-symbol.ts +0 -22
- package/src/symbols/scopes.ts +0 -61
- 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
|
@@ -2,7 +2,6 @@ import { refkey } from "@alloy-js/core";
|
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.jsx";
|
|
4
4
|
import { ClassDeclaration } from "../class/declaration.jsx";
|
|
5
|
-
import { SourceFile } from "../SourceFile.jsx";
|
|
6
5
|
import { Constructor } from "./constructor.jsx";
|
|
7
6
|
|
|
8
7
|
it("reference constructor parameters in body", () => {
|
|
@@ -16,25 +15,20 @@ it("reference constructor parameters in body", () => {
|
|
|
16
15
|
|
|
17
16
|
expect(
|
|
18
17
|
<TestNamespace>
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</ClassDeclaration>
|
|
26
|
-
</SourceFile>
|
|
18
|
+
<ClassDeclaration public name="TestClass">
|
|
19
|
+
<Constructor public parameters={ctorParams}>
|
|
20
|
+
{paramNameRefkey};<hbr />
|
|
21
|
+
{paramSizeRefkey};
|
|
22
|
+
</Constructor>
|
|
23
|
+
</ClassDeclaration>
|
|
27
24
|
</TestNamespace>,
|
|
28
25
|
).toRenderTo(`
|
|
29
|
-
|
|
26
|
+
public class TestClass
|
|
30
27
|
{
|
|
31
|
-
public
|
|
28
|
+
public TestClass(string name, int size)
|
|
32
29
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
name;
|
|
36
|
-
size;
|
|
37
|
-
}
|
|
30
|
+
name;
|
|
31
|
+
size;
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
34
|
`);
|
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Declaration,
|
|
4
|
-
Name,
|
|
5
|
-
Refkey,
|
|
6
|
-
refkey,
|
|
7
|
-
Scope,
|
|
8
|
-
} from "@alloy-js/core";
|
|
1
|
+
import { MethodScope } from "#components/method-scope.jsx";
|
|
2
|
+
import { Block, MemberDeclaration, MemberName, Refkey } from "@alloy-js/core";
|
|
9
3
|
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
10
4
|
import {
|
|
11
5
|
AccessModifiers,
|
|
12
6
|
computeModifiersPrefix,
|
|
13
7
|
getAccessModifier,
|
|
14
8
|
} from "../../modifiers.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
CSharpMemberScope,
|
|
19
|
-
useCSharpMemberScope,
|
|
20
|
-
} from "../../symbols/scopes.js";
|
|
9
|
+
import { useNamedTypeScope } from "../../scopes/contexts.js";
|
|
10
|
+
import { MethodSymbol } from "../../symbols/method.js";
|
|
21
11
|
import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
|
|
22
12
|
|
|
23
13
|
/**
|
|
@@ -35,28 +25,24 @@ export interface ConstructorProps extends AccessModifiers {
|
|
|
35
25
|
}
|
|
36
26
|
|
|
37
27
|
export function Constructor(props: ConstructorProps) {
|
|
38
|
-
const scope =
|
|
28
|
+
const scope = useNamedTypeScope();
|
|
39
29
|
|
|
40
|
-
const name =
|
|
41
|
-
const ctorSymbol = new CSharpOutputSymbol(name, {
|
|
42
|
-
scope,
|
|
43
|
-
refkeys: props.refkey ?? refkey(name),
|
|
44
|
-
});
|
|
30
|
+
const name = scope.ownerSymbol.name;
|
|
45
31
|
|
|
46
|
-
const
|
|
47
|
-
|
|
32
|
+
const ctorSymbol = new MethodSymbol(name, scope.members, "constructor", {
|
|
33
|
+
refkeys: props.refkey,
|
|
48
34
|
});
|
|
49
35
|
|
|
50
36
|
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
51
37
|
|
|
52
38
|
return (
|
|
53
|
-
<
|
|
54
|
-
<
|
|
39
|
+
<MemberDeclaration symbol={ctorSymbol}>
|
|
40
|
+
<MethodScope>
|
|
55
41
|
{modifiers}
|
|
56
|
-
<
|
|
42
|
+
<MemberName />
|
|
57
43
|
<Parameters parameters={props.parameters} />
|
|
58
44
|
<Block newline>{props.children}</Block>
|
|
59
|
-
</
|
|
60
|
-
</
|
|
45
|
+
</MethodScope>
|
|
46
|
+
</MemberDeclaration>
|
|
61
47
|
);
|
|
62
48
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Namespace } from "#components/namespace.jsx";
|
|
2
|
+
import { SourceFile } from "#components/SourceFile.jsx";
|
|
3
|
+
import { Output, refkey } from "@alloy-js/core";
|
|
4
|
+
import { d } from "@alloy-js/core/testing";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import { EnumDeclaration } from "./declaration.jsx";
|
|
7
|
+
import { EnumMember } from "./member.jsx";
|
|
8
|
+
|
|
9
|
+
it("can reference things by refkey", () => {
|
|
10
|
+
const enumRK = refkey();
|
|
11
|
+
const twoRK = refkey();
|
|
12
|
+
|
|
13
|
+
const tree = (
|
|
14
|
+
<Output>
|
|
15
|
+
<Namespace name="TestCode">
|
|
16
|
+
<SourceFile path="Test.cs">
|
|
17
|
+
<EnumDeclaration public name="TestEnum" refkey={enumRK}>
|
|
18
|
+
<EnumMember name="One" />,<hbr />
|
|
19
|
+
<EnumMember name="Two" refkey={twoRK} />
|
|
20
|
+
</EnumDeclaration>
|
|
21
|
+
<hbr />
|
|
22
|
+
{enumRK};<hbr />
|
|
23
|
+
{twoRK};
|
|
24
|
+
</SourceFile>
|
|
25
|
+
</Namespace>
|
|
26
|
+
</Output>
|
|
27
|
+
);
|
|
28
|
+
expect(tree).toRenderTo(d`
|
|
29
|
+
namespace TestCode;
|
|
30
|
+
|
|
31
|
+
public enum TestEnum
|
|
32
|
+
{
|
|
33
|
+
One,
|
|
34
|
+
Two
|
|
35
|
+
}
|
|
36
|
+
TestEnum;
|
|
37
|
+
TestEnum.Two;
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("can reference things by refkey across files", () => {
|
|
42
|
+
const enumRK = refkey();
|
|
43
|
+
const barRK = refkey();
|
|
44
|
+
|
|
45
|
+
const tree = (
|
|
46
|
+
<Output>
|
|
47
|
+
<Namespace name="TestCode">
|
|
48
|
+
<SourceFile path="Test.cs">
|
|
49
|
+
<EnumDeclaration public name="TestEnum">
|
|
50
|
+
<EnumMember name="One" />,<hbr />
|
|
51
|
+
<EnumMember name="Two" />
|
|
52
|
+
</EnumDeclaration>
|
|
53
|
+
<hbr />
|
|
54
|
+
{enumRK};<hbr />
|
|
55
|
+
{barRK};
|
|
56
|
+
</SourceFile>
|
|
57
|
+
<SourceFile path="Other.cs">
|
|
58
|
+
<EnumDeclaration public name="OtherEnum" refkey={enumRK}>
|
|
59
|
+
<EnumMember name="Foo" />,<hbr />
|
|
60
|
+
<EnumMember name="Bar" refkey={barRK} />
|
|
61
|
+
</EnumDeclaration>
|
|
62
|
+
<hbr />
|
|
63
|
+
{enumRK};<hbr />
|
|
64
|
+
{barRK};
|
|
65
|
+
</SourceFile>
|
|
66
|
+
</Namespace>
|
|
67
|
+
</Output>
|
|
68
|
+
);
|
|
69
|
+
expect(tree).toRenderTo({
|
|
70
|
+
"Test.cs": d`
|
|
71
|
+
namespace TestCode;
|
|
72
|
+
|
|
73
|
+
public enum TestEnum
|
|
74
|
+
{
|
|
75
|
+
One,
|
|
76
|
+
Two
|
|
77
|
+
}
|
|
78
|
+
OtherEnum;
|
|
79
|
+
OtherEnum.Bar;
|
|
80
|
+
`,
|
|
81
|
+
"Other.cs": d`
|
|
82
|
+
namespace TestCode;
|
|
83
|
+
|
|
84
|
+
public enum OtherEnum
|
|
85
|
+
{
|
|
86
|
+
Foo,
|
|
87
|
+
Bar
|
|
88
|
+
}
|
|
89
|
+
OtherEnum;
|
|
90
|
+
OtherEnum.Bar;
|
|
91
|
+
`,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { toSourceText } from "#test/utils.jsx";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { EnumDeclaration } from "./declaration.jsx";
|
|
5
|
+
import { EnumMember } from "./member.jsx";
|
|
6
|
+
|
|
7
|
+
it("declares enum with no members", () => {
|
|
8
|
+
const res = toSourceText(<EnumDeclaration public name="TestEnum" />);
|
|
9
|
+
|
|
10
|
+
expect(res).toBe(d`
|
|
11
|
+
namespace TestCode;
|
|
12
|
+
|
|
13
|
+
public enum TestEnum;
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("applies naming policy to enum and members", () => {
|
|
18
|
+
const res = toSourceText(
|
|
19
|
+
<EnumDeclaration public name="testEnum">
|
|
20
|
+
<EnumMember name="one" />,<hbr />
|
|
21
|
+
<EnumMember name="two" />
|
|
22
|
+
</EnumDeclaration>,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(res).toBe(d`
|
|
26
|
+
namespace TestCode;
|
|
27
|
+
|
|
28
|
+
public enum TestEnum
|
|
29
|
+
{
|
|
30
|
+
One,
|
|
31
|
+
Two
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
Children,
|
|
4
|
+
Declaration,
|
|
5
|
+
MemberScope,
|
|
6
|
+
Refkey,
|
|
7
|
+
} from "@alloy-js/core";
|
|
8
|
+
import {
|
|
9
|
+
AccessModifiers,
|
|
10
|
+
computeModifiersPrefix,
|
|
11
|
+
getAccessModifier,
|
|
12
|
+
} from "../../modifiers.js";
|
|
13
|
+
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
14
|
+
import { createNamedTypeScope } from "../../scopes/factories.js";
|
|
15
|
+
import { createNamedTypeSymbol } from "../../symbols/factories.js";
|
|
16
|
+
import { Name } from "../Name.jsx";
|
|
17
|
+
|
|
18
|
+
// properties for creating an enum
|
|
19
|
+
export interface EnumDeclarationProps extends AccessModifiers {
|
|
20
|
+
name: string;
|
|
21
|
+
refkey?: Refkey | Refkey[];
|
|
22
|
+
children?: Children;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A C# enum declaration
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <EnumDeclaration public name="Color">
|
|
30
|
+
* <EnumMember name="Red" />
|
|
31
|
+
* <EnumMember name="Green" />
|
|
32
|
+
* <EnumMember name="Blue" />
|
|
33
|
+
* </EnumDeclaration>
|
|
34
|
+
* ```
|
|
35
|
+
* This will produce:
|
|
36
|
+
* ```csharp
|
|
37
|
+
* public enum Color
|
|
38
|
+
* {
|
|
39
|
+
* Red,
|
|
40
|
+
* Green,
|
|
41
|
+
* Blue
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function EnumDeclaration(props: EnumDeclarationProps) {
|
|
46
|
+
const name = useCSharpNamePolicy().getName(props.name!, "enum");
|
|
47
|
+
const symbol = createNamedTypeSymbol(name, "enum", {
|
|
48
|
+
refkeys: props.refkey,
|
|
49
|
+
});
|
|
50
|
+
const scope = createNamedTypeScope(symbol);
|
|
51
|
+
|
|
52
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Declaration symbol={symbol}>
|
|
56
|
+
{modifiers}enum <Name />
|
|
57
|
+
{!props.children && ";"}
|
|
58
|
+
{props.children && (
|
|
59
|
+
<MemberScope value={scope}>
|
|
60
|
+
<Block newline>{props.children}</Block>
|
|
61
|
+
</MemberScope>
|
|
62
|
+
)}
|
|
63
|
+
</Declaration>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { toSourceText } from "#test/utils.jsx";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { EnumDeclaration } from "./declaration.jsx";
|
|
5
|
+
import { EnumMember } from "./member.jsx";
|
|
6
|
+
|
|
7
|
+
it("declares enum with members", () => {
|
|
8
|
+
const res = toSourceText(
|
|
9
|
+
<EnumDeclaration public name="TestEnum">
|
|
10
|
+
<EnumMember name="One" />,<hbr />
|
|
11
|
+
<EnumMember name="Two" />
|
|
12
|
+
</EnumDeclaration>,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(res).toBe(d`
|
|
16
|
+
namespace TestCode;
|
|
17
|
+
|
|
18
|
+
public enum TestEnum
|
|
19
|
+
{
|
|
20
|
+
One,
|
|
21
|
+
Two
|
|
22
|
+
}
|
|
23
|
+
`);
|
|
24
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MemberDeclaration, MemberName, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
3
|
+
import { useNamedTypeScope } from "../../scopes/contexts.js";
|
|
4
|
+
import { CSharpSymbol } from "../../symbols/csharp.js";
|
|
5
|
+
|
|
6
|
+
// properties for creating a C# enum member
|
|
7
|
+
export interface EnumMemberProps {
|
|
8
|
+
name: string;
|
|
9
|
+
refkey?: Refkey;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// a member within a C# enum
|
|
13
|
+
export function EnumMember(props: EnumMemberProps) {
|
|
14
|
+
const scope = useNamedTypeScope();
|
|
15
|
+
|
|
16
|
+
if (!scope) {
|
|
17
|
+
throw new Error("EnumMember must be used within an EnumDeclaration.");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const symbol = scope.ownerSymbol;
|
|
21
|
+
|
|
22
|
+
if (symbol.typeKind !== "enum") {
|
|
23
|
+
throw new Error("EnumMember must be used within an EnumDeclaration.");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const name = useCSharpNamePolicy().getName(props.name, "enum-member");
|
|
27
|
+
const thisEnumValueSymbol = new CSharpSymbol(name, symbol.members, {
|
|
28
|
+
refkeys: props.refkey,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<MemberDeclaration symbol={thisEnumValueSymbol}>
|
|
33
|
+
<MemberName />
|
|
34
|
+
</MemberDeclaration>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -24,8 +24,8 @@ it("declares multiple fields", () => {
|
|
|
24
24
|
).toRenderTo(`
|
|
25
25
|
public class TestClass
|
|
26
26
|
{
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
public string MemberOne;
|
|
28
|
+
public int MemberTwo;
|
|
29
29
|
}
|
|
30
30
|
`);
|
|
31
31
|
});
|
|
@@ -46,7 +46,7 @@ describe("modifiers", () => {
|
|
|
46
46
|
).toRenderTo(`
|
|
47
47
|
public class TestClass
|
|
48
48
|
{
|
|
49
|
-
|
|
49
|
+
${accessModifier} string ${accessModifier === "private" ? "_testProp" : "TestProp"};
|
|
50
50
|
}
|
|
51
51
|
`);
|
|
52
52
|
},
|
|
@@ -68,7 +68,7 @@ describe("modifiers", () => {
|
|
|
68
68
|
).toRenderTo(`
|
|
69
69
|
public class TestClass
|
|
70
70
|
{
|
|
71
|
-
|
|
71
|
+
${methodModifier} string _testField;
|
|
72
72
|
}
|
|
73
73
|
`);
|
|
74
74
|
},
|
|
@@ -83,7 +83,7 @@ describe("modifiers", () => {
|
|
|
83
83
|
).toRenderTo(`
|
|
84
84
|
public class TestClass
|
|
85
85
|
{
|
|
86
|
-
|
|
86
|
+
public new string TestField;
|
|
87
87
|
}
|
|
88
88
|
`);
|
|
89
89
|
});
|
|
@@ -100,7 +100,7 @@ describe("naming", () => {
|
|
|
100
100
|
).toRenderTo(`
|
|
101
101
|
public class TestClass
|
|
102
102
|
{
|
|
103
|
-
|
|
103
|
+
public string MemberOne;
|
|
104
104
|
}
|
|
105
105
|
`);
|
|
106
106
|
});
|
|
@@ -115,7 +115,7 @@ describe("naming", () => {
|
|
|
115
115
|
).toRenderTo(`
|
|
116
116
|
public class TestClass
|
|
117
117
|
{
|
|
118
|
-
|
|
118
|
+
private string _memberOne;
|
|
119
119
|
}
|
|
120
120
|
`);
|
|
121
121
|
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Children, Declaration, Name,
|
|
1
|
+
import { Children, Declaration, Name, Refkey } from "@alloy-js/core";
|
|
2
2
|
import {
|
|
3
3
|
AccessModifiers,
|
|
4
4
|
computeModifiersPrefix,
|
|
5
5
|
getAccessModifier,
|
|
6
6
|
makeModifiers,
|
|
7
7
|
} from "../../modifiers.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import {
|
|
9
|
+
accessibilityFromProps,
|
|
10
|
+
nonAccessibilityFromProps,
|
|
11
|
+
} from "../../symbols/csharp.js";
|
|
12
|
+
import { createFieldSymbol } from "../../symbols/factories.js";
|
|
11
13
|
import { DocWhen } from "../doc/comment.jsx";
|
|
12
14
|
|
|
13
15
|
/** Field modifiers. */
|
|
@@ -35,17 +37,13 @@ export interface FieldProps extends AccessModifiers, FieldModifiers {
|
|
|
35
37
|
|
|
36
38
|
/** Render a c# field */
|
|
37
39
|
export function Field(props: FieldProps) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const scope = useCSharpMemberScope(["class-decl", "struct-decl"]);
|
|
40
|
+
const options = {
|
|
41
|
+
accessibility: accessibilityFromProps(props),
|
|
42
|
+
refkeys: props.refkey,
|
|
43
|
+
...nonAccessibilityFromProps(props),
|
|
44
|
+
};
|
|
44
45
|
|
|
45
|
-
const memberSymbol =
|
|
46
|
-
scope,
|
|
47
|
-
refkeys: props.refkey ?? refkey(props.name),
|
|
48
|
-
});
|
|
46
|
+
const memberSymbol = createFieldSymbol(props.name, options);
|
|
49
47
|
|
|
50
48
|
const modifiers = computeModifiersPrefix([
|
|
51
49
|
getAccessModifier(props),
|
package/src/components/index.ts
CHANGED
|
@@ -4,14 +4,17 @@ export * from "./constructor/constructor.jsx";
|
|
|
4
4
|
export * from "./Declaration.js";
|
|
5
5
|
export * from "./doc/comment.jsx";
|
|
6
6
|
export * from "./doc/from-markdown.jsx";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./enum/declaration.jsx";
|
|
8
|
+
export * from "./enum/member.jsx";
|
|
8
9
|
export * from "./field/field.jsx";
|
|
9
10
|
export * from "./interface/declaration.js";
|
|
10
11
|
export * from "./interface/method.js";
|
|
11
12
|
export * from "./interface/property.js";
|
|
13
|
+
export * from "./lexical-scope.jsx";
|
|
14
|
+
export * from "./method-scope.jsx";
|
|
12
15
|
export * from "./method/method.jsx";
|
|
13
16
|
export * from "./Name.js";
|
|
14
|
-
export * from "./
|
|
17
|
+
export * from "./namespace.js";
|
|
15
18
|
export * from "./parameters/parameters.jsx";
|
|
16
19
|
export * from "./ProjectDirectory.js";
|
|
17
20
|
export * from "./property/property.jsx";
|
|
@@ -2,7 +2,6 @@ import { List, 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";
|
|
5
|
-
import { SourceFile } from "../SourceFile.jsx";
|
|
6
5
|
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
7
6
|
import { InterfaceDeclaration } from "./declaration.jsx";
|
|
8
7
|
import { InterfaceProperty } from "./property.jsx";
|
|
@@ -75,37 +74,32 @@ describe("with type parameters", () => {
|
|
|
75
74
|
|
|
76
75
|
expect(
|
|
77
76
|
<TestNamespace>
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
>
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
</InterfaceDeclaration>
|
|
99
|
-
</SourceFile>
|
|
77
|
+
<InterfaceDeclaration
|
|
78
|
+
public
|
|
79
|
+
name="Test"
|
|
80
|
+
typeParameters={typeParameters}
|
|
81
|
+
>
|
|
82
|
+
<List>
|
|
83
|
+
<InterfaceProperty
|
|
84
|
+
name="PropA"
|
|
85
|
+
type={typeParameters[0].refkey}
|
|
86
|
+
get
|
|
87
|
+
set
|
|
88
|
+
/>
|
|
89
|
+
<InterfaceProperty
|
|
90
|
+
name="PropB"
|
|
91
|
+
type={typeParameters[1].refkey}
|
|
92
|
+
get
|
|
93
|
+
set
|
|
94
|
+
/>
|
|
95
|
+
</List>
|
|
96
|
+
</InterfaceDeclaration>
|
|
100
97
|
</TestNamespace>,
|
|
101
98
|
).toRenderTo(`
|
|
102
|
-
|
|
99
|
+
public interface Test<T, U>
|
|
103
100
|
{
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
T PropA { get; set; }
|
|
107
|
-
U PropB { get; set; }
|
|
108
|
-
}
|
|
101
|
+
T PropA { get; set; }
|
|
102
|
+
U PropB { get; set; }
|
|
109
103
|
}
|
|
110
104
|
`);
|
|
111
105
|
});
|
|
@@ -134,10 +128,10 @@ describe("with type parameters", () => {
|
|
|
134
128
|
</TestNamespace>,
|
|
135
129
|
).toRenderTo(`
|
|
136
130
|
public interface Test<T, U>
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
where T : IFoo
|
|
132
|
+
where U : IBar
|
|
139
133
|
{
|
|
140
|
-
|
|
134
|
+
// Body
|
|
141
135
|
}
|
|
142
136
|
`);
|
|
143
137
|
});
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
makeModifiers,
|
|
7
7
|
} from "../../modifiers.js";
|
|
8
8
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { createNamedTypeScope } from "../../scopes/factories.js";
|
|
10
|
+
import { createNamedTypeSymbol } from "../../symbols/factories.js";
|
|
11
11
|
import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
|
|
12
12
|
import { DocWhen } from "../doc/comment.jsx";
|
|
13
13
|
import { Name } from "../Name.jsx";
|
|
@@ -88,7 +88,7 @@ export interface InterfaceDeclarationProps
|
|
|
88
88
|
export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
|
|
89
89
|
const name = useCSharpNamePolicy().getName(props.name!, "interface");
|
|
90
90
|
|
|
91
|
-
const
|
|
91
|
+
const symbol = createNamedTypeSymbol(name, "interface", {
|
|
92
92
|
refkeys: props.refkey,
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -96,30 +96,28 @@ export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
|
|
|
96
96
|
// members will automatically "inherit" this scope so
|
|
97
97
|
// that refkeys to them will produce the fully-qualified
|
|
98
98
|
// name e.g. Foo.Bar.
|
|
99
|
-
const thisInterfaceScope =
|
|
100
|
-
owner: thisInterfaceSymbol,
|
|
101
|
-
});
|
|
99
|
+
const thisInterfaceScope = createNamedTypeScope(symbol);
|
|
102
100
|
|
|
103
101
|
const modifiers = computeModifiersPrefix([
|
|
104
102
|
getAccessModifier(props),
|
|
105
103
|
getInterfaceModifiers(props),
|
|
106
104
|
]);
|
|
107
105
|
return (
|
|
108
|
-
<core.Declaration symbol={
|
|
106
|
+
<core.Declaration symbol={symbol}>
|
|
109
107
|
<DocWhen doc={props.doc} />
|
|
110
108
|
<AttributeList attributes={props.attributes} endline />
|
|
111
109
|
{modifiers}interface <Name />
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<core.
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
<core.Scope value={thisInterfaceScope}>
|
|
111
|
+
{props.typeParameters && (
|
|
112
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
113
|
+
)}
|
|
114
|
+
{props.typeParameters && (
|
|
115
|
+
<TypeParameterConstraints parameters={props.typeParameters} />
|
|
116
|
+
)}
|
|
117
|
+
{props.children ?
|
|
118
|
+
<core.Block newline>{props.children}</core.Block>
|
|
119
|
+
: ";"}
|
|
120
|
+
</core.Scope>
|
|
123
121
|
</core.Declaration>
|
|
124
122
|
);
|
|
125
123
|
}
|