@alloy-js/csharp 0.16.0 → 0.17.0
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 +4 -0
- package/dist/src/components/Class.d.ts.map +1 -1
- package/dist/src/components/Class.js +21 -21
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +4 -2
- package/dist/src/components/Enum.d.ts.map +1 -1
- package/dist/src/components/Enum.js +11 -9
- package/dist/src/components/Namespace.d.ts.map +1 -1
- package/dist/src/components/Namespace.js +2 -2
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +3 -3
- package/dist/src/symbols/csharp-output-symbol.d.ts +4 -4
- package/dist/src/symbols/csharp-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/csharp-output-symbol.js +13 -13
- package/dist/src/symbols/scopes.d.ts +6 -8
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/scopes.js +14 -19
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/Class.tsx +21 -37
- package/src/components/Declaration.tsx +5 -2
- package/src/components/Enum.tsx +21 -24
- package/src/components/Namespace.tsx +2 -6
- package/src/components/Parameters.tsx +2 -3
- package/src/symbols/csharp-output-symbol.ts +13 -18
- package/src/symbols/reference.ts +1 -1
- package/src/symbols/scopes.ts +15 -34
- package/temp/api.json +131 -287
- package/tsdoc-metadata.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import {
|
|
2
|
+
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
3
3
|
|
|
4
4
|
// properties for creating a declaration
|
|
5
5
|
export interface DeclarationProps {
|
|
@@ -10,6 +10,9 @@ export interface DeclarationProps {
|
|
|
10
10
|
|
|
11
11
|
// declares a symbol in the program (class, enum, interface etc)
|
|
12
12
|
export function Declaration(props: DeclarationProps) {
|
|
13
|
-
const sym =
|
|
13
|
+
const sym = new CSharpOutputSymbol(props.name, {
|
|
14
|
+
refkeys: props.refkey,
|
|
15
|
+
});
|
|
16
|
+
|
|
14
17
|
return <core.Declaration symbol={sym}>{props.children}</core.Declaration>;
|
|
15
18
|
}
|
package/src/components/Enum.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import * as core from "@alloy-js/core";
|
|
|
2
2
|
import { AccessModifier, getAccessModifier } from "../modifiers.js";
|
|
3
3
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
4
4
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
5
|
-
import {
|
|
5
|
+
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
6
6
|
import { Name } from "./Name.jsx";
|
|
7
7
|
|
|
8
8
|
// properties for creating an enum
|
|
@@ -18,34 +18,32 @@ export function Enum(props: EnumProps) {
|
|
|
18
18
|
const name = useCSharpNamePolicy().getName(props.name!, "enum");
|
|
19
19
|
const scope = useCSharpScope();
|
|
20
20
|
|
|
21
|
-
const thisEnumSymbol =
|
|
22
|
-
name: name,
|
|
21
|
+
const thisEnumSymbol = new CSharpOutputSymbol(name, {
|
|
23
22
|
scope,
|
|
24
|
-
|
|
23
|
+
refkeys: props.refkey ?? core.refkey(props.name),
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
// this creates a new scope for the enum definition.
|
|
28
27
|
// members will automatically "inherit" this scope so
|
|
29
28
|
// that refkeys to them will produce the fully-qualified
|
|
30
29
|
// name e.g. Foo.Bar.
|
|
31
|
-
const thisEnumScope =
|
|
32
|
-
scope
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"enum-decl",
|
|
36
|
-
);
|
|
30
|
+
const thisEnumScope = new CSharpMemberScope("enum-decl", {
|
|
31
|
+
parent: scope,
|
|
32
|
+
owner: thisEnumSymbol,
|
|
33
|
+
});
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<core.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
if (thisEnumScope.owner)
|
|
36
|
+
return (
|
|
37
|
+
<core.Declaration symbol={thisEnumSymbol}>
|
|
38
|
+
{getAccessModifier(props.accessModifier)}enum <Name />
|
|
39
|
+
{!props.children && ";"}
|
|
40
|
+
{props.children && (
|
|
41
|
+
<core.Scope value={thisEnumScope}>
|
|
42
|
+
<core.Block newline>{props.children}</core.Block>
|
|
43
|
+
</core.Scope>
|
|
44
|
+
)}
|
|
45
|
+
</core.Declaration>
|
|
46
|
+
);
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
// properties for creating a C# enum member
|
|
@@ -64,10 +62,9 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
const name = useCSharpNamePolicy().getName(props.name, "enum-member");
|
|
67
|
-
const thisEnumValueSymbol =
|
|
68
|
-
name: name,
|
|
65
|
+
const thisEnumValueSymbol = new CSharpOutputSymbol(name, {
|
|
69
66
|
scope,
|
|
70
|
-
|
|
67
|
+
refkeys: props.refkey ?? core.refkey(props.name),
|
|
71
68
|
});
|
|
72
69
|
|
|
73
70
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import {
|
|
2
|
+
import { CSharpNamespaceScope } from "../symbols/scopes.js";
|
|
3
3
|
|
|
4
4
|
// contains the info for the current namespace
|
|
5
5
|
export interface NamespaceContext {
|
|
@@ -21,11 +21,7 @@ export interface NamespaceProps {
|
|
|
21
21
|
|
|
22
22
|
// a C# namespace. contains one or more source files
|
|
23
23
|
export function Namespace(props: NamespaceProps) {
|
|
24
|
-
const scope =
|
|
25
|
-
core.useBinder(),
|
|
26
|
-
core.useScope(),
|
|
27
|
-
props.name,
|
|
28
|
-
);
|
|
24
|
+
const scope = new CSharpNamespaceScope(props.name);
|
|
29
25
|
|
|
30
26
|
const namespaceCtx: NamespaceContext = {
|
|
31
27
|
name: props.name,
|
|
@@ -24,10 +24,9 @@ export function Parameter(props: ParameterProps) {
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const memberSymbol =
|
|
28
|
-
name: name,
|
|
27
|
+
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
29
28
|
scope,
|
|
30
|
-
|
|
29
|
+
refkeys: props.refkey ?? core.refkey(props.name),
|
|
31
30
|
});
|
|
32
31
|
|
|
33
32
|
return (
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import { DeclarationProps } from "../components/Declaration.jsx";
|
|
3
2
|
import { useNamespace } from "../components/Namespace.jsx";
|
|
4
3
|
import { CSharpOutputScope } from "./scopes.js";
|
|
5
4
|
|
|
6
5
|
// represents a symbol from a .cs file. Class, enum, interface etc.
|
|
7
|
-
export interface CSharpOutputSymbol extends core.OutputSymbol {
|
|
8
|
-
scope: CSharpOutputScope;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// creates a new C# symbol
|
|
12
|
-
export function createCSharpSymbol(props: DeclarationProps) {
|
|
13
|
-
const scope = core.useScope() as CSharpOutputScope;
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
|
27
22
|
}
|
package/src/symbols/reference.ts
CHANGED
package/src/symbols/scopes.ts
CHANGED
|
@@ -2,21 +2,10 @@ import * as core from "@alloy-js/core";
|
|
|
2
2
|
import { CSharpOutputSymbol } from "./csharp-output-symbol.js";
|
|
3
3
|
|
|
4
4
|
// indicates that the scope for a symbols is at the namespace level
|
|
5
|
-
export
|
|
6
|
-
kind
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// creates a new namespace scope
|
|
10
|
-
export function createCSharpNamespaceScope(
|
|
11
|
-
binder: core.Binder,
|
|
12
|
-
parent: core.OutputScope | undefined,
|
|
13
|
-
name: string,
|
|
14
|
-
): CSharpNamespaceScope {
|
|
15
|
-
return binder.createScope<CSharpNamespaceScope>({
|
|
16
|
-
kind: "namespace",
|
|
17
|
-
name,
|
|
18
|
-
parent,
|
|
19
|
-
});
|
|
5
|
+
export class CSharpNamespaceScope extends core.OutputScope {
|
|
6
|
+
get kind() {
|
|
7
|
+
return "namespace";
|
|
8
|
+
}
|
|
20
9
|
}
|
|
21
10
|
|
|
22
11
|
// the kind of member scope. i.e. are we in an enum, class, etc
|
|
@@ -29,26 +18,18 @@ export type CSharpMemberScopeName =
|
|
|
29
18
|
// indicates that the scope for a symbol resides within a type
|
|
30
19
|
// e.g. for an enum value, class field etc, these would have
|
|
31
20
|
// member scope where the owner is the containing type.
|
|
32
|
-
export
|
|
33
|
-
kind
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
binder: core.Binder,
|
|
42
|
-
parent: core.OutputScope,
|
|
43
|
-
owner: CSharpOutputSymbol,
|
|
44
|
-
name: CSharpMemberScopeName,
|
|
45
|
-
): CSharpMemberScope {
|
|
46
|
-
return binder.createScope<CSharpMemberScope>({
|
|
47
|
-
kind: "member",
|
|
48
|
-
name: name,
|
|
49
|
-
owner,
|
|
50
|
-
parent,
|
|
51
|
-
});
|
|
30
|
+
get owner() {
|
|
31
|
+
return super.owner as CSharpOutputSymbol;
|
|
32
|
+
}
|
|
52
33
|
}
|
|
53
34
|
|
|
54
35
|
// contains the possible scopes where a declaration can reside
|