@alloy-js/csharp 0.21.0-dev.0 → 0.21.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/enum/declaration.d.ts +2 -2
- package/dist/src/components/enum/declaration.d.ts.map +1 -1
- package/dist/src/components/enum/declaration.js +3 -3
- package/dist/src/components/enum/declaration.js.map +1 -1
- package/dist/src/components/enum/declaration.test.js +15 -1
- package/dist/src/components/enum/declaration.test.js.map +1 -1
- package/dist/src/components/enum/member.d.ts +2 -2
- package/dist/src/components/enum/member.d.ts.map +1 -1
- package/dist/src/components/enum/member.js +3 -3
- package/dist/src/components/enum/member.js.map +1 -1
- package/dist/src/components/enum/member.test.js +24 -1
- package/dist/src/components/enum/member.test.js.map +1 -1
- package/dist/src/components/field/field.d.ts +2 -2
- package/dist/src/components/field/field.d.ts.map +1 -1
- package/dist/src/components/field/field.js.map +1 -1
- package/dist/src/components/field/field.test.js +19 -1
- package/dist/src/components/field/field.test.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/interface/declaration.d.ts +1 -1
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +3 -3
- package/dist/src/components/interface/declaration.js.map +1 -1
- package/dist/src/components/interface/declaration.test.js +14 -1
- package/dist/src/components/interface/declaration.test.js.map +1 -1
- package/dist/src/components/interface/method.d.ts +2 -2
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js.map +1 -1
- package/dist/src/components/interface/method.test.js +17 -1
- package/dist/src/components/interface/method.test.js.map +1 -1
- package/dist/src/components/interface/property.d.ts +2 -2
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js.map +1 -1
- package/dist/src/components/interface/property.test.js +19 -0
- package/dist/src/components/interface/property.test.js.map +1 -1
- package/dist/src/components/namespace.d.ts +3 -1
- package/dist/src/components/namespace.d.ts.map +1 -1
- package/dist/src/components/namespace.js +3 -1
- package/dist/src/components/namespace.js.map +1 -1
- package/dist/src/components/namespace.ref.test.js +41 -9
- package/dist/src/components/namespace.ref.test.js.map +1 -1
- package/dist/src/components/namespace.test.js +14 -0
- package/dist/src/components/namespace.test.js.map +1 -1
- package/dist/src/components/record/declaration.d.ts +1 -1
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +3 -4
- package/dist/src/components/record/declaration.js.map +1 -1
- package/dist/src/components/record/declaration.test.js +14 -1
- package/dist/src/components/record/declaration.test.js.map +1 -1
- package/dist/src/components/source-file/source-file.js +2 -2
- package/dist/src/components/source-file/source-file.js.map +1 -1
- package/dist/src/components/source-file/using.test.d.ts.map +1 -0
- package/dist/{test → src/components/source-file}/using.test.js +30 -49
- package/dist/src/components/source-file/using.test.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +1 -1
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/components/struct/declaration.d.ts +1 -1
- package/dist/src/components/struct/declaration.d.ts.map +1 -1
- package/dist/src/components/struct/declaration.js +3 -3
- package/dist/src/components/struct/declaration.js.map +1 -1
- package/dist/src/components/struct/declaration.test.js +14 -1
- package/dist/src/components/struct/declaration.test.js.map +1 -1
- package/dist/src/components/type-parameters/type-parameter.d.ts +2 -2
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
- package/dist/src/components/type-parameters/type-parameter.js.map +1 -1
- package/dist/src/components/type-parameters/type-parameters.test.js +14 -0
- package/dist/src/components/type-parameters/type-parameters.test.js.map +1 -1
- package/dist/src/components/using/using.d.ts +28 -0
- package/dist/src/components/using/using.d.ts.map +1 -0
- package/dist/src/components/using/using.js +37 -0
- package/dist/src/components/using/using.js.map +1 -0
- package/dist/src/components/using/using.test.d.ts +2 -0
- package/dist/src/components/using/using.test.d.ts.map +1 -0
- package/dist/src/components/using/using.test.js +19 -0
- package/dist/src/components/using/using.test.js.map +1 -0
- package/dist/src/components/var/declaration.d.ts +2 -2
- package/dist/src/components/var/declaration.d.ts.map +1 -1
- package/dist/src/components/var/declaration.js.map +1 -1
- package/dist/src/components/var/declaration.test.js +22 -1
- package/dist/src/components/var/declaration.test.js.map +1 -1
- 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 +1 -0
- package/dist/src/name-policy.js.map +1 -1
- package/dist/src/symbols/factories.d.ts +1 -1
- package/dist/src/symbols/factories.d.ts.map +1 -1
- package/dist/src/symbols/factories.js +6 -4
- package/dist/src/symbols/factories.js.map +1 -1
- package/dist/src/symbols/namespace.d.ts +2 -2
- package/dist/src/symbols/namespace.d.ts.map +1 -1
- package/dist/src/symbols/namespace.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/enum/declaration.test.tsx +14 -1
- package/src/components/enum/declaration.tsx +4 -3
- package/src/components/enum/member.test.tsx +22 -1
- package/src/components/enum/member.tsx +4 -4
- package/src/components/field/field.test.tsx +14 -1
- package/src/components/field/field.tsx +2 -2
- package/src/components/index.ts +1 -1
- package/src/components/interface/declaration.test.tsx +11 -1
- package/src/components/interface/declaration.tsx +3 -4
- package/src/components/interface/method.test.tsx +14 -1
- package/src/components/interface/method.tsx +2 -1
- package/src/components/interface/property.test.tsx +13 -0
- package/src/components/interface/property.tsx +2 -1
- package/src/components/namespace.ref.test.tsx +33 -8
- package/src/components/namespace.test.tsx +13 -0
- package/src/components/namespace.tsx +6 -3
- package/src/components/record/declaration.test.tsx +11 -1
- package/src/components/record/declaration.tsx +3 -4
- package/src/components/source-file/source-file.tsx +2 -2
- package/src/components/source-file/using.test.tsx +94 -0
- package/src/components/stc/index.ts +1 -1
- package/src/components/struct/declaration.test.tsx +11 -1
- package/src/components/struct/declaration.tsx +3 -4
- package/src/components/type-parameters/type-parameter.tsx +2 -1
- package/src/components/type-parameters/type-parameters.test.tsx +9 -0
- package/src/components/using/using.test.tsx +15 -0
- package/src/components/using/using.tsx +52 -0
- package/src/components/var/declaration.test.tsx +16 -1
- package/src/components/var/declaration.tsx +2 -1
- package/src/name-policy.ts +3 -1
- package/src/symbols/factories.ts +12 -4
- package/src/symbols/namespace.ts +2 -2
- package/temp/api.json +266 -48
- package/dist/src/components/UsingDirective.d.ts +0 -10
- package/dist/src/components/UsingDirective.d.ts.map +0 -1
- package/dist/src/components/UsingDirective.js +0 -15
- package/dist/src/components/UsingDirective.js.map +0 -1
- package/dist/test/using.test.d.ts.map +0 -1
- package/dist/test/using.test.js.map +0 -1
- package/src/components/UsingDirective.tsx +0 -28
- package/test/using.test.tsx +0 -118
- /package/dist/{test → src/components/source-file}/using.test.d.ts +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import { Usings } from "./using.jsx";
|
|
3
|
+
|
|
4
|
+
it("single using", () => {
|
|
5
|
+
expect(<Usings namespaces={["Foo"]} />).toRenderTo(`
|
|
6
|
+
using Foo;
|
|
7
|
+
`);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("multiple using", () => {
|
|
11
|
+
expect(<Usings namespaces={["Foo", "Bar"]} />).toRenderTo(`
|
|
12
|
+
using Bar;
|
|
13
|
+
using Foo;
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { computed, For } from "@alloy-js/core";
|
|
2
|
+
import { NamespaceSymbol } from "../../symbols/namespace.js";
|
|
3
|
+
|
|
4
|
+
export interface UsingsProps {
|
|
5
|
+
/**
|
|
6
|
+
* Namespace symbols or namespace names to use to generate using statements.
|
|
7
|
+
*/
|
|
8
|
+
namespaces: (NamespaceSymbol | string)[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Component rendering csharp using directive
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <Usings namespaces={["System", "Models"]} />
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* will render
|
|
20
|
+
*
|
|
21
|
+
* ```csharp
|
|
22
|
+
* using Models;
|
|
23
|
+
* using System;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function Usings(props: UsingsProps) {
|
|
27
|
+
const sortedNamespaces = computed(() => {
|
|
28
|
+
return props.namespaces
|
|
29
|
+
.map(getNamespaceName)
|
|
30
|
+
.sort((n1, n2) => n1.localeCompare(n2));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<For each={sortedNamespaces}>
|
|
35
|
+
{(namespace) => <UsingNamespaceDirective namespace={namespace} />}
|
|
36
|
+
</For>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UsingNamespaceDirective {
|
|
41
|
+
namespace: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function UsingNamespaceDirective(props: UsingNamespaceDirective) {
|
|
45
|
+
return `using ${getNamespaceName(props.namespace)};`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getNamespaceName(namespace: string | NamespaceSymbol): string {
|
|
49
|
+
return typeof namespace === "string" ? namespace : (
|
|
50
|
+
namespace.getFullyQualifiedName({ omitGlobal: true })
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { List, refkey } from "@alloy-js/core";
|
|
1
|
+
import { List, namekey, refkey } from "@alloy-js/core";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { TestNamespace } from "../../../test/utils.jsx";
|
|
4
4
|
import { VarDeclaration } from "./declaration.jsx";
|
|
@@ -51,3 +51,18 @@ it("links refkey", () => {
|
|
|
51
51
|
var testVar2 = testVar;
|
|
52
52
|
`);
|
|
53
53
|
});
|
|
54
|
+
|
|
55
|
+
it("links namekey", () => {
|
|
56
|
+
const key = namekey("test-var");
|
|
57
|
+
expect(
|
|
58
|
+
<TestNamespace>
|
|
59
|
+
<List>
|
|
60
|
+
<VarDeclaration name={key}>42</VarDeclaration>
|
|
61
|
+
<VarDeclaration name="testVar2">{key}</VarDeclaration>
|
|
62
|
+
</List>
|
|
63
|
+
</TestNamespace>,
|
|
64
|
+
).toRenderTo(`
|
|
65
|
+
var testVar = 42;
|
|
66
|
+
var testVar2 = testVar;
|
|
67
|
+
`);
|
|
68
|
+
});
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
Declaration,
|
|
4
4
|
DeclarationProps,
|
|
5
5
|
Name,
|
|
6
|
+
Namekey,
|
|
6
7
|
Refkey,
|
|
7
8
|
} from "@alloy-js/core";
|
|
8
9
|
import { createVariableSymbol } from "../../symbols/factories.js";
|
|
@@ -11,7 +12,7 @@ import { createVariableSymbol } from "../../symbols/factories.js";
|
|
|
11
12
|
export interface VarDeclarationProps
|
|
12
13
|
extends Omit<DeclarationProps, "nameKind"> {
|
|
13
14
|
/** Variable name */
|
|
14
|
-
name: string;
|
|
15
|
+
name: string | Namekey;
|
|
15
16
|
/** Type of the variable declaration. If not specified, defaults to "var" */
|
|
16
17
|
type?: Children;
|
|
17
18
|
/** Variable refkey */
|
package/src/name-policy.ts
CHANGED
|
@@ -17,7 +17,8 @@ export type CSharpElements =
|
|
|
17
17
|
| "class-method"
|
|
18
18
|
| "class-property"
|
|
19
19
|
| "parameter"
|
|
20
|
-
| "type-parameter"
|
|
20
|
+
| "type-parameter"
|
|
21
|
+
| "namespace";
|
|
21
22
|
|
|
22
23
|
// creates the C# naming policy
|
|
23
24
|
export function createCSharpNamePolicy(): core.NamePolicy<CSharpElements> {
|
|
@@ -33,6 +34,7 @@ export function createCSharpNamePolicy(): core.NamePolicy<CSharpElements> {
|
|
|
33
34
|
case "class-method":
|
|
34
35
|
case "type-parameter":
|
|
35
36
|
case "class-property":
|
|
37
|
+
case "namespace":
|
|
36
38
|
return changecase.pascalCase(name);
|
|
37
39
|
case "constant":
|
|
38
40
|
return changecase.constantCase(name);
|
package/src/symbols/factories.ts
CHANGED
|
@@ -118,13 +118,21 @@ export function createNamedTypeSymbol(
|
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export function createNamespaceSymbol(
|
|
121
|
+
export function createNamespaceSymbol(
|
|
122
|
+
name: string | Namekey,
|
|
123
|
+
options: CSharpSymbolOptions = {},
|
|
124
|
+
) {
|
|
122
125
|
const scope = useEnclosingNamespaceScope();
|
|
123
126
|
const nsSymbol = scope?.ownerSymbol ?? getGlobalNamespace(useBinder());
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
const namePolicy =
|
|
128
|
+
options.namePolicy ?? useCSharpNamePolicy().for("namespace");
|
|
129
|
+
const expectedName = namePolicy(typeof name === "string" ? name : name.name);
|
|
130
|
+
if (nsSymbol.members.symbolNames.has(expectedName)) {
|
|
131
|
+
return nsSymbol.members.symbolNames.get(expectedName)! as NamespaceSymbol;
|
|
126
132
|
}
|
|
127
|
-
return withCleanup(
|
|
133
|
+
return withCleanup(
|
|
134
|
+
new NamespaceSymbol(name, nsSymbol, withNamePolicy(options, "namespace")),
|
|
135
|
+
);
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
export interface CreateMethodSymbolOptions extends CSharpSymbolOptions {
|
package/src/symbols/namespace.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutputSymbolOptions } from "@alloy-js/core";
|
|
1
|
+
import { Namekey, OutputSymbolOptions } from "@alloy-js/core";
|
|
2
2
|
import { NamedTypeSymbol } from "./named-type.js";
|
|
3
3
|
|
|
4
4
|
export interface NamespaceSymbolOptions extends OutputSymbolOptions {
|
|
@@ -11,7 +11,7 @@ export interface NamespaceSymbolOptions extends OutputSymbolOptions {
|
|
|
11
11
|
export class NamespaceSymbol extends NamedTypeSymbol {
|
|
12
12
|
public readonly symbolKind = "namespace";
|
|
13
13
|
constructor(
|
|
14
|
-
name: string,
|
|
14
|
+
name: string | Namekey,
|
|
15
15
|
parentNamespace?: NamespaceSymbol,
|
|
16
16
|
options?: NamespaceSymbolOptions,
|
|
17
17
|
) {
|