@alloy-js/typescript 0.4.0 → 0.6.0
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/CHANGELOG.md +19 -0
- package/dist/src/components/ArrayExpression.d.ts +1 -1
- package/dist/src/components/ArrayExpression.d.ts.map +1 -1
- package/dist/src/components/ArrayExpression.js +18 -28
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BarrelFile.d.ts +1 -1
- package/dist/src/components/BarrelFile.d.ts.map +1 -1
- package/dist/src/components/BarrelFile.js +11 -9
- package/dist/src/components/BarrelFile.js.map +1 -1
- 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 +8 -9
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/CommaList.d.ts +12 -0
- package/dist/src/components/CommaList.d.ts.map +1 -0
- package/dist/src/components/CommaList.js +19 -0
- package/dist/src/components/CommaList.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +1 -1
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +19 -17
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts +1 -1
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/ExportStatement.d.ts +1 -1
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.d.ts +3 -3
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionCallExpression.js +26 -9
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +9 -2
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +135 -33
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +25 -31
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/components/Interface.d.ts +3 -3
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +5 -5
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts +10 -0
- package/dist/src/components/JSDoc.d.ts.map +1 -0
- package/dist/src/components/JSDoc.js +24 -0
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.d.ts +11 -0
- package/dist/src/components/JSDocComment.d.ts.map +1 -0
- package/dist/src/components/JSDocComment.js +16 -0
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.d.ts +12 -0
- package/dist/src/components/JSDocExample.d.ts.map +1 -0
- package/dist/src/components/JSDocExample.js +26 -0
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParagraph.d.ts +10 -0
- package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
- package/dist/src/components/JSDocParagraph.js +23 -0
- package/dist/src/components/JSDocParagraph.js.map +1 -0
- package/dist/src/components/MemberChainExpression.d.ts +11 -0
- package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
- package/dist/src/components/MemberChainExpression.js +64 -0
- package/dist/src/components/MemberChainExpression.js.map +1 -0
- 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 +45 -42
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PackageDirectory.d.ts +1 -1
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +1 -1
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts +1 -1
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js.map +1 -1
- package/dist/src/components/Reference.d.ts +1 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +1 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +13 -6
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TsConfigJson.d.ts +1 -1
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TsConfigJson.js.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/ValueExpression.d.ts +2 -1
- package/dist/src/components/ValueExpression.d.ts.map +1 -1
- package/dist/src/components/ValueExpression.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +2 -2
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +21 -21
- 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/test/imports.test.d.ts.map +1 -1
- package/dist/test/jsdoc.test.d.ts +2 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -0
- package/dist/test/member-chain.test.d.ts +2 -0
- package/dist/test/member-chain.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -6
- package/src/components/ArrayExpression.tsx +18 -32
- package/src/components/BarrelFile.tsx +7 -13
- package/src/components/ClassDeclaration.tsx +33 -28
- package/src/components/CommaList.tsx +23 -0
- package/src/components/Declaration.tsx +7 -3
- package/src/components/EnumDeclaration.tsx +21 -14
- package/src/components/EnumMember.tsx +7 -4
- package/src/components/ExportStatement.tsx +6 -1
- package/src/components/FunctionCallExpression.tsx +18 -9
- package/src/components/FunctionDeclaration.tsx +170 -55
- package/src/components/ImportStatement.tsx +6 -9
- package/src/components/Interface.tsx +20 -13
- package/src/components/JSDoc.tsx +28 -0
- package/src/components/JSDocComment.tsx +23 -0
- package/src/components/JSDocExample.tsx +30 -0
- package/src/components/JSDocParagraph.tsx +35 -0
- package/src/components/MemberChainExpression.tsx +59 -0
- package/src/components/ObjectExpression.tsx +53 -48
- package/src/components/PackageDirectory.tsx +11 -9
- package/src/components/PackageJson.tsx +9 -6
- package/src/components/SourceFile.tsx +15 -8
- package/src/components/TsConfigJson.tsx +5 -3
- package/src/components/TypeDeclaration.tsx +5 -3
- package/src/components/ValueExpression.tsx +7 -5
- package/src/components/VarDeclaration.tsx +11 -5
- package/src/components/index.ts +2 -1
- package/src/components/stc/index.ts +1 -1
- package/temp/api.json +618 -208
- package/test/array.test.tsx +28 -7
- package/test/basic.test.tsx +26 -21
- package/test/class.test.tsx +65 -53
- package/test/enum.test.tsx +18 -13
- package/test/externals.test.tsx +6 -7
- package/test/function-call-expression.test.tsx +39 -17
- package/test/function-declaration.test.tsx +96 -78
- package/test/imports.test.tsx +90 -65
- package/test/interface.test.tsx +29 -19
- package/test/jsdoc.test.tsx +154 -0
- package/test/member-chain.test.tsx +47 -0
- package/test/name-policy.test.tsx +33 -26
- package/test/package-external.test.tsx +8 -4
- package/test/package.test.tsx +1 -2
- package/test/reference.test.tsx +2 -6
- package/test/utils.tsx +3 -1
- package/test/value-expression.test.tsx +2 -6
- package/test/values.test.tsx +67 -73
- package/test/var-declaration.test.tsx +11 -5
- package/test/vitest.d.ts +6 -1
- package/tsconfig.json +8 -1
- package/dist/src/components/Block.d.ts +0 -6
- package/dist/src/components/Block.d.ts.map +0 -1
- package/dist/src/components/Block.js +0 -11
- package/dist/src/components/Block.js.map +0 -1
- package/src/components/Block.tsx +0 -12
package/test/array.test.tsx
CHANGED
|
@@ -4,11 +4,32 @@ import { ArrayExpression } from "../src/index.js";
|
|
|
4
4
|
import { toSourceText } from "./utils.js";
|
|
5
5
|
|
|
6
6
|
it("works", () => {
|
|
7
|
-
expect(toSourceText(<ArrayExpression jsValue={[1,2,3]} />)).toBe(d`
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
expect(toSourceText(<ArrayExpression jsValue={[1, 2, 3]} />)).toBe(d`
|
|
8
|
+
[1, 2, 3]
|
|
9
|
+
`);
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
toSourceText(<ArrayExpression jsValue={[1, 2, 3, "foo".repeat(10)]} />, {
|
|
13
|
+
printWidth: 20,
|
|
14
|
+
}),
|
|
15
|
+
).toBe(d`
|
|
16
|
+
[
|
|
17
|
+
1,
|
|
18
|
+
2,
|
|
19
|
+
3,
|
|
20
|
+
"foofoofoofoofoofoofoofoofoofoo"
|
|
21
|
+
]
|
|
22
|
+
`);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("accepts children", () => {
|
|
26
|
+
expect(
|
|
27
|
+
toSourceText(
|
|
28
|
+
<ArrayExpression jsValue={[1, 2, 3]}>
|
|
29
|
+
<ArrayExpression jsValue={[4, 5, 6]} />
|
|
30
|
+
</ArrayExpression>,
|
|
31
|
+
),
|
|
32
|
+
).toBe(d`
|
|
33
|
+
[1, 2, 3, [4, 5, 6]]
|
|
34
|
+
`);
|
|
14
35
|
});
|
package/test/basic.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output, refkey, render, SourceFile } from "@alloy-js/core";
|
|
1
|
+
import { List, Output, refkey, render, SourceFile } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
@@ -24,30 +24,36 @@ it("works", () => {
|
|
|
24
24
|
<ts.SourceFile path="index.ts">
|
|
25
25
|
console.log("Hello world!");
|
|
26
26
|
</ts.SourceFile>
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
<ts.SourceFile path="test2.ts">
|
|
29
|
-
console.log(
|
|
30
|
-
|
|
29
|
+
console.log(
|
|
30
|
+
<Reference refkey={greetKey} />
|
|
31
|
+
("world"));
|
|
32
|
+
<hbr />
|
|
33
|
+
console.log(
|
|
34
|
+
<Reference refkey={farewellKey} />
|
|
35
|
+
("world"));
|
|
31
36
|
</ts.SourceFile>
|
|
32
37
|
|
|
33
38
|
<ts.SourceFile path="test1.ts">
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
<List hardline>
|
|
40
|
+
<ts.FunctionDeclaration
|
|
41
|
+
name={"say" + fnSpec.greeting}
|
|
42
|
+
refkey={greetKey}
|
|
43
|
+
parameters={{ str: "string" }}
|
|
44
|
+
>
|
|
45
|
+
return "{fnSpec.greeting} " + str;
|
|
46
|
+
</ts.FunctionDeclaration>
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
<ts.FunctionDeclaration
|
|
49
|
+
name={"say" + fnSpec.farewell}
|
|
50
|
+
refkey={farewellKey}
|
|
51
|
+
parameters={{ str: "string" }}
|
|
52
|
+
>
|
|
53
|
+
return "{fnSpec.farewell} " + str;
|
|
54
|
+
</ts.FunctionDeclaration>
|
|
55
|
+
</List>
|
|
49
56
|
</ts.SourceFile>
|
|
50
|
-
|
|
51
57
|
</Output>,
|
|
52
58
|
);
|
|
53
59
|
|
|
@@ -63,7 +69,6 @@ it("works", () => {
|
|
|
63
69
|
function sayHello(str: string) {
|
|
64
70
|
return "Hello " + str;
|
|
65
71
|
}
|
|
66
|
-
|
|
67
72
|
function sayGoodbye(str: string) {
|
|
68
73
|
return "Goodbye " + str;
|
|
69
74
|
}
|
|
@@ -71,7 +76,7 @@ it("works", () => {
|
|
|
71
76
|
|
|
72
77
|
expect(findFile(res, "test2.ts").contents).toEqual(d`
|
|
73
78
|
import { sayHello, sayGoodbye } from "./test1.js";
|
|
74
|
-
|
|
79
|
+
|
|
75
80
|
console.log(sayHello("world"));
|
|
76
81
|
console.log(sayGoodbye("world"));
|
|
77
82
|
`);
|
package/test/class.test.tsx
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { refkey } from "@alloy-js/core";
|
|
1
|
+
import { List, refkey } 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";
|
|
5
|
+
import { StatementList } from "../../core/src/components/StatementList.jsx";
|
|
5
6
|
import * as ts from "../src/components/index.js";
|
|
6
7
|
import { toSourceText } from "./utils.js";
|
|
7
8
|
|
|
8
9
|
it("declares classes", () => {
|
|
9
10
|
const res = toSourceText(<ts.ClassDeclaration name="Foo" />);
|
|
10
11
|
expect(res).toEqual(d`
|
|
11
|
-
class Foo {
|
|
12
|
-
|
|
13
|
-
}
|
|
12
|
+
class Foo {}
|
|
14
13
|
`);
|
|
15
14
|
});
|
|
16
15
|
|
|
17
16
|
it("accepts export and default", () => {
|
|
18
17
|
const res = toSourceText(<ts.ClassDeclaration name="Foo" export default />);
|
|
19
18
|
expect(res).toEqual(d`
|
|
20
|
-
export default class Foo {
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
export default class Foo {}
|
|
23
20
|
`);
|
|
24
21
|
});
|
|
25
22
|
|
|
@@ -27,9 +24,7 @@ it("creates extends", () => {
|
|
|
27
24
|
const res = toSourceText(<ts.ClassDeclaration name="Foo" extends="string" />);
|
|
28
25
|
|
|
29
26
|
expect(res).toEqual(d`
|
|
30
|
-
class Foo extends string {
|
|
31
|
-
|
|
32
|
-
}
|
|
27
|
+
class Foo extends string {}
|
|
33
28
|
`);
|
|
34
29
|
});
|
|
35
30
|
|
|
@@ -37,13 +32,17 @@ describe("instance members", () => {
|
|
|
37
32
|
it("can be created", () => {
|
|
38
33
|
const res = toSourceText(
|
|
39
34
|
<ts.ClassDeclaration name="Foo">
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
<StatementList>
|
|
36
|
+
<ts.ClassField name="one" />
|
|
37
|
+
<ts.ClassField name="two" public />
|
|
38
|
+
<ts.ClassField name="three" private />
|
|
39
|
+
<ts.ClassField name="four" protected />
|
|
40
|
+
<ts.ClassField name="five" type="number" />
|
|
41
|
+
<ts.ClassField name="six" type="number">
|
|
42
|
+
12
|
|
43
|
+
</ts.ClassField>
|
|
44
|
+
<ts.ClassField name="seven" jsPrivate />
|
|
45
|
+
</StatementList>
|
|
47
46
|
</ts.ClassDeclaration>,
|
|
48
47
|
);
|
|
49
48
|
|
|
@@ -64,8 +63,12 @@ describe("instance members", () => {
|
|
|
64
63
|
const one = refkey();
|
|
65
64
|
const res = toSourceText(
|
|
66
65
|
<ts.ClassDeclaration name="Foo">
|
|
67
|
-
<
|
|
68
|
-
|
|
66
|
+
<StatementList>
|
|
67
|
+
<ts.ClassField name="one" refkey={one}>
|
|
68
|
+
1
|
|
69
|
+
</ts.ClassField>
|
|
70
|
+
<ts.ClassField name="two">{one} + 1</ts.ClassField>
|
|
71
|
+
</StatementList>
|
|
69
72
|
</ts.ClassDeclaration>,
|
|
70
73
|
);
|
|
71
74
|
|
|
@@ -83,7 +86,11 @@ describe("instance members", () => {
|
|
|
83
86
|
toSourceText(
|
|
84
87
|
<>
|
|
85
88
|
<ts.ClassDeclaration name="Foo">
|
|
86
|
-
<
|
|
89
|
+
<StatementList>
|
|
90
|
+
<ts.ClassField name="one" refkey={one}>
|
|
91
|
+
1
|
|
92
|
+
</ts.ClassField>
|
|
93
|
+
</StatementList>
|
|
87
94
|
</ts.ClassDeclaration>
|
|
88
95
|
{one}
|
|
89
96
|
</>,
|
|
@@ -97,7 +104,11 @@ describe("static members", () => {
|
|
|
97
104
|
const one = refkey();
|
|
98
105
|
const res = toSourceText(
|
|
99
106
|
<ts.ClassDeclaration name="Foo">
|
|
100
|
-
<
|
|
107
|
+
<StatementList>
|
|
108
|
+
<ts.ClassField static name="one" refkey={one}>
|
|
109
|
+
1
|
|
110
|
+
</ts.ClassField>
|
|
111
|
+
</StatementList>
|
|
101
112
|
</ts.ClassDeclaration>,
|
|
102
113
|
);
|
|
103
114
|
|
|
@@ -113,8 +124,13 @@ describe("static members", () => {
|
|
|
113
124
|
const res = toSourceText(
|
|
114
125
|
<>
|
|
115
126
|
<ts.ClassDeclaration name="Foo">
|
|
116
|
-
<
|
|
127
|
+
<StatementList>
|
|
128
|
+
<ts.ClassField static name="one" refkey={one}>
|
|
129
|
+
1
|
|
130
|
+
</ts.ClassField>
|
|
131
|
+
</StatementList>
|
|
117
132
|
</ts.ClassDeclaration>
|
|
133
|
+
<hbr />
|
|
118
134
|
{one};
|
|
119
135
|
</>,
|
|
120
136
|
);
|
|
@@ -136,45 +152,41 @@ describe("instance methods", () => {
|
|
|
136
152
|
|
|
137
153
|
const res = toSourceText(
|
|
138
154
|
<ts.ClassDeclaration name="Foo">
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
<List hardline>
|
|
156
|
+
<ts.ClassMethod name="one" refkey={one} />
|
|
157
|
+
<ts.ClassMethod name="two" public />
|
|
158
|
+
<ts.ClassMethod name="three" private />
|
|
159
|
+
<ts.ClassMethod name="four" protected />
|
|
160
|
+
<ts.ClassMethod
|
|
161
|
+
name="five"
|
|
162
|
+
parameters={{ a: "string", b: "string" }}
|
|
163
|
+
/>
|
|
164
|
+
<ts.ClassMethod
|
|
165
|
+
name="six"
|
|
166
|
+
parameters={{
|
|
167
|
+
a: { type: "number", refkey: a },
|
|
168
|
+
b: { type: "number", refkey: b },
|
|
169
|
+
}}
|
|
170
|
+
returnType="number"
|
|
171
|
+
>
|
|
172
|
+
{one} = {a} + {b};
|
|
173
|
+
</ts.ClassMethod>
|
|
174
|
+
<ts.ClassMethod name="seven" jsPrivate />
|
|
175
|
+
</List>
|
|
152
176
|
</ts.ClassDeclaration>,
|
|
153
177
|
);
|
|
154
178
|
|
|
155
179
|
expect(res).toEqual(d`
|
|
156
180
|
class Foo {
|
|
157
|
-
one() {
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
private three() {
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
protected four() {
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
five(a: string, b: string) {
|
|
170
|
-
|
|
171
|
-
}
|
|
181
|
+
one() {}
|
|
182
|
+
public two() {}
|
|
183
|
+
private three() {}
|
|
184
|
+
protected four() {}
|
|
185
|
+
five(a: string, b: string) {}
|
|
172
186
|
six(a: number, b: number): number {
|
|
173
187
|
this.one = a + b;
|
|
174
188
|
}
|
|
175
|
-
#seven() {
|
|
176
|
-
|
|
177
|
-
}
|
|
189
|
+
#seven() {}
|
|
178
190
|
}
|
|
179
191
|
`);
|
|
180
192
|
});
|
package/test/enum.test.tsx
CHANGED
|
@@ -9,15 +9,17 @@ it("renders an enum with enum children", () => {
|
|
|
9
9
|
<Output>
|
|
10
10
|
<ts.SourceFile path="foo.ts">
|
|
11
11
|
<ts.EnumDeclaration name="MyEnum">
|
|
12
|
-
<ts.
|
|
13
|
-
|
|
12
|
+
<ts.CommaList>
|
|
13
|
+
<ts.EnumMember name="foo" value="1" />
|
|
14
|
+
<ts.EnumMember name="bar" value="2" />
|
|
15
|
+
</ts.CommaList>
|
|
14
16
|
</ts.EnumDeclaration>
|
|
15
17
|
</ts.SourceFile>
|
|
16
18
|
</Output>,
|
|
17
19
|
).toRenderTo(`
|
|
18
20
|
enum MyEnum {
|
|
19
21
|
foo = 1,
|
|
20
|
-
bar = 2
|
|
22
|
+
bar = 2,
|
|
21
23
|
}
|
|
22
24
|
`);
|
|
23
25
|
});
|
|
@@ -27,15 +29,17 @@ it("renders an enum with enum children specifying JS Value", () => {
|
|
|
27
29
|
<Output>
|
|
28
30
|
<ts.SourceFile path="foo.ts">
|
|
29
31
|
<ts.EnumDeclaration name="MyEnum">
|
|
30
|
-
<ts.
|
|
31
|
-
|
|
32
|
+
<ts.CommaList>
|
|
33
|
+
<ts.EnumMember name="foo" jsValue="1" />
|
|
34
|
+
<ts.EnumMember name="bar" jsValue={2} />
|
|
35
|
+
</ts.CommaList>
|
|
32
36
|
</ts.EnumDeclaration>
|
|
33
37
|
</ts.SourceFile>
|
|
34
38
|
</Output>,
|
|
35
39
|
).toRenderTo(`
|
|
36
40
|
enum MyEnum {
|
|
37
41
|
foo = "1",
|
|
38
|
-
bar = 2
|
|
42
|
+
bar = 2,
|
|
39
43
|
}
|
|
40
44
|
`);
|
|
41
45
|
});
|
|
@@ -55,7 +59,7 @@ it("renders an enum given a JS value", () => {
|
|
|
55
59
|
).toRenderTo(`
|
|
56
60
|
enum MyEnum {
|
|
57
61
|
foo = 1,
|
|
58
|
-
bar = 2
|
|
62
|
+
bar = 2,
|
|
59
63
|
}
|
|
60
64
|
`);
|
|
61
65
|
});
|
|
@@ -100,7 +104,7 @@ it("uses the naming policy", () => {
|
|
|
100
104
|
).toRenderTo(`
|
|
101
105
|
enum MyEnum {
|
|
102
106
|
FooProp = 1,
|
|
103
|
-
BarProp = 2
|
|
107
|
+
BarProp = 2,
|
|
104
108
|
}
|
|
105
109
|
`);
|
|
106
110
|
});
|
|
@@ -113,19 +117,20 @@ describe("symbols", () => {
|
|
|
113
117
|
<Output>
|
|
114
118
|
<ts.SourceFile path="foo.ts">
|
|
115
119
|
<ts.EnumDeclaration name="MyEnum">
|
|
116
|
-
<ts.
|
|
117
|
-
|
|
120
|
+
<ts.CommaList>
|
|
121
|
+
<ts.EnumMember name="foo" jsValue="1" refkey={memberOne} />
|
|
122
|
+
<ts.EnumMember name="bar" jsValue={2} />
|
|
123
|
+
</ts.CommaList>
|
|
118
124
|
</ts.EnumDeclaration>
|
|
119
|
-
|
|
125
|
+
<hbr />
|
|
120
126
|
{memberOne};
|
|
121
127
|
</ts.SourceFile>
|
|
122
128
|
</Output>,
|
|
123
129
|
).toRenderTo(`
|
|
124
130
|
enum MyEnum {
|
|
125
131
|
foo = "1",
|
|
126
|
-
bar = 2
|
|
132
|
+
bar = 2,
|
|
127
133
|
}
|
|
128
|
-
|
|
129
134
|
MyEnum.foo;
|
|
130
135
|
`);
|
|
131
136
|
});
|
package/test/externals.test.tsx
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
createPackage,
|
|
6
6
|
FunctionDeclaration,
|
|
7
7
|
PackageDirectory,
|
|
8
|
-
Reference,
|
|
9
8
|
SourceFile,
|
|
10
9
|
} from "../src/index.js";
|
|
11
10
|
import { assertFileContents } from "./utils.js";
|
|
@@ -29,8 +28,8 @@ it("can import builtins", () => {
|
|
|
29
28
|
<Output externals={[testLib, fs]}>
|
|
30
29
|
<PackageDirectory path="." name="test" version="1.0.0">
|
|
31
30
|
<SourceFile path="index.ts">
|
|
32
|
-
|
|
33
|
-
await
|
|
31
|
+
{testLib["./subpath"].nice};<hbr />
|
|
32
|
+
await {fs["./promises"].readFile}();
|
|
34
33
|
</SourceFile>
|
|
35
34
|
</PackageDirectory>
|
|
36
35
|
</Output>,
|
|
@@ -78,8 +77,8 @@ it("can import builtins without a package", () => {
|
|
|
78
77
|
const res = render(
|
|
79
78
|
<Output externals={[testLib, fs]}>
|
|
80
79
|
<SourceFile path="index.ts">
|
|
81
|
-
|
|
82
|
-
await
|
|
80
|
+
{testLib["./subpath"].nice};<hbr />
|
|
81
|
+
await {fs["./promises"].readFile}();
|
|
83
82
|
</SourceFile>
|
|
84
83
|
</Output>,
|
|
85
84
|
);
|
|
@@ -115,8 +114,8 @@ it("can import builtins without a package", () => {
|
|
|
115
114
|
<SourceFile path="index.ts">
|
|
116
115
|
<FunctionDeclaration name="foo">
|
|
117
116
|
<FunctionDeclaration name="bar">
|
|
118
|
-
|
|
119
|
-
await
|
|
117
|
+
{testLib["./subpath"].nice};<hbr />
|
|
118
|
+
await {fs["./promises"].readFile}();
|
|
120
119
|
</FunctionDeclaration>
|
|
121
120
|
</FunctionDeclaration>
|
|
122
121
|
</SourceFile>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Output, refkey, render } from "@alloy-js/core";
|
|
2
2
|
import { it } from "vitest";
|
|
3
|
+
import { StatementList } from "../../core/src/components/StatementList.jsx";
|
|
3
4
|
import {
|
|
4
5
|
FunctionCallExpression,
|
|
5
6
|
FunctionDeclaration,
|
|
@@ -13,22 +14,43 @@ it("can declare and call a function with parameters", () => {
|
|
|
13
14
|
const functionRefkey = refkey();
|
|
14
15
|
const res = render(
|
|
15
16
|
<Output>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
<PackageDirectory path="." name="test" version="1.0.0">
|
|
18
|
+
<SourceFile path="index.ts">
|
|
19
|
+
<VarDeclaration name="foo" value={`"Foo"`} const />;<hbr />
|
|
20
|
+
<FunctionDeclaration
|
|
21
|
+
refkey={functionRefkey}
|
|
22
|
+
name="bar"
|
|
23
|
+
parameters={{ "foo?": "string", "baz?": "number" }}
|
|
24
|
+
>
|
|
25
|
+
<StatementList>
|
|
26
|
+
<>const message = foo ? foo : "Hello, World!"</>
|
|
27
|
+
<>console.log(message)</>
|
|
28
|
+
<>if(baz) console.log(baz)</>
|
|
29
|
+
</StatementList>
|
|
30
|
+
</FunctionDeclaration>
|
|
31
|
+
<hbr />
|
|
32
|
+
<StatementList>
|
|
33
|
+
<FunctionCallExpression
|
|
34
|
+
target={functionRefkey}
|
|
35
|
+
args={[`"Hello!"`]}
|
|
36
|
+
/>
|
|
37
|
+
<FunctionCallExpression target={functionRefkey} />
|
|
38
|
+
<FunctionCallExpression
|
|
39
|
+
target={functionRefkey}
|
|
40
|
+
args={[<>"Hello {<>World</>}!"</>]}
|
|
41
|
+
/>
|
|
42
|
+
<FunctionCallExpression
|
|
43
|
+
target={functionRefkey}
|
|
44
|
+
args={[<>"Hey there!"</>]}
|
|
45
|
+
/>
|
|
46
|
+
<FunctionCallExpression
|
|
47
|
+
target={functionRefkey}
|
|
48
|
+
args={[<>"Hello World"</>, <>12345</>]}
|
|
49
|
+
/>
|
|
50
|
+
</StatementList>
|
|
51
|
+
</SourceFile>
|
|
52
|
+
</PackageDirectory>
|
|
53
|
+
</Output>,
|
|
32
54
|
);
|
|
33
55
|
|
|
34
56
|
assertFileContents(res, {
|
|
@@ -37,7 +59,7 @@ it("can declare and call a function with parameters", () => {
|
|
|
37
59
|
function bar(foo?: string, baz?: number) {
|
|
38
60
|
const message = foo ? foo : "Hello, World!";
|
|
39
61
|
console.log(message);
|
|
40
|
-
if(baz) console.log(baz)
|
|
62
|
+
if(baz) console.log(baz);
|
|
41
63
|
}
|
|
42
64
|
bar("Hello!");
|
|
43
65
|
bar();
|