@alloy-js/csharp 0.18.0-dev.3 → 0.18.0-dev.5
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 +47 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/{Class.js → ClassDeclaration.js} +33 -8
- package/dist/src/components/ClassMethod.d.ts +2 -4
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +2 -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} +25 -5
- 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 +17 -4
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +9 -29
- package/dist/test/class-method.test.js +16 -14
- package/dist/test/class.test.js +35 -35
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/projectdirectory.test.js +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/{Class.tsx → ClassDeclaration.tsx} +45 -16
- package/src/components/ClassMethod.tsx +6 -10
- package/src/components/{Enum.tsx → EnumDeclaration.tsx} +30 -6
- package/src/components/index.ts +2 -2
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +36 -39
- package/temp/api.json +407 -266
- package/test/class-method.test.tsx +8 -14
- package/test/class.test.tsx +35 -56
- package/test/enum.test.tsx +11 -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 +9 -9
- package/dist/src/components/Class.d.ts +0 -26
- 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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as core from "@alloy-js/core";
|
|
2
|
+
import { AccessModifiers } from "../modifiers.js";
|
|
3
|
+
import { ParameterProps } from "./Parameters.jsx";
|
|
4
|
+
export interface ClassProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers {
|
|
5
|
+
name: string;
|
|
6
|
+
refkey?: core.Refkey;
|
|
7
|
+
typeParameters?: Record<string, core.Refkey>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* CSharp class declaration.
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <ClassDeclaration public name="MyClass">
|
|
14
|
+
* <ClassMember public name="MyField" type="int" />
|
|
15
|
+
* <ClassConstructor>
|
|
16
|
+
* <Parameter name="value" type="int" />
|
|
17
|
+
* this.MyField = value;
|
|
18
|
+
* </ClassConstructor>
|
|
19
|
+
* </ClassDeclaration>
|
|
20
|
+
* ```
|
|
21
|
+
* This will produce:
|
|
22
|
+
* ```csharp
|
|
23
|
+
* public class MyClass
|
|
24
|
+
* {
|
|
25
|
+
* public int MyField;
|
|
26
|
+
* public MyClass(int value)
|
|
27
|
+
* {
|
|
28
|
+
* this.MyField = value;
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function ClassDeclaration(props: ClassProps): core.Children;
|
|
34
|
+
export interface ClassConstructorProps extends AccessModifiers {
|
|
35
|
+
parameters?: Array<ParameterProps>;
|
|
36
|
+
refkey?: core.Refkey;
|
|
37
|
+
symbol?: core.OutputSymbol;
|
|
38
|
+
children?: core.Children;
|
|
39
|
+
}
|
|
40
|
+
export declare function ClassConstructor(props: ClassConstructorProps): core.Children;
|
|
41
|
+
export interface ClassMemberProps extends AccessModifiers {
|
|
42
|
+
name: string;
|
|
43
|
+
type: core.Children;
|
|
44
|
+
refkey?: core.Refkey;
|
|
45
|
+
}
|
|
46
|
+
export declare function ClassMember(props: ClassMemberProps): core.Children;
|
|
47
|
+
//# 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,EAGhB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,MAAM,WAAW,UACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe;IACjB,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,UAAU,iBAqDjD;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,6 +1,6 @@
|
|
|
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 { getAccessModifier } from "../modifiers.js";
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier } 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";
|
|
@@ -9,8 +9,31 @@ import { Parameters } from "./Parameters.js";
|
|
|
9
9
|
|
|
10
10
|
// properties for creating a class
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* CSharp class declaration.
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <ClassDeclaration public name="MyClass">
|
|
17
|
+
* <ClassMember public name="MyField" type="int" />
|
|
18
|
+
* <ClassConstructor>
|
|
19
|
+
* <Parameter name="value" type="int" />
|
|
20
|
+
* this.MyField = value;
|
|
21
|
+
* </ClassConstructor>
|
|
22
|
+
* </ClassDeclaration>
|
|
23
|
+
* ```
|
|
24
|
+
* This will produce:
|
|
25
|
+
* ```csharp
|
|
26
|
+
* public class MyClass
|
|
27
|
+
* {
|
|
28
|
+
* public int MyField;
|
|
29
|
+
* public MyClass(int value)
|
|
30
|
+
* {
|
|
31
|
+
* this.MyField = value;
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function ClassDeclaration(props) {
|
|
14
37
|
const name = useCSharpNamePolicy().getName(props.name, "class");
|
|
15
38
|
const thisClassSymbol = new CSharpOutputSymbol(name, {
|
|
16
39
|
refkeys: props.refkey
|
|
@@ -46,10 +69,11 @@ export function Class(props) {
|
|
|
46
69
|
}
|
|
47
70
|
});
|
|
48
71
|
}
|
|
72
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
49
73
|
return _$createComponent(core.Declaration, {
|
|
50
74
|
symbol: thisClassSymbol,
|
|
51
75
|
get children() {
|
|
52
|
-
return [
|
|
76
|
+
return [modifiers, "class ", _$createComponent(Name, {}), typeParams, _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Block, {
|
|
53
77
|
newline: true,
|
|
54
78
|
get children() {
|
|
55
79
|
return _$createComponent(core.Scope, {
|
|
@@ -81,7 +105,7 @@ export function ClassConstructor(props) {
|
|
|
81
105
|
const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
|
|
82
106
|
owner: ctorSymbol
|
|
83
107
|
});
|
|
84
|
-
const
|
|
108
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
85
109
|
const params = props.parameters ? _$createComponent(Parameters, {
|
|
86
110
|
get parameters() {
|
|
87
111
|
return props.parameters;
|
|
@@ -95,7 +119,7 @@ export function ClassConstructor(props) {
|
|
|
95
119
|
return _$createComponent(core.Scope, {
|
|
96
120
|
value: ctorDeclScope,
|
|
97
121
|
get children() {
|
|
98
|
-
return [
|
|
122
|
+
return [modifiers, _$createComponent(Name, {}), "(", params, ")", _$createComponent(core.Block, {
|
|
99
123
|
newline: true,
|
|
100
124
|
get children() {
|
|
101
125
|
return props.children;
|
|
@@ -112,7 +136,7 @@ export function ClassConstructor(props) {
|
|
|
112
136
|
// a C# class member (i.e. a field within a class like "private int count")
|
|
113
137
|
export function ClassMember(props) {
|
|
114
138
|
let nameElement = "class-member-private";
|
|
115
|
-
if (props.
|
|
139
|
+
if (props.public) {
|
|
116
140
|
nameElement = "class-member-public";
|
|
117
141
|
}
|
|
118
142
|
const name = useCSharpNamePolicy().getName(props.name, nameElement);
|
|
@@ -124,10 +148,11 @@ export function ClassMember(props) {
|
|
|
124
148
|
scope,
|
|
125
149
|
refkeys: props.refkey ?? core.refkey(props.name)
|
|
126
150
|
});
|
|
151
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
127
152
|
return _$createComponent(core.Declaration, {
|
|
128
153
|
symbol: memberSymbol,
|
|
129
154
|
get children() {
|
|
130
|
-
return [
|
|
155
|
+
return [modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {})];
|
|
131
156
|
}
|
|
132
157
|
});
|
|
133
158
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import {
|
|
2
|
+
import { AccessModifiers, MethodModifiers } from "../modifiers.js";
|
|
3
3
|
import { ParameterProps } from "./Parameters.jsx";
|
|
4
|
-
export interface ClassMethodProps {
|
|
4
|
+
export interface ClassMethodProps extends AccessModifiers, MethodModifiers {
|
|
5
5
|
name: string;
|
|
6
6
|
refkey?: Refkey;
|
|
7
7
|
children?: Children;
|
|
8
|
-
accessModifier?: AccessModifier;
|
|
9
|
-
methodModifier?: MethodModifier;
|
|
10
8
|
parameters?: Array<ParameterProps>;
|
|
11
9
|
returns?: Children;
|
|
12
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassMethod.d.ts","sourceRoot":"","sources":["../../../src/components/ClassMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"ClassMethod.d.ts","sourceRoot":"","sources":["../../../src/components/ClassMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKf,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAC;AAG9D,MAAM,WAAW,gBAAiB,SAAQ,eAAe,EAAE,eAAe;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAoClD"}
|
|
@@ -30,7 +30,7 @@ export function ClassMethod(props) {
|
|
|
30
30
|
}
|
|
31
31
|
}) : "";
|
|
32
32
|
const returns = props.returns ?? (props.async ? "Task" : "void");
|
|
33
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props
|
|
33
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props), getAsyncModifier(props.async)]);
|
|
34
34
|
// note that scope wraps the method decl so that the params get the correct scope
|
|
35
35
|
return _$createComponent(MemberDeclaration, {
|
|
36
36
|
symbol: methodSymbol,
|
|
@@ -38,7 +38,7 @@ export function ClassMethod(props) {
|
|
|
38
38
|
return _$createComponent(Scope, {
|
|
39
39
|
value: methodScope,
|
|
40
40
|
get children() {
|
|
41
|
-
return [modifiers, returns, " ", name, "(", params, ")", _$memo(() => _$memo(() => props.
|
|
41
|
+
return [modifiers, returns, " ", name, "(", params, ")", _$memo(() => _$memo(() => !!props.abstract)() ? ";" : _$createComponent(Block, {
|
|
42
42
|
newline: true,
|
|
43
43
|
get children() {
|
|
44
44
|
return props.children;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as core from "@alloy-js/core";
|
|
2
|
+
import { AccessModifiers } from "../modifiers.js";
|
|
3
|
+
export interface EnumProps 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: EnumProps): 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,SAAU,SAAQ,eAAe;IAChD,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,SAAS,iBAgC/C;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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as core from "@alloy-js/core";
|
|
3
|
-
import { getAccessModifier } from "../modifiers.js";
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier } 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";
|
|
@@ -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, {
|
|
@@ -25,10 +44,11 @@ export function Enum(props) {
|
|
|
25
44
|
parent: scope,
|
|
26
45
|
owner: thisEnumSymbol
|
|
27
46
|
});
|
|
47
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
28
48
|
if (thisEnumScope.owner) return _$createComponent(core.Declaration, {
|
|
29
49
|
symbol: thisEnumSymbol,
|
|
30
50
|
get children() {
|
|
31
|
-
return [
|
|
51
|
+
return [modifiers, "enum ", _$createComponent(Name, {}), _$memo(() => !props.children && ";"), _$memo(() => _$memo(() => !!props.children)() && _$createComponent(core.Scope, {
|
|
32
52
|
value: thisEnumScope,
|
|
33
53
|
get children() {
|
|
34
54
|
return _$createComponent(core.Block, {
|
|
@@ -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.ClassProps>;
|
|
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.EnumProps>;
|
|
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,oCAAkC,CAAC;AAChE,eAAO,MAAM,gBAAgB,+CAAkC,CAAC;AAChE,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,eAAe,mCAAiC,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
|
@@ -1,7 +1,20 @@
|
|
|
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 function getAccessModifier(data: AccessModifiers): string;
|
|
10
|
+
/** Method modifiers. Can only be one. */
|
|
11
|
+
export interface MethodModifiers {
|
|
12
|
+
readonly abstract?: boolean;
|
|
13
|
+
readonly sealed?: boolean;
|
|
14
|
+
readonly static?: boolean;
|
|
15
|
+
readonly virtual?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function getMethodModifier(data: MethodModifiers): string;
|
|
5
18
|
export declare function getAsyncModifier(async?: boolean): string;
|
|
6
19
|
/** Resolve the modifier prefix */
|
|
7
20
|
export declare function computeModifiersPrefix(modifiers: Array<string | undefined>): string;
|
|
@@ -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,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAU/D;AAED,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,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAS/D;AAED,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"}
|
package/dist/src/modifiers.js
CHANGED
|
@@ -1,43 +1,23 @@
|
|
|
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
|
-
export function getAccessModifier(accessModifier) {
|
|
19
|
-
return accessModifier ? accessModifierLookup[accessModifier] : "";
|
|
6
|
+
export function getAccessModifier(data) {
|
|
7
|
+
return [data.public && "public", data.protected && "protected", data.private && "private", data.internal && "internal", data.file && "file"].filter(x => x).join(" ");
|
|
20
8
|
}
|
|
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
9
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export function getMethodModifier(
|
|
33
|
-
return
|
|
10
|
+
/** Method modifiers. Can only be one. */
|
|
11
|
+
|
|
12
|
+
export function getMethodModifier(data) {
|
|
13
|
+
return [data.abstract && "abstract", data.sealed && "sealed", data.static && "static", data.virtual && "virtual"].filter(x => x).join(" ");
|
|
34
14
|
}
|
|
35
15
|
export function getAsyncModifier(async) {
|
|
36
|
-
return async ? "async
|
|
16
|
+
return async ? "async" : "";
|
|
37
17
|
}
|
|
38
18
|
|
|
39
19
|
/** Resolve the modifier prefix */
|
|
40
20
|
export function computeModifiersPrefix(modifiers) {
|
|
41
21
|
const resolved = modifiers.filter(x => x);
|
|
42
|
-
return resolved.length > 0 ? resolved.join("") : "";
|
|
22
|
+
return resolved.length > 0 ? resolved.join(" ") + " " : "";
|
|
43
23
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
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(
|
|
8
|
-
|
|
7
|
+
return _$createComponent(ClassDeclaration, {
|
|
8
|
+
"public": true,
|
|
9
9
|
name: "TestClass",
|
|
10
10
|
get children() {
|
|
11
11
|
return props.children;
|
|
@@ -18,10 +18,11 @@ describe("modifiers", () => {
|
|
|
18
18
|
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
19
19
|
expect(_$createComponent(Wrapper, {
|
|
20
20
|
get children() {
|
|
21
|
-
return _$createComponent(ClassMethod, {
|
|
22
|
-
accessModifier:
|
|
21
|
+
return _$createComponent(ClassMethod, _$mergeProps({
|
|
22
|
+
[accessModifier]: true
|
|
23
|
+
}, {
|
|
23
24
|
name: "MethodOne"
|
|
24
|
-
});
|
|
25
|
+
}));
|
|
25
26
|
}
|
|
26
27
|
})).toRenderTo(`
|
|
27
28
|
public class TestClass
|
|
@@ -35,10 +36,11 @@ describe("modifiers", () => {
|
|
|
35
36
|
it.each(["static", "virtual", "sealed"])("%s", methodModifier => {
|
|
36
37
|
expect(_$createComponent(Wrapper, {
|
|
37
38
|
get children() {
|
|
38
|
-
return _$createComponent(ClassMethod, {
|
|
39
|
-
methodModifier:
|
|
39
|
+
return _$createComponent(ClassMethod, _$mergeProps({
|
|
40
|
+
[methodModifier]: true
|
|
41
|
+
}, {
|
|
40
42
|
name: "MethodOne"
|
|
41
|
-
});
|
|
43
|
+
}));
|
|
42
44
|
}
|
|
43
45
|
})).toRenderTo(`
|
|
44
46
|
public class TestClass
|
|
@@ -51,7 +53,7 @@ describe("modifiers", () => {
|
|
|
51
53
|
expect(_$createComponent(Wrapper, {
|
|
52
54
|
get children() {
|
|
53
55
|
return _$createComponent(ClassMethod, {
|
|
54
|
-
|
|
56
|
+
abstract: true,
|
|
55
57
|
name: "MethodOne"
|
|
56
58
|
});
|
|
57
59
|
}
|
|
@@ -84,8 +86,8 @@ describe("modifiers", () => {
|
|
|
84
86
|
return _$createComponent(ClassMethod, {
|
|
85
87
|
async: true,
|
|
86
88
|
returns: "Task",
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
"public": true,
|
|
90
|
+
abstract: true,
|
|
89
91
|
name: "MethodOne"
|
|
90
92
|
});
|
|
91
93
|
}
|
|
@@ -122,7 +124,7 @@ it("defines params and return type", () => {
|
|
|
122
124
|
const res = _$createComponent(Wrapper, {
|
|
123
125
|
get children() {
|
|
124
126
|
return _$createComponent(ClassMethod, {
|
|
125
|
-
|
|
127
|
+
"public": true,
|
|
126
128
|
name: "MethodOne",
|
|
127
129
|
parameters: params,
|
|
128
130
|
returns: "string"
|