@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,18 +1,15 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
3
2
|
|
|
4
3
|
// properties for creating a declaration
|
|
5
4
|
export interface DeclarationProps {
|
|
6
5
|
name: string;
|
|
7
|
-
refkey?: core.Refkey;
|
|
6
|
+
refkey?: core.Refkey | core.Refkey[];
|
|
8
7
|
children?: core.Children;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
// declares a symbol in the program (class, enum, interface etc)
|
|
12
11
|
export function Declaration(props: DeclarationProps) {
|
|
13
|
-
|
|
14
|
-
refkeys: props.refkey,
|
|
15
|
-
});
|
|
12
|
+
throw new Error("Not supported");
|
|
16
13
|
|
|
17
|
-
return <core.Declaration symbol={sym}>{props.children}</core.Declaration>;
|
|
14
|
+
//return <core.Declaration symbol={sym}>{props.children}</core.Declaration>;
|
|
18
15
|
}
|
|
@@ -8,6 +8,8 @@ export interface ReferenceProps {
|
|
|
8
8
|
// used to resolve refkey references within source files
|
|
9
9
|
export function Reference({ refkey }: ReferenceProps) {
|
|
10
10
|
const reference = ref(refkey);
|
|
11
|
+
const symbolRef = core.computed(() => reference()[1]);
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
core.emitSymbol(symbolRef);
|
|
14
|
+
return <>{reference()[0]}</>;
|
|
13
15
|
}
|
|
@@ -1,78 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
computed,
|
|
4
|
+
SourceFile as CoreSourceFile,
|
|
5
|
+
Scope,
|
|
6
|
+
Show,
|
|
7
|
+
useBinder,
|
|
8
|
+
} from "@alloy-js/core";
|
|
9
|
+
import { getGlobalNamespace } from "../contexts/global-namespace.js";
|
|
10
|
+
import { useNamespaceContext } from "../contexts/namespace.js";
|
|
11
|
+
import { CSharpSourceFileScope } from "../scopes/source-file.js";
|
|
12
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
13
|
+
import { NamespaceScope, NamespaceScopes } from "./namespace-scopes.jsx";
|
|
3
14
|
import { Reference } from "./Reference.jsx";
|
|
4
15
|
import { UsingDirective } from "./UsingDirective.jsx";
|
|
5
16
|
|
|
6
|
-
// contains the info for the current source file
|
|
7
|
-
export interface SourceFileContext {
|
|
8
|
-
// adds a namespace to the array of using statements
|
|
9
|
-
addUsing(namespace: string): void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const SourceFileContext = core.createContext<SourceFileContext>();
|
|
13
|
-
|
|
14
|
-
// returns the current source file
|
|
15
|
-
export function useSourceFile(): SourceFileContext | undefined {
|
|
16
|
-
return core.useContext(SourceFileContext) as SourceFileContext;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
17
|
export interface SourceFileProps {
|
|
20
18
|
/** Path of the source file */
|
|
21
19
|
path: string;
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
using?: Array<string>;
|
|
21
|
+
children?: Children;
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A list of using directives to explicitly include. Note that providing
|
|
25
|
+
* explicit usings is not necessary when referencing symbols via refkeys.
|
|
26
|
+
*/
|
|
27
|
+
using?: string[];
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
// a C# source file. exists within the context of a namespace
|
|
30
31
|
// contains using statements and declarations
|
|
31
32
|
export function SourceFile(props: SourceFileProps) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
if (!namespaceCtx) {
|
|
35
|
-
throw new Error("SourceFile must be declared inside a namespace");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const using: Array<string> = core.reactive(new Array<string>());
|
|
39
|
-
if (props.using) {
|
|
40
|
-
using.push(...props.using);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// adds the specified namespace to the array of using statements.
|
|
44
|
-
// called via SourceFileContext.addUsing when resolving refkeys.
|
|
45
|
-
function addUsing(namespace: string): void {
|
|
46
|
-
if (!using.includes(namespace)) {
|
|
47
|
-
using.push(namespace);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const sourceFileCtx: SourceFileContext = {
|
|
52
|
-
addUsing,
|
|
53
|
-
};
|
|
33
|
+
const sourceFileScope = new CSharpSourceFileScope(props.path);
|
|
54
34
|
|
|
35
|
+
const nsContext = useNamespaceContext();
|
|
36
|
+
const globalNs = getGlobalNamespace(useBinder());
|
|
37
|
+
const nsSymbol = nsContext ? nsContext.symbol : globalNs;
|
|
38
|
+
const nsRef = nsContext ? nsContext.symbol.name : undefined;
|
|
39
|
+
const usings = computed(() => {
|
|
40
|
+
return (
|
|
41
|
+
Array.from(sourceFileScope.usings) as (NamespaceSymbol | string)[]
|
|
42
|
+
).concat(props.using ?? []);
|
|
43
|
+
});
|
|
55
44
|
return (
|
|
56
|
-
<
|
|
45
|
+
<CoreSourceFile
|
|
57
46
|
path={props.path}
|
|
58
47
|
filetype="cs"
|
|
59
48
|
reference={Reference}
|
|
60
49
|
tabWidth={4}
|
|
61
50
|
printWidth={120}
|
|
62
51
|
>
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
52
|
+
<Scope value={sourceFileScope}>
|
|
53
|
+
{(sourceFileScope.usings.size > 0 ||
|
|
54
|
+
(props.using && props.using.length > 0)) && (
|
|
55
|
+
<>
|
|
56
|
+
<UsingDirective namespaces={usings.value} />
|
|
57
|
+
<hbr />
|
|
58
|
+
<hbr />
|
|
59
|
+
</>
|
|
60
|
+
)}
|
|
61
|
+
<Show when={!!nsContext && nsSymbol !== globalNs}>
|
|
62
|
+
<Show when={sourceFileScope.hasBlockNamespace}>
|
|
63
|
+
namespace {nsRef}
|
|
64
|
+
{" {"}
|
|
65
|
+
<hbr />
|
|
66
|
+
{" "}
|
|
67
|
+
</Show>
|
|
68
|
+
|
|
69
|
+
<Show when={!sourceFileScope.hasBlockNamespace}>
|
|
70
|
+
namespace {nsRef};<hbr />
|
|
71
|
+
<hbr />
|
|
72
|
+
</Show>
|
|
73
|
+
<align width={sourceFileScope.hasBlockNamespace ? 4 : 0}>
|
|
74
|
+
<NamespaceScopes symbol={nsContext!.symbol}>
|
|
75
|
+
{props.children}
|
|
76
|
+
</NamespaceScopes>
|
|
77
|
+
</align>
|
|
78
|
+
<Show when={sourceFileScope.hasBlockNamespace}>
|
|
79
|
+
<hbr />
|
|
80
|
+
{"}"}
|
|
81
|
+
</Show>
|
|
82
|
+
</Show>
|
|
83
|
+
<Show when={!nsContext || nsSymbol === globalNs}>
|
|
84
|
+
<NamespaceScope symbol={getGlobalNamespace(useBinder())}>
|
|
85
|
+
{props.children}
|
|
86
|
+
</NamespaceScope>
|
|
87
|
+
</Show>
|
|
88
|
+
</Scope>
|
|
89
|
+
</CoreSourceFile>
|
|
77
90
|
);
|
|
78
91
|
}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
2
3
|
|
|
3
4
|
export interface UsingDirectiveProps {
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Namespace symbols or namespace names to use to generate using statements.
|
|
7
|
+
*/
|
|
8
|
+
namespaces?: (NamespaceSymbol | string)[];
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
// one ore more C# using directives
|
|
8
12
|
export function UsingDirective(props: UsingDirectiveProps) {
|
|
9
13
|
const sortedNamespaces = core.computed(() => {
|
|
10
|
-
return props
|
|
14
|
+
return props
|
|
15
|
+
.namespaces!.map((ns) =>
|
|
16
|
+
typeof ns === "string" ? ns : (
|
|
17
|
+
ns.getFullyQualifiedName({ omitGlobal: true })
|
|
18
|
+
),
|
|
19
|
+
)
|
|
20
|
+
.sort((n1, n2) => n1.localeCompare(n2));
|
|
11
21
|
});
|
|
12
22
|
|
|
13
23
|
return (
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Constructor } from "#components/constructor/constructor.jsx";
|
|
2
|
+
import { EnumDeclaration } from "#components/enum/declaration.jsx";
|
|
3
|
+
import { EnumMember } from "#components/enum/member.jsx";
|
|
1
4
|
import {
|
|
2
5
|
Children,
|
|
3
6
|
code,
|
|
@@ -15,19 +18,13 @@ import { createCSharpNamePolicy } from "../../name-policy.js";
|
|
|
15
18
|
import { Attribute } from "../attributes/attributes.jsx";
|
|
16
19
|
import { Field } from "../field/field.jsx";
|
|
17
20
|
import { Method } from "../method/method.jsx";
|
|
18
|
-
import { Namespace } from "../Namespace.jsx";
|
|
19
21
|
import { Property } from "../property/property.jsx";
|
|
20
22
|
import { SourceFile } from "../SourceFile.jsx";
|
|
21
|
-
import { Constructor, EnumDeclaration, EnumMember } from "../stc/index.js";
|
|
22
23
|
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
23
24
|
import { ClassDeclaration } from "./declaration.jsx";
|
|
24
25
|
|
|
25
26
|
function Wrapper({ children }: { children: Children }) {
|
|
26
|
-
return
|
|
27
|
-
<TestNamespace>
|
|
28
|
-
<SourceFile path="Test.cs">{children}</SourceFile>
|
|
29
|
-
</TestNamespace>
|
|
30
|
-
);
|
|
27
|
+
return <TestNamespace>{children}</TestNamespace>;
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
it("declares class with no members", () => {
|
|
@@ -70,6 +67,24 @@ describe("modifiers", () => {
|
|
|
70
67
|
public abstract partial class TestClass;
|
|
71
68
|
`);
|
|
72
69
|
});
|
|
70
|
+
|
|
71
|
+
it("places visibility, attributes, and modifiers in the correct order", () => {
|
|
72
|
+
expect(
|
|
73
|
+
<TestNamespace>
|
|
74
|
+
<ClassDeclaration
|
|
75
|
+
partial
|
|
76
|
+
public
|
|
77
|
+
abstract
|
|
78
|
+
sealed
|
|
79
|
+
name="TestClass"
|
|
80
|
+
attributes={[<Attribute name="Test" />]}
|
|
81
|
+
/>
|
|
82
|
+
</TestNamespace>,
|
|
83
|
+
).toRenderTo(`
|
|
84
|
+
[Test]
|
|
85
|
+
public abstract sealed partial class TestClass;
|
|
86
|
+
`);
|
|
87
|
+
});
|
|
73
88
|
});
|
|
74
89
|
|
|
75
90
|
describe("base", () => {
|
|
@@ -109,45 +124,43 @@ describe("base", () => {
|
|
|
109
124
|
});
|
|
110
125
|
|
|
111
126
|
it("declares class with some members", () => {
|
|
112
|
-
const
|
|
113
|
-
<
|
|
114
|
-
<
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
const tree = (
|
|
128
|
+
<TestNamespace>
|
|
129
|
+
<ClassDeclaration public name="TestClass">
|
|
130
|
+
<List>
|
|
131
|
+
<Field public name="MemberOne" type="string" />
|
|
132
|
+
<Field public name="MemberTwo" type="int" />
|
|
133
|
+
</List>
|
|
134
|
+
</ClassDeclaration>
|
|
135
|
+
</TestNamespace>
|
|
119
136
|
);
|
|
120
137
|
|
|
121
|
-
expect(
|
|
122
|
-
|
|
138
|
+
expect(tree).toRenderTo(coretest.d`
|
|
139
|
+
public class TestClass
|
|
123
140
|
{
|
|
124
|
-
public
|
|
125
|
-
|
|
126
|
-
public string MemberOne;
|
|
127
|
-
public int MemberTwo;
|
|
128
|
-
}
|
|
141
|
+
public string MemberOne;
|
|
142
|
+
public int MemberTwo;
|
|
129
143
|
}
|
|
130
144
|
`);
|
|
131
145
|
});
|
|
132
146
|
|
|
133
147
|
it("declares class with some methods", () => {
|
|
134
|
-
const
|
|
135
|
-
<
|
|
136
|
-
<
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
148
|
+
const tree = (
|
|
149
|
+
<TestNamespace>
|
|
150
|
+
<ClassDeclaration public name="TestClass">
|
|
151
|
+
<List>
|
|
152
|
+
<Method public name="MethodOne" />
|
|
153
|
+
<Method private virtual name="MethodTwo" />
|
|
154
|
+
</List>
|
|
155
|
+
</ClassDeclaration>
|
|
156
|
+
</TestNamespace>
|
|
141
157
|
);
|
|
142
158
|
|
|
143
|
-
expect(
|
|
144
|
-
|
|
159
|
+
expect(tree).toRenderTo(coretest.d`
|
|
160
|
+
public class TestClass
|
|
145
161
|
{
|
|
146
|
-
public
|
|
147
|
-
{
|
|
148
|
-
public void MethodOne() {}
|
|
149
|
-
private virtual void MethodTwo() {}
|
|
150
|
-
}
|
|
162
|
+
public void MethodOne() {}
|
|
163
|
+
private virtual void MethodTwo() {}
|
|
151
164
|
}
|
|
152
165
|
`);
|
|
153
166
|
});
|
|
@@ -170,57 +183,52 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
170
183
|
|
|
171
184
|
const res = render(
|
|
172
185
|
<Output namePolicy={createCSharpNamePolicy()}>
|
|
173
|
-
<
|
|
174
|
-
<
|
|
175
|
-
<
|
|
176
|
-
<
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
186
|
+
<SourceFile path="Test.cs">
|
|
187
|
+
<EnumDeclaration public name="TestEnum" refkey={enumTypeRefkey}>
|
|
188
|
+
<List comma hardline>
|
|
189
|
+
<EnumMember name="One" />
|
|
190
|
+
<EnumMember name="Two" />
|
|
191
|
+
</List>
|
|
192
|
+
</EnumDeclaration>
|
|
193
|
+
<hbr />
|
|
194
|
+
<ClassDeclaration public name="TestInput" refkey={inputTypeRefkey} />
|
|
195
|
+
<hbr />
|
|
196
|
+
<ClassDeclaration
|
|
197
|
+
public
|
|
198
|
+
name="TestResult"
|
|
199
|
+
refkey={testResultTypeRefkey}
|
|
200
|
+
/>
|
|
201
|
+
<hbr />
|
|
202
|
+
<ClassDeclaration public name="TestClass">
|
|
203
|
+
<Field private name="MemberOne" type={enumTypeRefkey} />
|
|
183
204
|
<hbr />
|
|
184
|
-
<
|
|
205
|
+
<Method
|
|
185
206
|
public
|
|
186
|
-
name="
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
public
|
|
195
|
-
name="MethodOne"
|
|
196
|
-
parameters={params}
|
|
197
|
-
returns={testResultTypeRefkey}
|
|
198
|
-
>
|
|
199
|
-
return new {testResultTypeRefkey}();
|
|
200
|
-
</Method>
|
|
201
|
-
</ClassDeclaration>
|
|
202
|
-
</SourceFile>
|
|
203
|
-
</Namespace>
|
|
207
|
+
name="MethodOne"
|
|
208
|
+
parameters={params}
|
|
209
|
+
returns={testResultTypeRefkey}
|
|
210
|
+
>
|
|
211
|
+
return new {testResultTypeRefkey}();
|
|
212
|
+
</Method>
|
|
213
|
+
</ClassDeclaration>
|
|
214
|
+
</SourceFile>
|
|
204
215
|
</Output>,
|
|
205
216
|
);
|
|
206
217
|
|
|
207
218
|
expect(findFile(res, "Test.cs").contents).toBe(coretest.d`
|
|
208
|
-
|
|
219
|
+
public enum TestEnum
|
|
209
220
|
{
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
221
|
+
One,
|
|
222
|
+
Two
|
|
223
|
+
}
|
|
224
|
+
public class TestInput;
|
|
225
|
+
public class TestResult;
|
|
226
|
+
public class TestClass
|
|
227
|
+
{
|
|
228
|
+
private TestEnum _memberOne;
|
|
229
|
+
public TestResult MethodOne(int intParam, TestInput bodyParam)
|
|
218
230
|
{
|
|
219
|
-
|
|
220
|
-
public TestResult MethodOne(int intParam, TestInput bodyParam)
|
|
221
|
-
{
|
|
222
|
-
return new TestResult();
|
|
223
|
-
}
|
|
231
|
+
return new TestResult();
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
234
|
`);
|
|
@@ -241,27 +249,22 @@ describe("with type parameters", () => {
|
|
|
241
249
|
|
|
242
250
|
expect(
|
|
243
251
|
<TestNamespace>
|
|
244
|
-
<
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
>
|
|
250
|
-
<
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
</ClassDeclaration>
|
|
255
|
-
</SourceFile>
|
|
252
|
+
<ClassDeclaration
|
|
253
|
+
public
|
|
254
|
+
name="TestClass"
|
|
255
|
+
typeParameters={typeParameters}
|
|
256
|
+
>
|
|
257
|
+
<List>
|
|
258
|
+
<Property name="PropA" type={typeParameters[0].refkey} get set />
|
|
259
|
+
<Property name="PropB" type={typeParameters[1].refkey} get set />
|
|
260
|
+
</List>
|
|
261
|
+
</ClassDeclaration>
|
|
256
262
|
</TestNamespace>,
|
|
257
263
|
).toRenderTo(`
|
|
258
|
-
|
|
264
|
+
public class TestClass<T, U>
|
|
259
265
|
{
|
|
260
|
-
|
|
261
|
-
{
|
|
262
|
-
T PropA { get; set; }
|
|
263
|
-
U PropB { get; set; }
|
|
264
|
-
}
|
|
266
|
+
T PropA { get; set; }
|
|
267
|
+
U PropB { get; set; }
|
|
265
268
|
}
|
|
266
269
|
`);
|
|
267
270
|
});
|
|
@@ -290,10 +293,10 @@ describe("with type parameters", () => {
|
|
|
290
293
|
</TestNamespace>,
|
|
291
294
|
).toRenderTo(`
|
|
292
295
|
public class TestClass<T, U>
|
|
293
|
-
|
|
294
|
-
|
|
296
|
+
where T : IFoo
|
|
297
|
+
where U : IBar
|
|
295
298
|
{
|
|
296
|
-
|
|
299
|
+
// Body
|
|
297
300
|
}
|
|
298
301
|
`);
|
|
299
302
|
});
|
|
@@ -308,25 +311,24 @@ it("declares class with invalid members", () => {
|
|
|
308
311
|
);
|
|
309
312
|
|
|
310
313
|
expect(() => toSourceText(decl)).toThrow(
|
|
311
|
-
"
|
|
314
|
+
"EnumMember must be used within an EnumDeclaration.",
|
|
312
315
|
);
|
|
313
316
|
});
|
|
314
317
|
|
|
315
318
|
describe("constructor", () => {
|
|
316
319
|
it("declares with constructor", () => {
|
|
317
|
-
const
|
|
318
|
-
<
|
|
319
|
-
<
|
|
320
|
-
|
|
320
|
+
const tree = (
|
|
321
|
+
<TestNamespace>
|
|
322
|
+
<ClassDeclaration public name="TestClass">
|
|
323
|
+
<Constructor public />
|
|
324
|
+
</ClassDeclaration>
|
|
325
|
+
</TestNamespace>
|
|
321
326
|
);
|
|
322
327
|
|
|
323
|
-
expect(
|
|
324
|
-
|
|
328
|
+
expect(tree).toRenderTo(coretest.d`
|
|
329
|
+
public class TestClass
|
|
325
330
|
{
|
|
326
|
-
public
|
|
327
|
-
{
|
|
328
|
-
public TestClass() {}
|
|
329
|
-
}
|
|
331
|
+
public TestClass() {}
|
|
330
332
|
}
|
|
331
333
|
`);
|
|
332
334
|
});
|
|
@@ -350,33 +352,32 @@ describe("constructor", () => {
|
|
|
350
352
|
},
|
|
351
353
|
];
|
|
352
354
|
|
|
353
|
-
const
|
|
354
|
-
<
|
|
355
|
-
<
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
355
|
+
const tree = (
|
|
356
|
+
<TestNamespace>
|
|
357
|
+
<ClassDeclaration public name="TestClass">
|
|
358
|
+
<Field private name="name" type="string" refkey={thisNameRefkey} />
|
|
359
|
+
<hbr />
|
|
360
|
+
<Field private name="size" type="int" refkey={thisSizeRefkey} />
|
|
361
|
+
<hbr />
|
|
362
|
+
<Constructor public parameters={ctorParams}>
|
|
363
|
+
{thisNameRefkey} = {paramNameRefkey};<hbr />
|
|
364
|
+
{thisSizeRefkey} = {paramSizeRefkey};
|
|
365
|
+
</Constructor>
|
|
366
|
+
</ClassDeclaration>
|
|
367
|
+
</TestNamespace>
|
|
364
368
|
);
|
|
365
369
|
|
|
366
370
|
// TODO: assignments to members should have this. prefix
|
|
367
371
|
// e.g. this.name = name;
|
|
368
|
-
expect(
|
|
369
|
-
|
|
372
|
+
expect(tree).toRenderTo(coretest.d`
|
|
373
|
+
public class TestClass
|
|
370
374
|
{
|
|
371
|
-
|
|
375
|
+
private string _name;
|
|
376
|
+
private int _size;
|
|
377
|
+
public TestClass(string name, int size)
|
|
372
378
|
{
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
public TestClass(string name, int size)
|
|
376
|
-
{
|
|
377
|
-
_name = name;
|
|
378
|
-
_size = size;
|
|
379
|
-
}
|
|
379
|
+
_name = name;
|
|
380
|
+
_size = size;
|
|
380
381
|
}
|
|
381
382
|
}
|
|
382
383
|
`);
|
|
@@ -415,12 +416,9 @@ describe("constructor", () => {
|
|
|
415
416
|
</ClassDeclaration>
|
|
416
417
|
</Wrapper>,
|
|
417
418
|
).toRenderTo(`
|
|
418
|
-
|
|
419
|
+
public class TestClass(string name, int size)
|
|
419
420
|
{
|
|
420
|
-
|
|
421
|
-
{
|
|
422
|
-
string PrettyName { get; } = $"{name} {size}";
|
|
423
|
-
}
|
|
421
|
+
string PrettyName { get; } = $"{name} {size}";
|
|
424
422
|
}
|
|
425
423
|
`);
|
|
426
424
|
});
|
|
@@ -441,12 +439,9 @@ describe("constructor", () => {
|
|
|
441
439
|
</NamePolicyContext.Provider>
|
|
442
440
|
</Wrapper>,
|
|
443
441
|
).toRenderTo(`
|
|
444
|
-
|
|
442
|
+
public class TestClass(string name)
|
|
445
443
|
{
|
|
446
|
-
|
|
447
|
-
{
|
|
448
|
-
string name_2;
|
|
449
|
-
}
|
|
444
|
+
string name_2;
|
|
450
445
|
}
|
|
451
446
|
`);
|
|
452
447
|
});
|
|
@@ -474,8 +469,8 @@ it("supports class member doc comments", () => {
|
|
|
474
469
|
/// This is a test
|
|
475
470
|
class Test
|
|
476
471
|
{
|
|
477
|
-
|
|
478
|
-
|
|
472
|
+
/// This is a member
|
|
473
|
+
public int Member;
|
|
479
474
|
}
|
|
480
475
|
`);
|
|
481
476
|
});
|