@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
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
DeclarationProps,
|
|
6
6
|
join,
|
|
7
7
|
Name,
|
|
8
|
+
Namekey,
|
|
8
9
|
Refkey,
|
|
9
10
|
Scope,
|
|
10
11
|
} from "@alloy-js/core";
|
|
@@ -14,9 +15,8 @@ import {
|
|
|
14
15
|
getAccessModifier,
|
|
15
16
|
makeModifiers,
|
|
16
17
|
} from "../../modifiers.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { CSharpMemberScope } from "../../symbols/scopes.js";
|
|
18
|
+
import { createClassScope } from "../../scopes/factories.js";
|
|
19
|
+
import { createNamedTypeSymbol } from "../../symbols/factories.js";
|
|
20
20
|
import { AttributeList, AttributesProp } from "../attributes/attributes.jsx";
|
|
21
21
|
import { DocWhen } from "../doc/comment.jsx";
|
|
22
22
|
import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
|
|
@@ -33,9 +33,9 @@ export interface ClassModifiers {
|
|
|
33
33
|
|
|
34
34
|
const getClassModifiers = makeModifiers<ClassModifiers>([
|
|
35
35
|
"abstract",
|
|
36
|
-
"partial",
|
|
37
36
|
"sealed",
|
|
38
37
|
"static",
|
|
38
|
+
"partial",
|
|
39
39
|
]);
|
|
40
40
|
|
|
41
41
|
// properties for creating a class
|
|
@@ -43,7 +43,7 @@ export interface ClassDeclarationProps
|
|
|
43
43
|
extends Omit<DeclarationProps, "nameKind">,
|
|
44
44
|
AccessModifiers,
|
|
45
45
|
ClassModifiers {
|
|
46
|
-
name: string;
|
|
46
|
+
name: string | Namekey;
|
|
47
47
|
/** Doc comment */
|
|
48
48
|
doc?: Children;
|
|
49
49
|
refkey?: Refkey;
|
|
@@ -130,19 +130,10 @@ export interface ClassDeclarationProps
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
const thisClassSymbol = new CSharpOutputSymbol(name, {
|
|
133
|
+
const thisClassSymbol = createNamedTypeSymbol(props.name, "class", {
|
|
136
134
|
refkeys: props.refkey,
|
|
137
135
|
});
|
|
138
|
-
|
|
139
|
-
// this creates a new scope for the class definition.
|
|
140
|
-
// members will automatically "inherit" this scope so
|
|
141
|
-
// that refkeys to them will produce the fully-qualified
|
|
142
|
-
// name e.g. Foo.Bar.
|
|
143
|
-
const thisClassScope = new CSharpMemberScope("class-decl", {
|
|
144
|
-
owner: thisClassSymbol,
|
|
145
|
-
});
|
|
136
|
+
const thisClassScope = createClassScope(thisClassSymbol);
|
|
146
137
|
|
|
147
138
|
const bases = [
|
|
148
139
|
...(props.baseType ? [props.baseType] : []),
|
|
@@ -159,24 +150,20 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
|
159
150
|
<DocWhen doc={props.doc} />
|
|
160
151
|
<AttributeList attributes={props.attributes} endline />
|
|
161
152
|
{modifiers}class <Name />
|
|
162
|
-
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
153
|
+
<Scope value={thisClassScope}>
|
|
154
|
+
{props.typeParameters && (
|
|
155
|
+
<TypeParameters parameters={props.typeParameters} />
|
|
156
|
+
)}
|
|
157
|
+
{props.primaryConstructor && (
|
|
167
158
|
<Parameters parameters={props.primaryConstructor} />
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
<Block newline>
|
|
177
|
-
<Scope value={thisClassScope}>{props.children}</Scope>
|
|
178
|
-
</Block>
|
|
179
|
-
)}
|
|
159
|
+
)}
|
|
160
|
+
{base}
|
|
161
|
+
{props.typeParameters && (
|
|
162
|
+
<TypeParameterConstraints parameters={props.typeParameters} />
|
|
163
|
+
)}
|
|
164
|
+
{!props.children && ";"}
|
|
165
|
+
{props.children && <Block newline>{props.children}</Block>}
|
|
166
|
+
</Scope>
|
|
180
167
|
</Declaration>
|
|
181
168
|
);
|
|
182
169
|
}
|
|
@@ -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,20 +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 { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
9
|
+
import { useNamedTypeScope } from "../../scopes/contexts.js";
|
|
10
|
+
import { MethodSymbol } from "../../symbols/method.js";
|
|
18
11
|
import { ParameterProps, Parameters } from "../parameters/parameters.jsx";
|
|
19
12
|
|
|
20
13
|
/**
|
|
@@ -32,36 +25,24 @@ export interface ConstructorProps extends AccessModifiers {
|
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
export function Constructor(props: ConstructorProps) {
|
|
35
|
-
const scope =
|
|
36
|
-
if (
|
|
37
|
-
scope.kind !== "member" ||
|
|
38
|
-
(scope.name !== "class-decl" && scope.name !== "struct-decl")
|
|
39
|
-
) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
"can't define a class method outside of a class or struct scope",
|
|
42
|
-
);
|
|
43
|
-
}
|
|
28
|
+
const scope = useNamedTypeScope();
|
|
44
29
|
|
|
45
|
-
const name =
|
|
46
|
-
const ctorSymbol = new CSharpOutputSymbol(name, {
|
|
47
|
-
scope,
|
|
48
|
-
refkeys: props.refkey ?? refkey(name),
|
|
49
|
-
});
|
|
30
|
+
const name = scope.ownerSymbol.name;
|
|
50
31
|
|
|
51
|
-
const
|
|
52
|
-
|
|
32
|
+
const ctorSymbol = new MethodSymbol(name, scope.members, "constructor", {
|
|
33
|
+
refkeys: props.refkey,
|
|
53
34
|
});
|
|
54
35
|
|
|
55
36
|
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
56
37
|
|
|
57
38
|
return (
|
|
58
|
-
<
|
|
59
|
-
<
|
|
39
|
+
<MemberDeclaration symbol={ctorSymbol}>
|
|
40
|
+
<MethodScope>
|
|
60
41
|
{modifiers}
|
|
61
|
-
<
|
|
42
|
+
<MemberName />
|
|
62
43
|
<Parameters parameters={props.parameters} />
|
|
63
44
|
<Block newline>{props.children}</Block>
|
|
64
|
-
</
|
|
65
|
-
</
|
|
45
|
+
</MethodScope>
|
|
46
|
+
</MemberDeclaration>
|
|
66
47
|
);
|
|
67
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,25 +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 = useCSharpScope();
|
|
44
|
-
if (
|
|
45
|
-
scope.kind !== "member" ||
|
|
46
|
-
(scope.name !== "class-decl" && scope.name !== "struct-decl")
|
|
47
|
-
) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
"can't define a class member outside of a class or struct scope",
|
|
50
|
-
);
|
|
51
|
-
}
|
|
40
|
+
const options = {
|
|
41
|
+
accessibility: accessibilityFromProps(props),
|
|
42
|
+
refkeys: props.refkey,
|
|
43
|
+
...nonAccessibilityFromProps(props),
|
|
44
|
+
};
|
|
52
45
|
|
|
53
|
-
const memberSymbol =
|
|
54
|
-
scope,
|
|
55
|
-
refkeys: props.refkey ?? refkey(props.name),
|
|
56
|
-
});
|
|
46
|
+
const memberSymbol = createFieldSymbol(props.name, options);
|
|
57
47
|
|
|
58
48
|
const modifiers = computeModifiersPrefix([
|
|
59
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
|
});
|