@alloy-js/csharp 0.1.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/LICENSE.txt +7 -0
- package/api-extractor.json +4 -0
- package/babel.config.cjs +4 -0
- package/dist/src/components/Class.d.ts +33 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/Class.js +170 -0
- package/dist/src/components/Class.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +8 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +18 -0
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/Enum.d.ts +13 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/Enum.js +65 -0
- package/dist/src/components/Enum.js.map +1 -0
- package/dist/src/components/Name.d.ts +2 -0
- package/dist/src/components/Name.d.ts.map +1 -0
- package/dist/src/components/Name.js +12 -0
- package/dist/src/components/Name.js.map +1 -0
- package/dist/src/components/Namespace.d.ts +11 -0
- package/dist/src/components/Namespace.d.ts.map +1 -0
- package/dist/src/components/Namespace.js +35 -0
- package/dist/src/components/Namespace.js.map +1 -0
- package/dist/src/components/Parameters.d.ts +13 -0
- package/dist/src/components/Parameters.d.ts.map +1 -0
- package/dist/src/components/Parameters.js +34 -0
- package/dist/src/components/Parameters.js.map +1 -0
- package/dist/src/components/ProjectDirectory.d.ts +12 -0
- package/dist/src/components/ProjectDirectory.d.ts.map +1 -0
- package/dist/src/components/ProjectDirectory.js +48 -0
- package/dist/src/components/ProjectDirectory.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +9 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +12 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +72 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/UsingDirective.d.ts +5 -0
- package/dist/src/components/UsingDirective.d.ts.map +1 -0
- package/dist/src/components/UsingDirective.js +13 -0
- package/dist/src/components/UsingDirective.js.map +1 -0
- package/dist/src/components/index.d.ts +11 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +11 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +43 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +13 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/modifiers.d.ts +5 -0
- package/dist/src/modifiers.d.ts.map +1 -0
- package/dist/src/modifiers.js +35 -0
- package/dist/src/modifiers.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +30 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/symbols/csharp-output-symbol.d.ts +7 -0
- package/dist/src/symbols/csharp-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/csharp-output-symbol.js +20 -0
- package/dist/src/symbols/csharp-output-symbol.js.map +1 -0
- package/dist/src/symbols/index.d.ts +4 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +4 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +3 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +55 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +16 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +37 -0
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/enum.test.d.ts +2 -0
- package/dist/test/enum.test.d.ts.map +1 -0
- package/dist/test/namespace.test.d.ts +2 -0
- package/dist/test/namespace.test.d.ts.map +1 -0
- package/dist/test/projectdirectory.test.d.ts +2 -0
- package/dist/test/projectdirectory.test.d.ts.map +1 -0
- package/dist/test/sourcefile.test.d.ts +2 -0
- package/dist/test/sourcefile.test.d.ts.map +1 -0
- package/dist/test/using.test.d.ts +2 -0
- package/dist/test/using.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +6 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +51 -0
- package/src/components/Class.tsx +210 -0
- package/src/components/Declaration.tsx +17 -0
- package/src/components/Enum.tsx +74 -0
- package/src/components/Name.tsx +11 -0
- package/src/components/Namespace.tsx +39 -0
- package/src/components/Parameters.tsx +52 -0
- package/src/components/ProjectDirectory.tsx +54 -0
- package/src/components/Reference.tsx +13 -0
- package/src/components/SourceFile.tsx +69 -0
- package/src/components/UsingDirective.tsx +19 -0
- package/src/components/index.ts +10 -0
- package/src/components/stc/index.ts +13 -0
- package/src/index.ts +4 -0
- package/src/modifiers.ts +45 -0
- package/src/name-policy.ts +41 -0
- package/src/symbols/csharp-output-symbol.ts +26 -0
- package/src/symbols/index.ts +3 -0
- package/src/symbols/reference.ts +65 -0
- package/src/symbols/scopes.ts +60 -0
- package/temp/api.json +3474 -0
- package/test/class.test.tsx +249 -0
- package/test/enum.test.tsx +147 -0
- package/test/namespace.test.tsx +59 -0
- package/test/projectdirectory.test.tsx +106 -0
- package/test/sourcefile.test.tsx +46 -0
- package/test/using.test.tsx +97 -0
- package/test/utils.tsx +69 -0
- package/tsconfig.json +11 -0
- package/tsdoc-metadata.json +11 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export interface CSharpOutputSymbol extends core.OutputSymbol {
|
|
7
|
+
scope: CSharpOutputScope;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// creates a new C# symbol
|
|
11
|
+
export function createCSharpSymbol(props: core.DeclarationProps) {
|
|
12
|
+
const scope = core.useScope() as CSharpOutputScope;
|
|
13
|
+
|
|
14
|
+
const namespaceCtx = useNamespace();
|
|
15
|
+
if (!namespaceCtx) {
|
|
16
|
+
throw new Error("symbol must be declared inside a namespace");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const sym = scope.binder.createSymbol<CSharpOutputSymbol>({
|
|
20
|
+
name: props.name!,
|
|
21
|
+
scope,
|
|
22
|
+
refkey: props.refkey ?? core.refkey(props.name),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return sym;
|
|
26
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as core from "@alloy-js/core";
|
|
2
|
+
import { useNamespace } from "../components/Namespace.jsx";
|
|
3
|
+
import { useSourceFile } from "../components/SourceFile.jsx";
|
|
4
|
+
import { CSharpOutputSymbol } from "./csharp-output-symbol.js";
|
|
5
|
+
import { CSharpOutputScope } from "./scopes.js";
|
|
6
|
+
|
|
7
|
+
// when resolving references across source files, the last element
|
|
8
|
+
// in pathDown will be the containing source file. we only need this
|
|
9
|
+
// here so we can find and remove this scope as it's not useful
|
|
10
|
+
// when building the reference
|
|
11
|
+
interface SourceFileScope extends core.OutputScope {
|
|
12
|
+
kind: "source-file";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ReferenceScope = CSharpOutputScope | SourceFileScope;
|
|
16
|
+
|
|
17
|
+
// converts a refkey to its fully qualified name
|
|
18
|
+
// e.g. if refkey is for bar in enum type foo, and
|
|
19
|
+
// foo is in the same namespace as the refkey, then
|
|
20
|
+
// the result would be foo.bar.
|
|
21
|
+
export function ref(refkey: core.Refkey): () => string {
|
|
22
|
+
const targetNamespaceCtx = useNamespace();
|
|
23
|
+
const resolveResult = core.resolve<ReferenceScope, CSharpOutputSymbol>(
|
|
24
|
+
refkey as core.Refkey,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return core.memo(() => {
|
|
28
|
+
if (resolveResult.value === undefined) {
|
|
29
|
+
return "<Unresolved Symbol>";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// targetDeclaration is the symbol with the refkey
|
|
33
|
+
// pathDown is an array of scopes to that symbol and can be empty.
|
|
34
|
+
// the entries are top-down, so namespace, source-file, member
|
|
35
|
+
// - referencing a type within the same namespace will have an empty path
|
|
36
|
+
// - referencing a member (e.g. enum value) within the same namespace will
|
|
37
|
+
// have a single path entry that contains the owning type
|
|
38
|
+
// - referencing a type within the same namespace but in a different source
|
|
39
|
+
// file will have at least a source-file entry
|
|
40
|
+
// - referencing a symbol outside the current namespace will have at least
|
|
41
|
+
// two entries, namespace, source-file
|
|
42
|
+
const { targetDeclaration, pathDown } = resolveResult.value;
|
|
43
|
+
|
|
44
|
+
const sourceNamespace = pathDown.find((v) => {
|
|
45
|
+
return v.kind === "namespace";
|
|
46
|
+
});
|
|
47
|
+
if (sourceNamespace && sourceNamespace.name !== targetNamespaceCtx!.name) {
|
|
48
|
+
// the source symbol is in a different namespace that the target refkey.
|
|
49
|
+
// add the applicable using statement to the target's source file.
|
|
50
|
+
const targetSrc = useSourceFile();
|
|
51
|
+
targetSrc!.addUsing(sourceNamespace.name);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// we only need to build the fully-qualified name for members
|
|
55
|
+
// TODO: possibly a subset of members
|
|
56
|
+
const syms = (pathDown as ReferenceScope[])
|
|
57
|
+
.filter((v) => {
|
|
58
|
+
return v.kind === "member";
|
|
59
|
+
})
|
|
60
|
+
.map((s) => s.owner);
|
|
61
|
+
syms.push(targetDeclaration);
|
|
62
|
+
|
|
63
|
+
return syms.map((sym) => sym.name).join(".");
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 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
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// the kind of member scope. i.e. are we in an enum, class, etc
|
|
23
|
+
export type CSharpMemberScopeName =
|
|
24
|
+
| "class-decl"
|
|
25
|
+
| "constructor-decl"
|
|
26
|
+
| "enum-decl"
|
|
27
|
+
| "method-decl";
|
|
28
|
+
|
|
29
|
+
// indicates that the scope for a symbol resides within a type
|
|
30
|
+
// e.g. for an enum value, class field etc, these would have
|
|
31
|
+
// 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
|
+
}
|
|
37
|
+
|
|
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
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// contains the possible scopes where a declaration can reside
|
|
55
|
+
export type CSharpOutputScope = CSharpMemberScope | CSharpNamespaceScope;
|
|
56
|
+
|
|
57
|
+
// returns the current C# scope
|
|
58
|
+
export function useCSharpScope(): CSharpOutputScope {
|
|
59
|
+
return core.useScope() as CSharpOutputScope;
|
|
60
|
+
}
|