@alloy-js/typescript 0.7.0 → 0.8.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.map +1 -1
- package/dist/src/components/ArrayExpression.js +9 -3
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BlockScope.d.ts +13 -0
- package/dist/src/components/BlockScope.d.ts.map +1 -0
- package/dist/src/components/BlockScope.js +20 -0
- package/dist/src/components/BlockScope.js.map +1 -0
- package/dist/src/components/CallSignature.d.ts +38 -0
- package/dist/src/components/CallSignature.d.ts.map +1 -0
- package/dist/src/components/CallSignature.js +26 -0
- package/dist/src/components/CallSignature.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts +3 -4
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +99 -41
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/Declaration.d.ts +21 -8
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +39 -21
- 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 +18 -6
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts +8 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +27 -5
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.js +1 -1
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +21 -13
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +79 -45
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/IfStatement.d.ts +25 -0
- package/dist/src/components/IfStatement.d.ts.map +1 -0
- package/dist/src/components/IfStatement.js +34 -0
- package/dist/src/components/IfStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +10 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +66 -6
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts.map +1 -1
- package/dist/src/components/JSDoc.js +1 -5
- package/dist/src/components/JSDoc.js.map +1 -1
- package/dist/src/components/JSDocParam.d.ts +22 -0
- package/dist/src/components/JSDocParam.d.ts.map +1 -0
- package/dist/src/components/JSDocParam.js +121 -0
- package/dist/src/components/JSDocParam.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +9 -2
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PropertyName.d.ts +19 -0
- package/dist/src/components/PropertyName.d.ts.map +1 -0
- package/dist/src/components/PropertyName.js +36 -0
- package/dist/src/components/PropertyName.js.map +1 -0
- package/dist/src/components/SingleLineCommentBlock.d.ts +10 -0
- package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -0
- package/dist/src/components/SingleLineCommentBlock.js +20 -0
- package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +6 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +31 -0
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/SwitchStatement.d.ts +31 -0
- package/dist/src/components/SwitchStatement.d.ts.map +1 -0
- package/dist/src/components/SwitchStatement.js +48 -0
- package/dist/src/components/SwitchStatement.js.map +1 -0
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js +16 -3
- package/dist/src/components/TypeDeclaration.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 +19 -6
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +7 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +35 -112
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +8 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/context/index.d.ts +2 -0
- package/dist/src/context/index.d.ts.map +1 -0
- package/dist/src/context/index.js +1 -0
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/private-scope.d.ts +18 -0
- package/dist/src/context/private-scope.d.ts.map +1 -0
- package/dist/src/context/private-scope.js +9 -0
- package/dist/src/context/private-scope.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts +60 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -0
- package/dist/src/parameter-descriptor.js +1 -0
- package/dist/src/parameter-descriptor.js.map +1 -0
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +50 -12
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/symbols/ts-member-scope.d.ts +1 -1
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +2 -0
- package/dist/src/symbols/ts-member-scope.js.map +1 -1
- package/dist/src/symbols/ts-output-symbol.d.ts +7 -4
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +11 -2
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/src/utils.d.ts +7 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +17 -0
- package/dist/src/utils.js.map +1 -1
- package/dist/test/block-scope.test.d.ts +2 -0
- package/dist/test/block-scope.test.d.ts.map +1 -0
- package/dist/test/enum-jsdoc.test.d.ts +2 -0
- package/dist/test/enum-jsdoc.test.d.ts.map +1 -0
- package/dist/test/function-declaration-jsdoc.test.d.ts +2 -0
- package/dist/test/function-declaration-jsdoc.test.d.ts.map +1 -0
- package/dist/test/if-statement.test.d.ts +2 -0
- package/dist/test/if-statement.test.d.ts.map +1 -0
- package/dist/test/interface-jsdoc.test.d.ts +2 -0
- package/dist/test/interface-jsdoc.test.d.ts.map +1 -0
- package/dist/test/jscomment.test.d.ts +2 -0
- package/dist/test/jscomment.test.d.ts.map +1 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -1
- package/dist/test/jsdocparam.test.d.ts +2 -0
- package/dist/test/jsdocparam.test.d.ts.map +1 -0
- package/dist/test/name-conflict.test.d.ts +2 -0
- package/dist/test/name-conflict.test.d.ts.map +1 -0
- package/dist/test/package-json.test.d.ts +2 -0
- package/dist/test/package-json.test.d.ts.map +1 -0
- package/dist/test/source-file.test.d.ts +2 -0
- package/dist/test/source-file.test.d.ts.map +1 -0
- package/dist/test/switch-statement.test.d.ts +2 -0
- package/dist/test/switch-statement.test.d.ts.map +1 -0
- package/dist/test/var-declaration-jsdoc.test.d.ts +2 -0
- package/dist/test/var-declaration-jsdoc.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/ArrayExpression.tsx +13 -12
- package/src/components/BlockScope.tsx +31 -0
- package/src/components/CallSignature.tsx +67 -0
- package/src/components/ClassDeclaration.tsx +103 -50
- package/src/components/Declaration.tsx +72 -27
- package/src/components/EnumDeclaration.tsx +26 -18
- package/src/components/EnumMember.tsx +24 -4
- package/src/components/FunctionCallExpression.tsx +1 -1
- package/src/components/FunctionDeclaration.tsx +106 -82
- package/src/components/IfStatement.tsx +51 -0
- package/src/components/Interface.tsx +61 -14
- package/src/components/JSDoc.tsx +1 -10
- package/src/components/JSDocParam.tsx +115 -0
- package/src/components/ObjectExpression.tsx +7 -2
- package/src/components/PropertyName.tsx +50 -0
- package/src/components/SingleLineCommentBlock.tsx +21 -0
- package/src/components/SourceFile.tsx +29 -0
- package/src/components/SwitchStatement.tsx +78 -0
- package/src/components/TypeDeclaration.tsx +11 -4
- package/src/components/VarDeclaration.tsx +19 -11
- package/src/components/index.ts +7 -0
- package/src/components/stc/index.ts +8 -1
- package/src/context/index.ts +1 -0
- package/src/context/private-scope.ts +23 -0
- package/src/index.ts +1 -0
- package/src/parameter-descriptor.ts +71 -0
- package/src/symbols/reference.ts +70 -18
- package/src/symbols/ts-member-scope.ts +6 -2
- package/src/symbols/ts-output-symbol.ts +24 -11
- package/src/utils.ts +33 -0
- package/temp/api.json +3816 -1925
- package/test/array.test.tsx +60 -0
- package/test/basic.test.tsx +2 -2
- package/test/block-scope.test.tsx +29 -0
- package/test/class.test.tsx +173 -5
- package/test/enum-jsdoc.test.tsx +74 -0
- package/test/enum.test.tsx +50 -3
- package/test/function-call-expression.test.tsx +5 -2
- package/test/function-declaration-jsdoc.test.tsx +89 -0
- package/test/function-declaration.test.tsx +13 -9
- package/test/if-statement.test.tsx +28 -0
- package/test/interface-jsdoc.test.tsx +164 -0
- package/test/interface.test.tsx +14 -0
- package/test/jscomment.test.tsx +104 -0
- package/test/jsdoc.test.tsx +9 -15
- package/test/jsdocparam.test.tsx +188 -0
- package/test/name-conflict.test.tsx +105 -0
- package/test/name-policy.test.tsx +1 -1
- package/test/package-json.test.tsx +93 -0
- package/test/reference.test.tsx +6 -2
- package/test/source-file.test.tsx +38 -0
- package/test/switch-statement.test.tsx +50 -0
- package/test/value-expression.test.tsx +9 -0
- package/test/var-declaration-jsdoc.test.tsx +70 -0
- package/test/var-declaration.test.tsx +1 -1
- package/tsconfig.json +1 -8
- package/vitest.config.ts +2 -10
- package/dist/src/components/JSDocParagraph.d.ts +0 -10
- package/dist/src/components/JSDocParagraph.d.ts.map +0 -1
- package/dist/src/components/JSDocParagraph.js +0 -23
- package/dist/src/components/JSDocParagraph.js.map +0 -1
- package/src/components/JSDocParagraph.tsx +0 -35
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
ElseClause,
|
|
5
|
+
ElseIfClause,
|
|
6
|
+
IfStatement,
|
|
7
|
+
} from "../src/components/IfStatement.jsx";
|
|
8
|
+
import { toSourceText } from "./utils.jsx";
|
|
9
|
+
|
|
10
|
+
it("works with blocks", () => {
|
|
11
|
+
const text = toSourceText(
|
|
12
|
+
<>
|
|
13
|
+
<IfStatement condition="x === 1">// do thing</IfStatement>
|
|
14
|
+
<ElseIfClause condition="x === 2">// do another thing</ElseIfClause>
|
|
15
|
+
<ElseClause>// do default thing</ElseClause>
|
|
16
|
+
</>,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(text).toBe(d`
|
|
20
|
+
if (x === 1) {
|
|
21
|
+
// do thing
|
|
22
|
+
} else if (x === 2) {
|
|
23
|
+
// do another thing
|
|
24
|
+
} else {
|
|
25
|
+
// do default thing
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { StatementList } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as ts from "../src/index.js";
|
|
5
|
+
import { toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("renders an interface declaration with documentation", () => {
|
|
8
|
+
const res = toSourceText(
|
|
9
|
+
<ts.InterfaceDeclaration
|
|
10
|
+
name="Person"
|
|
11
|
+
doc="Interface representing a person"
|
|
12
|
+
>
|
|
13
|
+
<StatementList>
|
|
14
|
+
<ts.InterfaceMember name="name" type="string" />
|
|
15
|
+
<ts.InterfaceMember name="age" type="number" />
|
|
16
|
+
</StatementList>
|
|
17
|
+
</ts.InterfaceDeclaration>,
|
|
18
|
+
);
|
|
19
|
+
expect(res).toEqual(d`
|
|
20
|
+
/**
|
|
21
|
+
* Interface representing a person
|
|
22
|
+
**/
|
|
23
|
+
interface Person {
|
|
24
|
+
name: string;
|
|
25
|
+
age: number;
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("renders an interface declaration with docs from a string array with single element", () => {
|
|
31
|
+
const res = toSourceText(
|
|
32
|
+
<ts.InterfaceDeclaration
|
|
33
|
+
name="Person"
|
|
34
|
+
doc={["Interface representing a person"]}
|
|
35
|
+
>
|
|
36
|
+
<StatementList>
|
|
37
|
+
<ts.InterfaceMember name="name" type="string" />
|
|
38
|
+
<ts.InterfaceMember name="age" type="number" />
|
|
39
|
+
</StatementList>
|
|
40
|
+
</ts.InterfaceDeclaration>,
|
|
41
|
+
);
|
|
42
|
+
expect(res).toEqual(d`
|
|
43
|
+
/**
|
|
44
|
+
* Interface representing a person
|
|
45
|
+
**/
|
|
46
|
+
interface Person {
|
|
47
|
+
name: string;
|
|
48
|
+
age: number;
|
|
49
|
+
}
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("renders an interface declaration with docs from a string array", () => {
|
|
54
|
+
const res = toSourceText(
|
|
55
|
+
<ts.InterfaceDeclaration
|
|
56
|
+
name="Person"
|
|
57
|
+
doc={[
|
|
58
|
+
"Interface representing a person",
|
|
59
|
+
"This should be another paragraph",
|
|
60
|
+
]}
|
|
61
|
+
>
|
|
62
|
+
<StatementList>
|
|
63
|
+
<ts.InterfaceMember name="name" type="string" />
|
|
64
|
+
<ts.InterfaceMember name="age" type="number" />
|
|
65
|
+
</StatementList>
|
|
66
|
+
</ts.InterfaceDeclaration>,
|
|
67
|
+
);
|
|
68
|
+
expect(res).toEqual(d`
|
|
69
|
+
/**
|
|
70
|
+
* Interface representing a person
|
|
71
|
+
*
|
|
72
|
+
* This should be another paragraph
|
|
73
|
+
**/
|
|
74
|
+
interface Person {
|
|
75
|
+
name: string;
|
|
76
|
+
age: number;
|
|
77
|
+
}
|
|
78
|
+
`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("renders an interface declaration with documented properties", () => {
|
|
82
|
+
const res = toSourceText(
|
|
83
|
+
<ts.InterfaceDeclaration
|
|
84
|
+
export
|
|
85
|
+
name="APIResponse"
|
|
86
|
+
doc="Standard API response format"
|
|
87
|
+
>
|
|
88
|
+
<StatementList>
|
|
89
|
+
<ts.InterfaceMember
|
|
90
|
+
name="success"
|
|
91
|
+
type="boolean"
|
|
92
|
+
doc="Wether or not the request completed successfully"
|
|
93
|
+
/>
|
|
94
|
+
<ts.InterfaceMember
|
|
95
|
+
name="data"
|
|
96
|
+
type="unknown"
|
|
97
|
+
doc="the response payload"
|
|
98
|
+
/>
|
|
99
|
+
<ts.InterfaceMember name="error" optional type="string" />
|
|
100
|
+
</StatementList>
|
|
101
|
+
</ts.InterfaceDeclaration>,
|
|
102
|
+
);
|
|
103
|
+
expect(res).toEqual(d`
|
|
104
|
+
/**
|
|
105
|
+
* Standard API response format
|
|
106
|
+
**/
|
|
107
|
+
export interface APIResponse {
|
|
108
|
+
/**
|
|
109
|
+
* Wether or not the request completed successfully
|
|
110
|
+
**/
|
|
111
|
+
success: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* the response payload
|
|
114
|
+
**/
|
|
115
|
+
data: unknown;
|
|
116
|
+
error?: string;
|
|
117
|
+
}
|
|
118
|
+
`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("renders an interface declaration with array documented properties ", () => {
|
|
122
|
+
const res = toSourceText(
|
|
123
|
+
<ts.InterfaceDeclaration
|
|
124
|
+
export
|
|
125
|
+
name="APIResponse"
|
|
126
|
+
doc="Standard API response format"
|
|
127
|
+
>
|
|
128
|
+
<StatementList>
|
|
129
|
+
<ts.InterfaceMember
|
|
130
|
+
name="success"
|
|
131
|
+
type="boolean"
|
|
132
|
+
doc={[
|
|
133
|
+
"Wether or not the request completed successfully",
|
|
134
|
+
"This is another paragraph",
|
|
135
|
+
]}
|
|
136
|
+
/>
|
|
137
|
+
<ts.InterfaceMember
|
|
138
|
+
name="data"
|
|
139
|
+
type="unknown"
|
|
140
|
+
doc="the response payload"
|
|
141
|
+
/>
|
|
142
|
+
<ts.InterfaceMember name="error" optional type="string" />
|
|
143
|
+
</StatementList>
|
|
144
|
+
</ts.InterfaceDeclaration>,
|
|
145
|
+
);
|
|
146
|
+
expect(res).toEqual(d`
|
|
147
|
+
/**
|
|
148
|
+
* Standard API response format
|
|
149
|
+
**/
|
|
150
|
+
export interface APIResponse {
|
|
151
|
+
/**
|
|
152
|
+
* Wether or not the request completed successfully
|
|
153
|
+
*
|
|
154
|
+
* This is another paragraph
|
|
155
|
+
**/
|
|
156
|
+
success: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* the response payload
|
|
159
|
+
**/
|
|
160
|
+
data: unknown;
|
|
161
|
+
error?: string;
|
|
162
|
+
}
|
|
163
|
+
`);
|
|
164
|
+
});
|
package/test/interface.test.tsx
CHANGED
|
@@ -132,3 +132,17 @@ it("supports the naming policy", () => {
|
|
|
132
132
|
}
|
|
133
133
|
`);
|
|
134
134
|
});
|
|
135
|
+
|
|
136
|
+
it("handles invalid identifier names", () => {
|
|
137
|
+
const res = toSourceText(
|
|
138
|
+
<ts.InterfaceExpression>
|
|
139
|
+
<ts.InterfaceMember name="invalid-name" type="string" />;
|
|
140
|
+
</ts.InterfaceExpression>,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(res).toEqual(d`
|
|
144
|
+
{
|
|
145
|
+
"invalid-name": string;
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { List } from "@alloy-js/core";
|
|
2
|
+
import "@alloy-js/core/testing";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { SingleLineCommentBlock } from "../src/components/SingleLineCommentBlock.jsx";
|
|
6
|
+
|
|
7
|
+
describe("JSComment", () => {
|
|
8
|
+
it("formats properly a simple comment", () => {
|
|
9
|
+
const template = (
|
|
10
|
+
<>
|
|
11
|
+
<SingleLineCommentBlock>Hello!</SingleLineCommentBlock>
|
|
12
|
+
<hbr />
|
|
13
|
+
Should not be part of the comment
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(template).toRenderTo(
|
|
18
|
+
d`
|
|
19
|
+
// Hello!
|
|
20
|
+
Should not be part of the comment
|
|
21
|
+
`,
|
|
22
|
+
{ printWidth: 40 },
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should not add extra line breaks", () => {
|
|
27
|
+
const template = (
|
|
28
|
+
<>
|
|
29
|
+
<List hardline>
|
|
30
|
+
<SingleLineCommentBlock>
|
|
31
|
+
Hello!
|
|
32
|
+
<hbr />
|
|
33
|
+
<hbr />
|
|
34
|
+
This is another line
|
|
35
|
+
</SingleLineCommentBlock>
|
|
36
|
+
</List>
|
|
37
|
+
<hbr />
|
|
38
|
+
Hello
|
|
39
|
+
</>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(template).toRenderTo(
|
|
43
|
+
d`
|
|
44
|
+
// Hello!
|
|
45
|
+
//
|
|
46
|
+
// This is another line
|
|
47
|
+
Hello
|
|
48
|
+
`,
|
|
49
|
+
{ printWidth: 40 },
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("formats properly multiple children", () => {
|
|
54
|
+
const template = (
|
|
55
|
+
<>
|
|
56
|
+
<SingleLineCommentBlock>
|
|
57
|
+
Hello!
|
|
58
|
+
<hbr />
|
|
59
|
+
<hbr />
|
|
60
|
+
This is another line
|
|
61
|
+
</SingleLineCommentBlock>
|
|
62
|
+
<hbr />
|
|
63
|
+
foo should be outside the comment
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(template).toRenderTo(
|
|
68
|
+
d`
|
|
69
|
+
// Hello!
|
|
70
|
+
//
|
|
71
|
+
// This is another line
|
|
72
|
+
foo should be outside the comment
|
|
73
|
+
`,
|
|
74
|
+
{ printWidth: 40 },
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("It correctly do word wrapping", () => {
|
|
79
|
+
const template = (
|
|
80
|
+
<>
|
|
81
|
+
<SingleLineCommentBlock>
|
|
82
|
+
This is a very long line that should be broken into multiple lines. It
|
|
83
|
+
should also be aligned properly. The line breaks in this paragraph
|
|
84
|
+
should not be carried over into the JSDoc comment.
|
|
85
|
+
</SingleLineCommentBlock>
|
|
86
|
+
<hbr />
|
|
87
|
+
<>This should not be part of the comment</>
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(template).toRenderTo(
|
|
92
|
+
d`
|
|
93
|
+
// This is a very long line that should
|
|
94
|
+
// be broken into multiple lines. It
|
|
95
|
+
// should also be aligned properly. The
|
|
96
|
+
// line breaks in this paragraph should
|
|
97
|
+
// not be carried over into the JSDoc
|
|
98
|
+
// comment.
|
|
99
|
+
This should not be part of the comment
|
|
100
|
+
`,
|
|
101
|
+
{ printWidth: 40 },
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
});
|
package/test/jsdoc.test.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Prose } from "@alloy-js/core";
|
|
1
2
|
import "@alloy-js/core/testing";
|
|
2
3
|
import { d } from "@alloy-js/core/testing";
|
|
3
4
|
import { describe, expect, it } from "vitest";
|
|
4
5
|
import { JSDoc } from "../src/components/JSDoc.jsx";
|
|
5
6
|
import { JSDocComment } from "../src/components/JSDocComment.jsx";
|
|
6
7
|
import { JSDocExample } from "../src/components/JSDocExample.jsx";
|
|
7
|
-
import { JSDocParagraph } from "../src/components/JSDocParagraph.jsx";
|
|
8
8
|
import { FunctionCallExpression } from "../src/index.js";
|
|
9
9
|
|
|
10
10
|
describe("JSDoc", () => {
|
|
@@ -31,19 +31,19 @@ describe("JSDoc", () => {
|
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
describe("
|
|
34
|
+
describe("Prose", () => {
|
|
35
35
|
it("formats properly", () => {
|
|
36
36
|
const template = (
|
|
37
37
|
<JSDoc>
|
|
38
|
-
<
|
|
38
|
+
<Prose>
|
|
39
39
|
This is a long paragraph that should end up being broken into multiple
|
|
40
40
|
paragraphs. Moreover, the line breaks in this paragraph should not be
|
|
41
41
|
carried over into the JSDoc comment.
|
|
42
|
-
</
|
|
43
|
-
<
|
|
42
|
+
</Prose>
|
|
43
|
+
<Prose>
|
|
44
44
|
This is another paragraph. There should be a couple breaks in front of
|
|
45
45
|
it.
|
|
46
|
-
</
|
|
46
|
+
</Prose>
|
|
47
47
|
</JSDoc>
|
|
48
48
|
);
|
|
49
49
|
|
|
@@ -70,9 +70,7 @@ describe("JSDocExample", () => {
|
|
|
70
70
|
it("creates unfenced code samples", () => {
|
|
71
71
|
const template = (
|
|
72
72
|
<JSDoc>
|
|
73
|
-
<
|
|
74
|
-
This API is awesome, and it comes with an example!
|
|
75
|
-
</JSDocParagraph>
|
|
73
|
+
<Prose>This API is awesome, and it comes with an example!</Prose>
|
|
76
74
|
<JSDocExample>console.log("Hello world!")</JSDocExample>
|
|
77
75
|
</JSDoc>
|
|
78
76
|
);
|
|
@@ -94,9 +92,7 @@ describe("JSDocExample", () => {
|
|
|
94
92
|
it("creates fenced code samples", () => {
|
|
95
93
|
const template = (
|
|
96
94
|
<JSDoc>
|
|
97
|
-
<
|
|
98
|
-
This API is awesome, and it comes with an example!
|
|
99
|
-
</JSDocParagraph>
|
|
95
|
+
<Prose>This API is awesome, and it comes with an example!</Prose>
|
|
100
96
|
<JSDocExample fenced language="ts">
|
|
101
97
|
console.log("Hello world!")
|
|
102
98
|
</JSDocExample>
|
|
@@ -122,9 +118,7 @@ describe("JSDocExample", () => {
|
|
|
122
118
|
it("creates code samples using other components", () => {
|
|
123
119
|
const template = (
|
|
124
120
|
<JSDoc>
|
|
125
|
-
<
|
|
126
|
-
This API is awesome, and it comes with an example!
|
|
127
|
-
</JSDocParagraph>
|
|
121
|
+
<Prose>This API is awesome, and it comes with an example!</Prose>
|
|
128
122
|
<JSDocExample language="ts">
|
|
129
123
|
// make a function call.
|
|
130
124
|
<hbr />
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { JSDocParam } from "../src/components/JSDocParam.jsx";
|
|
4
|
+
import { JSDoc } from "../src/index.js";
|
|
5
|
+
|
|
6
|
+
it("name only", () => {
|
|
7
|
+
const template = (
|
|
8
|
+
<JSDoc>
|
|
9
|
+
<JSDocParam name="somebody" />
|
|
10
|
+
</JSDoc>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
expect(template).toRenderTo(
|
|
14
|
+
d`
|
|
15
|
+
/**
|
|
16
|
+
* @param somebody
|
|
17
|
+
**/
|
|
18
|
+
`,
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("name and type", () => {
|
|
23
|
+
const template = (
|
|
24
|
+
<JSDoc>
|
|
25
|
+
<JSDocParam name="somebody" type="string" />
|
|
26
|
+
</JSDoc>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(template).toRenderTo(
|
|
30
|
+
d`
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} somebody
|
|
33
|
+
**/
|
|
34
|
+
`,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("name, type and description", () => {
|
|
39
|
+
const template = (
|
|
40
|
+
<JSDoc>
|
|
41
|
+
<JSDocParam name="somebody" type="string">
|
|
42
|
+
Somebody's name.
|
|
43
|
+
</JSDocParam>
|
|
44
|
+
</JSDoc>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(template).toRenderTo(
|
|
48
|
+
d`
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} somebody Somebody's name.
|
|
51
|
+
**/
|
|
52
|
+
`,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("name, type and description with hyphen", () => {
|
|
57
|
+
const template = (
|
|
58
|
+
<JSDoc>
|
|
59
|
+
<JSDocParam name="somebody" type="string" hyphen>
|
|
60
|
+
Somebody's name.
|
|
61
|
+
</JSDocParam>
|
|
62
|
+
</JSDoc>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(template).toRenderTo(
|
|
66
|
+
d`
|
|
67
|
+
/**
|
|
68
|
+
* @param {string} somebody - Somebody's name.
|
|
69
|
+
**/
|
|
70
|
+
`,
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("name, type, description, hyphen and optional", () => {
|
|
75
|
+
const template = (
|
|
76
|
+
<JSDoc>
|
|
77
|
+
<JSDocParam name="somebody" type="string" optional hyphen>
|
|
78
|
+
Somebody's name.
|
|
79
|
+
</JSDocParam>
|
|
80
|
+
</JSDoc>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(template).toRenderTo(
|
|
84
|
+
d`
|
|
85
|
+
/**
|
|
86
|
+
* @param {string} [somebody] - Somebody's name.
|
|
87
|
+
**/
|
|
88
|
+
`,
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("name, type, description, hyphen and optional with default value", () => {
|
|
93
|
+
const template = (
|
|
94
|
+
<JSDoc>
|
|
95
|
+
<JSDocParam
|
|
96
|
+
name="somebody"
|
|
97
|
+
type="string"
|
|
98
|
+
optional
|
|
99
|
+
defaultValue="John Doe"
|
|
100
|
+
hyphen
|
|
101
|
+
>
|
|
102
|
+
Somebody's name.
|
|
103
|
+
</JSDocParam>
|
|
104
|
+
</JSDoc>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(template).toRenderTo(
|
|
108
|
+
d`
|
|
109
|
+
/**
|
|
110
|
+
* @param {string} [somebody=John Doe] - Somebody's name.
|
|
111
|
+
**/
|
|
112
|
+
`,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("name, type, description, hyphen and optional with default value with a very lon description", () => {
|
|
117
|
+
const template = (
|
|
118
|
+
<JSDoc>
|
|
119
|
+
<JSDocParam
|
|
120
|
+
name="somebody"
|
|
121
|
+
type="string"
|
|
122
|
+
optional
|
|
123
|
+
defaultValue="John Doe"
|
|
124
|
+
hyphen
|
|
125
|
+
>
|
|
126
|
+
Somebody's name. This can be any string representing a person, whether
|
|
127
|
+
it's a first name, full name, nickname, or even a codename (e.g., "Agent
|
|
128
|
+
X"). It's used primarily for display purposes, logging, or greeting
|
|
129
|
+
messages and is not required to be unique or validated unless specified
|
|
130
|
+
by the caller.
|
|
131
|
+
</JSDocParam>
|
|
132
|
+
<JSDocParam name="somebody2" type="string" hyphen>
|
|
133
|
+
Somebody's name. This can be any string representing a person, whether
|
|
134
|
+
it's a first name, full name, nickname, or even a codename (e.g., "Agent
|
|
135
|
+
X"). It's used primarily for display purposes, logging, or greeting
|
|
136
|
+
messages and is not required to be unique or validated unless specified
|
|
137
|
+
by the caller.
|
|
138
|
+
</JSDocParam>
|
|
139
|
+
</JSDoc>
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(template).toRenderTo(
|
|
143
|
+
d`
|
|
144
|
+
/**
|
|
145
|
+
* @param {string} [somebody=John Doe] - Somebody's name. This can be any string
|
|
146
|
+
* representing a person, whether it's a first name, full name, nickname, or
|
|
147
|
+
* even a codename (e.g., "Agent X"). It's used primarily for display
|
|
148
|
+
* purposes, logging, or greeting messages and is not required to be unique or
|
|
149
|
+
* validated unless specified by the caller.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} somebody2 - Somebody's name. This can be any string
|
|
152
|
+
* representing a person, whether it's a first name, full name, nickname, or
|
|
153
|
+
* even a codename (e.g., "Agent X"). It's used primarily for display
|
|
154
|
+
* purposes, logging, or greeting messages and is not required to be unique or
|
|
155
|
+
* validated unless specified by the caller.
|
|
156
|
+
**/
|
|
157
|
+
`,
|
|
158
|
+
{ printWidth: 80 },
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("name, type, description, hyphen and optional with default value with a description containing a linebreak", () => {
|
|
163
|
+
const template = (
|
|
164
|
+
<JSDoc>
|
|
165
|
+
<JSDocParam
|
|
166
|
+
name="somebody"
|
|
167
|
+
type="string"
|
|
168
|
+
optional
|
|
169
|
+
defaultValue="John Doe"
|
|
170
|
+
hyphen
|
|
171
|
+
>
|
|
172
|
+
Somebody's name. This is one line
|
|
173
|
+
<hbr />
|
|
174
|
+
This is another line
|
|
175
|
+
</JSDocParam>
|
|
176
|
+
</JSDoc>
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(template).toRenderTo(
|
|
180
|
+
d`
|
|
181
|
+
/**
|
|
182
|
+
* @param {string} [somebody=John Doe] - Somebody's name. This is one line
|
|
183
|
+
* This is another line
|
|
184
|
+
**/
|
|
185
|
+
`,
|
|
186
|
+
{ printWidth: 80 },
|
|
187
|
+
);
|
|
188
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Output, render } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { camelCase } from "change-case";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import {
|
|
6
|
+
FunctionDeclaration,
|
|
7
|
+
SourceFile,
|
|
8
|
+
TSOutputSymbol,
|
|
9
|
+
TSSymbolFlags,
|
|
10
|
+
} from "../src/index.js";
|
|
11
|
+
import { ParameterDescriptor } from "../src/parameter-descriptor.js";
|
|
12
|
+
it("handles custom name conflict resolver based on metadata", () => {
|
|
13
|
+
function resolver(name: string, symbols: TSOutputSymbol[]) {
|
|
14
|
+
const goodNamedSymbols = symbols.filter(
|
|
15
|
+
(s) => ~s.tsFlags & TSSymbolFlags.LocalImportSymbol,
|
|
16
|
+
);
|
|
17
|
+
const badNamedSymbols = symbols.filter(
|
|
18
|
+
(s) => s.tsFlags & TSSymbolFlags.LocalImportSymbol,
|
|
19
|
+
);
|
|
20
|
+
let nameCount = 1;
|
|
21
|
+
|
|
22
|
+
// always rename local import symbols (we don't care about them)
|
|
23
|
+
for (const sym of badNamedSymbols) {
|
|
24
|
+
sym.name = name + "_" + nameCount++;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// otherwise check the symbol metadata to see how to rename.
|
|
28
|
+
|
|
29
|
+
// group by symbol metadata
|
|
30
|
+
const groupedSymbols = new Map<string | undefined, TSOutputSymbol[]>([
|
|
31
|
+
["body", []],
|
|
32
|
+
["query", []],
|
|
33
|
+
["header", []],
|
|
34
|
+
[undefined, []],
|
|
35
|
+
]);
|
|
36
|
+
for (const sym of goodNamedSymbols) {
|
|
37
|
+
const sourceLocation = sym.metadata.sourceLocation as
|
|
38
|
+
| "body"
|
|
39
|
+
| "query"
|
|
40
|
+
| "header"
|
|
41
|
+
| undefined;
|
|
42
|
+
groupedSymbols.get(sourceLocation)!.push(sym);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const [sourceLocation, symbols] of groupedSymbols) {
|
|
46
|
+
let locationCount = 0;
|
|
47
|
+
if (sourceLocation === undefined) {
|
|
48
|
+
for (const sym of symbols) {
|
|
49
|
+
if (locationCount > 0) {
|
|
50
|
+
sym.name = name + locationCount;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
locationCount++;
|
|
54
|
+
}
|
|
55
|
+
} else if (symbols.length < 0) {
|
|
56
|
+
continue;
|
|
57
|
+
} else if (symbols.length === 1) {
|
|
58
|
+
symbols[0].name = camelCase(name + "_" + sourceLocation);
|
|
59
|
+
} else {
|
|
60
|
+
for (const sym of symbols) {
|
|
61
|
+
sym.name = camelCase(
|
|
62
|
+
name + "_" + sourceLocation + locationCount++,
|
|
63
|
+
{},
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const testParameters: ParameterDescriptor[] = [
|
|
71
|
+
{ name: "foo" },
|
|
72
|
+
{ name: "foo" },
|
|
73
|
+
{ name: "foo", metadata: { sourceLocation: "body" } },
|
|
74
|
+
{ name: "foo", metadata: { sourceLocation: "query" } },
|
|
75
|
+
{ name: "foo", metadata: { sourceLocation: "query" } },
|
|
76
|
+
{ name: "foo", metadata: { sourceLocation: "header" } },
|
|
77
|
+
{ name: "foo", metadata: { sourceLocation: "header" } },
|
|
78
|
+
{ name: "foo", metadata: { sourceLocation: "header" } },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const res = render(
|
|
82
|
+
<Output nameConflictResolver={resolver}>
|
|
83
|
+
<SourceFile path="test.ts">
|
|
84
|
+
<FunctionDeclaration
|
|
85
|
+
export
|
|
86
|
+
name="conflicty"
|
|
87
|
+
parameters={testParameters}
|
|
88
|
+
/>
|
|
89
|
+
</SourceFile>
|
|
90
|
+
</Output>,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(res.contents[0].contents).toBe(d`
|
|
94
|
+
export function conflicty(
|
|
95
|
+
foo,
|
|
96
|
+
foo1,
|
|
97
|
+
fooBody,
|
|
98
|
+
fooQuery0,
|
|
99
|
+
fooQuery1,
|
|
100
|
+
fooHeader0,
|
|
101
|
+
fooHeader1,
|
|
102
|
+
fooHeader2,
|
|
103
|
+
) {}
|
|
104
|
+
`);
|
|
105
|
+
});
|