@alloy-js/typescript 0.20.0 → 0.21.0-dev.3
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 +4 -4
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +6 -11
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/Declaration.d.ts +27 -24
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +12 -8
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts +2 -2
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +3 -3
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts +2 -2
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +8 -10
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +3 -2
- package/dist/src/components/FunctionBase.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +2 -2
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +0 -3
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/Interface.d.ts +13 -8
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +46 -43
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/InterfaceMethod.d.ts +2 -2
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
- package/dist/src/components/InterfaceMethod.js +3 -8
- package/dist/src/components/InterfaceMethod.js.map +1 -1
- package/dist/src/components/MemberDeclaration.d.ts +10 -13
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +4 -5
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts +2 -2
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts +2 -2
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +3 -3
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts +3 -3
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/symbols/index.d.ts +9 -9
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js.map +1 -1
- package/dist/src/symbols/ts-output-symbol.d.ts +2 -2
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/test/class.test.js +29 -1
- package/dist/test/class.test.js.map +1 -1
- package/dist/test/enum.test.js +30 -1
- package/dist/test/enum.test.js.map +1 -1
- package/dist/test/function-declaration.test.js +18 -1
- package/dist/test/function-declaration.test.js.map +1 -1
- package/dist/test/interface.test.d.ts.map +1 -1
- package/dist/test/interface.test.js +25 -1
- package/dist/test/interface.test.js.map +1 -1
- package/dist/test/reference.test.js +2 -0
- package/dist/test/reference.test.js.map +1 -1
- package/dist/test/var-declaration.test.d.ts.map +1 -1
- package/dist/test/var-declaration.test.js +18 -1
- package/dist/test/var-declaration.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/components/ClassDeclaration.tsx +9 -12
- package/src/components/Declaration.tsx +39 -32
- package/src/components/EnumDeclaration.tsx +4 -4
- package/src/components/EnumMember.tsx +8 -13
- package/src/components/FunctionBase.tsx +7 -9
- package/src/components/FunctionDeclaration.tsx +3 -3
- package/src/components/Interface.tsx +57 -51
- package/src/components/InterfaceMethod.tsx +12 -7
- package/src/components/MemberDeclaration.tsx +20 -24
- package/src/components/TypeDeclaration.tsx +2 -2
- package/src/components/VarDeclaration.tsx +4 -4
- package/src/parameter-descriptor.ts +3 -3
- package/src/symbols/index.ts +12 -9
- package/src/symbols/ts-output-symbol.ts +2 -1
- package/temp/api.json +756 -508
- package/test/class.test.tsx +19 -1
- package/test/enum.test.tsx +21 -1
- package/test/function-declaration.test.tsx +15 -0
- package/test/interface.test.tsx +29 -0
- package/test/reference.test.tsx +2 -2
- package/test/var-declaration.test.tsx +17 -1
package/test/class.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { List, Output, refkey, StatementList } from "@alloy-js/core";
|
|
1
|
+
import { List, namekey, Output, refkey, StatementList } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
@@ -27,6 +27,24 @@ it("creates extends", () => {
|
|
|
27
27
|
`);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
it("takes namekeys for all elements", () => {
|
|
31
|
+
const res = toSourceText(
|
|
32
|
+
<ts.ClassDeclaration name={namekey("foo")}>
|
|
33
|
+
<StatementList>
|
|
34
|
+
<ts.ClassField name={namekey("myField")} />
|
|
35
|
+
<ts.ClassMethod name={namekey("myMethod")} />
|
|
36
|
+
</StatementList>
|
|
37
|
+
</ts.ClassDeclaration>,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(res).toRenderTo(`
|
|
41
|
+
class foo {
|
|
42
|
+
myField;
|
|
43
|
+
myMethod() {};
|
|
44
|
+
}
|
|
45
|
+
`);
|
|
46
|
+
});
|
|
47
|
+
|
|
30
48
|
describe("instance members", () => {
|
|
31
49
|
it("can be created", () => {
|
|
32
50
|
const res = toSourceText(
|
package/test/enum.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output, refkey } from "@alloy-js/core";
|
|
1
|
+
import { namekey, Output, refkey } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
|
|
@@ -149,6 +149,26 @@ it("uses the naming policy", () => {
|
|
|
149
149
|
`);
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
+
it("takes a namekey for all its elements", () => {
|
|
153
|
+
const enumKey = namekey("my-enum");
|
|
154
|
+
const memberKey = namekey("member-one");
|
|
155
|
+
expect(
|
|
156
|
+
<Output>
|
|
157
|
+
<ts.SourceFile path="foo.ts">
|
|
158
|
+
<ts.EnumDeclaration name={enumKey}>
|
|
159
|
+
<ts.CommaList>
|
|
160
|
+
<ts.EnumMember name={memberKey} />
|
|
161
|
+
</ts.CommaList>
|
|
162
|
+
</ts.EnumDeclaration>
|
|
163
|
+
</ts.SourceFile>
|
|
164
|
+
</Output>,
|
|
165
|
+
).toRenderTo(`
|
|
166
|
+
enum my-enum {
|
|
167
|
+
"member-one",
|
|
168
|
+
}
|
|
169
|
+
`);
|
|
170
|
+
});
|
|
171
|
+
|
|
152
172
|
describe("symbols", () => {
|
|
153
173
|
it("can reference enum members by refkey", () => {
|
|
154
174
|
const memberOne = refkey();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
List,
|
|
3
3
|
memberRefkey,
|
|
4
|
+
namekey,
|
|
4
5
|
Props,
|
|
5
6
|
refkey,
|
|
6
7
|
StatementList,
|
|
@@ -96,7 +97,21 @@ it("supports type parameters by descriptor object", () => {
|
|
|
96
97
|
function foo<a extends any, b extends any>() {}
|
|
97
98
|
`);
|
|
98
99
|
});
|
|
100
|
+
it("supports type parameters with namekeys", () => {
|
|
101
|
+
const decl = (
|
|
102
|
+
<FunctionDeclaration
|
|
103
|
+
name="foo"
|
|
104
|
+
typeParameters={[
|
|
105
|
+
{ name: namekey("a"), extends: "any" },
|
|
106
|
+
{ name: namekey("b"), extends: "any" },
|
|
107
|
+
]}
|
|
108
|
+
></FunctionDeclaration>
|
|
109
|
+
);
|
|
99
110
|
|
|
111
|
+
expect(toSourceText(decl)).toBe(d`
|
|
112
|
+
function foo<a extends any, b extends any>() {}
|
|
113
|
+
`);
|
|
114
|
+
});
|
|
100
115
|
it("supports type parameters by descriptor array", () => {
|
|
101
116
|
const decl = (
|
|
102
117
|
<FunctionDeclaration
|
package/test/interface.test.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
namekey,
|
|
2
3
|
NamePolicyContext,
|
|
3
4
|
Props,
|
|
4
5
|
refkey,
|
|
@@ -299,6 +300,34 @@ it("accepts type parameters children", () => {
|
|
|
299
300
|
`);
|
|
300
301
|
});
|
|
301
302
|
|
|
303
|
+
it("takes namekeys for all its elements", () => {
|
|
304
|
+
const ifaceKey = namekey("Foo");
|
|
305
|
+
const TKey = namekey("T");
|
|
306
|
+
const memberKey = namekey("member");
|
|
307
|
+
|
|
308
|
+
const res = toSourceText(
|
|
309
|
+
<>
|
|
310
|
+
<ts.InterfaceDeclaration
|
|
311
|
+
name={ifaceKey}
|
|
312
|
+
typeParameters={[{ name: TKey }]}
|
|
313
|
+
>
|
|
314
|
+
<ts.InterfaceMember name={memberKey} type={TKey} />;
|
|
315
|
+
</ts.InterfaceDeclaration>
|
|
316
|
+
<hbr />
|
|
317
|
+
{ifaceKey};<hbr />
|
|
318
|
+
{memberKey};
|
|
319
|
+
</>,
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
expect(res).toRenderTo(`
|
|
323
|
+
interface Foo<T> {
|
|
324
|
+
member: T;
|
|
325
|
+
}
|
|
326
|
+
Foo;
|
|
327
|
+
Foo["member"];
|
|
328
|
+
`);
|
|
329
|
+
});
|
|
330
|
+
|
|
302
331
|
describe("method members", () => {
|
|
303
332
|
it("render basic", () => {
|
|
304
333
|
expect(
|
package/test/reference.test.tsx
CHANGED
|
@@ -8,7 +8,7 @@ it("works with back references", () => {
|
|
|
8
8
|
expect(
|
|
9
9
|
<Output>
|
|
10
10
|
<ts.SourceFile path="test1.ts">
|
|
11
|
-
<ts.Declaration name="foo" refkey={refkey("foo")}>
|
|
11
|
+
<ts.Declaration name="foo" nameKind="variable" refkey={refkey("foo")}>
|
|
12
12
|
const foo = 1;
|
|
13
13
|
</ts.Declaration>
|
|
14
14
|
</ts.SourceFile>
|
|
@@ -36,7 +36,7 @@ it("works with forward references", () => {
|
|
|
36
36
|
const v = <Reference refkey={refkey("foo")} />;
|
|
37
37
|
</ts.SourceFile>
|
|
38
38
|
<ts.SourceFile path="test1.ts">
|
|
39
|
-
<ts.Declaration name="foo" refkey={refkey("foo")}>
|
|
39
|
+
<ts.Declaration nameKind="variable" name="foo" refkey={refkey("foo")}>
|
|
40
40
|
const foo = 1;
|
|
41
41
|
</ts.Declaration>
|
|
42
42
|
</ts.SourceFile>
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
memberRefkey,
|
|
3
|
+
namekey,
|
|
4
|
+
Output,
|
|
5
|
+
refkey,
|
|
6
|
+
StatementList,
|
|
7
|
+
} from "@alloy-js/core";
|
|
2
8
|
import "@alloy-js/core/testing";
|
|
3
9
|
import { expect, it } from "vitest";
|
|
4
10
|
import * as ts from "../src/index.js";
|
|
@@ -13,6 +19,16 @@ it("works", () => {
|
|
|
13
19
|
).toRenderTo("const hi = 12;");
|
|
14
20
|
});
|
|
15
21
|
|
|
22
|
+
it("takes namekeys", () => {
|
|
23
|
+
expect(
|
|
24
|
+
<Output>
|
|
25
|
+
<ts.SourceFile path="test.js">
|
|
26
|
+
<ts.VarDeclaration name={namekey("foo")} initializer="12" />;
|
|
27
|
+
</ts.SourceFile>
|
|
28
|
+
</Output>,
|
|
29
|
+
).toRenderTo("const foo = 12;");
|
|
30
|
+
});
|
|
31
|
+
|
|
16
32
|
it("works end-to-end", () => {
|
|
17
33
|
const TestType = refkey("TestType");
|
|
18
34
|
|