@alloy-js/csharp 0.18.0-dev.18 → 0.18.0-dev.2
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/Class.d.ts +26 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/{ClassDeclaration.js → Class.js} +32 -59
- package/dist/src/components/ClassMethod.d.ts +4 -25
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +3 -22
- package/dist/src/components/Enum.d.ts +15 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
- package/dist/src/components/Parameters.d.ts +1 -6
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +2 -3
- package/dist/src/components/index.d.ts +3 -12
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +4 -13
- 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 +4 -10
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +32 -9
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +0 -2
- package/dist/test/class-method.test.js +14 -37
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/class.test.js +298 -0
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/projectdirectory.test.d.ts +2 -0
- package/dist/test/projectdirectory.test.d.ts.map +1 -0
- package/dist/test/{project-directory.test.js → 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 +21 -21
- package/src/components/{ClassDeclaration.tsx → Class.tsx} +43 -108
- package/src/components/ClassMethod.tsx +12 -53
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
- package/src/components/Parameters.tsx +3 -10
- package/src/components/index.ts +3 -12
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +42 -25
- package/src/name-policy.ts +0 -5
- package/temp/api.json +714 -5256
- package/test/class-method.test.tsx +14 -24
- package/test/class.test.tsx +292 -0
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/vitest.config.ts +0 -3
- package/LICENSE +0 -7
- package/dist/src/components/ClassDeclaration.d.ts +0 -74
- package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.d.ts +0 -34
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/doc/comment.d.ts +0 -70
- package/dist/src/components/doc/comment.d.ts.map +0 -1
- package/dist/src/components/doc/comment.js +0 -88
- package/dist/src/components/doc/comment.test.d.ts +0 -2
- package/dist/src/components/doc/comment.test.d.ts.map +0 -1
- package/dist/src/components/doc/comment.test.js +0 -348
- package/dist/src/components/doc/from-markdown.d.ts +0 -6
- package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.js +0 -58
- package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
- package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.test.js +0 -83
- package/dist/src/components/interface/declaration.d.ts +0 -47
- package/dist/src/components/interface/declaration.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.js +0 -77
- package/dist/src/components/interface/declaration.test.d.ts +0 -2
- package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.test.js +0 -153
- package/dist/src/components/interface/method.d.ts +0 -32
- package/dist/src/components/interface/method.d.ts.map +0 -1
- package/dist/src/components/interface/method.js +0 -69
- package/dist/src/components/interface/method.test.d.ts +0 -2
- package/dist/src/components/interface/method.test.d.ts.map +0 -1
- package/dist/src/components/interface/method.test.js +0 -254
- package/dist/src/components/interface/property.d.ts +0 -38
- package/dist/src/components/interface/property.d.ts.map +0 -1
- package/dist/src/components/interface/property.js +0 -67
- package/dist/src/components/interface/property.test.d.ts +0 -2
- package/dist/src/components/interface/property.test.d.ts.map +0 -1
- package/dist/src/components/interface/property.test.js +0 -165
- package/dist/src/components/property/property.d.ts +0 -57
- package/dist/src/components/property/property.d.ts.map +0 -1
- package/dist/src/components/property/property.js +0 -70
- package/dist/src/components/property/property.test.d.ts +0 -2
- package/dist/src/components/property/property.test.d.ts.map +0 -1
- package/dist/src/components/property/property.test.js +0 -218
- package/dist/src/components/record/declaration.d.ts +0 -35
- package/dist/src/components/record/declaration.d.ts.map +0 -1
- package/dist/src/components/record/declaration.js +0 -90
- package/dist/src/components/record/declaration.test.d.ts +0 -2
- package/dist/src/components/record/declaration.test.d.ts.map +0 -1
- package/dist/src/components/record/declaration.test.js +0 -94
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
- package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter.js +0 -22
- package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.js +0 -65
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.test.js +0 -26
- package/dist/src/components/var/declaration.d.ts +0 -35
- package/dist/src/components/var/declaration.d.ts.map +0 -1
- package/dist/src/components/var/declaration.js +0 -40
- package/dist/src/components/var/declaration.test.d.ts +0 -2
- package/dist/src/components/var/declaration.test.d.ts.map +0 -1
- package/dist/src/components/var/declaration.test.js +0 -73
- package/dist/test/class-declaration.test.d.ts +0 -2
- package/dist/test/class-declaration.test.d.ts.map +0 -1
- package/dist/test/class-declaration.test.js +0 -463
- package/dist/test/project-directory.test.d.ts +0 -2
- package/dist/test/project-directory.test.d.ts.map +0 -1
- package/dist/test/vitest.setup.d.ts +0 -2
- package/dist/test/vitest.setup.d.ts.map +0 -1
- package/dist/test/vitest.setup.js +0 -1
- package/src/components/doc/comment.test.tsx +0 -337
- package/src/components/doc/comment.tsx +0 -152
- package/src/components/doc/from-markdown.test.tsx +0 -103
- package/src/components/doc/from-markdown.tsx +0 -58
- package/src/components/interface/declaration.test.tsx +0 -143
- package/src/components/interface/declaration.tsx +0 -105
- package/src/components/interface/method.test.tsx +0 -250
- package/src/components/interface/method.tsx +0 -105
- package/src/components/interface/property.test.tsx +0 -144
- package/src/components/interface/property.tsx +0 -107
- package/src/components/property/property.test.tsx +0 -187
- package/src/components/property/property.tsx +0 -146
- package/src/components/record/declaration.test.tsx +0 -73
- package/src/components/record/declaration.tsx +0 -109
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
- package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
- package/src/components/type-parameters/type-parameter.tsx +0 -35
- package/src/components/type-parameters/type-parameters.test.tsx +0 -19
- package/src/components/type-parameters/type-parameters.tsx +0 -72
- package/src/components/var/declaration.test.tsx +0 -59
- package/src/components/var/declaration.tsx +0 -47
- package/test/class-declaration.test.tsx +0 -418
- package/test/vitest.setup.ts +0 -1
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
import { DocFromMarkdown } from "./from-markdown.js";
|
|
5
|
-
it("convert code block to <code>", () => {
|
|
6
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
7
|
-
markdown: d`
|
|
8
|
-
Some markdown with code
|
|
9
|
-
\`\`\`csharp
|
|
10
|
-
var foo = "bar";
|
|
11
|
-
\`\`\`
|
|
12
|
-
`
|
|
13
|
-
})).toRenderTo(`
|
|
14
|
-
Some markdown with code
|
|
15
|
-
<code>
|
|
16
|
-
var foo = "bar";
|
|
17
|
-
</code>
|
|
18
|
-
`);
|
|
19
|
-
});
|
|
20
|
-
it("convert inline code block to <c>", () => {
|
|
21
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
22
|
-
markdown: d`
|
|
23
|
-
Some markdown with \`inline\` code
|
|
24
|
-
`
|
|
25
|
-
})).toRenderTo(`
|
|
26
|
-
Some markdown with <c>inline</c> code
|
|
27
|
-
`);
|
|
28
|
-
});
|
|
29
|
-
it("convert link to <see>", () => {
|
|
30
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
31
|
-
markdown: d`
|
|
32
|
-
Some markdown with [link](https://example.com)
|
|
33
|
-
`
|
|
34
|
-
})).toRenderTo(`
|
|
35
|
-
Some markdown with <see href="https://example.com">link</see>
|
|
36
|
-
`);
|
|
37
|
-
});
|
|
38
|
-
it("convert bullet list to <list>", () => {
|
|
39
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
40
|
-
markdown: d`
|
|
41
|
-
- Item 1
|
|
42
|
-
- Item 2
|
|
43
|
-
- Item 3
|
|
44
|
-
`
|
|
45
|
-
})).toRenderTo(`
|
|
46
|
-
<list type="bullet">
|
|
47
|
-
<item><description>Item 1</description></item>
|
|
48
|
-
<item><description>Item 2</description></item>
|
|
49
|
-
<item><description>Item 3</description></item>
|
|
50
|
-
</list>
|
|
51
|
-
`);
|
|
52
|
-
});
|
|
53
|
-
it("convert numbered list to <list>", () => {
|
|
54
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
55
|
-
markdown: d`
|
|
56
|
-
1. Item 1
|
|
57
|
-
2. Item 2
|
|
58
|
-
3. Item 3
|
|
59
|
-
`
|
|
60
|
-
})).toRenderTo(`
|
|
61
|
-
<list type="number">
|
|
62
|
-
<item><description>Item 1</description></item>
|
|
63
|
-
<item><description>Item 2</description></item>
|
|
64
|
-
<item><description>Item 3</description></item>
|
|
65
|
-
</list>
|
|
66
|
-
`);
|
|
67
|
-
});
|
|
68
|
-
describe("strip unsupported elements", () => {
|
|
69
|
-
it("bold", () => {
|
|
70
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
71
|
-
markdown: d`
|
|
72
|
-
Some markdown with **bold** text
|
|
73
|
-
`
|
|
74
|
-
})).toRenderTo(`Some markdown with bold text`);
|
|
75
|
-
});
|
|
76
|
-
it("italic", () => {
|
|
77
|
-
expect(_$createComponent(DocFromMarkdown, {
|
|
78
|
-
markdown: d`
|
|
79
|
-
Some markdown with *italic* text
|
|
80
|
-
`
|
|
81
|
-
})).toRenderTo(`Some markdown with italic text`);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as core from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
4
|
-
export interface InterfaceModifiers {
|
|
5
|
-
readonly partial?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface InterfaceDeclarationProps extends Omit<core.DeclarationProps, "nameKind">, AccessModifiers, InterfaceModifiers {
|
|
8
|
-
name: string;
|
|
9
|
-
/** Doc comment */
|
|
10
|
-
doc?: core.Children;
|
|
11
|
-
refkey?: core.Refkey;
|
|
12
|
-
/**
|
|
13
|
-
* Type parameters for the interface
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* <InterfaceDeclaration name="IList" typeParameters={["T"]} />
|
|
18
|
-
* ```
|
|
19
|
-
* This will produce:
|
|
20
|
-
* ```csharp
|
|
21
|
-
* public interface IList<T>
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
typeParameters?: (TypeParameterProps | string)[];
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* CSharp interface declaration.
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* <InterfaceDeclaration public name="IMyInterface">
|
|
31
|
-
* <InterfaceMember public name="MyProperty" type="int" />
|
|
32
|
-
* <InterfaceMethod public name="MyMethod" returnType="void">
|
|
33
|
-
* <Parameter name="value" type="int" />
|
|
34
|
-
* </InterfaceMethod>
|
|
35
|
-
* </InterfaceDeclaration>
|
|
36
|
-
* ```
|
|
37
|
-
* This will produce:
|
|
38
|
-
* ```csharp
|
|
39
|
-
* public interface MyIface
|
|
40
|
-
* {
|
|
41
|
-
* public int MyProperty { get; set; }
|
|
42
|
-
* public void MyMethod(int value);
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare function InterfaceDeclaration(props: InterfaceDeclarationProps): core.Children;
|
|
47
|
-
//# sourceMappingURL=declaration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAKD,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC7C,eAAe,EACf,kBAAkB;IACpB,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;CAClD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,iBAoCpE"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import * as core from "@alloy-js/core";
|
|
3
|
-
import { computeModifiersPrefix, getAccessModifier, makeModifiers } from "../../modifiers.js";
|
|
4
|
-
import { useCSharpNamePolicy } from "../../name-policy.js";
|
|
5
|
-
import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
|
|
6
|
-
import { CSharpMemberScope } from "../../symbols/scopes.js";
|
|
7
|
-
import { DocWhen } from "../doc/comment.js";
|
|
8
|
-
import { Name } from "../Name.js";
|
|
9
|
-
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
10
|
-
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
11
|
-
const getInterfaceModifiers = makeModifiers(["partial"]);
|
|
12
|
-
|
|
13
|
-
// properties for creating a class
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* CSharp interface declaration.
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* <InterfaceDeclaration public name="IMyInterface">
|
|
20
|
-
* <InterfaceMember public name="MyProperty" type="int" />
|
|
21
|
-
* <InterfaceMethod public name="MyMethod" returnType="void">
|
|
22
|
-
* <Parameter name="value" type="int" />
|
|
23
|
-
* </InterfaceMethod>
|
|
24
|
-
* </InterfaceDeclaration>
|
|
25
|
-
* ```
|
|
26
|
-
* This will produce:
|
|
27
|
-
* ```csharp
|
|
28
|
-
* public interface MyIface
|
|
29
|
-
* {
|
|
30
|
-
* public int MyProperty { get; set; }
|
|
31
|
-
* public void MyMethod(int value);
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export function InterfaceDeclaration(props) {
|
|
36
|
-
const name = useCSharpNamePolicy().getName(props.name, "interface");
|
|
37
|
-
const thisInterfaceSymbol = new CSharpOutputSymbol(name, {
|
|
38
|
-
refkeys: props.refkey
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// this creates a new scope for the interface definition.
|
|
42
|
-
// members will automatically "inherit" this scope so
|
|
43
|
-
// that refkeys to them will produce the fully-qualified
|
|
44
|
-
// name e.g. Foo.Bar.
|
|
45
|
-
const thisInterfaceScope = new CSharpMemberScope("interface-decl", {
|
|
46
|
-
owner: thisInterfaceSymbol
|
|
47
|
-
});
|
|
48
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props), getInterfaceModifiers(props)]);
|
|
49
|
-
return _$createComponent(core.Declaration, {
|
|
50
|
-
symbol: thisInterfaceSymbol,
|
|
51
|
-
get children() {
|
|
52
|
-
return [_$createComponent(DocWhen, {
|
|
53
|
-
get doc() {
|
|
54
|
-
return props.doc;
|
|
55
|
-
}
|
|
56
|
-
}), modifiers, "interface ", _$createComponent(Name, {}), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
57
|
-
get parameters() {
|
|
58
|
-
return props.typeParameters;
|
|
59
|
-
}
|
|
60
|
-
})), _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
61
|
-
get parameters() {
|
|
62
|
-
return props.typeParameters;
|
|
63
|
-
}
|
|
64
|
-
})), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(core.Block, {
|
|
65
|
-
newline: true,
|
|
66
|
-
get children() {
|
|
67
|
-
return _$createComponent(core.Scope, {
|
|
68
|
-
value: thisInterfaceScope,
|
|
69
|
-
get children() {
|
|
70
|
-
return props.children;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}) : ";")];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"declaration.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/declaration.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { List, refkey } from "@alloy-js/core";
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
import { TestNamespace } from "../../../test/utils.js";
|
|
5
|
-
import { SourceFile } from "../SourceFile.js";
|
|
6
|
-
import { InterfaceDeclaration } from "./declaration.js";
|
|
7
|
-
import { InterfaceProperty } from "./property.js";
|
|
8
|
-
it("declares class with no members", () => {
|
|
9
|
-
expect(_$createComponent(TestNamespace, {
|
|
10
|
-
get children() {
|
|
11
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
12
|
-
name: "TestInterface"
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
})).toRenderTo(`
|
|
16
|
-
interface TestInterface;
|
|
17
|
-
`);
|
|
18
|
-
});
|
|
19
|
-
describe("modifiers", () => {
|
|
20
|
-
it.each(["public", "private", "internal"])("%s", mod => {
|
|
21
|
-
expect(_$createComponent(TestNamespace, {
|
|
22
|
-
get children() {
|
|
23
|
-
return _$createComponent(InterfaceDeclaration, _$mergeProps({
|
|
24
|
-
[mod]: true
|
|
25
|
-
}, {
|
|
26
|
-
name: "TestInterface"
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
})).toRenderTo(`
|
|
30
|
-
${mod} interface TestInterface;
|
|
31
|
-
`);
|
|
32
|
-
});
|
|
33
|
-
it.each(["partial"])("%s", mod => {
|
|
34
|
-
expect(_$createComponent(TestNamespace, {
|
|
35
|
-
get children() {
|
|
36
|
-
return _$createComponent(InterfaceDeclaration, _$mergeProps({
|
|
37
|
-
[mod]: true
|
|
38
|
-
}, {
|
|
39
|
-
name: "TestInterface"
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
})).toRenderTo(`
|
|
43
|
-
${mod} interface TestInterface;
|
|
44
|
-
`);
|
|
45
|
-
});
|
|
46
|
-
it("combines modifiers", () => {
|
|
47
|
-
expect(_$createComponent(TestNamespace, {
|
|
48
|
-
get children() {
|
|
49
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
50
|
-
"public": true,
|
|
51
|
-
partial: true,
|
|
52
|
-
name: "TestInterface"
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
})).toRenderTo(`
|
|
56
|
-
public partial interface TestInterface;
|
|
57
|
-
`);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
it("specify doc comment", () => {
|
|
61
|
-
expect(_$createComponent(TestNamespace, {
|
|
62
|
-
get children() {
|
|
63
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
64
|
-
name: "TestInterface",
|
|
65
|
-
doc: "This is a test"
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
})).toRenderTo(`
|
|
69
|
-
/// This is a test
|
|
70
|
-
interface TestInterface;
|
|
71
|
-
`);
|
|
72
|
-
});
|
|
73
|
-
describe("with type parameters", () => {
|
|
74
|
-
it("reference parameters", () => {
|
|
75
|
-
const typeParameters = [{
|
|
76
|
-
name: "T",
|
|
77
|
-
refkey: refkey()
|
|
78
|
-
}, {
|
|
79
|
-
name: "U",
|
|
80
|
-
refkey: refkey()
|
|
81
|
-
}];
|
|
82
|
-
expect(_$createComponent(TestNamespace, {
|
|
83
|
-
get children() {
|
|
84
|
-
return _$createComponent(SourceFile, {
|
|
85
|
-
path: "Test.cs",
|
|
86
|
-
get children() {
|
|
87
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
88
|
-
"public": true,
|
|
89
|
-
name: "Test",
|
|
90
|
-
typeParameters: typeParameters,
|
|
91
|
-
get children() {
|
|
92
|
-
return _$createComponent(List, {
|
|
93
|
-
get children() {
|
|
94
|
-
return [_$createComponent(InterfaceProperty, {
|
|
95
|
-
name: "PropA",
|
|
96
|
-
get type() {
|
|
97
|
-
return typeParameters[0].refkey;
|
|
98
|
-
},
|
|
99
|
-
get: true,
|
|
100
|
-
set: true
|
|
101
|
-
}), _$createComponent(InterfaceProperty, {
|
|
102
|
-
name: "PropB",
|
|
103
|
-
get type() {
|
|
104
|
-
return typeParameters[1].refkey;
|
|
105
|
-
},
|
|
106
|
-
get: true,
|
|
107
|
-
set: true
|
|
108
|
-
})];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
})).toRenderTo(`
|
|
117
|
-
namespace TestCode
|
|
118
|
-
{
|
|
119
|
-
public interface Test<T, U>
|
|
120
|
-
{
|
|
121
|
-
T PropA { get; set; }
|
|
122
|
-
U PropB { get; set; }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
`);
|
|
126
|
-
});
|
|
127
|
-
it("defines with constraints", () => {
|
|
128
|
-
const typeParameters = [{
|
|
129
|
-
name: "T",
|
|
130
|
-
constraints: "IFoo"
|
|
131
|
-
}, {
|
|
132
|
-
name: "U",
|
|
133
|
-
constraints: "IBar"
|
|
134
|
-
}];
|
|
135
|
-
expect(_$createComponent(TestNamespace, {
|
|
136
|
-
get children() {
|
|
137
|
-
return _$createComponent(InterfaceDeclaration, {
|
|
138
|
-
"public": true,
|
|
139
|
-
name: "Test",
|
|
140
|
-
typeParameters: typeParameters,
|
|
141
|
-
children: "// Body"
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
})).toRenderTo(`
|
|
145
|
-
public interface Test<T, U>
|
|
146
|
-
where T : IFoo
|
|
147
|
-
where U : IBar
|
|
148
|
-
{
|
|
149
|
-
// Body
|
|
150
|
-
}
|
|
151
|
-
`);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { AccessModifiers } from "../../modifiers.js";
|
|
3
|
-
import { ParameterProps } from "../Parameters.jsx";
|
|
4
|
-
import { TypeParameterProps } from "../type-parameters/type-parameter.jsx";
|
|
5
|
-
/** Method modifiers. Can only be one. */
|
|
6
|
-
export interface InterfaceMethodModifiers {
|
|
7
|
-
readonly new?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface InterfaceMethodProps extends AccessModifiers, InterfaceMethodModifiers {
|
|
10
|
-
name: string;
|
|
11
|
-
refkey?: Refkey;
|
|
12
|
-
children?: Children;
|
|
13
|
-
parameters?: Array<ParameterProps>;
|
|
14
|
-
/**
|
|
15
|
-
* Type parameters for the method
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* <InterfaceMethod name="Test" typeParameters={["T"]} />
|
|
20
|
-
* ```
|
|
21
|
-
* This will produce:
|
|
22
|
-
* ```csharp
|
|
23
|
-
* public void Test<T>()
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
typeParameters?: (TypeParameterProps | string)[];
|
|
27
|
-
returns?: Children;
|
|
28
|
-
/** Doc comment */
|
|
29
|
-
doc?: Children;
|
|
30
|
-
}
|
|
31
|
-
export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
|
|
32
|
-
//# sourceMappingURL=method.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,MAAM,EAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,cAAc,EAAc,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAKD,MAAM,WAAW,oBACf,SAAQ,eAAe,EACrB,wBAAwB;IAC1B,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;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC;IACjD,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB,kBAAkB;IAClB,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA8C1D"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Block, MemberDeclaration, refkey, Scope } from "@alloy-js/core";
|
|
3
|
-
import { computeModifiersPrefix, getAccessModifier, 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 { Parameters } from "../Parameters.js";
|
|
8
|
-
import { DocWhen } from "../doc/comment.js";
|
|
9
|
-
import { TypeParameterConstraints } from "../type-parameters/type-parameter-constraints.js";
|
|
10
|
-
import { TypeParameters } from "../type-parameters/type-parameters.js";
|
|
11
|
-
|
|
12
|
-
/** Method modifiers. Can only be one. */
|
|
13
|
-
|
|
14
|
-
const getMethodModifier = makeModifiers(["new"]);
|
|
15
|
-
|
|
16
|
-
// properties for creating a method
|
|
17
|
-
|
|
18
|
-
// a C# interface method
|
|
19
|
-
export function InterfaceMethod(props) {
|
|
20
|
-
const name = useCSharpNamePolicy().getName(props.name, "class-method");
|
|
21
|
-
const scope = useCSharpScope();
|
|
22
|
-
if (scope.kind !== "member" || scope.name !== "interface-decl") {
|
|
23
|
-
throw new Error("can't define an interface method outside of an interface scope");
|
|
24
|
-
}
|
|
25
|
-
const methodSymbol = new CSharpOutputSymbol(name, {
|
|
26
|
-
scope,
|
|
27
|
-
refkeys: props.refkey ?? refkey(props.name)
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// scope for method declaration
|
|
31
|
-
const methodScope = new CSharpMemberScope("method-decl", {
|
|
32
|
-
owner: methodSymbol
|
|
33
|
-
});
|
|
34
|
-
const params = props.parameters ? _$createComponent(Parameters, {
|
|
35
|
-
get parameters() {
|
|
36
|
-
return props.parameters;
|
|
37
|
-
}
|
|
38
|
-
}) : "";
|
|
39
|
-
const modifiers = computeModifiersPrefix([getAccessModifier(props), getMethodModifier(props)]);
|
|
40
|
-
// note that scope wraps the method decl so that the params get the correct scope
|
|
41
|
-
return _$createComponent(MemberDeclaration, {
|
|
42
|
-
symbol: methodSymbol,
|
|
43
|
-
get children() {
|
|
44
|
-
return _$createComponent(Scope, {
|
|
45
|
-
value: methodScope,
|
|
46
|
-
get children() {
|
|
47
|
-
return [_$createComponent(DocWhen, {
|
|
48
|
-
get doc() {
|
|
49
|
-
return props.doc;
|
|
50
|
-
}
|
|
51
|
-
}), modifiers, _$memo(() => props.returns ?? "void"), " ", _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameters, {
|
|
52
|
-
get parameters() {
|
|
53
|
-
return props.typeParameters;
|
|
54
|
-
}
|
|
55
|
-
})), name, "(", params, ")", _$memo(() => _$memo(() => !!props.typeParameters)() && _$createComponent(TypeParameterConstraints, {
|
|
56
|
-
get parameters() {
|
|
57
|
-
return props.typeParameters;
|
|
58
|
-
}
|
|
59
|
-
})), _$memo(() => _$memo(() => !!props.children)() ? _$createComponent(Block, {
|
|
60
|
-
newline: true,
|
|
61
|
-
get children() {
|
|
62
|
-
return props.children;
|
|
63
|
-
}
|
|
64
|
-
}) : ";")];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"method.test.d.ts","sourceRoot":"","sources":["../../../../src/components/interface/method.test.tsx"],"names":[],"mappings":""}
|