@alloy-js/csharp 0.15.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.
@@ -1,5 +1,5 @@
1
1
  import * as core from "@alloy-js/core";
2
- import { createCSharpSymbol } from "../symbols/csharp-output-symbol.js";
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 = createCSharpSymbol(props);
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
  }
@@ -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 { createCSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
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 = scope.binder.createSymbol<CSharpOutputSymbol>({
22
- name: name,
21
+ const thisEnumSymbol = new CSharpOutputSymbol(name, {
23
22
  scope,
24
- refkey: props.refkey ?? core.refkey(props.name),
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 = createCSharpMemberScope(
32
- scope.binder,
33
- scope,
34
- thisEnumSymbol,
35
- "enum-decl",
36
- );
30
+ const thisEnumScope = new CSharpMemberScope("enum-decl", {
31
+ parent: scope,
32
+ owner: thisEnumSymbol,
33
+ });
37
34
 
38
- return (
39
- <core.Declaration symbol={thisEnumSymbol}>
40
- {getAccessModifier(props.accessModifier)}enum <Name />
41
- {!props.children && ";"}
42
- {props.children && (
43
- <core.Scope value={thisEnumScope}>
44
- <core.Block newline>{props.children}</core.Block>
45
- </core.Scope>
46
- )}
47
- </core.Declaration>
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 = scope.binder.createSymbol<CSharpOutputSymbol>({
68
- name: name,
65
+ const thisEnumValueSymbol = new CSharpOutputSymbol(name, {
69
66
  scope,
70
- refkey: props.refkey ?? core.refkey(props.name),
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 { createCSharpNamespaceScope } from "../symbols/scopes.js";
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 = createCSharpNamespaceScope(
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 = scope.binder.createSymbol<CSharpOutputSymbol>({
28
- name: name,
27
+ const memberSymbol = new CSharpOutputSymbol(name, {
29
28
  scope,
30
- refkey: props.refkey ?? core.refkey(props.name),
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
- const namespaceCtx = useNamespace();
16
- if (!namespaceCtx) {
17
- throw new Error("symbol must be declared inside a namespace");
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
- const sym = scope.binder.createSymbol<CSharpOutputSymbol>({
21
- name: props.name!,
22
- scope,
23
- refkey: props.refkey ?? core.refkey(props.name),
24
- });
25
-
26
- return sym;
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
  }
@@ -57,7 +57,7 @@ export function ref(refkey: core.Refkey): () => string {
57
57
  .filter((v) => {
58
58
  return v.kind === "member";
59
59
  })
60
- .map((s) => s.owner);
60
+ .map((s) => s.owner!);
61
61
  syms.push(targetDeclaration);
62
62
 
63
63
  return syms.map((sym) => sym.name).join(".");
@@ -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 interface CSharpNamespaceScope extends core.OutputScope {
6
- kind: "namespace";
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 interface CSharpMemberScope extends core.OutputScope {
33
- kind: "member";
34
- name: CSharpMemberScopeName;
35
- owner: CSharpOutputSymbol;
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
- // creates a new member scope.
39
- // parent is the owning symbol.
40
- export function createCSharpMemberScope(
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