@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
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import {
|
|
3
|
-
AccessModifiers,
|
|
4
|
-
computeModifiersPrefix,
|
|
5
|
-
getAccessModifier,
|
|
6
|
-
} from "../modifiers.js";
|
|
7
|
-
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
8
|
-
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
9
|
-
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
10
|
-
import { Name } from "./Name.jsx";
|
|
11
|
-
|
|
12
|
-
// properties for creating an enum
|
|
13
|
-
export interface EnumDeclarationProps extends AccessModifiers {
|
|
14
|
-
name: string;
|
|
15
|
-
refkey?: core.Refkey;
|
|
16
|
-
children?: core.Children;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A C# enum declaration
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* <EnumDeclaration public name="Color">
|
|
24
|
-
* <EnumMember name="Red" />
|
|
25
|
-
* <EnumMember name="Green" />
|
|
26
|
-
* <EnumMember name="Blue" />
|
|
27
|
-
* </EnumDeclaration>
|
|
28
|
-
* ```
|
|
29
|
-
* This will produce:
|
|
30
|
-
* ```csharp
|
|
31
|
-
* public enum Color
|
|
32
|
-
* {
|
|
33
|
-
* Red,
|
|
34
|
-
* Green,
|
|
35
|
-
* Blue
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export function EnumDeclaration(props: EnumDeclarationProps) {
|
|
40
|
-
const name = useCSharpNamePolicy().getName(props.name!, "enum");
|
|
41
|
-
const scope = useCSharpScope();
|
|
42
|
-
|
|
43
|
-
const thisEnumSymbol = new CSharpOutputSymbol(name, {
|
|
44
|
-
scope,
|
|
45
|
-
refkeys: props.refkey ?? core.refkey(props.name),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// this creates a new scope for the enum definition.
|
|
49
|
-
// members will automatically "inherit" this scope so
|
|
50
|
-
// that refkeys to them will produce the fully-qualified
|
|
51
|
-
// name e.g. Foo.Bar.
|
|
52
|
-
const thisEnumScope = new CSharpMemberScope("enum-decl", {
|
|
53
|
-
parent: scope,
|
|
54
|
-
owner: thisEnumSymbol,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
58
|
-
|
|
59
|
-
if (thisEnumScope.owner)
|
|
60
|
-
return (
|
|
61
|
-
<core.Declaration symbol={thisEnumSymbol}>
|
|
62
|
-
{modifiers}enum <Name />
|
|
63
|
-
{!props.children && ";"}
|
|
64
|
-
{props.children && (
|
|
65
|
-
<core.Scope value={thisEnumScope}>
|
|
66
|
-
<core.Block newline>{props.children}</core.Block>
|
|
67
|
-
</core.Scope>
|
|
68
|
-
)}
|
|
69
|
-
</core.Declaration>
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// properties for creating a C# enum member
|
|
74
|
-
export interface EnumMemberProps {
|
|
75
|
-
name: string;
|
|
76
|
-
refkey?: core.Refkey;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// a member within a C# enum
|
|
80
|
-
export function EnumMember(props: EnumMemberProps) {
|
|
81
|
-
const scope = useCSharpScope();
|
|
82
|
-
if (scope.kind === "member" && scope.name !== "enum-decl") {
|
|
83
|
-
throw new Error(
|
|
84
|
-
"can't define an enum member outside of an enum-decl scope",
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const name = useCSharpNamePolicy().getName(props.name, "enum-member");
|
|
89
|
-
const thisEnumValueSymbol = new CSharpOutputSymbol(name, {
|
|
90
|
-
scope,
|
|
91
|
-
refkeys: props.refkey ?? core.refkey(props.name),
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<core.Declaration symbol={thisEnumValueSymbol}>
|
|
96
|
-
<Name />
|
|
97
|
-
</core.Declaration>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import { CSharpNamespaceScope } from "../symbols/scopes.js";
|
|
3
|
-
|
|
4
|
-
// contains the info for the current namespace
|
|
5
|
-
export interface NamespaceContext {
|
|
6
|
-
name: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const NamespaceContext = core.createContext<NamespaceContext>();
|
|
10
|
-
|
|
11
|
-
// returns the current namespace
|
|
12
|
-
export function useNamespace(): NamespaceContext | undefined {
|
|
13
|
-
return core.useContext(NamespaceContext) as NamespaceContext;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// properties for creating a C# namespace
|
|
17
|
-
export interface NamespaceProps {
|
|
18
|
-
name: string;
|
|
19
|
-
children?: core.Children;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// a C# namespace. contains one or more source files
|
|
23
|
-
export function Namespace(props: NamespaceProps) {
|
|
24
|
-
const scope = new CSharpNamespaceScope(props.name);
|
|
25
|
-
|
|
26
|
-
const namespaceCtx: NamespaceContext = {
|
|
27
|
-
name: props.name,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<NamespaceContext.Provider value={namespaceCtx}>
|
|
32
|
-
<core.Scope value={scope}>{props.children}</core.Scope>
|
|
33
|
-
</NamespaceContext.Provider>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import { useNamespace } from "../components/Namespace.jsx";
|
|
3
|
-
import { CSharpOutputScope } from "./scopes.js";
|
|
4
|
-
|
|
5
|
-
// represents a symbol from a .cs file. Class, enum, interface etc.
|
|
6
|
-
|
|
7
|
-
export class CSharpOutputSymbol extends core.OutputSymbol {
|
|
8
|
-
get scope() {
|
|
9
|
-
return super.scope as CSharpOutputScope;
|
|
10
|
-
}
|
|
11
|
-
set scope(value: CSharpOutputScope) {
|
|
12
|
-
super.scope = value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
constructor(name: string, options?: core.OutputSymbolOptions) {
|
|
16
|
-
const namespaceCtx = useNamespace();
|
|
17
|
-
if (!namespaceCtx) {
|
|
18
|
-
throw new Error("symbol must be declared inside a namespace");
|
|
19
|
-
}
|
|
20
|
-
super(name, options);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/symbols/scopes.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import { CSharpOutputSymbol } from "./csharp-output-symbol.js";
|
|
3
|
-
|
|
4
|
-
// indicates that the scope for a symbols is at the namespace level
|
|
5
|
-
export class CSharpNamespaceScope extends core.OutputScope {
|
|
6
|
-
get kind() {
|
|
7
|
-
return "namespace";
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// the kind of member scope. i.e. are we in an enum, class, etc
|
|
12
|
-
export type CSharpMemberScopeName =
|
|
13
|
-
| "class-decl"
|
|
14
|
-
| "constructor-decl"
|
|
15
|
-
| "enum-decl"
|
|
16
|
-
| "method-decl";
|
|
17
|
-
|
|
18
|
-
// indicates that the scope for a symbol resides within a type
|
|
19
|
-
// e.g. for an enum value, class field etc, these would have
|
|
20
|
-
// member scope where the owner is the containing type.
|
|
21
|
-
export class CSharpMemberScope extends core.OutputScope {
|
|
22
|
-
get kind() {
|
|
23
|
-
return "member";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get name() {
|
|
27
|
-
return super.name as CSharpMemberScopeName;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get owner() {
|
|
31
|
-
return super.owner as CSharpOutputSymbol;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// contains the possible scopes where a declaration can reside
|
|
36
|
-
export type CSharpOutputScope = CSharpMemberScope | CSharpNamespaceScope;
|
|
37
|
-
|
|
38
|
-
// returns the current C# scope
|
|
39
|
-
export function useCSharpScope(): CSharpOutputScope {
|
|
40
|
-
return core.useScope() as CSharpOutputScope;
|
|
41
|
-
}
|
package/test/enum.test.tsx
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import * as coretest from "@alloy-js/core/testing";
|
|
3
|
-
import { expect, it } from "vitest";
|
|
4
|
-
import * as csharp from "../src/index.js";
|
|
5
|
-
import * as utils from "./utils.js";
|
|
6
|
-
import { findFile } from "./utils.js";
|
|
7
|
-
|
|
8
|
-
it("declares enum with no members", () => {
|
|
9
|
-
const res = utils.toSourceText(
|
|
10
|
-
<csharp.EnumDeclaration public name="TestEnum" />,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
expect(res).toBe(coretest.d`
|
|
14
|
-
namespace TestCode
|
|
15
|
-
{
|
|
16
|
-
public enum TestEnum;
|
|
17
|
-
}
|
|
18
|
-
`);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("declares enum with members", () => {
|
|
22
|
-
const res = utils.toSourceText(
|
|
23
|
-
<csharp.EnumDeclaration public name="TestEnum">
|
|
24
|
-
<csharp.EnumMember name="One" />,<hbr />
|
|
25
|
-
<csharp.EnumMember name="Two" />
|
|
26
|
-
</csharp.EnumDeclaration>,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
expect(res).toBe(coretest.d`
|
|
30
|
-
namespace TestCode
|
|
31
|
-
{
|
|
32
|
-
public enum TestEnum
|
|
33
|
-
{
|
|
34
|
-
One,
|
|
35
|
-
Two
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
`);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("applies naming policy to enum and members", () => {
|
|
42
|
-
const res = utils.toSourceText(
|
|
43
|
-
<csharp.EnumDeclaration public name="testEnum">
|
|
44
|
-
<csharp.EnumMember name="one" />,<hbr />
|
|
45
|
-
<csharp.EnumMember name="two" />
|
|
46
|
-
</csharp.EnumDeclaration>,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
expect(res).toBe(coretest.d`
|
|
50
|
-
namespace TestCode
|
|
51
|
-
{
|
|
52
|
-
public enum TestEnum
|
|
53
|
-
{
|
|
54
|
-
One,
|
|
55
|
-
Two
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
`);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("can reference things by refkey", () => {
|
|
62
|
-
const enumRK = core.refkey();
|
|
63
|
-
const twoRK = core.refkey();
|
|
64
|
-
|
|
65
|
-
const res = core.render(
|
|
66
|
-
<core.Output>
|
|
67
|
-
<csharp.Namespace name="TestCode">
|
|
68
|
-
<csharp.SourceFile path="Test.cs">
|
|
69
|
-
<csharp.EnumDeclaration public name="TestEnum" refkey={enumRK}>
|
|
70
|
-
<csharp.EnumMember name="One" />,<hbr />
|
|
71
|
-
<csharp.EnumMember name="Two" refkey={twoRK} />
|
|
72
|
-
</csharp.EnumDeclaration>
|
|
73
|
-
<hbr />
|
|
74
|
-
{enumRK};<hbr />
|
|
75
|
-
{twoRK};
|
|
76
|
-
</csharp.SourceFile>
|
|
77
|
-
</csharp.Namespace>
|
|
78
|
-
</core.Output>,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
|
|
82
|
-
namespace TestCode
|
|
83
|
-
{
|
|
84
|
-
public enum TestEnum
|
|
85
|
-
{
|
|
86
|
-
One,
|
|
87
|
-
Two
|
|
88
|
-
}
|
|
89
|
-
TestEnum;
|
|
90
|
-
TestEnum.Two;
|
|
91
|
-
}
|
|
92
|
-
`);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("can reference things by refkey across files", () => {
|
|
96
|
-
const enumRK = core.refkey();
|
|
97
|
-
const barRK = core.refkey();
|
|
98
|
-
|
|
99
|
-
const res = core.render(
|
|
100
|
-
<core.Output>
|
|
101
|
-
<csharp.Namespace name="TestCode">
|
|
102
|
-
<csharp.SourceFile path="Test.cs">
|
|
103
|
-
<csharp.EnumDeclaration public name="TestEnum">
|
|
104
|
-
<csharp.EnumMember name="One" />,<hbr />
|
|
105
|
-
<csharp.EnumMember name="Two" />
|
|
106
|
-
</csharp.EnumDeclaration>
|
|
107
|
-
<hbr />
|
|
108
|
-
{enumRK};<hbr />
|
|
109
|
-
{barRK};
|
|
110
|
-
</csharp.SourceFile>
|
|
111
|
-
<csharp.SourceFile path="Other.cs">
|
|
112
|
-
<csharp.EnumDeclaration public name="OtherEnum" refkey={enumRK}>
|
|
113
|
-
<csharp.EnumMember name="Foo" />,<hbr />
|
|
114
|
-
<csharp.EnumMember name="Bar" refkey={barRK} />
|
|
115
|
-
</csharp.EnumDeclaration>
|
|
116
|
-
<hbr />
|
|
117
|
-
{enumRK};<hbr />
|
|
118
|
-
{barRK};
|
|
119
|
-
</csharp.SourceFile>
|
|
120
|
-
</csharp.Namespace>
|
|
121
|
-
</core.Output>,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
|
|
125
|
-
namespace TestCode
|
|
126
|
-
{
|
|
127
|
-
public enum TestEnum
|
|
128
|
-
{
|
|
129
|
-
One,
|
|
130
|
-
Two
|
|
131
|
-
}
|
|
132
|
-
OtherEnum;
|
|
133
|
-
OtherEnum.Bar;
|
|
134
|
-
}
|
|
135
|
-
`);
|
|
136
|
-
|
|
137
|
-
expect(findFile(res, "Other.cs").contents).toBe(coretest.d`
|
|
138
|
-
namespace TestCode
|
|
139
|
-
{
|
|
140
|
-
public enum OtherEnum
|
|
141
|
-
{
|
|
142
|
-
Foo,
|
|
143
|
-
Bar
|
|
144
|
-
}
|
|
145
|
-
OtherEnum;
|
|
146
|
-
OtherEnum.Bar;
|
|
147
|
-
}
|
|
148
|
-
`);
|
|
149
|
-
});
|
package/test/namespace.test.tsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import * as coretest from "@alloy-js/core/testing";
|
|
3
|
-
import { it } from "vitest";
|
|
4
|
-
import * as csharp from "../src/index.js";
|
|
5
|
-
import { assertFileContents } from "./utils.jsx";
|
|
6
|
-
|
|
7
|
-
it("defines multiple namespaces and source files with unique content", () => {
|
|
8
|
-
const res = core.render(
|
|
9
|
-
<core.Output>
|
|
10
|
-
<csharp.Namespace name="Namespace1">
|
|
11
|
-
<csharp.SourceFile path="Model1.cs">
|
|
12
|
-
<csharp.ClassDeclaration public name="Model1" />
|
|
13
|
-
</csharp.SourceFile>
|
|
14
|
-
<csharp.SourceFile path="Model2.cs">
|
|
15
|
-
<csharp.ClassDeclaration public name="Model2" />
|
|
16
|
-
</csharp.SourceFile>
|
|
17
|
-
</csharp.Namespace>
|
|
18
|
-
<csharp.Namespace name="Namespace2">
|
|
19
|
-
<csharp.SourceFile path="Model3.cs">
|
|
20
|
-
<csharp.ClassDeclaration public name="Model3" />
|
|
21
|
-
</csharp.SourceFile>
|
|
22
|
-
<csharp.SourceFile path="Model4.cs">
|
|
23
|
-
<csharp.ClassDeclaration public name="Model4" />
|
|
24
|
-
</csharp.SourceFile>
|
|
25
|
-
</csharp.Namespace>
|
|
26
|
-
</core.Output>,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
assertFileContents(res, {
|
|
30
|
-
"Model1.cs": coretest.d`
|
|
31
|
-
namespace Namespace1
|
|
32
|
-
{
|
|
33
|
-
public class Model1;
|
|
34
|
-
}
|
|
35
|
-
`,
|
|
36
|
-
"Model2.cs": coretest.d`
|
|
37
|
-
namespace Namespace1
|
|
38
|
-
{
|
|
39
|
-
public class Model2;
|
|
40
|
-
}
|
|
41
|
-
`,
|
|
42
|
-
"Model3.cs": coretest.d`
|
|
43
|
-
namespace Namespace2
|
|
44
|
-
{
|
|
45
|
-
public class Model3;
|
|
46
|
-
}
|
|
47
|
-
`,
|
|
48
|
-
"Model4.cs": coretest.d`
|
|
49
|
-
namespace Namespace2
|
|
50
|
-
{
|
|
51
|
-
public class Model4;
|
|
52
|
-
}
|
|
53
|
-
`,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
File without changes
|