@alloy-js/csharp 0.19.0-dev.2 → 0.19.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 +0 -16
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +1 -74
- package/dist/src/components/constructor/constructor.d.ts +17 -0
- package/dist/src/components/constructor/constructor.d.ts.map +1 -0
- package/dist/src/components/constructor/constructor.js +47 -0
- package/dist/src/components/constructor/constructor.test.d.ts +2 -0
- package/dist/src/components/constructor/constructor.test.d.ts.map +1 -0
- package/dist/src/components/constructor/constructor.test.js +54 -0
- package/dist/src/components/field/field.d.ts +12 -0
- package/dist/src/components/field/field.d.ts.map +1 -0
- package/dist/src/components/field/field.js +34 -0
- package/dist/src/components/field/field.test.d.ts +2 -0
- package/dist/src/components/field/field.test.d.ts.map +1 -0
- package/dist/src/components/field/field.test.js +37 -0
- package/dist/src/components/index.d.ts +3 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +3 -1
- package/dist/src/components/{ClassMethod.d.ts → method/method.d.ts} +8 -8
- package/dist/src/components/method/method.d.ts.map +1 -0
- package/dist/src/components/{ClassMethod.js → method/method.js} +12 -12
- package/dist/src/components/method/method.test.d.ts +2 -0
- package/dist/src/components/method/method.test.d.ts.map +1 -0
- package/dist/{test/class-method.test.js → src/components/method/method.test.js} +11 -11
- package/dist/src/components/stc/index.d.ts +3 -3
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +3 -3
- package/dist/src/components/struct/declaration.d.ts +2 -0
- package/dist/src/components/struct/declaration.d.ts.map +1 -1
- package/dist/src/components/struct/declaration.js +6 -2
- package/dist/src/components/struct/declaration.test.js +85 -1
- package/dist/test/class-declaration.test.js +14 -12
- package/dist/test/using.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/ClassDeclaration.tsx +2 -84
- package/src/components/constructor/constructor.test.tsx +41 -0
- package/src/components/constructor/constructor.tsx +67 -0
- package/src/components/field/field.test.tsx +24 -0
- package/src/components/field/field.tsx +50 -0
- package/src/components/index.ts +3 -1
- package/{test/class-method.test.tsx → src/components/method/method.test.tsx} +12 -17
- package/src/components/{ClassMethod.tsx → method/method.tsx} +21 -18
- package/src/components/stc/index.ts +3 -3
- package/src/components/struct/declaration.test.tsx +63 -1
- package/src/components/struct/declaration.tsx +11 -0
- package/temp/api.json +2148 -2153
- package/test/class-declaration.test.tsx +16 -33
- package/test/using.test.tsx +1 -1
- package/dist/src/components/ClassMethod.d.ts.map +0 -1
- package/dist/test/class-method.test.d.ts +0 -2
- package/dist/test/class-method.test.d.ts.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import { AccessModifiers } from "../modifiers.js";
|
|
3
3
|
import { AttributesProp } from "./attributes/attributes.jsx";
|
|
4
|
-
import { ParameterProps } from "./parameters/parameters.jsx";
|
|
5
4
|
import { TypeParameterProps } from "./type-parameters/type-parameter.jsx";
|
|
6
5
|
export interface ClassModifiers {
|
|
7
6
|
readonly abstract?: boolean;
|
|
@@ -74,19 +73,4 @@ export interface ClassDeclarationProps extends Omit<core.DeclarationProps, "name
|
|
|
74
73
|
* ```
|
|
75
74
|
*/
|
|
76
75
|
export declare function ClassDeclaration(props: ClassDeclarationProps): core.Children;
|
|
77
|
-
export interface ClassConstructorProps extends AccessModifiers {
|
|
78
|
-
parameters?: Array<ParameterProps>;
|
|
79
|
-
refkey?: core.Refkey;
|
|
80
|
-
symbol?: core.OutputSymbol;
|
|
81
|
-
children?: core.Children;
|
|
82
|
-
}
|
|
83
|
-
export declare function ClassConstructor(props: ClassConstructorProps): core.Children;
|
|
84
|
-
export interface ClassMemberProps extends AccessModifiers {
|
|
85
|
-
name: string;
|
|
86
|
-
type: core.Children;
|
|
87
|
-
refkey?: core.Refkey;
|
|
88
|
-
/** Doc comment */
|
|
89
|
-
doc?: core.Children;
|
|
90
|
-
}
|
|
91
|
-
export declare function ClassMember(props: ClassMemberProps): core.Children;
|
|
92
76
|
//# sourceMappingURL=ClassDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAiB,cAAc,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EACL,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAiB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,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,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,CAAC;IAEjD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IAEzB,uCAAuC;IACvC,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;IAEjC;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,iBA6C5D"}
|
|
@@ -4,11 +4,10 @@ import { join } from "@alloy-js/core";
|
|
|
4
4
|
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../modifiers.js";
|
|
5
5
|
import { useCSharpNamePolicy } from "../name-policy.js";
|
|
6
6
|
import { CSharpOutputSymbol } from "../symbols/csharp-output-symbol.js";
|
|
7
|
-
import { CSharpMemberScope
|
|
7
|
+
import { CSharpMemberScope } from "../symbols/scopes.js";
|
|
8
8
|
import { AttributeList } from "./attributes/attributes.js";
|
|
9
9
|
import { DocWhen } from "./doc/comment.js";
|
|
10
10
|
import { Name } from "./Name.js";
|
|
11
|
-
import { Parameters } from "./parameters/parameters.js";
|
|
12
11
|
import { TypeParameterConstraints } from "./type-parameters/type-parameter-constraints.js";
|
|
13
12
|
import { TypeParameters } from "./type-parameters/type-parameters.js";
|
|
14
13
|
const getClassModifiers = makeModifiers(["abstract", "partial", "sealed", "static"]);
|
|
@@ -90,76 +89,4 @@ export function ClassDeclaration(props) {
|
|
|
90
89
|
}))];
|
|
91
90
|
}
|
|
92
91
|
});
|
|
93
|
-
}
|
|
94
|
-
// a C# class constructor
|
|
95
|
-
export function ClassConstructor(props) {
|
|
96
|
-
const scope = useCSharpScope();
|
|
97
|
-
if (scope.kind !== "member" || scope.name !== "class-decl") {
|
|
98
|
-
throw new Error("can't define a class constructor outside of a class-decl scope");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// fetch the class name from the scope
|
|
102
|
-
const name = useCSharpNamePolicy().getName(scope.owner.name, "class-method");
|
|
103
|
-
const ctorSymbol = new CSharpOutputSymbol(name, {
|
|
104
|
-
scope,
|
|
105
|
-
refkeys: props.refkey ?? core.refkey(name)
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// scope for ctor declaration
|
|
109
|
-
const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
|
|
110
|
-
owner: ctorSymbol
|
|
111
|
-
});
|
|
112
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
113
|
-
|
|
114
|
-
// note that scope wraps the ctor decl so that the params get the correct scope
|
|
115
|
-
return _$createComponent(core.Declaration, {
|
|
116
|
-
symbol: ctorSymbol,
|
|
117
|
-
get children() {
|
|
118
|
-
return _$createComponent(core.Scope, {
|
|
119
|
-
value: ctorDeclScope,
|
|
120
|
-
get children() {
|
|
121
|
-
return [modifiers, _$createComponent(Name, {}), _$createComponent(Parameters, {
|
|
122
|
-
get parameters() {
|
|
123
|
-
return props.parameters;
|
|
124
|
-
}
|
|
125
|
-
}), _$createComponent(core.Block, {
|
|
126
|
-
newline: true,
|
|
127
|
-
get children() {
|
|
128
|
-
return props.children;
|
|
129
|
-
}
|
|
130
|
-
})];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// properties for creating a class member
|
|
138
|
-
|
|
139
|
-
// a C# class member (i.e. a field within a class like "private int count")
|
|
140
|
-
export function ClassMember(props) {
|
|
141
|
-
let nameElement = "class-member-private";
|
|
142
|
-
if (props.public) {
|
|
143
|
-
nameElement = "class-member-public";
|
|
144
|
-
}
|
|
145
|
-
const name = useCSharpNamePolicy().getName(props.name, nameElement);
|
|
146
|
-
const scope = useCSharpScope();
|
|
147
|
-
if (scope.kind !== "member" || scope.name !== "class-decl") {
|
|
148
|
-
throw new Error("can't define a class member outside of a class-decl scope");
|
|
149
|
-
}
|
|
150
|
-
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
151
|
-
scope,
|
|
152
|
-
refkeys: props.refkey ?? core.refkey(props.name)
|
|
153
|
-
});
|
|
154
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
155
|
-
return _$createComponent(core.Declaration, {
|
|
156
|
-
symbol: memberSymbol,
|
|
157
|
-
get children() {
|
|
158
|
-
return [_$createComponent(DocWhen, {
|
|
159
|
-
get doc() {
|
|
160
|
-
return props.doc;
|
|
161
|
-
}
|
|
162
|
-
}), modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {})];
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
92
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Refkey } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { AccessModifiers } from "../../modifiers.js";
|
|
4
|
+
import { ParameterProps } from "../parameters/parameters.jsx";
|
|
5
|
+
/**
|
|
6
|
+
* Properties for {@link Constructor} component.
|
|
7
|
+
*/
|
|
8
|
+
export interface ConstructorProps extends AccessModifiers {
|
|
9
|
+
/** Constructor parameters */
|
|
10
|
+
parameters?: ParameterProps[];
|
|
11
|
+
/** Refkey */
|
|
12
|
+
refkey?: Refkey;
|
|
13
|
+
/** Constructor body */
|
|
14
|
+
children?: Children;
|
|
15
|
+
}
|
|
16
|
+
export declare function Constructor(props: ConstructorProps): Children;
|
|
17
|
+
//# sourceMappingURL=constructor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructor.d.ts","sourceRoot":"","sources":["../../../../src/components/constructor/constructor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,6BAA6B;IAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAE9B,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAiClD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Block, Declaration, Name, refkey, Scope } from "@alloy-js/core";
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier } from "../../modifiers.js";
|
|
4
|
+
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
|
+
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
+
import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
7
|
+
import { Parameters } from "../parameters/parameters.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Properties for {@link Constructor} component.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function Constructor(props) {
|
|
14
|
+
const scope = useCSharpScope();
|
|
15
|
+
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
|
|
16
|
+
throw new Error("can't define a class method outside of a class or struct scope");
|
|
17
|
+
}
|
|
18
|
+
const name = useCSharpNamePolicy().getName(scope.owner.name, "class-method");
|
|
19
|
+
const ctorSymbol = new CSharpOutputSymbol(name, {
|
|
20
|
+
scope,
|
|
21
|
+
refkeys: props.refkey ?? refkey(name)
|
|
22
|
+
});
|
|
23
|
+
const ctorDeclScope = new CSharpMemberScope("constructor-decl", {
|
|
24
|
+
owner: ctorSymbol
|
|
25
|
+
});
|
|
26
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
27
|
+
return _$createComponent(Declaration, {
|
|
28
|
+
symbol: ctorSymbol,
|
|
29
|
+
get children() {
|
|
30
|
+
return _$createComponent(Scope, {
|
|
31
|
+
value: ctorDeclScope,
|
|
32
|
+
get children() {
|
|
33
|
+
return [modifiers, _$createComponent(Name, {}), _$createComponent(Parameters, {
|
|
34
|
+
get parameters() {
|
|
35
|
+
return props.parameters;
|
|
36
|
+
}
|
|
37
|
+
}), _$createComponent(Block, {
|
|
38
|
+
newline: true,
|
|
39
|
+
get children() {
|
|
40
|
+
return props.children;
|
|
41
|
+
}
|
|
42
|
+
})];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructor.test.d.ts","sourceRoot":"","sources":["../../../../src/components/constructor/constructor.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { refkey } from "@alloy-js/core";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
+
import { ClassDeclaration } from "../ClassDeclaration.js";
|
|
6
|
+
import { SourceFile } from "../SourceFile.js";
|
|
7
|
+
import { Constructor } from "./constructor.js";
|
|
8
|
+
it("reference constructor parameters in body", () => {
|
|
9
|
+
const paramNameRefkey = refkey();
|
|
10
|
+
const paramSizeRefkey = refkey();
|
|
11
|
+
const ctorParams = [{
|
|
12
|
+
name: "name",
|
|
13
|
+
type: "string",
|
|
14
|
+
refkey: paramNameRefkey
|
|
15
|
+
}, {
|
|
16
|
+
name: "size",
|
|
17
|
+
type: "int",
|
|
18
|
+
refkey: paramSizeRefkey
|
|
19
|
+
}];
|
|
20
|
+
expect(_$createComponent(TestNamespace, {
|
|
21
|
+
get children() {
|
|
22
|
+
return _$createComponent(SourceFile, {
|
|
23
|
+
path: "Test.cs",
|
|
24
|
+
get children() {
|
|
25
|
+
return _$createComponent(ClassDeclaration, {
|
|
26
|
+
"public": true,
|
|
27
|
+
name: "TestClass",
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(Constructor, {
|
|
30
|
+
"public": true,
|
|
31
|
+
parameters: ctorParams,
|
|
32
|
+
get children() {
|
|
33
|
+
return [paramNameRefkey, ";", _$createIntrinsic("hbr", {}), paramSizeRefkey, ";"];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
})).toRenderTo(`
|
|
42
|
+
namespace TestCode
|
|
43
|
+
{
|
|
44
|
+
public class TestClass
|
|
45
|
+
{
|
|
46
|
+
public TestClass(string name, int size)
|
|
47
|
+
{
|
|
48
|
+
name;
|
|
49
|
+
size;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`);
|
|
54
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
export interface FieldProps extends AccessModifiers {
|
|
4
|
+
name: string;
|
|
5
|
+
type: Children;
|
|
6
|
+
refkey?: Refkey;
|
|
7
|
+
/** Doc comment */
|
|
8
|
+
doc?: Children;
|
|
9
|
+
}
|
|
10
|
+
/** Render a c# field */
|
|
11
|
+
export declare function Field(props: FieldProps): Children;
|
|
12
|
+
//# sourceMappingURL=field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,eAAe,EAGhB,MAAM,oBAAoB,CAAC;AAM5B,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,wBAAwB;AACxB,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,YA6BtC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Declaration, Name, refkey } from "@alloy-js/core";
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier } from "../../modifiers.js";
|
|
4
|
+
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
|
+
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
+
import { useCSharpScope } from "../../symbols/scopes.js";
|
|
7
|
+
import { DocWhen } from "../doc/comment.js";
|
|
8
|
+
/** Render a c# field */
|
|
9
|
+
export function Field(props) {
|
|
10
|
+
let nameElement = "class-member-private";
|
|
11
|
+
if (props.public) {
|
|
12
|
+
nameElement = "class-member-public";
|
|
13
|
+
}
|
|
14
|
+
const name = useCSharpNamePolicy().getName(props.name, nameElement);
|
|
15
|
+
const scope = useCSharpScope();
|
|
16
|
+
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
|
|
17
|
+
throw new Error("can't define a class member outside of a class or struct scope");
|
|
18
|
+
}
|
|
19
|
+
const memberSymbol = new CSharpOutputSymbol(name, {
|
|
20
|
+
scope,
|
|
21
|
+
refkeys: props.refkey ?? refkey(props.name)
|
|
22
|
+
});
|
|
23
|
+
const modifiers = computeModifiersPrefix([getAccessModifier(props)]);
|
|
24
|
+
return _$createComponent(Declaration, {
|
|
25
|
+
symbol: memberSymbol,
|
|
26
|
+
get children() {
|
|
27
|
+
return [_$createComponent(DocWhen, {
|
|
28
|
+
get doc() {
|
|
29
|
+
return props.doc;
|
|
30
|
+
}
|
|
31
|
+
}), modifiers, _$memo(() => props.type), " ", _$createComponent(Name, {})];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.test.d.ts","sourceRoot":"","sources":["../../../../src/components/field/field.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { StatementList } from "@alloy-js/core";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
+
import { ClassDeclaration } from "../ClassDeclaration.js";
|
|
6
|
+
import { Field } from "./field.js";
|
|
7
|
+
it("declares some field", () => {
|
|
8
|
+
expect(_$createComponent(TestNamespace, {
|
|
9
|
+
get children() {
|
|
10
|
+
return _$createComponent(ClassDeclaration, {
|
|
11
|
+
"public": true,
|
|
12
|
+
name: "TestClass",
|
|
13
|
+
get children() {
|
|
14
|
+
return _$createComponent(StatementList, {
|
|
15
|
+
get children() {
|
|
16
|
+
return [_$createComponent(Field, {
|
|
17
|
+
"public": true,
|
|
18
|
+
name: "MemberOne",
|
|
19
|
+
type: "string"
|
|
20
|
+
}), _$createComponent(Field, {
|
|
21
|
+
"private": true,
|
|
22
|
+
name: "MemberTwo",
|
|
23
|
+
type: "int"
|
|
24
|
+
})];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
})).toRenderTo(`
|
|
31
|
+
public class TestClass
|
|
32
|
+
{
|
|
33
|
+
public string MemberOne;
|
|
34
|
+
private int memberTwo;
|
|
35
|
+
}
|
|
36
|
+
`);
|
|
37
|
+
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
export * from "./attributes/attributes.jsx";
|
|
2
2
|
export * from "./ClassDeclaration.jsx";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./constructor/constructor.jsx";
|
|
4
4
|
export * from "./Declaration.js";
|
|
5
5
|
export * from "./doc/comment.jsx";
|
|
6
6
|
export * from "./doc/from-markdown.jsx";
|
|
7
7
|
export * from "./EnumDeclaration.jsx";
|
|
8
|
+
export * from "./field/field.jsx";
|
|
8
9
|
export * from "./interface/declaration.js";
|
|
9
10
|
export * from "./interface/method.js";
|
|
10
11
|
export * from "./interface/property.js";
|
|
12
|
+
export * from "./method/method.jsx";
|
|
11
13
|
export * from "./Name.js";
|
|
12
14
|
export * from "./Namespace.js";
|
|
13
15
|
export * from "./parameters/parameters.jsx";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
export * from "./attributes/attributes.js";
|
|
2
2
|
export * from "./ClassDeclaration.js";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./constructor/constructor.js";
|
|
4
4
|
export * from "./Declaration.js";
|
|
5
5
|
export * from "./doc/comment.js";
|
|
6
6
|
export * from "./doc/from-markdown.js";
|
|
7
7
|
export * from "./EnumDeclaration.js";
|
|
8
|
+
export * from "./field/field.js";
|
|
8
9
|
export * from "./interface/declaration.js";
|
|
9
10
|
export * from "./interface/method.js";
|
|
10
11
|
export * from "./interface/property.js";
|
|
12
|
+
export * from "./method/method.js";
|
|
11
13
|
export * from "./Name.js";
|
|
12
14
|
export * from "./Namespace.js";
|
|
13
15
|
export * from "./parameters/parameters.js";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "
|
|
3
|
-
import { AttributesProp } from "
|
|
4
|
-
import { ParameterProps } from "
|
|
5
|
-
import { TypeParameterProps } from "
|
|
2
|
+
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
+
import { AttributesProp } from "../attributes/attributes.jsx";
|
|
4
|
+
import { ParameterProps } from "../parameters/parameters.jsx";
|
|
5
|
+
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
6
6
|
/** Method modifiers. Can only be one. */
|
|
7
|
-
export interface
|
|
7
|
+
export interface MethodModifiers {
|
|
8
8
|
readonly abstract?: boolean;
|
|
9
9
|
readonly sealed?: boolean;
|
|
10
10
|
readonly static?: boolean;
|
|
11
11
|
readonly virtual?: boolean;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface MethodProps extends AccessModifiers, MethodModifiers {
|
|
14
14
|
name: string;
|
|
15
15
|
refkey?: Refkey;
|
|
16
16
|
children?: Children;
|
|
@@ -67,5 +67,5 @@ export interface ClassMethodProps extends AccessModifiers, ClassMethodModifiers
|
|
|
67
67
|
*/
|
|
68
68
|
expression?: boolean;
|
|
69
69
|
}
|
|
70
|
-
export declare function
|
|
71
|
-
//# sourceMappingURL=
|
|
70
|
+
export declare function Method(props: MethodProps): Children;
|
|
71
|
+
//# sourceMappingURL=method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/method/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAKhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAc,MAAM,8BAA8B,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,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;AAUD,MAAM,WAAW,WAAY,SAAQ,eAAe,EAAE,eAAe;IACnE,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;IAEhB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;IAEf;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAGD,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,YAuDxC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { Block, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
|
|
3
|
-
import { computeModifiersPrefix, getAccessModifier, getAsyncModifier, makeModifiers } from "
|
|
4
|
-
import { useCSharpNamePolicy } from "
|
|
5
|
-
import { CSharpOutputSymbol } from "
|
|
6
|
-
import { CSharpMemberScope, useCSharpScope } from "
|
|
7
|
-
import { AttributeList } from "
|
|
8
|
-
import { DocWhen } from "
|
|
9
|
-
import { Parameters } from "
|
|
10
|
-
import { TypeParameterConstraints } from "
|
|
11
|
-
import { TypeParameters } from "
|
|
3
|
+
import { computeModifiersPrefix, getAccessModifier, getAsyncModifier, makeModifiers } from "../../modifiers.js";
|
|
4
|
+
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
|
+
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
+
import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
|
|
7
|
+
import { AttributeList } from "../attributes/attributes.js";
|
|
8
|
+
import { DocWhen } from "../doc/comment.js";
|
|
9
|
+
import { Parameters } from "../parameters/parameters.js";
|
|
10
|
+
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
11
|
+
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
12
12
|
|
|
13
13
|
/** Method modifiers. Can only be one. */
|
|
14
14
|
|
|
@@ -17,11 +17,11 @@ const getMethodModifier = makeModifiers(["abstract", "sealed", "static", "virtua
|
|
|
17
17
|
// properties for creating a method
|
|
18
18
|
|
|
19
19
|
// a C# class method
|
|
20
|
-
export function
|
|
20
|
+
export function Method(props) {
|
|
21
21
|
const name = useCSharpNamePolicy().getName(props.name, "class-method");
|
|
22
22
|
const scope = useCSharpScope();
|
|
23
|
-
if (scope.kind !== "member" || scope.name !== "class-decl") {
|
|
24
|
-
throw new Error("can't define a class method outside of a class scope");
|
|
23
|
+
if (scope.kind !== "member" || scope.name !== "class-decl" && scope.name !== "struct-decl") {
|
|
24
|
+
throw new Error("can't define a class method outside of a class or struct scope");
|
|
25
25
|
}
|
|
26
26
|
const methodSymbol = new CSharpOutputSymbol(name, {
|
|
27
27
|
scope,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.test.d.ts","sourceRoot":"","sources":["../../../../src/components/method/method.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
4
|
-
import {
|
|
3
|
+
import { TestNamespace } from "../../../test/utils.js";
|
|
4
|
+
import { ClassDeclaration, Method } from "../../index.js";
|
|
5
5
|
const Wrapper = props => _$createComponent(TestNamespace, {
|
|
6
6
|
get children() {
|
|
7
7
|
return _$createComponent(ClassDeclaration, {
|
|
@@ -18,7 +18,7 @@ describe("modifiers", () => {
|
|
|
18
18
|
it.each(["public", "private", "protected", "internal"])("%s", accessModifier => {
|
|
19
19
|
expect(_$createComponent(Wrapper, {
|
|
20
20
|
get children() {
|
|
21
|
-
return _$createComponent(
|
|
21
|
+
return _$createComponent(Method, _$mergeProps({
|
|
22
22
|
[accessModifier]: true
|
|
23
23
|
}, {
|
|
24
24
|
name: "MethodOne"
|
|
@@ -36,7 +36,7 @@ describe("modifiers", () => {
|
|
|
36
36
|
it.each(["static", "virtual", "sealed"])("%s", methodModifier => {
|
|
37
37
|
expect(_$createComponent(Wrapper, {
|
|
38
38
|
get children() {
|
|
39
|
-
return _$createComponent(
|
|
39
|
+
return _$createComponent(Method, _$mergeProps({
|
|
40
40
|
[methodModifier]: true
|
|
41
41
|
}, {
|
|
42
42
|
name: "MethodOne"
|
|
@@ -52,7 +52,7 @@ describe("modifiers", () => {
|
|
|
52
52
|
it("abstract exclude body", () => {
|
|
53
53
|
expect(_$createComponent(Wrapper, {
|
|
54
54
|
get children() {
|
|
55
|
-
return _$createComponent(
|
|
55
|
+
return _$createComponent(Method, {
|
|
56
56
|
abstract: true,
|
|
57
57
|
name: "MethodOne"
|
|
58
58
|
});
|
|
@@ -68,7 +68,7 @@ describe("modifiers", () => {
|
|
|
68
68
|
it("mark method async", () => {
|
|
69
69
|
expect(_$createComponent(Wrapper, {
|
|
70
70
|
get children() {
|
|
71
|
-
return _$createComponent(
|
|
71
|
+
return _$createComponent(Method, {
|
|
72
72
|
async: true,
|
|
73
73
|
name: "MethodOne"
|
|
74
74
|
});
|
|
@@ -83,7 +83,7 @@ describe("modifiers", () => {
|
|
|
83
83
|
it("combine modifiers", () => {
|
|
84
84
|
expect(_$createComponent(Wrapper, {
|
|
85
85
|
get children() {
|
|
86
|
-
return _$createComponent(
|
|
86
|
+
return _$createComponent(Method, {
|
|
87
87
|
async: true,
|
|
88
88
|
returns: "Task",
|
|
89
89
|
"public": true,
|
|
@@ -102,7 +102,7 @@ describe("modifiers", () => {
|
|
|
102
102
|
it("applies PascalCase naming policy", () => {
|
|
103
103
|
expect(_$createComponent(Wrapper, {
|
|
104
104
|
get children() {
|
|
105
|
-
return _$createComponent(
|
|
105
|
+
return _$createComponent(Method, {
|
|
106
106
|
name: "method_one"
|
|
107
107
|
});
|
|
108
108
|
}
|
|
@@ -123,7 +123,7 @@ it("defines params and return type", () => {
|
|
|
123
123
|
}];
|
|
124
124
|
const res = _$createComponent(Wrapper, {
|
|
125
125
|
get children() {
|
|
126
|
-
return _$createComponent(
|
|
126
|
+
return _$createComponent(Method, {
|
|
127
127
|
"public": true,
|
|
128
128
|
name: "MethodOne",
|
|
129
129
|
parameters: params,
|
|
@@ -144,7 +144,7 @@ it("specify doc comment", () => {
|
|
|
144
144
|
return _$createComponent(ClassDeclaration, {
|
|
145
145
|
name: "Test",
|
|
146
146
|
get children() {
|
|
147
|
-
return _$createComponent(
|
|
147
|
+
return _$createComponent(Method, {
|
|
148
148
|
name: "Method",
|
|
149
149
|
doc: "This is a test"
|
|
150
150
|
});
|
|
@@ -165,7 +165,7 @@ it("use expression body form", () => {
|
|
|
165
165
|
return _$createComponent(ClassDeclaration, {
|
|
166
166
|
name: "Test",
|
|
167
167
|
get children() {
|
|
168
|
-
return _$createComponent(
|
|
168
|
+
return _$createComponent(Method, {
|
|
169
169
|
name: "Method",
|
|
170
170
|
doc: "This is a test",
|
|
171
171
|
expression: true,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import * as base from "../index.js";
|
|
3
3
|
export declare const ClassDeclaration: core.StcSignature<base.ClassDeclarationProps>;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const ClassMethod: core.StcSignature<base.
|
|
4
|
+
export declare const Constructor: core.StcSignature<base.ConstructorProps>;
|
|
5
|
+
export declare const Field: core.StcSignature<base.FieldProps>;
|
|
6
|
+
export declare const ClassMethod: core.StcSignature<base.MethodProps>;
|
|
7
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>;
|
|
@@ -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,gBAAgB,+CAAkC,CAAC;AAChE,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,WAAW,0CAA6B,CAAC;AACtD,eAAO,MAAM,KAAK,oCAAuB,CAAC;AAC1C,eAAO,MAAM,WAAW,qCAAwB,CAAC;AACjD,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;AAC5D,eAAO,MAAM,iBAAiB,gDAAmC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as core from "@alloy-js/core";
|
|
2
2
|
import * as base from "../index.js";
|
|
3
3
|
export const ClassDeclaration = core.stc(base.ClassDeclaration);
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const ClassMethod = core.stc(base.
|
|
4
|
+
export const Constructor = core.stc(base.Constructor);
|
|
5
|
+
export const Field = core.stc(base.Field);
|
|
6
|
+
export const ClassMethod = core.stc(base.Method);
|
|
7
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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/struct/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/struct/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAiB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,eAAe;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IAEjD;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B,wCAAwC;IACxC,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,iBAwC9D"}
|