@alloy-js/csharp 0.16.0 → 0.18.0-dev.10
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/ClassDeclaration.d.ts +57 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Class.js → ClassDeclaration.js} +58 -69
- package/dist/src/components/ClassMethod.d.ts +25 -0
- package/dist/src/components/ClassMethod.d.ts.map +1 -0
- package/dist/src/components/ClassMethod.js +60 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +4 -2
- package/dist/src/components/EnumDeclaration.d.ts +34 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Enum.js → EnumDeclaration.js} +36 -14
- 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/components/doc/comment.d.ts +70 -0
- package/dist/src/components/doc/comment.d.ts.map +1 -0
- package/dist/src/components/doc/comment.js +88 -0
- package/dist/src/components/doc/comment.test.d.ts +2 -0
- package/dist/src/components/doc/comment.test.d.ts.map +1 -0
- package/dist/src/components/doc/comment.test.js +348 -0
- package/dist/src/components/doc/from-markdown.d.ts +6 -0
- package/dist/src/components/doc/from-markdown.d.ts.map +1 -0
- package/dist/src/components/doc/from-markdown.js +58 -0
- package/dist/src/components/doc/from-markdown.test.d.ts +2 -0
- package/dist/src/components/doc/from-markdown.test.d.ts.map +1 -0
- package/dist/src/components/doc/from-markdown.test.js +83 -0
- package/dist/src/components/index.d.ts +7 -2
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -2
- package/dist/src/components/interface/declaration.d.ts +34 -0
- package/dist/src/components/interface/declaration.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.js +90 -0
- package/dist/src/components/interface/declaration.test.d.ts +2 -0
- package/dist/src/components/interface/declaration.test.d.ts.map +1 -0
- package/dist/src/components/interface/declaration.test.js +69 -0
- package/dist/src/components/interface/method.d.ts +18 -0
- package/dist/src/components/interface/method.d.ts.map +1 -0
- package/dist/src/components/interface/method.js +59 -0
- package/dist/src/components/interface/method.test.d.ts +2 -0
- package/dist/src/components/interface/method.test.d.ts.map +1 -0
- package/dist/src/components/interface/method.test.js +131 -0
- package/dist/src/components/interface/property.d.ts +21 -0
- package/dist/src/components/interface/property.d.ts.map +1 -0
- package/dist/src/components/interface/property.js +59 -0
- package/dist/src/components/interface/property.test.d.ts +2 -0
- package/dist/src/components/interface/property.test.d.ts.map +1 -0
- package/dist/src/components/interface/property.test.js +165 -0
- package/dist/src/components/stc/index.d.ts +2 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/modifiers.d.ts +13 -4
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +13 -27
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +1 -0
- 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/test/class-declaration.test.d.ts +2 -0
- package/dist/test/class-declaration.test.d.ts.map +1 -0
- package/dist/test/{class.test.js → class-declaration.test.js} +123 -73
- package/dist/test/class-method.test.d.ts +2 -0
- package/dist/test/class-method.test.d.ts.map +1 -0
- package/dist/test/class-method.test.js +161 -0
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/project-directory.test.d.ts +2 -0
- package/dist/test/project-directory.test.d.ts.map +1 -0
- package/dist/test/{projectdirectory.test.js → project-directory.test.js} +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/test/utils.d.ts +3 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +15 -0
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/components/{Class.tsx → ClassDeclaration.tsx} +84 -98
- package/src/components/ClassMethod.tsx +94 -0
- package/src/components/Declaration.tsx +5 -2
- package/src/components/EnumDeclaration.tsx +99 -0
- package/src/components/Namespace.tsx +2 -6
- package/src/components/Parameters.tsx +2 -3
- package/src/components/doc/comment.test.tsx +337 -0
- package/src/components/doc/comment.tsx +152 -0
- package/src/components/doc/from-markdown.test.tsx +103 -0
- package/src/components/doc/from-markdown.tsx +58 -0
- package/src/components/index.ts +7 -2
- package/src/components/interface/declaration.test.tsx +56 -0
- package/src/components/interface/declaration.tsx +109 -0
- package/src/components/interface/method.test.tsx +120 -0
- package/src/components/interface/method.tsx +82 -0
- package/src/components/interface/property.test.tsx +144 -0
- package/src/components/interface/property.tsx +90 -0
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +32 -37
- package/src/name-policy.ts +2 -0
- 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 +3470 -649
- package/test/{class.test.tsx → class-declaration.test.tsx} +103 -99
- package/test/class-method.test.tsx +147 -0
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/test/utils.tsx +9 -0
- package/test/vitest.setup.ts +1 -0
- package/tsconfig.json +2 -1
- package/tsdoc-metadata.json +1 -1
- package/vitest.config.ts +3 -0
- package/dist/src/components/Class.d.ts +0 -36
- package/dist/src/components/Class.d.ts.map +0 -1
- package/dist/src/components/Enum.d.ts +0 -15
- package/dist/src/components/Enum.d.ts.map +0 -1
- package/dist/test/class.test.d.ts +0 -2
- package/dist/test/class.test.d.ts.map +0 -1
- package/dist/test/projectdirectory.test.d.ts +0 -2
- package/dist/test/projectdirectory.test.d.ts.map +0 -1
- package/src/components/Enum.tsx +0 -78
package/dist/src/modifiers.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** Access modifiers. */
|
|
2
|
+
export interface AccessModifiers {
|
|
3
|
+
readonly public?: boolean;
|
|
4
|
+
readonly protected?: boolean;
|
|
5
|
+
readonly private?: boolean;
|
|
6
|
+
readonly internal?: boolean;
|
|
7
|
+
readonly file?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const getAccessModifier: (data: AccessModifiers) => string;
|
|
10
|
+
export declare function getAsyncModifier(async?: boolean): string;
|
|
11
|
+
/** Resolve the modifier prefix */
|
|
12
|
+
export declare function computeModifiersPrefix(modifiers: Array<string | undefined>): string;
|
|
13
|
+
export declare function makeModifiers<T>(obj: Array<keyof T>): (data: T) => string;
|
|
5
14
|
//# sourceMappingURL=modifiers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"modifiers.d.ts","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAGA,yBAAyB;AACzB,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,eAAO,MAAM,iBAAiB,mCAM5B,CAAC;AAEH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,kCAAkC;AAClC,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,GACnC,MAAM,CAGR;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,IAC1C,MAAM,CAAC,YAMhB"}
|
package/dist/src/modifiers.js
CHANGED
|
@@ -1,34 +1,20 @@
|
|
|
1
1
|
// the possible C# access modifiers
|
|
2
2
|
// https://learn.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
// note that the C# keyword includes a trailing space
|
|
6
|
-
const accessModifierLookup = {
|
|
7
|
-
public: "public ",
|
|
8
|
-
protected: "protected ",
|
|
9
|
-
private: "private ",
|
|
10
|
-
internal: "internal ",
|
|
11
|
-
"protected-internal": "protected internal ",
|
|
12
|
-
"private-protected": "private protected ",
|
|
13
|
-
file: "file "
|
|
14
|
-
};
|
|
4
|
+
/** Access modifiers. */
|
|
15
5
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return accessModifier ? accessModifierLookup[accessModifier] : "";
|
|
6
|
+
export const getAccessModifier = makeModifiers(["public", "protected", "private", "internal", "file"]);
|
|
7
|
+
export function getAsyncModifier(async) {
|
|
8
|
+
return async ? "async" : "";
|
|
20
9
|
}
|
|
21
|
-
// maps the above method modifier value to its C# syntax.
|
|
22
|
-
// note that the C# keyword includes a trailing space
|
|
23
|
-
const methodModifierLookup = {
|
|
24
|
-
abstract: "abstract ",
|
|
25
|
-
sealed: "sealed ",
|
|
26
|
-
static: "static ",
|
|
27
|
-
virtual: "virtual "
|
|
28
|
-
};
|
|
29
10
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
11
|
+
/** Resolve the modifier prefix */
|
|
12
|
+
export function computeModifiersPrefix(modifiers) {
|
|
13
|
+
const resolved = modifiers.filter(x => x);
|
|
14
|
+
return resolved.length > 0 ? resolved.join(" ") + " " : "";
|
|
15
|
+
}
|
|
16
|
+
export function makeModifiers(obj) {
|
|
17
|
+
return data => {
|
|
18
|
+
return obj.map(key => data[key] ? key : undefined).filter(x => x).join(" ");
|
|
19
|
+
};
|
|
34
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
export type CSharpElements = "class" | "constant" | "enum" | "enum-member" | "function" | "interface" | "class-member-private" | "class-member-public" | "class-method" | "parameter" | "type-parameter";
|
|
2
|
+
export type CSharpElements = "class" | "constant" | "enum" | "enum-member" | "function" | "interface" | "class-member-private" | "class-member-public" | "class-method" | "class-property" | "parameter" | "type-parameter";
|
|
3
3
|
export declare function createCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
|
|
4
4
|
export declare function useCSharpNamePolicy(): core.NamePolicy<CSharpElements>;
|
|
5
5
|
//# sourceMappingURL=name-policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"name-policy.d.ts","sourceRoot":"","sources":["../../src/name-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAIvC,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,WAAW,GACX,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,WAAW,GACX,gBAAgB,CAAC;AAGrB,wBAAgB,sBAAsB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAkBxE;AAGD,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAErE"}
|
package/dist/src/name-policy.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
import { DeclarationProps } from "../components/Declaration.jsx";
|
|
3
2
|
import { CSharpOutputScope } from "./scopes.js";
|
|
4
|
-
export
|
|
5
|
-
scope: CSharpOutputScope;
|
|
3
|
+
export declare class CSharpOutputSymbol extends core.OutputSymbol {
|
|
4
|
+
get scope(): CSharpOutputScope;
|
|
5
|
+
set scope(value: CSharpOutputScope);
|
|
6
|
+
constructor(name: string, options?: core.OutputSymbolOptions);
|
|
6
7
|
}
|
|
7
|
-
export declare function createCSharpSymbol(props: DeclarationProps): CSharpOutputSymbol;
|
|
8
8
|
//# sourceMappingURL=csharp-output-symbol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/csharp-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"csharp-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/csharp-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,qBAAa,kBAAmB,SAAQ,IAAI,CAAC,YAAY;IACvD,IAAI,KAAK,IAGQ,iBAAiB,CADjC;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,iBAAiB,EAEjC;gBAEW,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB;CAO7D"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { useNamespace } from "../components/Namespace.js";
|
|
3
|
-
|
|
4
3
|
// represents a symbol from a .cs file. Class, enum, interface etc.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
export class CSharpOutputSymbol extends core.OutputSymbol {
|
|
6
|
+
get scope() {
|
|
7
|
+
return super.scope;
|
|
8
|
+
}
|
|
9
|
+
set scope(value) {
|
|
10
|
+
super.scope = value;
|
|
11
|
+
}
|
|
12
|
+
constructor(name, options) {
|
|
13
|
+
const namespaceCtx = useNamespace();
|
|
14
|
+
if (!namespaceCtx) {
|
|
15
|
+
throw new Error("symbol must be declared inside a namespace");
|
|
16
|
+
}
|
|
17
|
+
super(name, options);
|
|
12
18
|
}
|
|
13
|
-
const sym = scope.binder.createSymbol({
|
|
14
|
-
name: props.name,
|
|
15
|
-
scope,
|
|
16
|
-
refkey: props.refkey ?? core.refkey(props.name)
|
|
17
|
-
});
|
|
18
|
-
return sym;
|
|
19
19
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { CSharpOutputSymbol } from "./csharp-output-symbol.js";
|
|
3
|
-
export
|
|
4
|
-
kind:
|
|
3
|
+
export declare class CSharpNamespaceScope extends core.OutputScope {
|
|
4
|
+
get kind(): string;
|
|
5
5
|
}
|
|
6
|
-
export declare function createCSharpNamespaceScope(binder: core.Binder, parent: core.OutputScope | undefined, name: string): CSharpNamespaceScope;
|
|
7
6
|
export type CSharpMemberScopeName = "class-decl" | "constructor-decl" | "enum-decl" | "method-decl";
|
|
8
|
-
export
|
|
9
|
-
kind:
|
|
10
|
-
name: CSharpMemberScopeName;
|
|
11
|
-
owner: CSharpOutputSymbol;
|
|
7
|
+
export declare class CSharpMemberScope extends core.OutputScope {
|
|
8
|
+
get kind(): string;
|
|
9
|
+
get name(): CSharpMemberScopeName;
|
|
10
|
+
get owner(): CSharpOutputSymbol;
|
|
12
11
|
}
|
|
13
|
-
export declare function createCSharpMemberScope(binder: core.Binder, parent: core.OutputScope, owner: CSharpOutputSymbol, name: CSharpMemberScopeName): CSharpMemberScope;
|
|
14
12
|
export type CSharpOutputScope = CSharpMemberScope | CSharpNamespaceScope;
|
|
15
13
|
export declare function useCSharpScope(): CSharpOutputScope;
|
|
16
14
|
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,qBAAa,oBAAqB,SAAQ,IAAI,CAAC,WAAW;IACxD,IAAI,IAAI,WAEP;CACF;AAGD,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,kBAAkB,GAClB,WAAW,GACX,aAAa,CAAC;AAKlB,qBAAa,iBAAkB,SAAQ,IAAI,CAAC,WAAW;IACrD,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,IACe,qBAAqB,CAC3C;IAED,IAAI,KAAK,IACe,kBAAkB,CACzC;CACF;AAGD,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAGzE,wBAAgB,cAAc,IAAI,iBAAiB,CAElD"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
|
-
|
|
3
2
|
// indicates that the scope for a symbols is at the namespace level
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
kind: "namespace",
|
|
9
|
-
name,
|
|
10
|
-
parent
|
|
11
|
-
});
|
|
3
|
+
export class CSharpNamespaceScope extends core.OutputScope {
|
|
4
|
+
get kind() {
|
|
5
|
+
return "namespace";
|
|
6
|
+
}
|
|
12
7
|
}
|
|
13
8
|
|
|
14
9
|
// the kind of member scope. i.e. are we in an enum, class, etc
|
|
@@ -16,16 +11,16 @@ export function createCSharpNamespaceScope(binder, parent, name) {
|
|
|
16
11
|
// indicates that the scope for a symbol resides within a type
|
|
17
12
|
// e.g. for an enum value, class field etc, these would have
|
|
18
13
|
// member scope where the owner is the containing type.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
14
|
+
export class CSharpMemberScope extends core.OutputScope {
|
|
15
|
+
get kind() {
|
|
16
|
+
return "member";
|
|
17
|
+
}
|
|
18
|
+
get name() {
|
|
19
|
+
return super.name;
|
|
20
|
+
}
|
|
21
|
+
get owner() {
|
|
22
|
+
return super.owner;
|
|
23
|
+
}
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
// contains the possible scopes where a declaration can reside
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-declaration.test.d.ts","sourceRoot":"","sources":["../../test/class-declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,34 +1,76 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
1
|
+
import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as core from "@alloy-js/core";
|
|
3
3
|
import * as coretest from "@alloy-js/core/testing";
|
|
4
|
-
import { expect, it } from "vitest";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
5
|
import * as csharp from "../src/index.js";
|
|
6
|
+
import { ClassDeclaration, ClassMember } from "../src/index.js";
|
|
6
7
|
import * as utils from "./utils.js";
|
|
7
8
|
it("declares class with no members", () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
namespace TestCode
|
|
14
|
-
{
|
|
15
|
-
public class TestClass;
|
|
9
|
+
expect(_$createComponent(utils.TestNamespace, {
|
|
10
|
+
get children() {
|
|
11
|
+
return _$createComponent(ClassDeclaration, {
|
|
12
|
+
name: "TestClass"
|
|
13
|
+
});
|
|
16
14
|
}
|
|
15
|
+
})).toRenderTo(`
|
|
16
|
+
class TestClass;
|
|
17
17
|
`);
|
|
18
18
|
});
|
|
19
|
+
describe("modifiers", () => {
|
|
20
|
+
it.each(["public", "private"])("%s", mod => {
|
|
21
|
+
expect(_$createComponent(utils.TestNamespace, {
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(ClassDeclaration, _$mergeProps({
|
|
24
|
+
[mod]: true
|
|
25
|
+
}, {
|
|
26
|
+
name: "TestClass"
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
})).toRenderTo(`
|
|
30
|
+
${mod} class TestClass;
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
it.each(["partial", "abstract", "static", "sealed"])("%s", mod => {
|
|
34
|
+
expect(_$createComponent(utils.TestNamespace, {
|
|
35
|
+
get children() {
|
|
36
|
+
return _$createComponent(ClassDeclaration, _$mergeProps({
|
|
37
|
+
[mod]: true
|
|
38
|
+
}, {
|
|
39
|
+
name: "TestClass"
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
})).toRenderTo(`
|
|
43
|
+
${mod} class TestClass;
|
|
44
|
+
`);
|
|
45
|
+
});
|
|
46
|
+
it("combines modifiers", () => {
|
|
47
|
+
expect(_$createComponent(utils.TestNamespace, {
|
|
48
|
+
get children() {
|
|
49
|
+
return _$createComponent(ClassDeclaration, {
|
|
50
|
+
"public": true,
|
|
51
|
+
abstract: true,
|
|
52
|
+
partial: true,
|
|
53
|
+
name: "TestClass"
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
})).toRenderTo(`
|
|
57
|
+
public abstract partial class TestClass;
|
|
58
|
+
`);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
19
61
|
it("declares class with some members", () => {
|
|
20
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
21
|
-
|
|
62
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
63
|
+
"public": true,
|
|
22
64
|
name: "TestClass",
|
|
23
65
|
get children() {
|
|
24
66
|
return _$createComponent(core.StatementList, {
|
|
25
67
|
get children() {
|
|
26
68
|
return [_$createComponent(csharp.ClassMember, {
|
|
27
|
-
|
|
69
|
+
"public": true,
|
|
28
70
|
name: "MemberOne",
|
|
29
71
|
type: "string"
|
|
30
72
|
}), _$createComponent(csharp.ClassMember, {
|
|
31
|
-
|
|
73
|
+
"private": true,
|
|
32
74
|
name: "MemberTwo",
|
|
33
75
|
type: "int"
|
|
34
76
|
})];
|
|
@@ -48,18 +90,18 @@ it("declares class with some members", () => {
|
|
|
48
90
|
`);
|
|
49
91
|
});
|
|
50
92
|
it("declares class with some methods", () => {
|
|
51
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
52
|
-
|
|
93
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
94
|
+
"public": true,
|
|
53
95
|
name: "TestClass",
|
|
54
96
|
get children() {
|
|
55
97
|
return _$createComponent(core.List, {
|
|
56
98
|
get children() {
|
|
57
99
|
return [_$createComponent(csharp.ClassMethod, {
|
|
58
|
-
|
|
100
|
+
"public": true,
|
|
59
101
|
name: "MethodOne"
|
|
60
102
|
}), _$createComponent(csharp.ClassMethod, {
|
|
61
|
-
|
|
62
|
-
|
|
103
|
+
"private": true,
|
|
104
|
+
virtual: true,
|
|
63
105
|
name: "MethodTwo"
|
|
64
106
|
})];
|
|
65
107
|
}
|
|
@@ -77,36 +119,6 @@ it("declares class with some methods", () => {
|
|
|
77
119
|
}
|
|
78
120
|
`);
|
|
79
121
|
});
|
|
80
|
-
it("declares class with params and return type", () => {
|
|
81
|
-
const params = [{
|
|
82
|
-
name: "IntParam",
|
|
83
|
-
type: "int"
|
|
84
|
-
}, {
|
|
85
|
-
name: "StringParam",
|
|
86
|
-
type: "string"
|
|
87
|
-
}];
|
|
88
|
-
const res = utils.toSourceText(_$createComponent(csharp.Class, {
|
|
89
|
-
accessModifier: "public",
|
|
90
|
-
name: "TestClass",
|
|
91
|
-
get children() {
|
|
92
|
-
return _$createComponent(csharp.ClassMethod, {
|
|
93
|
-
accessModifier: "public",
|
|
94
|
-
name: "MethodOne",
|
|
95
|
-
parameters: params,
|
|
96
|
-
returns: "string"
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}));
|
|
100
|
-
expect(res).toBe(coretest.d`
|
|
101
|
-
namespace TestCode
|
|
102
|
-
{
|
|
103
|
-
public class TestClass
|
|
104
|
-
{
|
|
105
|
-
public string MethodOne(int intParam, string stringParam) {}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
`);
|
|
109
|
-
});
|
|
110
122
|
it("uses refkeys for members, params, and return type", () => {
|
|
111
123
|
const inputTypeRefkey = core.refkey();
|
|
112
124
|
const testResultTypeRefkey = core.refkey();
|
|
@@ -129,8 +141,8 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
129
141
|
return _$createComponent(csharp.SourceFile, {
|
|
130
142
|
path: "Test.cs",
|
|
131
143
|
get children() {
|
|
132
|
-
return [_$createComponent(csharp.
|
|
133
|
-
|
|
144
|
+
return [_$createComponent(csharp.EnumDeclaration, {
|
|
145
|
+
"public": true,
|
|
134
146
|
name: "TestEnum",
|
|
135
147
|
refkey: enumTypeRefkey,
|
|
136
148
|
get children() {
|
|
@@ -146,24 +158,24 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
146
158
|
}
|
|
147
159
|
});
|
|
148
160
|
}
|
|
149
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
150
|
-
|
|
161
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
162
|
+
"public": true,
|
|
151
163
|
name: "TestInput",
|
|
152
164
|
refkey: inputTypeRefkey
|
|
153
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
154
|
-
|
|
165
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
166
|
+
"public": true,
|
|
155
167
|
name: "TestResult",
|
|
156
168
|
refkey: testResultTypeRefkey
|
|
157
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
158
|
-
|
|
169
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
170
|
+
"public": true,
|
|
159
171
|
name: "TestClass",
|
|
160
172
|
get children() {
|
|
161
173
|
return [_$createComponent(csharp.ClassMember, {
|
|
162
|
-
|
|
174
|
+
"private": true,
|
|
163
175
|
name: "MemberOne",
|
|
164
176
|
type: enumTypeRefkey
|
|
165
177
|
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMethod, {
|
|
166
|
-
|
|
178
|
+
"public": true,
|
|
167
179
|
name: "MethodOne",
|
|
168
180
|
parameters: params,
|
|
169
181
|
returns: testResultTypeRefkey,
|
|
@@ -205,19 +217,19 @@ it("declares class with generic parameters", () => {
|
|
|
205
217
|
T: core.refkey(),
|
|
206
218
|
U: core.refkey()
|
|
207
219
|
};
|
|
208
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
209
|
-
|
|
220
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
221
|
+
"public": true,
|
|
210
222
|
name: "TestClass",
|
|
211
223
|
typeParameters: typeParameters,
|
|
212
224
|
get children() {
|
|
213
225
|
return [_$createComponent(csharp.ClassMember, {
|
|
214
|
-
|
|
226
|
+
"public": true,
|
|
215
227
|
name: "memberOne",
|
|
216
228
|
get type() {
|
|
217
229
|
return typeParameters.T;
|
|
218
230
|
}
|
|
219
231
|
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
|
|
220
|
-
|
|
232
|
+
"private": true,
|
|
221
233
|
name: "memberTwo",
|
|
222
234
|
get type() {
|
|
223
235
|
return typeParameters.U;
|
|
@@ -237,8 +249,8 @@ it("declares class with generic parameters", () => {
|
|
|
237
249
|
`);
|
|
238
250
|
});
|
|
239
251
|
it("declares class with invalid members", () => {
|
|
240
|
-
const decl = _$createComponent(csharp.
|
|
241
|
-
|
|
252
|
+
const decl = _$createComponent(csharp.ClassDeclaration, {
|
|
253
|
+
"public": true,
|
|
242
254
|
name: "TestClass",
|
|
243
255
|
get children() {
|
|
244
256
|
return [_$createComponent(csharp.EnumMember, {
|
|
@@ -251,12 +263,12 @@ it("declares class with invalid members", () => {
|
|
|
251
263
|
expect(() => utils.toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
|
|
252
264
|
});
|
|
253
265
|
it("declares class with constructor", () => {
|
|
254
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
255
|
-
|
|
266
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
267
|
+
"public": true,
|
|
256
268
|
name: "TestClass",
|
|
257
269
|
get children() {
|
|
258
270
|
return _$createComponent(csharp.ClassConstructor, {
|
|
259
|
-
|
|
271
|
+
"public": true
|
|
260
272
|
});
|
|
261
273
|
}
|
|
262
274
|
}));
|
|
@@ -284,22 +296,22 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
284
296
|
type: "int",
|
|
285
297
|
refkey: paramSizeRefkey
|
|
286
298
|
}];
|
|
287
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
288
|
-
|
|
299
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
300
|
+
"public": true,
|
|
289
301
|
name: "TestClass",
|
|
290
302
|
get children() {
|
|
291
303
|
return [_$createComponent(csharp.ClassMember, {
|
|
292
|
-
|
|
304
|
+
"private": true,
|
|
293
305
|
name: "name",
|
|
294
306
|
type: "string",
|
|
295
307
|
refkey: thisNameRefkey
|
|
296
308
|
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
|
|
297
|
-
|
|
309
|
+
"private": true,
|
|
298
310
|
name: "size",
|
|
299
311
|
type: "int",
|
|
300
312
|
refkey: thisSizeRefkey
|
|
301
313
|
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassConstructor, {
|
|
302
|
-
|
|
314
|
+
"public": true,
|
|
303
315
|
parameters: ctorParams,
|
|
304
316
|
get children() {
|
|
305
317
|
return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
|
|
@@ -325,4 +337,42 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
325
337
|
}
|
|
326
338
|
}
|
|
327
339
|
`);
|
|
340
|
+
});
|
|
341
|
+
it("specify doc comment", () => {
|
|
342
|
+
expect(_$createComponent(utils.TestNamespace, {
|
|
343
|
+
get children() {
|
|
344
|
+
return _$createComponent(ClassDeclaration, {
|
|
345
|
+
name: "Test",
|
|
346
|
+
doc: "This is a test"
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
})).toRenderTo(`
|
|
350
|
+
/// This is a test
|
|
351
|
+
class Test;
|
|
352
|
+
`);
|
|
353
|
+
});
|
|
354
|
+
it("supports class member doc comments", () => {
|
|
355
|
+
expect(_$createComponent(utils.TestNamespace, {
|
|
356
|
+
get children() {
|
|
357
|
+
return _$createComponent(ClassDeclaration, {
|
|
358
|
+
name: "Test",
|
|
359
|
+
doc: "This is a test",
|
|
360
|
+
get children() {
|
|
361
|
+
return _$createComponent(ClassMember, {
|
|
362
|
+
name: "Member",
|
|
363
|
+
"public": true,
|
|
364
|
+
type: "int",
|
|
365
|
+
doc: "This is a member"
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
})).toRenderTo(`
|
|
371
|
+
/// This is a test
|
|
372
|
+
class Test
|
|
373
|
+
{
|
|
374
|
+
/// This is a member
|
|
375
|
+
public int Member
|
|
376
|
+
}
|
|
377
|
+
`);
|
|
328
378
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-method.test.d.ts","sourceRoot":"","sources":["../../test/class-method.test.tsx"],"names":[],"mappings":""}
|