@alloy-js/typescript 0.5.0 → 0.7.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 +28 -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.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.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 +4 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -2
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +21 -18
- package/dist/src/components/EnumDeclaration.js.map +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.map +1 -1
- package/dist/src/components/ExportStatement.js +3 -1
- package/dist/src/components/ExportStatement.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.d.ts +2 -2
- 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 +10 -2
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +136 -33
- package/dist/src/components/FunctionDeclaration.js.map +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 +1 -1
- 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 +100 -0
- package/dist/src/components/MemberChainExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +1 -1
- 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 -3
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +9 -16
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts +39 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js +30 -12
- package/dist/src/components/PackageJson.js.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.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.map +1 -1
- package/dist/src/components/TsConfigJson.js.map +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.map +1 -1
- package/dist/src/components/ValueExpression.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +5 -4
- 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/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +5 -2
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +4 -1
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts +0 -15
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +0 -8
- package/dist/src/symbols/ts-package-scope.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 +3 -5
- package/src/components/ArrayExpression.tsx +22 -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 +14 -5
- package/src/components/EnumDeclaration.tsx +23 -16
- package/src/components/EnumMember.tsx +7 -4
- package/src/components/ExportStatement.tsx +9 -2
- package/src/components/FunctionCallExpression.tsx +18 -9
- package/src/components/FunctionDeclaration.tsx +173 -56
- 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 +91 -0
- package/src/components/ObjectExpression.tsx +53 -48
- package/src/components/PackageDirectory.tsx +22 -30
- package/src/components/PackageJson.tsx +91 -29
- 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 +3 -1
- package/src/components/VarDeclaration.tsx +13 -7
- package/src/components/index.ts +2 -1
- package/src/components/stc/index.ts +1 -1
- package/src/symbols/reference.ts +7 -4
- package/src/symbols/ts-output-symbol.ts +6 -2
- package/src/symbols/ts-package-scope.ts +0 -28
- package/temp/api.json +802 -395
- package/test/array.test.tsx +40 -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 +115 -75
- package/test/interface.test.tsx +32 -22
- package/test/jsdoc.test.tsx +154 -0
- package/test/member-chain.test.tsx +124 -0
- package/test/name-policy.test.tsx +33 -26
- package/test/package-external.test.tsx +106 -7
- package/test/package.test.tsx +57 -5
- 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/interface.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NamePolicyContext, refkey } from "@alloy-js/core";
|
|
1
|
+
import { NamePolicyContext, 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 { expect, it } from "vitest";
|
|
@@ -10,9 +10,7 @@ import { toSourceText } from "./utils.js";
|
|
|
10
10
|
it("declares interfaces", () => {
|
|
11
11
|
const res = toSourceText(<ts.InterfaceDeclaration name="Foo" />);
|
|
12
12
|
expect(res).toEqual(d`
|
|
13
|
-
interface Foo {
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
interface Foo {}
|
|
16
14
|
`);
|
|
17
15
|
});
|
|
18
16
|
|
|
@@ -21,9 +19,7 @@ it("accepts export and default", () => {
|
|
|
21
19
|
<ts.InterfaceDeclaration name="Foo" export default />,
|
|
22
20
|
);
|
|
23
21
|
expect(res).toEqual(d`
|
|
24
|
-
export default interface Foo {
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
export default interface Foo {}
|
|
27
23
|
`);
|
|
28
24
|
});
|
|
29
25
|
|
|
@@ -33,18 +29,21 @@ it("creates extends", () => {
|
|
|
33
29
|
);
|
|
34
30
|
|
|
35
31
|
expect(res).toEqual(d`
|
|
36
|
-
interface Foo extends string {
|
|
37
|
-
|
|
38
|
-
}
|
|
32
|
+
interface Foo extends string {}
|
|
39
33
|
`);
|
|
40
34
|
});
|
|
41
35
|
|
|
42
36
|
it("can create members", () => {
|
|
43
37
|
const res = toSourceText(
|
|
44
|
-
<ts.InterfaceDeclaration name="Foo">
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
<ts.InterfaceDeclaration name="Foo" refkey={refkey("Foo")}>
|
|
39
|
+
<StatementList>
|
|
40
|
+
<ts.InterfaceMember name="member" type="string" />
|
|
41
|
+
<ts.InterfaceMember
|
|
42
|
+
name="circular"
|
|
43
|
+
type={<Reference refkey={refkey("Foo")} />}
|
|
44
|
+
/>
|
|
45
|
+
<ts.InterfaceMember indexer="str: string" type="number" />
|
|
46
|
+
</StatementList>
|
|
48
47
|
</ts.InterfaceDeclaration>,
|
|
49
48
|
);
|
|
50
49
|
|
|
@@ -59,10 +58,16 @@ it("can create members", () => {
|
|
|
59
58
|
|
|
60
59
|
it("can create optional members", () => {
|
|
61
60
|
const res = toSourceText(
|
|
62
|
-
<ts.InterfaceDeclaration name="Foo">
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
<ts.InterfaceDeclaration name="Foo" refkey={refkey("Foo")}>
|
|
62
|
+
<StatementList>
|
|
63
|
+
<ts.InterfaceMember name="member" type="string" />
|
|
64
|
+
<ts.InterfaceMember
|
|
65
|
+
optional
|
|
66
|
+
name="circular"
|
|
67
|
+
type={<Reference refkey={refkey("Foo")} />}
|
|
68
|
+
/>
|
|
69
|
+
<ts.InterfaceMember indexer="str: string" type="number" />
|
|
70
|
+
</StatementList>
|
|
66
71
|
</ts.InterfaceDeclaration>,
|
|
67
72
|
);
|
|
68
73
|
|
|
@@ -77,10 +82,15 @@ it("can create optional members", () => {
|
|
|
77
82
|
|
|
78
83
|
it("can create readonly members", () => {
|
|
79
84
|
const res = toSourceText(
|
|
80
|
-
<ts.InterfaceDeclaration name="Foo">
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
<ts.InterfaceDeclaration name="Foo" refkey={refkey("Foo")}>
|
|
86
|
+
<StatementList>
|
|
87
|
+
<ts.InterfaceMember readonly name="member" type="string" />
|
|
88
|
+
<ts.InterfaceMember
|
|
89
|
+
name="circular"
|
|
90
|
+
type={<Reference refkey={refkey("Foo")} />}
|
|
91
|
+
/>
|
|
92
|
+
<ts.InterfaceMember indexer="str: string" type="number" />
|
|
93
|
+
</StatementList>
|
|
84
94
|
</ts.InterfaceDeclaration>,
|
|
85
95
|
);
|
|
86
96
|
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { JSDoc } from "../src/components/JSDoc.jsx";
|
|
5
|
+
import { JSDocComment } from "../src/components/JSDocComment.jsx";
|
|
6
|
+
import { JSDocExample } from "../src/components/JSDocExample.jsx";
|
|
7
|
+
import { JSDocParagraph } from "../src/components/JSDocParagraph.jsx";
|
|
8
|
+
import { FunctionCallExpression } from "../src/index.js";
|
|
9
|
+
|
|
10
|
+
describe("JSDoc", () => {
|
|
11
|
+
it("formats properly", () => {
|
|
12
|
+
const template = (
|
|
13
|
+
<JSDocComment>
|
|
14
|
+
Hello!
|
|
15
|
+
<hbr />
|
|
16
|
+
<hbr />
|
|
17
|
+
This is another line
|
|
18
|
+
</JSDocComment>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(template).toRenderTo(
|
|
22
|
+
d`
|
|
23
|
+
/**
|
|
24
|
+
* Hello!
|
|
25
|
+
*
|
|
26
|
+
* This is another line
|
|
27
|
+
**/
|
|
28
|
+
`,
|
|
29
|
+
{ printWidth: 40 },
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("JSDocParagraph", () => {
|
|
35
|
+
it("formats properly", () => {
|
|
36
|
+
const template = (
|
|
37
|
+
<JSDoc>
|
|
38
|
+
<JSDocParagraph>
|
|
39
|
+
This is a long paragraph that should end up being broken into multiple
|
|
40
|
+
paragraphs. Moreover, the line breaks in this paragraph should not be
|
|
41
|
+
carried over into the JSDoc comment.
|
|
42
|
+
</JSDocParagraph>
|
|
43
|
+
<JSDocParagraph>
|
|
44
|
+
This is another paragraph. There should be a couple breaks in front of
|
|
45
|
+
it.
|
|
46
|
+
</JSDocParagraph>
|
|
47
|
+
</JSDoc>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(template).toRenderTo(
|
|
51
|
+
d`
|
|
52
|
+
/**
|
|
53
|
+
* This is a long paragraph that should
|
|
54
|
+
* end up being broken into multiple
|
|
55
|
+
* paragraphs. Moreover, the line breaks
|
|
56
|
+
* in this paragraph should not be
|
|
57
|
+
* carried over into the JSDoc comment.
|
|
58
|
+
*
|
|
59
|
+
* This is another paragraph. There
|
|
60
|
+
* should be a couple breaks in front of
|
|
61
|
+
* it.
|
|
62
|
+
**/
|
|
63
|
+
`,
|
|
64
|
+
{ printWidth: 40 },
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("JSDocExample", () => {
|
|
70
|
+
it("creates unfenced code samples", () => {
|
|
71
|
+
const template = (
|
|
72
|
+
<JSDoc>
|
|
73
|
+
<JSDocParagraph>
|
|
74
|
+
This API is awesome, and it comes with an example!
|
|
75
|
+
</JSDocParagraph>
|
|
76
|
+
<JSDocExample>console.log("Hello world!")</JSDocExample>
|
|
77
|
+
</JSDoc>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(template).toRenderTo(
|
|
81
|
+
d`
|
|
82
|
+
/**
|
|
83
|
+
* This API is awesome, and it comes
|
|
84
|
+
* with an example!
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* console.log("Hello world!")
|
|
88
|
+
**/
|
|
89
|
+
`,
|
|
90
|
+
{ printWidth: 40 },
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("creates fenced code samples", () => {
|
|
95
|
+
const template = (
|
|
96
|
+
<JSDoc>
|
|
97
|
+
<JSDocParagraph>
|
|
98
|
+
This API is awesome, and it comes with an example!
|
|
99
|
+
</JSDocParagraph>
|
|
100
|
+
<JSDocExample fenced language="ts">
|
|
101
|
+
console.log("Hello world!")
|
|
102
|
+
</JSDocExample>
|
|
103
|
+
</JSDoc>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(template).toRenderTo(
|
|
107
|
+
d`
|
|
108
|
+
/**
|
|
109
|
+
* This API is awesome, and it comes
|
|
110
|
+
* with an example!
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* \`\`\`ts
|
|
114
|
+
* console.log("Hello world!")
|
|
115
|
+
* \`\`\`
|
|
116
|
+
**/
|
|
117
|
+
`,
|
|
118
|
+
{ printWidth: 40 },
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("creates code samples using other components", () => {
|
|
123
|
+
const template = (
|
|
124
|
+
<JSDoc>
|
|
125
|
+
<JSDocParagraph>
|
|
126
|
+
This API is awesome, and it comes with an example!
|
|
127
|
+
</JSDocParagraph>
|
|
128
|
+
<JSDocExample language="ts">
|
|
129
|
+
// make a function call.
|
|
130
|
+
<hbr />
|
|
131
|
+
<FunctionCallExpression
|
|
132
|
+
target="console.log"
|
|
133
|
+
args={["arg1", "arg2"]}
|
|
134
|
+
/>
|
|
135
|
+
;
|
|
136
|
+
</JSDocExample>
|
|
137
|
+
</JSDoc>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(template).toRenderTo(
|
|
141
|
+
d`
|
|
142
|
+
/**
|
|
143
|
+
* This API is awesome, and it comes
|
|
144
|
+
* with an example!
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // make a function call.
|
|
148
|
+
* console.log(arg1, arg2);
|
|
149
|
+
**/
|
|
150
|
+
`,
|
|
151
|
+
{ printWidth: 40 },
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { MemberChainExpression } from "../src/components/MemberChainExpression.jsx";
|
|
4
|
+
import { FunctionCallExpression, ValueExpression } from "../src/index.js";
|
|
5
|
+
import { toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("works", () => {
|
|
8
|
+
expect(
|
|
9
|
+
toSourceText(
|
|
10
|
+
<MemberChainExpression>
|
|
11
|
+
<>z</>
|
|
12
|
+
<FunctionCallExpression target="string" />
|
|
13
|
+
<FunctionCallExpression target="array" />
|
|
14
|
+
<FunctionCallExpression target="min" args={[5]} />
|
|
15
|
+
<FunctionCallExpression target="max" args={[10]} />
|
|
16
|
+
</MemberChainExpression>,
|
|
17
|
+
{ printWidth: 10 },
|
|
18
|
+
),
|
|
19
|
+
).toBe(d`
|
|
20
|
+
z.string()
|
|
21
|
+
.array()
|
|
22
|
+
.min(5)
|
|
23
|
+
.max(10)
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("works with args which break", () => {
|
|
28
|
+
expect(
|
|
29
|
+
toSourceText(
|
|
30
|
+
<MemberChainExpression>
|
|
31
|
+
<>z</>
|
|
32
|
+
<FunctionCallExpression
|
|
33
|
+
target="object"
|
|
34
|
+
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
35
|
+
/>
|
|
36
|
+
<FunctionCallExpression target="array" />
|
|
37
|
+
</MemberChainExpression>,
|
|
38
|
+
{ printWidth: 10 },
|
|
39
|
+
),
|
|
40
|
+
).toBe(d`
|
|
41
|
+
z.object({
|
|
42
|
+
a: 1,
|
|
43
|
+
b: 2,
|
|
44
|
+
})
|
|
45
|
+
.array()
|
|
46
|
+
`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("works with args when it doesn't break", () => {
|
|
50
|
+
expect(
|
|
51
|
+
toSourceText(
|
|
52
|
+
<MemberChainExpression>
|
|
53
|
+
<>z</>
|
|
54
|
+
<FunctionCallExpression
|
|
55
|
+
target="object"
|
|
56
|
+
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
57
|
+
/>
|
|
58
|
+
</MemberChainExpression>,
|
|
59
|
+
),
|
|
60
|
+
).toBe(d`
|
|
61
|
+
z.object({
|
|
62
|
+
a: 1,
|
|
63
|
+
b: 2,
|
|
64
|
+
})
|
|
65
|
+
`);
|
|
66
|
+
|
|
67
|
+
expect(
|
|
68
|
+
toSourceText(
|
|
69
|
+
<MemberChainExpression>
|
|
70
|
+
<>z</>
|
|
71
|
+
<>z2</>
|
|
72
|
+
<>z3</>
|
|
73
|
+
<FunctionCallExpression
|
|
74
|
+
target="object"
|
|
75
|
+
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
76
|
+
/>
|
|
77
|
+
</MemberChainExpression>,
|
|
78
|
+
),
|
|
79
|
+
).toBe(d`
|
|
80
|
+
z.z2.z3.object({
|
|
81
|
+
a: 1,
|
|
82
|
+
b: 2,
|
|
83
|
+
})
|
|
84
|
+
`);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("works with nested call member chains", () => {
|
|
88
|
+
expect(
|
|
89
|
+
toSourceText(
|
|
90
|
+
<MemberChainExpression>
|
|
91
|
+
<>z</>
|
|
92
|
+
<FunctionCallExpression target="string" />
|
|
93
|
+
<FunctionCallExpression target="array" />
|
|
94
|
+
<MemberChainExpression>
|
|
95
|
+
<FunctionCallExpression target="min" args={[5]} />
|
|
96
|
+
<FunctionCallExpression target="max" args={[10]} />
|
|
97
|
+
</MemberChainExpression>
|
|
98
|
+
<FunctionCallExpression target="array" />
|
|
99
|
+
</MemberChainExpression>,
|
|
100
|
+
{ printWidth: 10 },
|
|
101
|
+
),
|
|
102
|
+
).toBe(d`
|
|
103
|
+
z.string()
|
|
104
|
+
.array()
|
|
105
|
+
.min(5)
|
|
106
|
+
.max(10)
|
|
107
|
+
.array()
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("works without function call expressions", () => {
|
|
112
|
+
expect(
|
|
113
|
+
toSourceText(
|
|
114
|
+
<MemberChainExpression>
|
|
115
|
+
<>z</>
|
|
116
|
+
<>string</>
|
|
117
|
+
<>min</>
|
|
118
|
+
</MemberChainExpression>,
|
|
119
|
+
{ printWidth: 5 },
|
|
120
|
+
),
|
|
121
|
+
).toBe(d`
|
|
122
|
+
z.string.min
|
|
123
|
+
`);
|
|
124
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output, refkey, render } from "@alloy-js/core";
|
|
1
|
+
import { Output, refkey, render, StatementList } 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";
|
|
@@ -14,19 +14,20 @@ it("applies to functions and variables", () => {
|
|
|
14
14
|
<Output namePolicy={namePolicy}>
|
|
15
15
|
<ts.SourceFile path="test.ts">
|
|
16
16
|
<ts.FunctionDeclaration name="foo-bar" refkey={ref1} />
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
<hbr />
|
|
18
|
+
<StatementList>
|
|
19
|
+
<ts.VarDeclaration name="one-two" refkey={ref2}>
|
|
20
|
+
"hello"
|
|
21
|
+
</ts.VarDeclaration>
|
|
22
|
+
<ts.Reference refkey={ref1} />
|
|
23
|
+
<ts.Reference refkey={ref2} />
|
|
24
|
+
</StatementList>
|
|
22
25
|
</ts.SourceFile>
|
|
23
26
|
</Output>,
|
|
24
27
|
);
|
|
25
28
|
|
|
26
29
|
expect(res.contents[0].contents).toEqual(d`
|
|
27
|
-
function fooBar() {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
+
function fooBar() {}
|
|
30
31
|
const oneTwo = "hello";
|
|
31
32
|
fooBar;
|
|
32
33
|
oneTwo;
|
|
@@ -42,19 +43,20 @@ it("keeps _ and $ prefix", () => {
|
|
|
42
43
|
<Output namePolicy={namePolicy}>
|
|
43
44
|
<ts.SourceFile path="test.ts">
|
|
44
45
|
<ts.FunctionDeclaration name="_foo-bar" refkey={ref1} />
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
<hbr />
|
|
47
|
+
<StatementList>
|
|
48
|
+
<ts.VarDeclaration name="$one-two" refkey={ref2}>
|
|
49
|
+
"hello"
|
|
50
|
+
</ts.VarDeclaration>
|
|
51
|
+
<ts.Reference refkey={ref1} />
|
|
52
|
+
<ts.Reference refkey={ref2} />
|
|
53
|
+
</StatementList>
|
|
50
54
|
</ts.SourceFile>
|
|
51
55
|
</Output>,
|
|
52
56
|
);
|
|
53
57
|
|
|
54
58
|
expect(res.contents[0].contents).toEqual(d`
|
|
55
|
-
function _fooBar() {
|
|
56
|
-
|
|
57
|
-
}
|
|
59
|
+
function _fooBar() {}
|
|
58
60
|
const $oneTwo = "hello";
|
|
59
61
|
_fooBar;
|
|
60
62
|
$oneTwo;
|
|
@@ -69,20 +71,25 @@ it("appends _ to reserved words", () => {
|
|
|
69
71
|
const res = render(
|
|
70
72
|
<Output namePolicy={namePolicy}>
|
|
71
73
|
<ts.SourceFile path="test.ts">
|
|
72
|
-
<ts.FunctionDeclaration
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
<
|
|
74
|
+
<ts.FunctionDeclaration
|
|
75
|
+
name="default"
|
|
76
|
+
refkey={ref1}
|
|
77
|
+
parameters={{ await: "any" }}
|
|
78
|
+
/>
|
|
79
|
+
<hbr />
|
|
80
|
+
<StatementList>
|
|
81
|
+
<ts.VarDeclaration name="super" refkey={ref2}>
|
|
82
|
+
"hello"
|
|
83
|
+
</ts.VarDeclaration>
|
|
84
|
+
<ts.Reference refkey={ref1} />
|
|
85
|
+
<ts.Reference refkey={ref2} />
|
|
86
|
+
</StatementList>
|
|
78
87
|
</ts.SourceFile>
|
|
79
88
|
</Output>,
|
|
80
89
|
);
|
|
81
90
|
|
|
82
91
|
expect(res.contents[0].contents).toEqual(d`
|
|
83
|
-
function default_(await_: any) {
|
|
84
|
-
|
|
85
|
-
}
|
|
92
|
+
function default_(await_: any) {}
|
|
86
93
|
const super_ = "hello";
|
|
87
94
|
default_;
|
|
88
95
|
super_;
|
|
@@ -5,28 +5,127 @@ import * as ts from "../src/index.js";
|
|
|
5
5
|
import { findFile } from "./utils.js";
|
|
6
6
|
|
|
7
7
|
it("imports external packages", () => {
|
|
8
|
-
debug.component.tree();
|
|
9
8
|
const res = render(
|
|
10
9
|
<Output>
|
|
11
|
-
<ts.PackageDirectory
|
|
10
|
+
<ts.PackageDirectory
|
|
11
|
+
name="greeting-lib"
|
|
12
|
+
path="greeting-lib"
|
|
13
|
+
version="1.0.0"
|
|
14
|
+
>
|
|
12
15
|
<ts.SourceFile path="greetings.ts">
|
|
13
|
-
<ts.FunctionDeclaration
|
|
16
|
+
<ts.FunctionDeclaration
|
|
17
|
+
name="getGreeting"
|
|
18
|
+
refkey={refkey("getGreeting")}
|
|
19
|
+
>
|
|
14
20
|
return "Hello world!";
|
|
15
21
|
</ts.FunctionDeclaration>
|
|
16
22
|
</ts.SourceFile>
|
|
17
23
|
|
|
18
24
|
<ts.SourceFile path="logGreetings.ts">
|
|
19
|
-
<ts.FunctionDeclaration
|
|
25
|
+
<ts.FunctionDeclaration
|
|
26
|
+
export
|
|
27
|
+
name="printGreeting"
|
|
28
|
+
refkey={refkey("printGreeting")}
|
|
29
|
+
>
|
|
20
30
|
console.log("Hello world!");
|
|
21
31
|
</ts.FunctionDeclaration>
|
|
22
32
|
</ts.SourceFile>
|
|
23
|
-
|
|
33
|
+
|
|
24
34
|
<ts.BarrelFile export="." />
|
|
25
35
|
</ts.PackageDirectory>
|
|
26
36
|
|
|
27
37
|
<ts.PackageDirectory name="consumer" path="consumer" version="1.0.0">
|
|
28
38
|
<ts.SourceFile export="." path="ref.ts">
|
|
29
|
-
<ts.Reference refkey={refkey("getGreeting")} />
|
|
39
|
+
<ts.Reference refkey={refkey("getGreeting")} />
|
|
40
|
+
();
|
|
41
|
+
</ts.SourceFile>
|
|
42
|
+
</ts.PackageDirectory>
|
|
43
|
+
</Output>,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const consumerPkgJson = findFile(res, "consumer/package.json")!;
|
|
47
|
+
const greetingPkgJson = findFile(res, "greeting-lib/package.json")!;
|
|
48
|
+
const refFile = findFile(res, "consumer/ref.ts")!;
|
|
49
|
+
|
|
50
|
+
expect(consumerPkgJson.contents).toEqual(d`
|
|
51
|
+
{
|
|
52
|
+
"name": "consumer",
|
|
53
|
+
"version": "1.0.0",
|
|
54
|
+
"type": "module",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"greeting-lib": "1.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"typescript": "^5.5.2"
|
|
60
|
+
},
|
|
61
|
+
"exports": {
|
|
62
|
+
".": "./dist/ref.js"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`);
|
|
66
|
+
|
|
67
|
+
expect(greetingPkgJson.contents).toEqual(d`
|
|
68
|
+
{
|
|
69
|
+
"name": "greeting-lib",
|
|
70
|
+
"version": "1.0.0",
|
|
71
|
+
"type": "module",
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"typescript": "^5.5.2"
|
|
74
|
+
},
|
|
75
|
+
"exports": {
|
|
76
|
+
".": "./dist/index.js"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
|
|
81
|
+
expect(refFile.contents).toEqual(d`
|
|
82
|
+
import { getGreeting } from "greeting-lib";
|
|
83
|
+
|
|
84
|
+
getGreeting();
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("combines explicit dependencies with referenced dependencies", () => {
|
|
89
|
+
const res = render(
|
|
90
|
+
<Output>
|
|
91
|
+
<ts.PackageDirectory
|
|
92
|
+
name="greeting-lib"
|
|
93
|
+
path="greeting-lib"
|
|
94
|
+
version="1.0.0"
|
|
95
|
+
>
|
|
96
|
+
<ts.SourceFile path="greetings.ts">
|
|
97
|
+
<ts.FunctionDeclaration
|
|
98
|
+
name="getGreeting"
|
|
99
|
+
refkey={refkey("getGreeting")}
|
|
100
|
+
>
|
|
101
|
+
return "Hello world!";
|
|
102
|
+
</ts.FunctionDeclaration>
|
|
103
|
+
</ts.SourceFile>
|
|
104
|
+
|
|
105
|
+
<ts.SourceFile path="logGreetings.ts">
|
|
106
|
+
<ts.FunctionDeclaration
|
|
107
|
+
export
|
|
108
|
+
name="printGreeting"
|
|
109
|
+
refkey={refkey("printGreeting")}
|
|
110
|
+
>
|
|
111
|
+
console.log("Hello world!");
|
|
112
|
+
</ts.FunctionDeclaration>
|
|
113
|
+
</ts.SourceFile>
|
|
114
|
+
|
|
115
|
+
<ts.BarrelFile export="." />
|
|
116
|
+
</ts.PackageDirectory>
|
|
117
|
+
|
|
118
|
+
<ts.PackageDirectory
|
|
119
|
+
name="consumer"
|
|
120
|
+
path="consumer"
|
|
121
|
+
version="1.0.0"
|
|
122
|
+
dependencies={{
|
|
123
|
+
foo: "bar",
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
<ts.SourceFile export="." path="ref.ts">
|
|
127
|
+
<ts.Reference refkey={refkey("getGreeting")} />
|
|
128
|
+
();
|
|
30
129
|
</ts.SourceFile>
|
|
31
130
|
</ts.PackageDirectory>
|
|
32
131
|
</Output>,
|
|
@@ -42,6 +141,7 @@ it("imports external packages", () => {
|
|
|
42
141
|
"version": "1.0.0",
|
|
43
142
|
"type": "module",
|
|
44
143
|
"dependencies": {
|
|
144
|
+
"foo": "bar",
|
|
45
145
|
"greeting-lib": "1.0.0"
|
|
46
146
|
},
|
|
47
147
|
"devDependencies": {
|
|
@@ -58,7 +158,6 @@ it("imports external packages", () => {
|
|
|
58
158
|
"name": "greeting-lib",
|
|
59
159
|
"version": "1.0.0",
|
|
60
160
|
"type": "module",
|
|
61
|
-
"dependencies": {},
|
|
62
161
|
"devDependencies": {
|
|
63
162
|
"typescript": "^5.5.2"
|
|
64
163
|
},
|