@alloy-js/csharp 0.18.0-dev.4 → 0.18.0-dev.6
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/dist/src/components/ClassDeclaration.d.ts +53 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Class.js → ClassDeclaration.js} +28 -4
- 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} +21 -2
- package/dist/src/components/index.d.ts +2 -2
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -2
- 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 +3 -2
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +7 -6
- package/dist/test/class-method.test.js +2 -2
- package/dist/test/class.test.js +62 -20
- package/dist/test/enum.test.js +6 -6
- package/dist/test/namespace.test.js +4 -4
- package/dist/test/projectdirectory.test.js +4 -4
- package/dist/test/sourcefile.test.js +2 -2
- package/dist/test/using.test.js +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/{Class.tsx → ClassDeclaration.tsx} +49 -7
- package/src/components/{Enum.tsx → EnumDeclaration.tsx} +22 -3
- package/src/components/index.ts +2 -2
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +22 -21
- package/temp/api.json +428 -234
- package/test/class-method.test.tsx +3 -3
- package/test/class.test.tsx +70 -26
- package/test/enum.test.tsx +13 -11
- package/test/namespace.test.tsx +4 -4
- package/test/projectdirectory.test.tsx +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +14 -6
- package/dist/src/components/Class.d.ts +0 -23
- package/dist/src/components/Class.d.ts.map +0 -1
- package/dist/src/components/Enum.d.ts +0 -14
- package/dist/src/components/Enum.d.ts.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as core from "@alloy-js/core";
|
|
2
|
+
import { AccessModifiers } from "../modifiers.js";
|
|
3
|
+
import { ParameterProps } from "./Parameters.jsx";
|
|
4
|
+
export interface ClassModifiers {
|
|
5
|
+
readonly abstract?: boolean;
|
|
6
|
+
readonly partial?: boolean;
|
|
7
|
+
readonly sealed?: boolean;
|
|
8
|
+
readonly static?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, ClassModifiers {
|
|
11
|
+
name: string;
|
|
12
|
+
refkey?: core.Refkey;
|
|
13
|
+
typeParameters?: Record<string, core.Refkey>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* CSharp class declaration.
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <ClassDeclaration public name="MyClass">
|
|
20
|
+
* <ClassMember public name="MyField" type="int" />
|
|
21
|
+
* <ClassConstructor>
|
|
22
|
+
* <Parameter name="value" type="int" />
|
|
23
|
+
* this.MyField = value;
|
|
24
|
+
* </ClassConstructor>
|
|
25
|
+
* </ClassDeclaration>
|
|
26
|
+
* ```
|
|
27
|
+
* This will produce:
|
|
28
|
+
* ```csharp
|
|
29
|
+
* public class MyClass
|
|
30
|
+
* {
|
|
31
|
+
* public int MyField;
|
|
32
|
+
* public MyClass(int value)
|
|
33
|
+
* {
|
|
34
|
+
* this.MyField = value;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function ClassDeclaration(props: ClassDeclarationProps): core.Children;
|
|
40
|
+
export interface ClassConstructorProps extends AccessModifiers {
|
|
41
|
+
parameters?: Array<ParameterProps>;
|
|
42
|
+
refkey?: core.Refkey;
|
|
43
|
+
symbol?: core.OutputSymbol;
|
|
44
|
+
children?: core.Children;
|
|
45
|
+
}
|
|
46
|
+
export declare function ClassConstructor(props: ClassConstructorProps): core.Children;
|
|
47
|
+
export interface ClassMemberProps extends AccessModifiers {
|
|
48
|
+
name: string;
|
|
49
|
+
type: core.Children;
|
|
50
|
+
refkey?: core.Refkey;
|
|
51
|
+
}
|
|
52
|
+
export declare function ClassMember(props: ClassMemberProps): core.Children;
|
|
53
|
+
//# sourceMappingURL=ClassDeclaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAUD,MAAM,WAAW,qBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,cAAc;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBAwD5D;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBAkC5D;AAGD,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;CACtB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,iBAyBlD"}
|
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as core from "@alloy-js/core";
|
|
3
|
-
import { computeModifiersPrefix, getAccessModifier } from "../modifiers.js";
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../modifiers.js";
|
|
4
4
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
5
5
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
6
6
|
import { CSharpMemberScope, useCSharpScope } from "../symbols/scopes.js";
|
|
7
7
|
import { Name } from "./Name.js";
|
|
8
8
|
import { Parameters } from "./Parameters.js";
|
|
9
|
+
const getClassModifiers = makeModifiers(["abstract", "partial", "sealed", "static"]);
|
|
9
10
|
|
|
10
11
|
// properties for creating a class
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* CSharp class declaration.
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <ClassDeclaration public name="MyClass">
|
|
18
|
+
* <ClassMember public name="MyField" type="int" />
|
|
19
|
+
* <ClassConstructor>
|
|
20
|
+
* <Parameter name="value" type="int" />
|
|
21
|
+
* this.MyField = value;
|
|
22
|
+
* </ClassConstructor>
|
|
23
|
+
* </ClassDeclaration>
|
|
24
|
+
* ```
|
|
25
|
+
* This will produce:
|
|
26
|
+
* ```csharp
|
|
27
|
+
* public class MyClass
|
|
28
|
+
* {
|
|
29
|
+
* public int MyField;
|
|
30
|
+
* public MyClass(int value)
|
|
31
|
+
* {
|
|
32
|
+
* this.MyField = value;
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function ClassDeclaration(props) {
|
|
14
38
|
const name = useCSharpNamePolicy().getName(props.name, "class");
|
|
15
39
|
const thisClassSymbol = new CSharpOutputSymbol(name, {
|
|
16
40
|
refkeys: props.refkey
|
|
@@ -46,7 +70,7 @@ export function Class(props) {
|
|
|
46
70
|
}
|
|
47
71
|
});
|
|
48
72
|
}
|
|
49
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
73
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props), getClassModifiers(props)]);
|
|
50
74
|
return _$createComponent(core.Declaration, {
|
|
51
75
|
symbol: thisClassSymbol,
|
|
52
76
|
get children() {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as core from "@alloy-js/core";
|
|
2
|
+
import { AccessModifiers } from "../modifiers.js";
|
|
3
|
+
export interface EnumDeclarationProps extends AccessModifiers {
|
|
4
|
+
name: string;
|
|
5
|
+
refkey?: core.Refkey;
|
|
6
|
+
children?: core.Children;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A C# enum declaration
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <EnumDeclaration public name="Color">
|
|
13
|
+
* <EnumMember name="Red" />
|
|
14
|
+
* <EnumMember name="Green" />
|
|
15
|
+
* <EnumMember name="Blue" />
|
|
16
|
+
* </EnumDeclaration>
|
|
17
|
+
* ```
|
|
18
|
+
* This will produce:
|
|
19
|
+
* ```csharp
|
|
20
|
+
* public enum Color
|
|
21
|
+
* {
|
|
22
|
+
* Red,
|
|
23
|
+
* Green,
|
|
24
|
+
* Blue
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function EnumDeclaration(props: EnumDeclarationProps): core.Children;
|
|
29
|
+
export interface EnumMemberProps {
|
|
30
|
+
name: string;
|
|
31
|
+
refkey?: core.Refkey;
|
|
32
|
+
}
|
|
33
|
+
export declare function EnumMember(props: EnumMemberProps): core.Children;
|
|
34
|
+
//# sourceMappingURL=EnumDeclaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAGhB,MAAM,iBAAiB,CAAC;AAOzB,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,iBAgC1D;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;CACtB;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,iBAmBhD"}
|
|
@@ -8,8 +8,27 @@ import { Name } from "./Name.js";
|
|
|
8
8
|
|
|
9
9
|
// properties for creating an enum
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A C# enum declaration
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <EnumDeclaration public name="Color">
|
|
16
|
+
* <EnumMember name="Red" />
|
|
17
|
+
* <EnumMember name="Green" />
|
|
18
|
+
* <EnumMember name="Blue" />
|
|
19
|
+
* </EnumDeclaration>
|
|
20
|
+
* ```
|
|
21
|
+
* This will produce:
|
|
22
|
+
* ```csharp
|
|
23
|
+
* public enum Color
|
|
24
|
+
* {
|
|
25
|
+
* Red,
|
|
26
|
+
* Green,
|
|
27
|
+
* Blue
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function EnumDeclaration(props) {
|
|
13
32
|
const name = useCSharpNamePolicy().getName(props.name, "enum");
|
|
14
33
|
const scope = useCSharpScope();
|
|
15
34
|
const thisEnumSymbol = new CSharpOutputSymbol(name, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./ClassDeclaration.jsx";
|
|
2
2
|
export { ClassMethod, type ClassMethodProps } from "./ClassMethod.jsx";
|
|
3
3
|
export * from "./Declaration.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./EnumDeclaration.jsx";
|
|
5
5
|
export * from "./Name.js";
|
|
6
6
|
export * from "./Namespace.js";
|
|
7
7
|
export * from "./Parameters.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./ClassDeclaration.js";
|
|
2
2
|
export { ClassMethod } from "./ClassMethod.js";
|
|
3
3
|
export * from "./Declaration.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./EnumDeclaration.js";
|
|
5
5
|
export * from "./Name.js";
|
|
6
6
|
export * from "./Namespace.js";
|
|
7
7
|
export * from "./Parameters.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import * as base from "../index.js";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const ClassDeclaration: core.StcSignature<base.ClassDeclarationProps>;
|
|
4
4
|
export declare const ClassConstructor: core.StcSignature<base.ClassConstructorProps>;
|
|
5
5
|
export declare const ClassMember: core.StcSignature<base.ClassMemberProps>;
|
|
6
6
|
export declare const ClassMethod: core.StcSignature<base.ClassMethodProps>;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const EnumDeclaration: core.StcSignature<base.EnumDeclarationProps>;
|
|
8
8
|
export declare const EnumMember: core.StcSignature<base.EnumMemberProps>;
|
|
9
9
|
export declare const Parameter: core.StcSignature<base.ParameterProps>;
|
|
10
10
|
export declare const Parameters: core.StcSignature<base.ParametersProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,eAAe,8CAAiC,CAAC;AAC9D,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,SAAS,wCAA2B,CAAC;AAClD,eAAO,MAAM,UAAU,yCAA4B,CAAC;AACpD,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,cAAc,6CAAgC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import * as base from "../index.js";
|
|
3
|
-
export const
|
|
3
|
+
export const ClassDeclaration = core.stc(base.ClassDeclaration);
|
|
4
4
|
export const ClassConstructor = core.stc(base.ClassConstructor);
|
|
5
5
|
export const ClassMember = core.stc(base.ClassMember);
|
|
6
6
|
export const ClassMethod = core.stc(base.ClassMethod);
|
|
7
|
-
export const
|
|
7
|
+
export const EnumDeclaration = core.stc(base.EnumDeclaration);
|
|
8
8
|
export const EnumMember = core.stc(base.EnumMember);
|
|
9
9
|
export const Parameter = core.stc(base.Parameter);
|
|
10
10
|
export const Parameters = core.stc(base.Parameters);
|
package/dist/src/modifiers.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface AccessModifiers {
|
|
|
6
6
|
readonly internal?: boolean;
|
|
7
7
|
readonly file?: boolean;
|
|
8
8
|
}
|
|
9
|
-
export declare
|
|
9
|
+
export declare const getAccessModifier: (data: AccessModifiers) => string;
|
|
10
10
|
/** Method modifiers. Can only be one. */
|
|
11
11
|
export interface MethodModifiers {
|
|
12
12
|
readonly abstract?: boolean;
|
|
@@ -14,8 +14,9 @@ export interface MethodModifiers {
|
|
|
14
14
|
readonly static?: boolean;
|
|
15
15
|
readonly virtual?: boolean;
|
|
16
16
|
}
|
|
17
|
-
export declare
|
|
17
|
+
export declare const getMethodModifier: (data: MethodModifiers) => string;
|
|
18
18
|
export declare function getAsyncModifier(async?: boolean): string;
|
|
19
19
|
/** Resolve the modifier prefix */
|
|
20
20
|
export declare function computeModifiersPrefix(modifiers: Array<string | undefined>): string;
|
|
21
|
+
export declare function makeModifiers<T>(obj: Array<keyof T>): (data: T) => string;
|
|
21
22
|
//# sourceMappingURL=modifiers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,eAAO,MAAM,iBAAiB,mCAK5B,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
|
@@ -3,15 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
/** Access modifiers. */
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
return [data.public && "public", data.protected && "protected", data.private && "private", data.internal && "internal", data.file && "file"].filter(x => x).join(" ");
|
|
8
|
-
}
|
|
6
|
+
export const getAccessModifier = makeModifiers(["public", "protected", "private", "internal", "file"]);
|
|
9
7
|
|
|
10
8
|
/** Method modifiers. Can only be one. */
|
|
11
9
|
|
|
12
|
-
export
|
|
13
|
-
return [data.abstract && "abstract", data.sealed && "sealed", data.static && "static", data.virtual && "virtual"].filter(x => x).join(" ");
|
|
14
|
-
}
|
|
10
|
+
export const getMethodModifier = makeModifiers(["abstract", "sealed", "static", "virtual"]);
|
|
15
11
|
export function getAsyncModifier(async) {
|
|
16
12
|
return async ? "async" : "";
|
|
17
13
|
}
|
|
@@ -20,4 +16,9 @@ export function getAsyncModifier(async) {
|
|
|
20
16
|
export function computeModifiersPrefix(modifiers) {
|
|
21
17
|
const resolved = modifiers.filter(x => x);
|
|
22
18
|
return resolved.length > 0 ? resolved.join(" ") + " " : "";
|
|
19
|
+
}
|
|
20
|
+
export function makeModifiers(obj) {
|
|
21
|
+
return data => {
|
|
22
|
+
return obj.map(key => data[key] ? key : undefined).filter(x => x).join(" ");
|
|
23
|
+
};
|
|
23
24
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { memo as _$memo, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { ClassDeclaration, ClassMethod } from "../src/index.js";
|
|
4
4
|
import { TestNamespace } from "./utils.js";
|
|
5
5
|
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
6
6
|
get children() {
|
|
7
|
-
return _$createComponent(
|
|
7
|
+
return _$createComponent(ClassDeclaration, {
|
|
8
8
|
"public": true,
|
|
9
9
|
name: "TestClass",
|
|
10
10
|
get children() {
|
package/dist/test/class.test.js
CHANGED
|
@@ -1,23 +1,65 @@
|
|
|
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 } 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.
|
|
62
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
21
63
|
"public": true,
|
|
22
64
|
name: "TestClass",
|
|
23
65
|
get children() {
|
|
@@ -48,7 +90,7 @@ 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.
|
|
93
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
52
94
|
"public": true,
|
|
53
95
|
name: "TestClass",
|
|
54
96
|
get children() {
|
|
@@ -99,7 +141,7 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
99
141
|
return _$createComponent(csharp.SourceFile, {
|
|
100
142
|
path: "Test.cs",
|
|
101
143
|
get children() {
|
|
102
|
-
return [_$createComponent(csharp.
|
|
144
|
+
return [_$createComponent(csharp.EnumDeclaration, {
|
|
103
145
|
"public": true,
|
|
104
146
|
name: "TestEnum",
|
|
105
147
|
refkey: enumTypeRefkey,
|
|
@@ -116,15 +158,15 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
116
158
|
}
|
|
117
159
|
});
|
|
118
160
|
}
|
|
119
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
161
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
120
162
|
"public": true,
|
|
121
163
|
name: "TestInput",
|
|
122
164
|
refkey: inputTypeRefkey
|
|
123
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
165
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
124
166
|
"public": true,
|
|
125
167
|
name: "TestResult",
|
|
126
168
|
refkey: testResultTypeRefkey
|
|
127
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
169
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
128
170
|
"public": true,
|
|
129
171
|
name: "TestClass",
|
|
130
172
|
get children() {
|
|
@@ -175,7 +217,7 @@ it("declares class with generic parameters", () => {
|
|
|
175
217
|
T: core.refkey(),
|
|
176
218
|
U: core.refkey()
|
|
177
219
|
};
|
|
178
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
220
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
179
221
|
"public": true,
|
|
180
222
|
name: "TestClass",
|
|
181
223
|
typeParameters: typeParameters,
|
|
@@ -207,7 +249,7 @@ it("declares class with generic parameters", () => {
|
|
|
207
249
|
`);
|
|
208
250
|
});
|
|
209
251
|
it("declares class with invalid members", () => {
|
|
210
|
-
const decl = _$createComponent(csharp.
|
|
252
|
+
const decl = _$createComponent(csharp.ClassDeclaration, {
|
|
211
253
|
"public": true,
|
|
212
254
|
name: "TestClass",
|
|
213
255
|
get children() {
|
|
@@ -221,7 +263,7 @@ it("declares class with invalid members", () => {
|
|
|
221
263
|
expect(() => utils.toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
|
|
222
264
|
});
|
|
223
265
|
it("declares class with constructor", () => {
|
|
224
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
266
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
225
267
|
"public": true,
|
|
226
268
|
name: "TestClass",
|
|
227
269
|
get children() {
|
|
@@ -254,7 +296,7 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
254
296
|
type: "int",
|
|
255
297
|
refkey: paramSizeRefkey
|
|
256
298
|
}];
|
|
257
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
299
|
+
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
258
300
|
"public": true,
|
|
259
301
|
name: "TestClass",
|
|
260
302
|
get children() {
|
package/dist/test/enum.test.js
CHANGED
|
@@ -5,7 +5,7 @@ import { expect, it } from "vitest";
|
|
|
5
5
|
import * as csharp from "../src/index.js";
|
|
6
6
|
import * as utils from "./utils.js";
|
|
7
7
|
it("declares enum with no members", () => {
|
|
8
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
8
|
+
const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
|
|
9
9
|
"public": true,
|
|
10
10
|
name: "TestEnum"
|
|
11
11
|
}));
|
|
@@ -17,7 +17,7 @@ it("declares enum with no members", () => {
|
|
|
17
17
|
`);
|
|
18
18
|
});
|
|
19
19
|
it("declares enum with members", () => {
|
|
20
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
20
|
+
const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
|
|
21
21
|
"public": true,
|
|
22
22
|
name: "TestEnum",
|
|
23
23
|
get children() {
|
|
@@ -40,7 +40,7 @@ it("declares enum with members", () => {
|
|
|
40
40
|
`);
|
|
41
41
|
});
|
|
42
42
|
it("applies naming policy to enum and members", () => {
|
|
43
|
-
const res = utils.toSourceText(_$createComponent(csharp.
|
|
43
|
+
const res = utils.toSourceText(_$createComponent(csharp.EnumDeclaration, {
|
|
44
44
|
"public": true,
|
|
45
45
|
name: "testEnum",
|
|
46
46
|
get children() {
|
|
@@ -73,7 +73,7 @@ it("can reference things by refkey", () => {
|
|
|
73
73
|
return _$createComponent(csharp.SourceFile, {
|
|
74
74
|
path: "Test.cs",
|
|
75
75
|
get children() {
|
|
76
|
-
return [_$createComponent(csharp.
|
|
76
|
+
return [_$createComponent(csharp.EnumDeclaration, {
|
|
77
77
|
"public": true,
|
|
78
78
|
name: "TestEnum",
|
|
79
79
|
refkey: enumRK,
|
|
@@ -116,7 +116,7 @@ it("can reference things by refkey across files", () => {
|
|
|
116
116
|
return [_$createComponent(csharp.SourceFile, {
|
|
117
117
|
path: "Test.cs",
|
|
118
118
|
get children() {
|
|
119
|
-
return [_$createComponent(csharp.
|
|
119
|
+
return [_$createComponent(csharp.EnumDeclaration, {
|
|
120
120
|
"public": true,
|
|
121
121
|
name: "TestEnum",
|
|
122
122
|
get children() {
|
|
@@ -131,7 +131,7 @@ it("can reference things by refkey across files", () => {
|
|
|
131
131
|
}), _$createComponent(csharp.SourceFile, {
|
|
132
132
|
path: "Other.cs",
|
|
133
133
|
get children() {
|
|
134
|
-
return [_$createComponent(csharp.
|
|
134
|
+
return [_$createComponent(csharp.EnumDeclaration, {
|
|
135
135
|
"public": true,
|
|
136
136
|
name: "OtherEnum",
|
|
137
137
|
refkey: enumRK,
|
|
@@ -12,7 +12,7 @@ it("defines multiple namespaces and source files with unique content", () => {
|
|
|
12
12
|
return [_$createComponent(csharp.SourceFile, {
|
|
13
13
|
path: "Model1.cs",
|
|
14
14
|
get children() {
|
|
15
|
-
return _$createComponent(csharp.
|
|
15
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
16
16
|
"public": true,
|
|
17
17
|
name: "Model1"
|
|
18
18
|
});
|
|
@@ -20,7 +20,7 @@ it("defines multiple namespaces and source files with unique content", () => {
|
|
|
20
20
|
}), _$createComponent(csharp.SourceFile, {
|
|
21
21
|
path: "Model2.cs",
|
|
22
22
|
get children() {
|
|
23
|
-
return _$createComponent(csharp.
|
|
23
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
24
24
|
"public": true,
|
|
25
25
|
name: "Model2"
|
|
26
26
|
});
|
|
@@ -33,7 +33,7 @@ it("defines multiple namespaces and source files with unique content", () => {
|
|
|
33
33
|
return [_$createComponent(csharp.SourceFile, {
|
|
34
34
|
path: "Model3.cs",
|
|
35
35
|
get children() {
|
|
36
|
-
return _$createComponent(csharp.
|
|
36
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
37
37
|
"public": true,
|
|
38
38
|
name: "Model3"
|
|
39
39
|
});
|
|
@@ -41,7 +41,7 @@ it("defines multiple namespaces and source files with unique content", () => {
|
|
|
41
41
|
}), _$createComponent(csharp.SourceFile, {
|
|
42
42
|
path: "Model4.cs",
|
|
43
43
|
get children() {
|
|
44
|
-
return _$createComponent(csharp.
|
|
44
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
45
45
|
"public": true,
|
|
46
46
|
name: "Model4"
|
|
47
47
|
});
|
|
@@ -18,7 +18,7 @@ it("defines a project directory file with multiple source files", () => {
|
|
|
18
18
|
return [_$createComponent(csharp.SourceFile, {
|
|
19
19
|
path: "Test1.cs",
|
|
20
20
|
get children() {
|
|
21
|
-
return _$createComponent(csharp.
|
|
21
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
22
22
|
"public": true,
|
|
23
23
|
name: "TestClass1"
|
|
24
24
|
});
|
|
@@ -26,7 +26,7 @@ it("defines a project directory file with multiple source files", () => {
|
|
|
26
26
|
}), _$createComponent(csharp.SourceFile, {
|
|
27
27
|
path: "Test2.cs",
|
|
28
28
|
get children() {
|
|
29
|
-
return _$createComponent(csharp.
|
|
29
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
30
30
|
"public": true,
|
|
31
31
|
name: "TestClass2"
|
|
32
32
|
});
|
|
@@ -82,7 +82,7 @@ it("defines a project directory file with multiple source files and a custom TFM
|
|
|
82
82
|
return [_$createComponent(csharp.SourceFile, {
|
|
83
83
|
path: "Test1.cs",
|
|
84
84
|
get children() {
|
|
85
|
-
return _$createComponent(csharp.
|
|
85
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
86
86
|
"public": true,
|
|
87
87
|
name: "TestClass1"
|
|
88
88
|
});
|
|
@@ -90,7 +90,7 @@ it("defines a project directory file with multiple source files and a custom TFM
|
|
|
90
90
|
}), _$createComponent(csharp.SourceFile, {
|
|
91
91
|
path: "Test2.cs",
|
|
92
92
|
get children() {
|
|
93
|
-
return _$createComponent(csharp.
|
|
93
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
94
94
|
"public": true,
|
|
95
95
|
name: "TestClass2"
|
|
96
96
|
});
|
|
@@ -12,7 +12,7 @@ it("defines multiple source files with unique content", () => {
|
|
|
12
12
|
return [_$createComponent(csharp.SourceFile, {
|
|
13
13
|
path: "Test1.cs",
|
|
14
14
|
get children() {
|
|
15
|
-
return _$createComponent(csharp.
|
|
15
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
16
16
|
"public": true,
|
|
17
17
|
name: "TestClass1"
|
|
18
18
|
});
|
|
@@ -20,7 +20,7 @@ it("defines multiple source files with unique content", () => {
|
|
|
20
20
|
}), _$createComponent(csharp.SourceFile, {
|
|
21
21
|
path: "Test2.cs",
|
|
22
22
|
get children() {
|
|
23
|
-
return _$createComponent(csharp.
|
|
23
|
+
return _$createComponent(csharp.ClassDeclaration, {
|
|
24
24
|
"public": true,
|
|
25
25
|
name: "TestClass2"
|
|
26
26
|
});
|
package/dist/test/using.test.js
CHANGED
|
@@ -63,15 +63,15 @@ it("adds using statement across namespaces", () => {
|
|
|
63
63
|
return _$createComponent(csharp.SourceFile, {
|
|
64
64
|
path: "Models.cs",
|
|
65
65
|
get children() {
|
|
66
|
-
return [_$createComponent(csharp.
|
|
66
|
+
return [_$createComponent(csharp.ClassDeclaration, {
|
|
67
67
|
"public": true,
|
|
68
68
|
name: "Input",
|
|
69
69
|
refkey: inputTypeRefkey
|
|
70
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
70
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
71
71
|
"public": true,
|
|
72
72
|
name: "Output",
|
|
73
73
|
refkey: outputTypeRefkey
|
|
74
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
74
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumDeclaration, {
|
|
75
75
|
"public": true,
|
|
76
76
|
name: "TestEnum",
|
|
77
77
|
get children() {
|
|
@@ -93,7 +93,7 @@ it("adds using statement across namespaces", () => {
|
|
|
93
93
|
path: "Client.cs",
|
|
94
94
|
using: ["System"],
|
|
95
95
|
get children() {
|
|
96
|
-
return [_$createComponent(csharp.
|
|
96
|
+
return [_$createComponent(csharp.ClassDeclaration, {
|
|
97
97
|
"public": true,
|
|
98
98
|
name: "Client",
|
|
99
99
|
get children() {
|