@alloy-js/csharp 0.19.0-dev.2 → 0.19.0-dev.4
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 -8
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +0 -43
- 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/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -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 +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/components/struct/declaration.test.js +40 -0
- package/dist/test/class-declaration.test.js +6 -5
- package/dist/test/using.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/ClassDeclaration.tsx +0 -44
- package/src/components/constructor/constructor.test.tsx +41 -0
- package/src/components/constructor/constructor.tsx +67 -0
- package/src/components/index.ts +2 -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 +2 -2
- package/src/components/struct/declaration.test.tsx +32 -0
- package/temp/api.json +1733 -1770
- package/test/class-declaration.test.tsx +8 -7
- 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,13 +73,6 @@ 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
76
|
export interface ClassMemberProps extends AccessModifiers {
|
|
85
77
|
name: string;
|
|
86
78
|
type: core.Children;
|
|
@@ -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;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;IACrB,kBAAkB;IAClB,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;CACrB;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,iBA0BlD"}
|
|
@@ -8,7 +8,6 @@ import { CSharpMemberScope, useCSharpScope } 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"]);
|
|
@@ -91,48 +90,6 @@ export function ClassDeclaration(props) {
|
|
|
91
90
|
}
|
|
92
91
|
});
|
|
93
92
|
}
|
|
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
93
|
|
|
137
94
|
// properties for creating a class member
|
|
138
95
|
|
|
@@ -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
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
@@ -8,6 +8,7 @@ export * from "./EnumDeclaration.jsx";
|
|
|
8
8
|
export * from "./interface/declaration.js";
|
|
9
9
|
export * from "./interface/method.js";
|
|
10
10
|
export * from "./interface/property.js";
|
|
11
|
+
export * from "./method/method.jsx";
|
|
11
12
|
export * from "./Name.js";
|
|
12
13
|
export * from "./Namespace.js";
|
|
13
14
|
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,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,6 +1,6 @@
|
|
|
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";
|
|
@@ -8,6 +8,7 @@ export * from "./EnumDeclaration.js";
|
|
|
8
8
|
export * from "./interface/declaration.js";
|
|
9
9
|
export * from "./interface/method.js";
|
|
10
10
|
export * from "./interface/property.js";
|
|
11
|
+
export * from "./method/method.js";
|
|
11
12
|
export * from "./Name.js";
|
|
12
13
|
export * from "./Namespace.js";
|
|
13
14
|
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
|
|
4
|
+
export declare const Constructor: core.StcSignature<base.ConstructorProps>;
|
|
5
5
|
export declare const ClassMember: core.StcSignature<base.ClassMemberProps>;
|
|
6
|
-
export declare const ClassMethod: core.StcSignature<base.
|
|
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,WAAW,0CAA6B,CAAC;AACtD,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
|
|
4
|
+
export const Constructor = core.stc(base.Constructor);
|
|
5
5
|
export const ClassMember = core.stc(base.ClassMember);
|
|
6
|
-
export const ClassMethod = core.stc(base.
|
|
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);
|
|
@@ -3,6 +3,8 @@ import { List, refkey } from "@alloy-js/core";
|
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { TestNamespace } from "../../../test/utils.js";
|
|
5
5
|
import { Attribute } from "../attributes/attributes.js";
|
|
6
|
+
import { Constructor } from "../constructor/constructor.js";
|
|
7
|
+
import { Method } from "../method/method.js";
|
|
6
8
|
import { Property } from "../property/property.js";
|
|
7
9
|
import { SourceFile } from "../SourceFile.js";
|
|
8
10
|
import { StructDeclaration } from "./declaration.js";
|
|
@@ -168,4 +170,42 @@ it("specify attributes", () => {
|
|
|
168
170
|
[Test]
|
|
169
171
|
struct Test;
|
|
170
172
|
`);
|
|
173
|
+
});
|
|
174
|
+
it("define methods", () => {
|
|
175
|
+
expect(_$createComponent(TestNamespace, {
|
|
176
|
+
get children() {
|
|
177
|
+
return _$createComponent(StructDeclaration, {
|
|
178
|
+
name: "Test",
|
|
179
|
+
get children() {
|
|
180
|
+
return _$createComponent(Method, {
|
|
181
|
+
name: "MethodOne"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
})).toRenderTo(`
|
|
187
|
+
struct Test
|
|
188
|
+
{
|
|
189
|
+
void MethodOne() {}
|
|
190
|
+
}
|
|
191
|
+
`);
|
|
192
|
+
});
|
|
193
|
+
it("define constructor", () => {
|
|
194
|
+
expect(_$createComponent(TestNamespace, {
|
|
195
|
+
get children() {
|
|
196
|
+
return _$createComponent(StructDeclaration, {
|
|
197
|
+
name: "Test",
|
|
198
|
+
get children() {
|
|
199
|
+
return _$createComponent(Constructor, {
|
|
200
|
+
"public": true
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
})).toRenderTo(`
|
|
206
|
+
struct Test
|
|
207
|
+
{
|
|
208
|
+
public Test() {}
|
|
209
|
+
}
|
|
210
|
+
`);
|
|
171
211
|
});
|
|
@@ -4,6 +4,7 @@ import { List, refkey } from "@alloy-js/core";
|
|
|
4
4
|
import * as coretest from "@alloy-js/core/testing";
|
|
5
5
|
import { describe, expect, it } from "vitest";
|
|
6
6
|
import { Attribute } from "../src/components/attributes/attributes.js";
|
|
7
|
+
import { Constructor } from "../src/components/stc/index.js";
|
|
7
8
|
import * as csharp from "../src/index.js";
|
|
8
9
|
import { ClassDeclaration, ClassMember, Property, SourceFile } from "../src/index.js";
|
|
9
10
|
import * as utils from "./utils.js";
|
|
@@ -137,10 +138,10 @@ it("declares class with some methods", () => {
|
|
|
137
138
|
get children() {
|
|
138
139
|
return _$createComponent(core.List, {
|
|
139
140
|
get children() {
|
|
140
|
-
return [_$createComponent(csharp.
|
|
141
|
+
return [_$createComponent(csharp.Method, {
|
|
141
142
|
"public": true,
|
|
142
143
|
name: "MethodOne"
|
|
143
|
-
}), _$createComponent(csharp.
|
|
144
|
+
}), _$createComponent(csharp.Method, {
|
|
144
145
|
"private": true,
|
|
145
146
|
virtual: true,
|
|
146
147
|
name: "MethodTwo"
|
|
@@ -215,7 +216,7 @@ it("uses refkeys for members, params, and return type", () => {
|
|
|
215
216
|
"private": true,
|
|
216
217
|
name: "MemberOne",
|
|
217
218
|
type: enumTypeRefkey
|
|
218
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.
|
|
219
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.Method, {
|
|
219
220
|
"public": true,
|
|
220
221
|
name: "MethodOne",
|
|
221
222
|
parameters: params,
|
|
@@ -353,7 +354,7 @@ it("declares class with constructor", () => {
|
|
|
353
354
|
"public": true,
|
|
354
355
|
name: "TestClass",
|
|
355
356
|
get children() {
|
|
356
|
-
return _$createComponent(
|
|
357
|
+
return _$createComponent(Constructor, {
|
|
357
358
|
"public": true
|
|
358
359
|
});
|
|
359
360
|
}
|
|
@@ -396,7 +397,7 @@ it("declares class with constructor params and assigns values to fields", () =>
|
|
|
396
397
|
name: "size",
|
|
397
398
|
type: "int",
|
|
398
399
|
refkey: thisSizeRefkey
|
|
399
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(
|
|
400
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(Constructor, {
|
|
400
401
|
"public": true,
|
|
401
402
|
parameters: ctorParams,
|
|
402
403
|
get children() {
|
package/dist/test/using.test.js
CHANGED
|
@@ -97,7 +97,7 @@ it("adds using statement across namespaces", () => {
|
|
|
97
97
|
"public": true,
|
|
98
98
|
name: "Client",
|
|
99
99
|
get children() {
|
|
100
|
-
return _$createComponent(csharp.
|
|
100
|
+
return _$createComponent(csharp.Method, {
|
|
101
101
|
"public": true,
|
|
102
102
|
name: "MethodOne",
|
|
103
103
|
parameters: params,
|