@alloy-js/typescript 0.21.0-dev.0 → 0.21.0-dev.12
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/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +6 -1
- package/dist/src/components/CallSignature.js.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts +5 -5
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +7 -12
- 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/ObjectExpression.d.ts +2 -2
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +25 -18
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PropertyName.d.ts.map +1 -1
- package/dist/src/components/PropertyName.js +7 -5
- package/dist/src/components/PropertyName.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 +16 -4
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.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/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +2 -2
- package/dist/src/symbols/reference.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 +63 -3
- package/dist/test/function-declaration.test.js.map +1 -1
- package/dist/test/imports.test.js +3 -2
- package/dist/test/imports.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/object.test.js +55 -2
- package/dist/test/object.test.js.map +1 -1
- package/dist/test/reference.test.js +14 -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 +33 -1
- package/dist/test/var-declaration.test.js.map +1 -1
- package/dist/testing/create-wrapper.d.ts +3 -0
- package/dist/testing/create-wrapper.d.ts.map +1 -0
- package/dist/testing/create-wrapper.js +12 -0
- package/dist/testing/create-wrapper.js.map +1 -0
- package/dist/testing/create-wrapper.test.d.ts +2 -0
- package/dist/testing/create-wrapper.test.d.ts.map +1 -0
- package/dist/testing/create-wrapper.test.js +159 -0
- package/dist/testing/create-wrapper.test.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -2
- package/src/components/CallSignature.tsx +5 -1
- package/src/components/ClassDeclaration.tsx +10 -13
- 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/ObjectExpression.tsx +20 -16
- package/src/components/PropertyName.tsx +7 -5
- package/src/components/TypeDeclaration.tsx +2 -2
- package/src/components/VarDeclaration.tsx +11 -6
- package/src/components/index.ts +1 -0
- package/src/parameter-descriptor.ts +3 -3
- package/src/symbols/index.ts +12 -9
- package/src/symbols/reference.tsx +3 -1
- package/src/symbols/ts-output-symbol.ts +2 -1
- package/temp/api.json +843 -497
- package/test/class.test.tsx +19 -1
- package/test/enum.test.tsx +21 -1
- package/test/function-declaration.test.tsx +52 -0
- package/test/imports.test.tsx +2 -1
- package/test/interface.test.tsx +29 -0
- package/test/object.test.tsx +40 -1
- package/test/reference.test.tsx +12 -2
- package/test/var-declaration.test.tsx +27 -1
- package/testing/create-wrapper.test.tsx +107 -0
- package/testing/create-wrapper.tsx +12 -0
- package/testing/index.ts +1 -0
- package/tsconfig.json +8 -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,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
List,
|
|
3
3
|
memberRefkey,
|
|
4
|
+
namekey,
|
|
5
|
+
Output,
|
|
4
6
|
Props,
|
|
5
7
|
refkey,
|
|
6
8
|
StatementList,
|
|
@@ -13,6 +15,8 @@ import {
|
|
|
13
15
|
FunctionDeclaration,
|
|
14
16
|
InterfaceDeclaration,
|
|
15
17
|
InterfaceMember,
|
|
18
|
+
SourceFile,
|
|
19
|
+
TypeDeclaration,
|
|
16
20
|
VarDeclaration,
|
|
17
21
|
} from "../src/index.js";
|
|
18
22
|
import { ParameterDescriptor } from "../src/parameter-descriptor.js";
|
|
@@ -96,7 +100,21 @@ it("supports type parameters by descriptor object", () => {
|
|
|
96
100
|
function foo<a extends any, b extends any>() {}
|
|
97
101
|
`);
|
|
98
102
|
});
|
|
103
|
+
it("supports type parameters with namekeys", () => {
|
|
104
|
+
const decl = (
|
|
105
|
+
<FunctionDeclaration
|
|
106
|
+
name="foo"
|
|
107
|
+
typeParameters={[
|
|
108
|
+
{ name: namekey("a"), extends: "any" },
|
|
109
|
+
{ name: namekey("b"), extends: "any" },
|
|
110
|
+
]}
|
|
111
|
+
></FunctionDeclaration>
|
|
112
|
+
);
|
|
99
113
|
|
|
114
|
+
expect(toSourceText(decl)).toBe(d`
|
|
115
|
+
function foo<a extends any, b extends any>() {}
|
|
116
|
+
`);
|
|
117
|
+
});
|
|
100
118
|
it("supports type parameters by descriptor array", () => {
|
|
101
119
|
const decl = (
|
|
102
120
|
<FunctionDeclaration
|
|
@@ -371,3 +389,37 @@ describe("symbols", () => {
|
|
|
371
389
|
`);
|
|
372
390
|
});
|
|
373
391
|
});
|
|
392
|
+
|
|
393
|
+
it("has parameters and return type in type ref context", () => {
|
|
394
|
+
const i1 = namekey("iface1");
|
|
395
|
+
const i2 = namekey("iface2");
|
|
396
|
+
const template = (
|
|
397
|
+
<Output>
|
|
398
|
+
<SourceFile path="test1.ts">
|
|
399
|
+
<TypeDeclaration name={i1}>any</TypeDeclaration>
|
|
400
|
+
<hbr />
|
|
401
|
+
<TypeDeclaration name={i2}>any</TypeDeclaration>
|
|
402
|
+
</SourceFile>
|
|
403
|
+
|
|
404
|
+
<SourceFile path="test2.ts">
|
|
405
|
+
<FunctionDeclaration
|
|
406
|
+
name="foo"
|
|
407
|
+
parameters={[{ name: "a", type: i1 }]}
|
|
408
|
+
returnType={i2}
|
|
409
|
+
/>
|
|
410
|
+
</SourceFile>
|
|
411
|
+
</Output>
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
expect(template).toRenderTo({
|
|
415
|
+
"test1.ts": `
|
|
416
|
+
type iface1 = any;
|
|
417
|
+
type iface2 = any;
|
|
418
|
+
`,
|
|
419
|
+
"test2.ts": `
|
|
420
|
+
import type { iface1, iface2 } from "./test1.js";
|
|
421
|
+
|
|
422
|
+
function foo(a: iface1): iface2 {}
|
|
423
|
+
`,
|
|
424
|
+
});
|
|
425
|
+
});
|
package/test/imports.test.tsx
CHANGED
|
@@ -410,10 +410,11 @@ it("handles conflicts with local declarations", () => {
|
|
|
410
410
|
<ts.FunctionDeclaration export name="test" />
|
|
411
411
|
</ts.SourceFile>
|
|
412
412
|
</Output>,
|
|
413
|
+
// cspell:ignore stest2
|
|
413
414
|
).toRenderTo({
|
|
414
415
|
"src/test1.ts": `
|
|
415
416
|
export function test() {}
|
|
416
|
-
const v = <Unresolved Symbol>;
|
|
417
|
+
const v = <Unresolved Symbol: refkey[stest2]>;
|
|
417
418
|
`,
|
|
418
419
|
"test2.ts": `
|
|
419
420
|
import { test as test_1 } from "./src/test1.js";
|
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/object.test.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { List } from "@alloy-js/core";
|
|
1
|
+
import { List, namekey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
4
|
import {
|
|
5
|
+
CommaList,
|
|
5
6
|
ObjectExpression,
|
|
6
7
|
ObjectProperty,
|
|
7
8
|
ObjectSpreadProperty,
|
|
@@ -46,3 +47,41 @@ it("spread property", () => {
|
|
|
46
47
|
}
|
|
47
48
|
`);
|
|
48
49
|
});
|
|
50
|
+
|
|
51
|
+
it("Works with both children and jsvalue", () => {
|
|
52
|
+
const comp = (
|
|
53
|
+
<ObjectExpression jsValue={{ a: 1, b: 2 }}>
|
|
54
|
+
<ObjectProperty name="c" value={3} />
|
|
55
|
+
</ObjectExpression>
|
|
56
|
+
);
|
|
57
|
+
expect(toSourceText(comp)).toBe(d`
|
|
58
|
+
{
|
|
59
|
+
a: 1,
|
|
60
|
+
b: 2,
|
|
61
|
+
c: 3
|
|
62
|
+
}
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("Handles name conflicts and namekeys", () => {
|
|
67
|
+
const nk1 = namekey("a");
|
|
68
|
+
const nk2 = namekey("a");
|
|
69
|
+
const nk3 = namekey("a", { ignoreNameConflict: true });
|
|
70
|
+
|
|
71
|
+
const comp = (
|
|
72
|
+
<ObjectExpression>
|
|
73
|
+
<CommaList>
|
|
74
|
+
<ObjectProperty name={nk1} value={3} />
|
|
75
|
+
<ObjectProperty name={nk2} value={1} />
|
|
76
|
+
<ObjectProperty name={nk3} value={1} />
|
|
77
|
+
</CommaList>
|
|
78
|
+
</ObjectExpression>
|
|
79
|
+
);
|
|
80
|
+
expect(toSourceText(comp)).toBe(d`
|
|
81
|
+
{
|
|
82
|
+
a: 3,
|
|
83
|
+
a_2: 1,
|
|
84
|
+
a: 1,
|
|
85
|
+
}
|
|
86
|
+
`);
|
|
87
|
+
});
|
package/test/reference.test.tsx
CHANGED
|
@@ -4,11 +4,21 @@ import { expect, it } from "vitest";
|
|
|
4
4
|
import * as ts from "../src/components/index.js";
|
|
5
5
|
import { Reference } from "../src/components/Reference.js";
|
|
6
6
|
|
|
7
|
+
it("using refkey that is missing declration show info about it", () => {
|
|
8
|
+
const key = refkey("foo");
|
|
9
|
+
expect(
|
|
10
|
+
<Output>
|
|
11
|
+
<ts.SourceFile path="test1.ts">{key}</ts.SourceFile>
|
|
12
|
+
</Output>,
|
|
13
|
+
// cspell:ignore sfoo
|
|
14
|
+
).toRenderTo(`<Unresolved Symbol: refkey[sfoo]>`);
|
|
15
|
+
});
|
|
16
|
+
|
|
7
17
|
it("works with back references", () => {
|
|
8
18
|
expect(
|
|
9
19
|
<Output>
|
|
10
20
|
<ts.SourceFile path="test1.ts">
|
|
11
|
-
<ts.Declaration name="foo" refkey={refkey("foo")}>
|
|
21
|
+
<ts.Declaration name="foo" nameKind="variable" refkey={refkey("foo")}>
|
|
12
22
|
const foo = 1;
|
|
13
23
|
</ts.Declaration>
|
|
14
24
|
</ts.SourceFile>
|
|
@@ -36,7 +46,7 @@ it("works with forward references", () => {
|
|
|
36
46
|
const v = <Reference refkey={refkey("foo")} />;
|
|
37
47
|
</ts.SourceFile>
|
|
38
48
|
<ts.SourceFile path="test1.ts">
|
|
39
|
-
<ts.Declaration name="foo" refkey={refkey("foo")}>
|
|
49
|
+
<ts.Declaration nameKind="variable" name="foo" refkey={refkey("foo")}>
|
|
40
50
|
const foo = 1;
|
|
41
51
|
</ts.Declaration>
|
|
42
52
|
</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,26 @@ it("works", () => {
|
|
|
13
19
|
).toRenderTo("const hi = 12;");
|
|
14
20
|
});
|
|
15
21
|
|
|
22
|
+
it("allows omitting the initializer", () => {
|
|
23
|
+
expect(
|
|
24
|
+
<Output>
|
|
25
|
+
<ts.SourceFile path="test.js">
|
|
26
|
+
<ts.VarDeclaration let name="hi" />;
|
|
27
|
+
</ts.SourceFile>
|
|
28
|
+
</Output>,
|
|
29
|
+
).toRenderTo("let hi;");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("takes namekeys", () => {
|
|
33
|
+
expect(
|
|
34
|
+
<Output>
|
|
35
|
+
<ts.SourceFile path="test.js">
|
|
36
|
+
<ts.VarDeclaration name={namekey("foo")} initializer="12" />;
|
|
37
|
+
</ts.SourceFile>
|
|
38
|
+
</Output>,
|
|
39
|
+
).toRenderTo("const foo = 12;");
|
|
40
|
+
});
|
|
41
|
+
|
|
16
42
|
it("works end-to-end", () => {
|
|
17
43
|
const TestType = refkey("TestType");
|
|
18
44
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassDeclaration,
|
|
3
|
+
ClassField,
|
|
4
|
+
ClassMethod,
|
|
5
|
+
} from "#components/index.js";
|
|
6
|
+
import { List, Refkey } from "@alloy-js/core";
|
|
7
|
+
import { d } from "@alloy-js/core/testing";
|
|
8
|
+
import { expect, it } from "vitest";
|
|
9
|
+
import { createTSTestWrapper } from "./create-wrapper.jsx";
|
|
10
|
+
|
|
11
|
+
it("should render defkey inline", async () => {
|
|
12
|
+
const { Wrapper, defkey } = createTSTestWrapper();
|
|
13
|
+
|
|
14
|
+
expect(<Wrapper>return {defkey("myResult")};</Wrapper>).toRenderTo(
|
|
15
|
+
`return myResult;`,
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("reuses declarations across multiple usage sites", () => {
|
|
20
|
+
const { Wrapper, defkey } = createTSTestWrapper();
|
|
21
|
+
const T = defkey("Thing");
|
|
22
|
+
const R = defkey("Result");
|
|
23
|
+
|
|
24
|
+
expect(
|
|
25
|
+
<Wrapper>
|
|
26
|
+
<ClassDeclaration name="A">
|
|
27
|
+
<List>
|
|
28
|
+
<ClassMethod
|
|
29
|
+
name="a"
|
|
30
|
+
returnType={R}
|
|
31
|
+
parameters={[{ name: "x", type: T }]}
|
|
32
|
+
/>
|
|
33
|
+
<ClassMethod
|
|
34
|
+
name="b"
|
|
35
|
+
returnType={R}
|
|
36
|
+
parameters={[{ name: "y", type: T }]}
|
|
37
|
+
/>
|
|
38
|
+
</List>
|
|
39
|
+
</ClassDeclaration>
|
|
40
|
+
</Wrapper>,
|
|
41
|
+
).toRenderTo(d`
|
|
42
|
+
class A {
|
|
43
|
+
a(x: Thing): Result {}
|
|
44
|
+
b(y: Thing): Result {}
|
|
45
|
+
}`);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("reuses declarations across multiple defkeys", () => {
|
|
49
|
+
const { Wrapper, defkey } = createTSTestWrapper();
|
|
50
|
+
|
|
51
|
+
expect(
|
|
52
|
+
<Wrapper>
|
|
53
|
+
<ClassDeclaration name="A">
|
|
54
|
+
<List>
|
|
55
|
+
<ClassMethod
|
|
56
|
+
name="a"
|
|
57
|
+
returnType={defkey("Result")}
|
|
58
|
+
parameters={[{ name: "x", type: defkey("Thing") }]}
|
|
59
|
+
/>
|
|
60
|
+
<ClassMethod
|
|
61
|
+
name="b"
|
|
62
|
+
returnType={defkey("Result")}
|
|
63
|
+
parameters={[{ name: "y", type: defkey("Thing") }]}
|
|
64
|
+
/>
|
|
65
|
+
</List>
|
|
66
|
+
</ClassDeclaration>
|
|
67
|
+
</Wrapper>,
|
|
68
|
+
).toRenderTo(d`
|
|
69
|
+
class A {
|
|
70
|
+
a(x: Thing): Result {}
|
|
71
|
+
b(y: Thing): Result {}
|
|
72
|
+
}`);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should render defkey in nested component", async () => {
|
|
76
|
+
function TestComponent(props: { returnTypeRef: Refkey }) {
|
|
77
|
+
return <ClassMethod name="foo" returnType={props.returnTypeRef} />;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { Wrapper, defkey } = createTSTestWrapper();
|
|
81
|
+
|
|
82
|
+
expect(
|
|
83
|
+
<Wrapper>
|
|
84
|
+
<ClassDeclaration name="MyClass">
|
|
85
|
+
<TestComponent returnTypeRef={defkey("MyType")} />
|
|
86
|
+
</ClassDeclaration>
|
|
87
|
+
</Wrapper>,
|
|
88
|
+
).toRenderTo(d`
|
|
89
|
+
class MyClass {
|
|
90
|
+
foo(): MyType {}
|
|
91
|
+
}`);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should render defkey in class property", async () => {
|
|
95
|
+
const { Wrapper, defkey } = createTSTestWrapper();
|
|
96
|
+
|
|
97
|
+
expect(
|
|
98
|
+
<Wrapper>
|
|
99
|
+
<ClassDeclaration name="TestClass">
|
|
100
|
+
<ClassField name="MyProperty" type={defkey("MyType")} />
|
|
101
|
+
</ClassDeclaration>
|
|
102
|
+
</Wrapper>,
|
|
103
|
+
).toRenderTo(d`
|
|
104
|
+
class TestClass {
|
|
105
|
+
MyProperty: MyType
|
|
106
|
+
}`);
|
|
107
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SourceFile } from "#components/index.js";
|
|
2
|
+
import { createTestWrapper, type TestWrapper } from "@alloy-js/core/testing";
|
|
3
|
+
import { TSOutputSymbol, useTSScope } from "../src/index.js";
|
|
4
|
+
|
|
5
|
+
export function createTSTestWrapper(): TestWrapper {
|
|
6
|
+
return createTestWrapper({
|
|
7
|
+
filePath: "test.ts",
|
|
8
|
+
useScope: useTSScope,
|
|
9
|
+
makeSymbol: (nk, scope) => new TSOutputSymbol(nk, scope.spaces),
|
|
10
|
+
SourceFile,
|
|
11
|
+
});
|
|
12
|
+
}
|
package/testing/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./create-wrapper.jsx";
|
package/tsconfig.json
CHANGED
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
"types": ["@alloy-js/core/testing/matchers"]
|
|
8
8
|
},
|
|
9
9
|
"references": [{ "path": "../core" }],
|
|
10
|
-
"include": [
|
|
10
|
+
"include": [
|
|
11
|
+
"src/**/*.ts",
|
|
12
|
+
"src/**/*.tsx",
|
|
13
|
+
"test/**/*.ts",
|
|
14
|
+
"test/**/*.tsx",
|
|
15
|
+
"testing/**/*.ts",
|
|
16
|
+
"testing/**/*.tsx"
|
|
17
|
+
],
|
|
11
18
|
"exclude": ["node_modules", "dist"]
|
|
12
19
|
}
|