@alloy-js/csharp 0.23.0-dev.0 → 0.23.0-dev.3
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/CHANGELOG.md +1 -14
- package/dist/src/components/access-expression/access-expression.d.ts +1 -1
- package/dist/src/components/access-expression/access-expression.d.ts.map +1 -1
- package/dist/src/components/enum/member.d.ts.map +1 -1
- package/dist/src/components/enum/member.js +2 -2
- package/dist/src/components/enum/member.js.map +1 -1
- package/dist/src/components/lexical-scope.d.ts.map +1 -1
- package/dist/src/components/lexical-scope.js +4 -3
- package/dist/src/components/lexical-scope.js.map +1 -1
- package/dist/src/components/method-scope.d.ts.map +1 -1
- package/dist/src/components/method-scope.js +4 -3
- package/dist/src/components/method-scope.js.map +1 -1
- package/dist/src/components/source-file/source-file.d.ts +2 -0
- package/dist/src/components/source-file/source-file.d.ts.map +1 -1
- package/dist/src/components/source-file/source-file.js +41 -3
- package/dist/src/components/source-file/source-file.js.map +1 -1
- package/dist/src/components/source-file/source-file.test.js +40 -1
- package/dist/src/components/source-file/source-file.test.js.map +1 -1
- package/dist/src/contexts/global-namespace.d.ts.map +1 -1
- package/dist/src/contexts/global-namespace.js +4 -4
- package/dist/src/contexts/global-namespace.js.map +1 -1
- package/dist/src/create-library.d.ts.map +1 -1
- package/dist/src/create-library.js +7 -7
- package/dist/src/create-library.js.map +1 -1
- package/dist/src/scopes/csharp.d.ts +1 -0
- package/dist/src/scopes/csharp.d.ts.map +1 -1
- package/dist/src/scopes/csharp.js +10 -0
- package/dist/src/scopes/csharp.js.map +1 -1
- package/dist/src/scopes/factories.d.ts.map +1 -1
- package/dist/src/scopes/factories.js +4 -3
- package/dist/src/scopes/factories.js.map +1 -1
- package/dist/src/scopes/namespace.js +2 -2
- package/dist/src/scopes/namespace.js.map +1 -1
- package/dist/src/symbols/csharp.d.ts +1 -0
- package/dist/src/symbols/csharp.d.ts.map +1 -1
- package/dist/src/symbols/csharp.js +19 -2
- package/dist/src/symbols/csharp.js.map +1 -1
- package/dist/src/symbols/factories.d.ts.map +1 -1
- package/dist/src/symbols/factories.js +42 -10
- package/dist/src/symbols/factories.js.map +1 -1
- package/dist/src/symbols/named-type.d.ts +1 -0
- package/dist/src/symbols/named-type.d.ts.map +1 -1
- package/dist/src/symbols/named-type.js +12 -1
- package/dist/src/symbols/named-type.js.map +1 -1
- package/dist/src/symbols/namespace.d.ts +1 -0
- package/dist/src/symbols/namespace.d.ts.map +1 -1
- package/dist/src/symbols/namespace.js +11 -1
- package/dist/src/symbols/namespace.js.map +1 -1
- package/dist/testing/create-wrapper.d.ts.map +1 -1
- package/dist/testing/create-wrapper.js +2 -1
- package/dist/testing/create-wrapper.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -7
- package/src/components/enum/member.tsx +16 -5
- package/src/components/lexical-scope.tsx +15 -4
- package/src/components/method-scope.tsx +15 -4
- package/src/components/source-file/source-file.test.tsx +35 -1
- package/src/components/source-file/source-file.tsx +44 -2
- package/src/contexts/global-namespace.ts +11 -6
- package/src/create-library.ts +18 -9
- package/src/scopes/csharp.ts +11 -0
- package/src/scopes/factories.ts +4 -4
- package/src/scopes/namespace.ts +2 -2
- package/src/symbols/csharp.ts +20 -1
- package/src/symbols/factories.ts +46 -34
- package/src/symbols/named-type.ts +15 -3
- package/src/symbols/namespace.ts +12 -2
- package/temp/api.json +196 -234
- package/testing/create-wrapper.tsx +2 -1
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/csharp",
|
|
3
|
-
"version": "0.23.0-dev.
|
|
3
|
+
"version": "0.23.0-dev.3",
|
|
4
4
|
"description": "Alloy components for CSharp language.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/alloy-framework/alloy.git"
|
|
8
|
+
},
|
|
5
9
|
"exports": {
|
|
6
10
|
".": {
|
|
7
11
|
"import": "./dist/src/index.js"
|
|
@@ -32,23 +36,23 @@
|
|
|
32
36
|
"author": "jhendrix@microsoft.com",
|
|
33
37
|
"license": "MIT",
|
|
34
38
|
"dependencies": {
|
|
35
|
-
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.
|
|
36
|
-
"@alloy-js/msbuild": "~0.22.0 || >= 0.23.0-dev.
|
|
39
|
+
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.8",
|
|
40
|
+
"@alloy-js/msbuild": "~0.22.0 || >= 0.23.0-dev.1",
|
|
37
41
|
"change-case": "^5.4.4",
|
|
38
42
|
"marked": "^16.1.1",
|
|
39
43
|
"pathe": "^2.0.3"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.
|
|
43
|
-
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.
|
|
44
|
-
"@alloy-js/typescript": "~0.22.0 || >= 0.23.0-dev.
|
|
46
|
+
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.3",
|
|
47
|
+
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.1",
|
|
48
|
+
"@alloy-js/typescript": "~0.22.0 || >= 0.23.0-dev.4",
|
|
45
49
|
"@microsoft/api-extractor": "~7.52.8",
|
|
46
50
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
47
51
|
"@types/js-yaml": "^4.0.9",
|
|
48
52
|
"concurrently": "^9.2.0",
|
|
49
53
|
"js-yaml": "^4.1.0",
|
|
50
54
|
"typescript": "^5.8.3",
|
|
51
|
-
"vitest": "
|
|
55
|
+
"vitest": "3.2.4"
|
|
52
56
|
},
|
|
53
57
|
"type": "module",
|
|
54
58
|
"scripts": {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createSymbol,
|
|
3
|
+
MemberDeclaration,
|
|
4
|
+
MemberName,
|
|
5
|
+
Namekey,
|
|
6
|
+
Refkey,
|
|
7
|
+
} from "@alloy-js/core";
|
|
2
8
|
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
3
9
|
import { useNamedTypeScope } from "../../scopes/contexts.js";
|
|
4
10
|
import { CSharpSymbol } from "../../symbols/csharp.js";
|
|
@@ -23,10 +29,15 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
23
29
|
throw new Error("EnumMember must be used within an EnumDeclaration.");
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
const thisEnumValueSymbol =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const thisEnumValueSymbol = createSymbol(
|
|
33
|
+
CSharpSymbol,
|
|
34
|
+
props.name,
|
|
35
|
+
symbol.members,
|
|
36
|
+
{
|
|
37
|
+
refkeys: props.refkey,
|
|
38
|
+
namePolicy: useCSharpNamePolicy().for("enum-member"),
|
|
39
|
+
},
|
|
40
|
+
);
|
|
30
41
|
|
|
31
42
|
return (
|
|
32
43
|
<MemberDeclaration symbol={thisEnumValueSymbol}>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Scope,
|
|
3
|
+
ScopePropsWithInfo,
|
|
4
|
+
ScopePropsWithValue,
|
|
5
|
+
createScope,
|
|
6
|
+
} from "@alloy-js/core";
|
|
2
7
|
import { useCSharpScope } from "../scopes/contexts.js";
|
|
3
8
|
import { CSharpLexicalScope } from "../scopes/lexical.js";
|
|
4
9
|
|
|
@@ -20,9 +25,15 @@ export function LexicalScope(props: LexicalScopeProps) {
|
|
|
20
25
|
scope = props.value;
|
|
21
26
|
} else {
|
|
22
27
|
const parentScope = useCSharpScope();
|
|
23
|
-
scope =
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
scope = createScope(
|
|
29
|
+
CSharpLexicalScope,
|
|
30
|
+
props.name ?? "lexical scope",
|
|
31
|
+
parentScope,
|
|
32
|
+
{
|
|
33
|
+
...props,
|
|
34
|
+
binder: parentScope?.binder,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
return <Scope value={scope}>{props.children}</Scope>;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Scope,
|
|
3
|
+
ScopePropsWithInfo,
|
|
4
|
+
ScopePropsWithValue,
|
|
5
|
+
createScope,
|
|
6
|
+
} from "@alloy-js/core";
|
|
2
7
|
import { useCSharpScope } from "../scopes/contexts.js";
|
|
3
8
|
import { CSharpMethodScope } from "../scopes/method.js";
|
|
4
9
|
|
|
@@ -18,9 +23,15 @@ export function MethodScope(props: MethodScopeProps) {
|
|
|
18
23
|
scope = props.value;
|
|
19
24
|
} else {
|
|
20
25
|
const parentScope = useCSharpScope();
|
|
21
|
-
scope =
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
scope = createScope(
|
|
27
|
+
CSharpMethodScope,
|
|
28
|
+
props.name ?? "method scope",
|
|
29
|
+
parentScope,
|
|
30
|
+
{
|
|
31
|
+
...props,
|
|
32
|
+
binder: parentScope?.binder,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
return <Scope value={scope}>{props.children}</Scope>;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { Attribute } from "#components/attributes/attributes.jsx";
|
|
1
2
|
import { ClassDeclaration } from "#components/class/declaration.jsx";
|
|
2
3
|
import { Namespace } from "#components/namespace/namespace.jsx";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
FormatOptions,
|
|
7
|
+
Indent,
|
|
8
|
+
List,
|
|
9
|
+
Output,
|
|
10
|
+
Prose,
|
|
11
|
+
} from "@alloy-js/core";
|
|
12
|
+
import { Serialization } from "@alloy-js/csharp/global/System/Text/Json";
|
|
4
13
|
import { describe, expect, it } from "vitest";
|
|
5
14
|
import { CSharpFormatOptions } from "../../contexts/format-options.js";
|
|
6
15
|
import { SourceFile } from "./source-file.jsx";
|
|
@@ -93,4 +102,29 @@ describe("format options", () => {
|
|
|
93
102
|
indented 3 spaces
|
|
94
103
|
`);
|
|
95
104
|
});
|
|
105
|
+
|
|
106
|
+
it("respect docComment and using (and docComment before using)", () => {
|
|
107
|
+
expect(
|
|
108
|
+
<Output>
|
|
109
|
+
<SourceFile
|
|
110
|
+
path="Test1.cs"
|
|
111
|
+
headerComment={"This is a file comment"}
|
|
112
|
+
header={<Prose>// ---------Some Fake Heder-----------</Prose>}
|
|
113
|
+
>
|
|
114
|
+
<List>
|
|
115
|
+
<Attribute name={Serialization.JsonConverterAttribute} />
|
|
116
|
+
<ClassDeclaration public name="TestClass1" />
|
|
117
|
+
</List>
|
|
118
|
+
</SourceFile>
|
|
119
|
+
</Output>,
|
|
120
|
+
).toRenderTo(`
|
|
121
|
+
/// This is a file comment
|
|
122
|
+
// ---------Some Fake Heder-----------
|
|
123
|
+
|
|
124
|
+
using System.Text.Json.Serialization;
|
|
125
|
+
|
|
126
|
+
[JsonConverter]
|
|
127
|
+
public class TestClass1;
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
96
130
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DocComment } from "#components/doc/comment.jsx";
|
|
1
2
|
import { NamespaceScopes } from "#components/namespace-scopes.jsx";
|
|
2
3
|
import { NamespaceName } from "#components/namespace/namespace-name.jsx";
|
|
3
4
|
import { Reference } from "#components/Reference.jsx";
|
|
@@ -7,7 +8,10 @@ import {
|
|
|
7
8
|
Children,
|
|
8
9
|
computed,
|
|
9
10
|
SourceFile as CoreSourceFile,
|
|
11
|
+
createScope,
|
|
12
|
+
List,
|
|
10
13
|
Scope,
|
|
14
|
+
Show,
|
|
11
15
|
useBinder,
|
|
12
16
|
} from "@alloy-js/core";
|
|
13
17
|
import {
|
|
@@ -34,14 +38,26 @@ export interface SourceFileProps extends CSharpFormatOptions {
|
|
|
34
38
|
* explicit usings is not necessary when referencing symbols via refkeys.
|
|
35
39
|
*/
|
|
36
40
|
using?: string[];
|
|
41
|
+
/* * Optional header content to include at the top of the file */
|
|
42
|
+
header?: Children;
|
|
43
|
+
/* * Optional doc comment to include at the top of the file, this will be before 'header' if both are provided */
|
|
44
|
+
headerComment?: string;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
/** A C# source file exists within the context of a namespace contains using statements and declarations */
|
|
40
48
|
export function SourceFile(props: SourceFileProps) {
|
|
41
|
-
const
|
|
49
|
+
const binder = useBinder();
|
|
50
|
+
const sourceFileScope = createScope(
|
|
51
|
+
CSharpSourceFileScope,
|
|
52
|
+
props.path,
|
|
53
|
+
undefined,
|
|
54
|
+
{
|
|
55
|
+
binder,
|
|
56
|
+
},
|
|
57
|
+
);
|
|
42
58
|
|
|
43
59
|
const nsContext = useNamespaceContext();
|
|
44
|
-
const globalNs = getGlobalNamespace(
|
|
60
|
+
const globalNs = getGlobalNamespace(binder);
|
|
45
61
|
const nsSymbol = nsContext ? nsContext.symbol : globalNs;
|
|
46
62
|
const usings = computed(() => {
|
|
47
63
|
return (
|
|
@@ -59,12 +75,21 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
59
75
|
useTabs: props.useTabs,
|
|
60
76
|
});
|
|
61
77
|
|
|
78
|
+
const header =
|
|
79
|
+
props.header || props.headerComment ?
|
|
80
|
+
<SourceFileHeader
|
|
81
|
+
header={props.header}
|
|
82
|
+
headerComment={props.headerComment}
|
|
83
|
+
/>
|
|
84
|
+
: undefined;
|
|
85
|
+
|
|
62
86
|
return (
|
|
63
87
|
<CoreSourceFile
|
|
64
88
|
path={props.path}
|
|
65
89
|
filetype="cs"
|
|
66
90
|
reference={Reference}
|
|
67
91
|
{...opts}
|
|
92
|
+
header={header}
|
|
68
93
|
>
|
|
69
94
|
<Scope value={sourceFileScope}>
|
|
70
95
|
{(sourceFileScope.usings.size > 0 ||
|
|
@@ -96,3 +121,20 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
96
121
|
</CoreSourceFile>
|
|
97
122
|
);
|
|
98
123
|
}
|
|
124
|
+
|
|
125
|
+
interface SourceFileHeaderProps {
|
|
126
|
+
header?: Children;
|
|
127
|
+
headerComment?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function SourceFileHeader(props: SourceFileHeaderProps) {
|
|
131
|
+
return (
|
|
132
|
+
<List>
|
|
133
|
+
<Show when={props.headerComment !== undefined}>
|
|
134
|
+
<DocComment>{props.headerComment}</DocComment>
|
|
135
|
+
</Show>
|
|
136
|
+
<Show when={props.header !== undefined}>{props.header}</Show>
|
|
137
|
+
<hbr />
|
|
138
|
+
</List>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Binder, useBinder } from "@alloy-js/core";
|
|
1
|
+
import { Binder, createSymbol, useBinder } from "@alloy-js/core";
|
|
2
2
|
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
3
3
|
|
|
4
4
|
export function useGlobalNamespace() {
|
|
@@ -7,12 +7,17 @@ export function useGlobalNamespace() {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const globalNamespaces = new WeakMap<Binder, NamespaceSymbol>();
|
|
10
|
-
let defaultGlobalNamespace =
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
let defaultGlobalNamespace = createSymbol(
|
|
11
|
+
NamespaceSymbol,
|
|
12
|
+
"global",
|
|
13
|
+
undefined,
|
|
14
|
+
{
|
|
15
|
+
isGlobal: true,
|
|
16
|
+
},
|
|
17
|
+
);
|
|
13
18
|
|
|
14
19
|
export function resetGlobalNamespace() {
|
|
15
|
-
defaultGlobalNamespace =
|
|
20
|
+
defaultGlobalNamespace = createSymbol(NamespaceSymbol, "global", undefined, {
|
|
16
21
|
isGlobal: true,
|
|
17
22
|
});
|
|
18
23
|
}
|
|
@@ -25,7 +30,7 @@ export function getGlobalNamespace(binder: Binder | undefined) {
|
|
|
25
30
|
let namespace = globalNamespaces.get(binder);
|
|
26
31
|
|
|
27
32
|
if (!namespace) {
|
|
28
|
-
namespace =
|
|
33
|
+
namespace = createSymbol(NamespaceSymbol, "global", undefined, {
|
|
29
34
|
binder,
|
|
30
35
|
isGlobal: true,
|
|
31
36
|
});
|
package/src/create-library.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Binder,
|
|
3
|
+
createSymbol,
|
|
3
4
|
LibrarySymbolReference,
|
|
4
5
|
namekey,
|
|
5
6
|
refkey,
|
|
@@ -124,10 +125,15 @@ export function createLibrary<T extends Record<string, Descriptor>>(
|
|
|
124
125
|
name,
|
|
125
126
|
)! as NamespaceSymbol;
|
|
126
127
|
} else {
|
|
127
|
-
ownerSymbol =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
ownerSymbol = createSymbol(
|
|
129
|
+
NamespaceSymbol,
|
|
130
|
+
namekey(name),
|
|
131
|
+
ownerSymbol!,
|
|
132
|
+
{
|
|
133
|
+
binder,
|
|
134
|
+
refkeys: refkey(),
|
|
135
|
+
},
|
|
136
|
+
);
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
|
|
@@ -214,7 +220,8 @@ function createSymbolFromDescriptor(
|
|
|
214
220
|
if (ownerSymbol.members.symbolNames.has(name)) {
|
|
215
221
|
return ownerSymbol.members.symbolNames.get(name)! as NamespaceSymbol;
|
|
216
222
|
}
|
|
217
|
-
return
|
|
223
|
+
return createSymbol(
|
|
224
|
+
NamespaceSymbol,
|
|
218
225
|
namekey(name),
|
|
219
226
|
ownerSymbol as NamespaceSymbol,
|
|
220
227
|
{
|
|
@@ -228,7 +235,8 @@ function createSymbolFromDescriptor(
|
|
|
228
235
|
case "interface":
|
|
229
236
|
case "struct":
|
|
230
237
|
case "record":
|
|
231
|
-
return
|
|
238
|
+
return createSymbol(
|
|
239
|
+
NamedTypeSymbol,
|
|
232
240
|
namekey(name),
|
|
233
241
|
ownerSymbol.members,
|
|
234
242
|
descriptor.kind,
|
|
@@ -239,7 +247,8 @@ function createSymbolFromDescriptor(
|
|
|
239
247
|
},
|
|
240
248
|
);
|
|
241
249
|
case "method":
|
|
242
|
-
return
|
|
250
|
+
return createSymbol(
|
|
251
|
+
MethodSymbol,
|
|
243
252
|
namekey(name),
|
|
244
253
|
ownerSymbol.members,
|
|
245
254
|
descriptor.methodKind,
|
|
@@ -250,7 +259,7 @@ function createSymbolFromDescriptor(
|
|
|
250
259
|
);
|
|
251
260
|
case "field":
|
|
252
261
|
case "property":
|
|
253
|
-
return
|
|
262
|
+
return createSymbol(CSharpSymbol, namekey(name), ownerSymbol.members, {
|
|
254
263
|
binder,
|
|
255
264
|
refkeys: refkey(),
|
|
256
265
|
type:
|
|
@@ -262,7 +271,7 @@ function createSymbolFromDescriptor(
|
|
|
262
271
|
lazyMemberInitializer,
|
|
263
272
|
});
|
|
264
273
|
case "generic":
|
|
265
|
-
return
|
|
274
|
+
return createSymbol(CSharpSymbol, namekey(name), ownerSymbol.members, {
|
|
266
275
|
binder,
|
|
267
276
|
refkeys: refkey(),
|
|
268
277
|
});
|
package/src/scopes/csharp.ts
CHANGED
|
@@ -20,4 +20,15 @@ export class CSharpScope extends OutputScope {
|
|
|
20
20
|
get ownerSymbol(): CSharpSymbol | undefined {
|
|
21
21
|
return super.ownerSymbol as CSharpSymbol | undefined;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
override get debugInfo(): Record<string, unknown> {
|
|
25
|
+
const info = super.debugInfo;
|
|
26
|
+
if (this.enclosingNamespace) {
|
|
27
|
+
return {
|
|
28
|
+
...info,
|
|
29
|
+
enclosingNamespace: this.enclosingNamespace.name,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return info;
|
|
33
|
+
}
|
|
23
34
|
}
|
package/src/scopes/factories.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutputScopeOptions } from "@alloy-js/core";
|
|
1
|
+
import { OutputScopeOptions, createScope } from "@alloy-js/core";
|
|
2
2
|
import { NamedTypeSymbol } from "../symbols/named-type.js";
|
|
3
3
|
import { CSharpClassScope } from "./class.js";
|
|
4
4
|
import { useCSharpScope, useNamedTypeScope } from "./contexts.js";
|
|
@@ -21,7 +21,7 @@ export function createNamedTypeScope(
|
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
return
|
|
24
|
+
return createScope(CSharpNamedTypeScope, ownerSymbol, currentScope, options);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function createClassScope(
|
|
@@ -37,9 +37,9 @@ export function createClassScope(
|
|
|
37
37
|
"Can't create C# class scope inside of " + currentScope.constructor.name,
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return createScope(CSharpClassScope, ownerSymbol, currentScope, options);
|
|
41
41
|
}
|
|
42
42
|
export function createMethodScope(options: OutputScopeOptions = {}) {
|
|
43
43
|
const parentScope = useNamedTypeScope();
|
|
44
|
-
return
|
|
44
|
+
return createScope(CSharpMethodScope, "method scope", parentScope, options);
|
|
45
45
|
}
|
package/src/scopes/namespace.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutputScope, useScope } from "@alloy-js/core";
|
|
1
|
+
import { OutputScope, createScope, useScope } from "@alloy-js/core";
|
|
2
2
|
import type { NamespaceSymbol } from "../symbols/namespace.js";
|
|
3
3
|
import { CSharpNamedTypeScope } from "./named-type.js";
|
|
4
4
|
import { CSharpSourceFileScope } from "./source-file.js";
|
|
@@ -32,7 +32,7 @@ export function createCSharpNamespaceScope(namespaceSymbol: NamespaceSymbol) {
|
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const scope =
|
|
35
|
+
const scope = createScope(CSharpNamespaceScope, namespaceSymbol, parentScope);
|
|
36
36
|
|
|
37
37
|
return scope;
|
|
38
38
|
}
|
package/src/symbols/csharp.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createSymbol,
|
|
2
3
|
Namekey,
|
|
3
4
|
OutputDeclarationSpace,
|
|
4
5
|
OutputMemberSpace,
|
|
@@ -128,8 +129,10 @@ export class CSharpSymbol extends OutputSymbol {
|
|
|
128
129
|
|
|
129
130
|
copy() {
|
|
130
131
|
const options = this.getCopyOptions();
|
|
131
|
-
const
|
|
132
|
+
const binder = this.binder;
|
|
133
|
+
const copy = createSymbol(CSharpSymbol, this.name, undefined, {
|
|
132
134
|
...options,
|
|
135
|
+
binder,
|
|
133
136
|
accessibility: this.#accessibility,
|
|
134
137
|
isStatic: this.#isStatic,
|
|
135
138
|
isVirtual: this.#isVirtual,
|
|
@@ -151,6 +154,22 @@ export class CSharpSymbol extends OutputSymbol {
|
|
|
151
154
|
return copy;
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
override get debugInfo(): Record<string, unknown> {
|
|
158
|
+
return {
|
|
159
|
+
...super.debugInfo,
|
|
160
|
+
kind: this.symbolKind,
|
|
161
|
+
accessibility: this.accessibility,
|
|
162
|
+
isAbstract: this.isAbstract,
|
|
163
|
+
isVirtual: this.isVirtual,
|
|
164
|
+
isOverride: this.isOverride,
|
|
165
|
+
isStatic: this.isStatic,
|
|
166
|
+
isSealed: this.isSealed,
|
|
167
|
+
isExtern: this.isExtern,
|
|
168
|
+
isReadOnly: this.isReadOnly,
|
|
169
|
+
isNullable: this.isNullable,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
154
173
|
/**
|
|
155
174
|
* Whether this symbol is static.
|
|
156
175
|
*/
|
package/src/symbols/factories.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createSymbol,
|
|
2
3
|
Namekey,
|
|
3
4
|
NamePolicyGetter,
|
|
4
5
|
onCleanup,
|
|
@@ -37,11 +38,11 @@ export function createParameterSymbol(
|
|
|
37
38
|
`Can't create parameter symbol outside of a method or class scope.`,
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
);
|
|
41
|
+
const binder = options.binder ?? scope.binder;
|
|
42
|
+
return createSymbol(CSharpSymbol, originalName, scope.parameters, {
|
|
43
|
+
...withNamePolicy(options, "parameter"),
|
|
44
|
+
binder,
|
|
45
|
+
});
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export interface CreateTypeParameterSymbolOptions extends CSharpSymbolOptions {
|
|
@@ -61,11 +62,11 @@ export function createTypeParameterSymbol(
|
|
|
61
62
|
);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
65
|
+
const binder = options.binder ?? scope.binder;
|
|
66
|
+
return createSymbol(CSharpSymbol, originalName, scope.typeParameters, {
|
|
67
|
+
...withNamePolicy(options, "type-parameter"),
|
|
68
|
+
binder,
|
|
69
|
+
});
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
export function createFieldSymbol(
|
|
@@ -91,11 +92,11 @@ export function createFieldSymbol(
|
|
|
91
92
|
throw new Error(`Can't define a field outside of a class or struct.`);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
);
|
|
95
|
+
const binder = options.binder ?? scope.binder;
|
|
96
|
+
return createSymbol(CSharpSymbol, originalName, scope.members, {
|
|
97
|
+
...withNamePolicy(options, nameElement),
|
|
98
|
+
binder,
|
|
99
|
+
});
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function withCleanup<T extends CSharpSymbol>(sym: T): T {
|
|
@@ -111,8 +112,12 @@ export function createNamedTypeSymbol(
|
|
|
111
112
|
options?: OutputSymbolOptions,
|
|
112
113
|
) {
|
|
113
114
|
const scope = useNamedTypeScope();
|
|
115
|
+
const binder = options?.binder ?? scope.ownerSymbol.binder;
|
|
114
116
|
return withCleanup(
|
|
115
|
-
|
|
117
|
+
createSymbol(NamedTypeSymbol, name, scope.ownerSymbol.members, kind, {
|
|
118
|
+
...options,
|
|
119
|
+
binder,
|
|
120
|
+
}),
|
|
116
121
|
);
|
|
117
122
|
}
|
|
118
123
|
|
|
@@ -121,7 +126,9 @@ export function createNamespaceSymbol(
|
|
|
121
126
|
options: CSharpSymbolOptions = {},
|
|
122
127
|
): NamespaceSymbol {
|
|
123
128
|
const scope = useNamespaceContext();
|
|
124
|
-
const parentSymbol =
|
|
129
|
+
const parentSymbol =
|
|
130
|
+
scope?.symbol ??
|
|
131
|
+
getGlobalNamespace(options.binder ?? scope?.symbol?.binder ?? useBinder());
|
|
125
132
|
const names = normalizeNamespaceName(name);
|
|
126
133
|
let current = parentSymbol;
|
|
127
134
|
for (const name of names) {
|
|
@@ -155,12 +162,12 @@ function createNamespaceSymbolInternal(
|
|
|
155
162
|
expectedName,
|
|
156
163
|
)! as NamespaceSymbol;
|
|
157
164
|
}
|
|
165
|
+
const binder = options.binder ?? parentSymbol.binder;
|
|
158
166
|
return withCleanup(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
),
|
|
167
|
+
createSymbol(NamespaceSymbol, name, parentSymbol, {
|
|
168
|
+
...withNamePolicy(options, "namespace"),
|
|
169
|
+
binder,
|
|
170
|
+
}),
|
|
164
171
|
);
|
|
165
172
|
}
|
|
166
173
|
|
|
@@ -184,12 +191,17 @@ export function createMethodSymbol(
|
|
|
184
191
|
);
|
|
185
192
|
}
|
|
186
193
|
|
|
194
|
+
const binder = options.binder ?? scope.binder;
|
|
187
195
|
return withCleanup(
|
|
188
|
-
|
|
196
|
+
createSymbol(
|
|
197
|
+
MethodSymbol,
|
|
189
198
|
originalName,
|
|
190
199
|
scope.members,
|
|
191
200
|
options.methodKind ?? "ordinary",
|
|
192
|
-
|
|
201
|
+
{
|
|
202
|
+
...withNamePolicy(options, "class-method"),
|
|
203
|
+
binder,
|
|
204
|
+
},
|
|
193
205
|
),
|
|
194
206
|
);
|
|
195
207
|
}
|
|
@@ -199,12 +211,12 @@ export function createPropertySymbol(
|
|
|
199
211
|
options: CSharpSymbolOptions,
|
|
200
212
|
) {
|
|
201
213
|
const scope = useNamedTypeScope();
|
|
214
|
+
const binder = options.binder ?? scope.binder;
|
|
202
215
|
return withCleanup(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
),
|
|
216
|
+
createSymbol(CSharpSymbol, name, scope.members, {
|
|
217
|
+
...withNamePolicy(options, "class-property"),
|
|
218
|
+
binder,
|
|
219
|
+
}),
|
|
208
220
|
);
|
|
209
221
|
}
|
|
210
222
|
|
|
@@ -232,12 +244,12 @@ export function createVariableSymbol(
|
|
|
232
244
|
`Can't create variable symbol outside of a lexical scope, got a ${scope.constructor.name}.`,
|
|
233
245
|
);
|
|
234
246
|
}
|
|
247
|
+
const binder = options.binder ?? scope.binder;
|
|
235
248
|
return withCleanup(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
),
|
|
249
|
+
createSymbol(CSharpSymbol, originalName, scope.localVariables, {
|
|
250
|
+
...withNamePolicy(options, "variable"),
|
|
251
|
+
binder,
|
|
252
|
+
}),
|
|
241
253
|
);
|
|
242
254
|
}
|
|
243
255
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Namekey, OutputSpace } from "@alloy-js/core";
|
|
1
|
+
import { Namekey, OutputSpace, createSymbol } from "@alloy-js/core";
|
|
2
2
|
import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
|
|
3
3
|
|
|
4
4
|
// represents a symbol from a .cs file. Class, enum, interface etc.
|
|
@@ -38,11 +38,16 @@ export class NamedTypeSymbol extends CSharpSymbol {
|
|
|
38
38
|
|
|
39
39
|
copy() {
|
|
40
40
|
const options = this.getCopyOptions();
|
|
41
|
-
const
|
|
41
|
+
const binder = this.binder;
|
|
42
|
+
const copy = createSymbol(
|
|
43
|
+
NamedTypeSymbol,
|
|
42
44
|
this.name,
|
|
43
45
|
undefined,
|
|
44
46
|
this.#typeKind,
|
|
45
|
-
|
|
47
|
+
{
|
|
48
|
+
...options,
|
|
49
|
+
binder,
|
|
50
|
+
},
|
|
46
51
|
);
|
|
47
52
|
this.initializeCopy(copy);
|
|
48
53
|
return copy;
|
|
@@ -51,4 +56,11 @@ export class NamedTypeSymbol extends CSharpSymbol {
|
|
|
51
56
|
get members() {
|
|
52
57
|
return this.memberSpaceFor("members")!;
|
|
53
58
|
}
|
|
59
|
+
|
|
60
|
+
override get debugInfo(): Record<string, unknown> {
|
|
61
|
+
return {
|
|
62
|
+
...super.debugInfo,
|
|
63
|
+
typeKind: this.typeKind,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
54
66
|
}
|