@alloy-js/csharp 0.22.0 → 0.23.0-dev.1
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/source-file/source-file.d.ts +2 -0
- package/dist/src/components/source-file/source-file.d.ts.map +1 -1
- package/dist/src/components/source-file/source-file.js +36 -1
- package/dist/src/components/source-file/source-file.js.map +1 -1
- package/dist/src/components/source-file/source-file.test.js +40 -1
- package/dist/src/components/source-file/source-file.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/components/source-file/source-file.test.tsx +35 -1
- package/src/components/source-file/source-file.tsx +33 -0
- package/temp/api.json +55 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/csharp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0-dev.1",
|
|
4
4
|
"description": "Alloy components for CSharp language.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
"author": "jhendrix@microsoft.com",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.1",
|
|
36
|
+
"@alloy-js/msbuild": "~0.22.0 || >= 0.23.0-dev.0",
|
|
35
37
|
"change-case": "^5.4.4",
|
|
36
38
|
"marked": "^16.1.1",
|
|
37
|
-
"pathe": "^2.0.3"
|
|
38
|
-
"@alloy-js/msbuild": "~0.22.0",
|
|
39
|
-
"@alloy-js/core": "~0.22.0"
|
|
39
|
+
"pathe": "^2.0.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.1",
|
|
43
|
+
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
|
|
44
|
+
"@alloy-js/typescript": "~0.22.0 || >= 0.23.0-dev.2",
|
|
42
45
|
"@microsoft/api-extractor": "~7.52.8",
|
|
43
46
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
44
47
|
"@types/js-yaml": "^4.0.9",
|
|
45
48
|
"concurrently": "^9.2.0",
|
|
46
49
|
"js-yaml": "^4.1.0",
|
|
47
50
|
"typescript": "^5.8.3",
|
|
48
|
-
"vitest": "^3.2.4"
|
|
49
|
-
"@alloy-js/rollup-plugin": "~0.1.0",
|
|
50
|
-
"@alloy-js/typescript": "~0.22.0",
|
|
51
|
-
"@alloy-js/cli": "~0.22.0"
|
|
51
|
+
"vitest": "^3.2.4"
|
|
52
52
|
},
|
|
53
53
|
"type": "module",
|
|
54
54
|
"scripts": {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { Attribute } from "#components/attributes/attributes.jsx";
|
|
1
2
|
import { ClassDeclaration } from "#components/class/declaration.jsx";
|
|
2
3
|
import { Namespace } from "#components/namespace/namespace.jsx";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
FormatOptions,
|
|
7
|
+
Indent,
|
|
8
|
+
List,
|
|
9
|
+
Output,
|
|
10
|
+
Prose,
|
|
11
|
+
} from "@alloy-js/core";
|
|
12
|
+
import { Serialization } from "@alloy-js/csharp/global/System/Text/Json";
|
|
4
13
|
import { describe, expect, it } from "vitest";
|
|
5
14
|
import { CSharpFormatOptions } from "../../contexts/format-options.js";
|
|
6
15
|
import { SourceFile } from "./source-file.jsx";
|
|
@@ -93,4 +102,29 @@ describe("format options", () => {
|
|
|
93
102
|
indented 3 spaces
|
|
94
103
|
`);
|
|
95
104
|
});
|
|
105
|
+
|
|
106
|
+
it("respect docComment and using (and docComment before using)", () => {
|
|
107
|
+
expect(
|
|
108
|
+
<Output>
|
|
109
|
+
<SourceFile
|
|
110
|
+
path="Test1.cs"
|
|
111
|
+
headerComment={"This is a file comment"}
|
|
112
|
+
header={<Prose>// ---------Some Fake Heder-----------</Prose>}
|
|
113
|
+
>
|
|
114
|
+
<List>
|
|
115
|
+
<Attribute name={Serialization.JsonConverterAttribute} />
|
|
116
|
+
<ClassDeclaration public name="TestClass1" />
|
|
117
|
+
</List>
|
|
118
|
+
</SourceFile>
|
|
119
|
+
</Output>,
|
|
120
|
+
).toRenderTo(`
|
|
121
|
+
/// This is a file comment
|
|
122
|
+
// ---------Some Fake Heder-----------
|
|
123
|
+
|
|
124
|
+
using System.Text.Json.Serialization;
|
|
125
|
+
|
|
126
|
+
[JsonConverter]
|
|
127
|
+
public class TestClass1;
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
96
130
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DocComment } from "#components/doc/comment.jsx";
|
|
1
2
|
import { NamespaceScopes } from "#components/namespace-scopes.jsx";
|
|
2
3
|
import { NamespaceName } from "#components/namespace/namespace-name.jsx";
|
|
3
4
|
import { Reference } from "#components/Reference.jsx";
|
|
@@ -7,7 +8,9 @@ import {
|
|
|
7
8
|
Children,
|
|
8
9
|
computed,
|
|
9
10
|
SourceFile as CoreSourceFile,
|
|
11
|
+
List,
|
|
10
12
|
Scope,
|
|
13
|
+
Show,
|
|
11
14
|
useBinder,
|
|
12
15
|
} from "@alloy-js/core";
|
|
13
16
|
import {
|
|
@@ -34,6 +37,10 @@ export interface SourceFileProps extends CSharpFormatOptions {
|
|
|
34
37
|
* explicit usings is not necessary when referencing symbols via refkeys.
|
|
35
38
|
*/
|
|
36
39
|
using?: string[];
|
|
40
|
+
/* * Optional header content to include at the top of the file */
|
|
41
|
+
header?: Children;
|
|
42
|
+
/* * Optional doc comment to include at the top of the file, this will be before 'header' if both are provided */
|
|
43
|
+
headerComment?: string;
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
/** A C# source file exists within the context of a namespace contains using statements and declarations */
|
|
@@ -59,12 +66,21 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
59
66
|
useTabs: props.useTabs,
|
|
60
67
|
});
|
|
61
68
|
|
|
69
|
+
const header =
|
|
70
|
+
props.header || props.headerComment ?
|
|
71
|
+
<SourceFileHeader
|
|
72
|
+
header={props.header}
|
|
73
|
+
headerComment={props.headerComment}
|
|
74
|
+
/>
|
|
75
|
+
: undefined;
|
|
76
|
+
|
|
62
77
|
return (
|
|
63
78
|
<CoreSourceFile
|
|
64
79
|
path={props.path}
|
|
65
80
|
filetype="cs"
|
|
66
81
|
reference={Reference}
|
|
67
82
|
{...opts}
|
|
83
|
+
header={header}
|
|
68
84
|
>
|
|
69
85
|
<Scope value={sourceFileScope}>
|
|
70
86
|
{(sourceFileScope.usings.size > 0 ||
|
|
@@ -96,3 +112,20 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
96
112
|
</CoreSourceFile>
|
|
97
113
|
);
|
|
98
114
|
}
|
|
115
|
+
|
|
116
|
+
interface SourceFileHeaderProps {
|
|
117
|
+
header?: Children;
|
|
118
|
+
headerComment?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function SourceFileHeader(props: SourceFileHeaderProps) {
|
|
122
|
+
return (
|
|
123
|
+
<List>
|
|
124
|
+
<Show when={props.headerComment !== undefined}>
|
|
125
|
+
<DocComment>{props.headerComment}</DocComment>
|
|
126
|
+
</Show>
|
|
127
|
+
<Show when={props.header !== undefined}>{props.header}</Show>
|
|
128
|
+
<hbr />
|
|
129
|
+
</List>
|
|
130
|
+
);
|
|
131
|
+
}
|
package/temp/api.json
CHANGED
|
@@ -15651,6 +15651,61 @@
|
|
|
15651
15651
|
"endIndex": 2
|
|
15652
15652
|
}
|
|
15653
15653
|
},
|
|
15654
|
+
{
|
|
15655
|
+
"kind": "PropertySignature",
|
|
15656
|
+
"canonicalReference": "@alloy-js/csharp!SourceFileProps#header:member",
|
|
15657
|
+
"docComment": "",
|
|
15658
|
+
"excerptTokens": [
|
|
15659
|
+
{
|
|
15660
|
+
"kind": "Content",
|
|
15661
|
+
"text": "header?: "
|
|
15662
|
+
},
|
|
15663
|
+
{
|
|
15664
|
+
"kind": "Reference",
|
|
15665
|
+
"text": "Children",
|
|
15666
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
15667
|
+
},
|
|
15668
|
+
{
|
|
15669
|
+
"kind": "Content",
|
|
15670
|
+
"text": ";"
|
|
15671
|
+
}
|
|
15672
|
+
],
|
|
15673
|
+
"isReadonly": false,
|
|
15674
|
+
"isOptional": true,
|
|
15675
|
+
"releaseTag": "Public",
|
|
15676
|
+
"name": "header",
|
|
15677
|
+
"propertyTypeTokenRange": {
|
|
15678
|
+
"startIndex": 1,
|
|
15679
|
+
"endIndex": 2
|
|
15680
|
+
}
|
|
15681
|
+
},
|
|
15682
|
+
{
|
|
15683
|
+
"kind": "PropertySignature",
|
|
15684
|
+
"canonicalReference": "@alloy-js/csharp!SourceFileProps#headerComment:member",
|
|
15685
|
+
"docComment": "",
|
|
15686
|
+
"excerptTokens": [
|
|
15687
|
+
{
|
|
15688
|
+
"kind": "Content",
|
|
15689
|
+
"text": "headerComment?: "
|
|
15690
|
+
},
|
|
15691
|
+
{
|
|
15692
|
+
"kind": "Content",
|
|
15693
|
+
"text": "string"
|
|
15694
|
+
},
|
|
15695
|
+
{
|
|
15696
|
+
"kind": "Content",
|
|
15697
|
+
"text": ";"
|
|
15698
|
+
}
|
|
15699
|
+
],
|
|
15700
|
+
"isReadonly": false,
|
|
15701
|
+
"isOptional": true,
|
|
15702
|
+
"releaseTag": "Public",
|
|
15703
|
+
"name": "headerComment",
|
|
15704
|
+
"propertyTypeTokenRange": {
|
|
15705
|
+
"startIndex": 1,
|
|
15706
|
+
"endIndex": 2
|
|
15707
|
+
}
|
|
15708
|
+
},
|
|
15654
15709
|
{
|
|
15655
15710
|
"kind": "PropertySignature",
|
|
15656
15711
|
"canonicalReference": "@alloy-js/csharp!SourceFileProps#path:member",
|