@alloy-js/typescript 0.9.0 → 0.11.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 +22 -0
- package/dist/src/builtins/node.js +1 -2
- package/dist/src/components/ArrayExpression.js +2 -5
- package/dist/src/components/ArrowFunction.d.ts +40 -0
- package/dist/src/components/ArrowFunction.d.ts.map +1 -0
- package/dist/src/components/ArrowFunction.js +67 -0
- package/dist/src/components/BarrelFile.js +1 -2
- package/dist/src/components/BlockScope.js +2 -4
- package/dist/src/components/CallSignature.js +2 -4
- package/dist/src/components/ClassDeclaration.js +2 -6
- package/dist/src/components/CommaList.js +2 -5
- package/dist/src/components/Declaration.js +3 -5
- package/dist/src/components/EnumDeclaration.js +2 -5
- package/dist/src/components/EnumMember.js +2 -4
- package/dist/src/components/ExportStatement.js +1 -2
- package/dist/src/components/FunctionBase.d.ts +60 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -0
- package/dist/src/components/FunctionBase.js +207 -0
- package/dist/src/components/FunctionCallExpression.js +2 -5
- package/dist/src/components/FunctionDeclaration.d.ts +3 -18
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +9 -157
- package/dist/src/components/FunctionExpression.d.ts +39 -0
- package/dist/src/components/FunctionExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionExpression.js +66 -0
- package/dist/src/components/FunctionType.d.ts +39 -0
- package/dist/src/components/FunctionType.d.ts.map +1 -0
- package/dist/src/components/FunctionType.js +73 -0
- package/dist/src/components/IfStatement.js +2 -4
- package/dist/src/components/ImportStatement.js +1 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +32 -11
- package/dist/src/components/InterfaceMethod.d.ts +43 -0
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -0
- package/dist/src/components/InterfaceMethod.js +87 -0
- package/dist/src/components/JSDoc.js +1 -2
- package/dist/src/components/JSDocComment.js +2 -4
- package/dist/src/components/JSDocExample.js +2 -5
- package/dist/src/components/JSDocParam.js +2 -5
- package/dist/src/components/MemberChainExpression.js +2 -4
- package/dist/src/components/MemberDeclaration.d.ts +30 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -0
- package/dist/src/components/MemberDeclaration.js +29 -0
- package/dist/src/components/MemberExpression.d.ts +1 -2
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +2 -5
- package/dist/src/components/ObjectExpression.js +2 -5
- package/dist/src/components/PackageDirectory.js +2 -5
- package/dist/src/components/PackageJson.js +1 -2
- package/dist/src/components/PropertyName.js +1 -2
- package/dist/src/components/Reference.js +1 -2
- package/dist/src/components/SingleLineCommentBlock.js +2 -4
- package/dist/src/components/SourceFile.js +2 -4
- package/dist/src/components/SwitchStatement.js +2 -5
- package/dist/src/components/TsConfigJson.js +1 -2
- package/dist/src/components/TypeDeclaration.js +2 -6
- package/dist/src/components/ValueExpression.js +1 -2
- package/dist/src/components/VarDeclaration.js +2 -5
- 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 -1
- package/dist/src/components/stc/index.d.ts +8 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +9 -2
- package/dist/src/context/private-scope.js +1 -2
- package/dist/src/create-package.js +1 -2
- package/dist/src/index.js +1 -2
- package/dist/src/name-conflict-resolver.js +1 -2
- package/dist/src/name-policy.js +1 -2
- package/dist/src/parameter-descriptor.d.ts +27 -17
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/source-directory-data.js +1 -2
- package/dist/src/symbols/index.js +1 -2
- package/dist/src/symbols/reference.js +2 -3
- package/dist/src/symbols/scopes.js +1 -2
- package/dist/src/symbols/ts-member-scope.js +1 -2
- package/dist/src/symbols/ts-module-scope.js +1 -2
- package/dist/src/symbols/ts-output-symbol.js +1 -2
- package/dist/src/symbols/ts-package-scope.js +1 -2
- package/dist/src/utils.js +1 -2
- package/dist/test/array.test.js +105 -0
- package/dist/test/arrow-function.test.d.ts +2 -0
- package/dist/test/arrow-function.test.d.ts.map +1 -0
- package/dist/test/arrow-function.test.js +194 -0
- package/dist/test/barrel.test.js +53 -0
- package/dist/test/basic.test.js +91 -0
- package/dist/test/block-scope.test.js +30 -0
- package/dist/test/class.test.js +438 -0
- package/dist/test/enum-jsdoc.test.js +88 -0
- package/dist/test/enum.test.js +247 -0
- package/dist/test/externals.test.js +145 -0
- package/dist/test/function-call-expression.test.js +87 -0
- package/dist/test/function-declaration-jsdoc.test.js +91 -0
- package/dist/test/function-declaration.test.js +228 -0
- package/dist/test/function-expression.test.d.ts +2 -0
- package/dist/test/function-expression.test.d.ts.map +1 -0
- package/dist/test/function-expression.test.js +194 -0
- package/dist/test/function-type.test.d.ts +2 -0
- package/dist/test/function-type.test.d.ts.map +1 -0
- package/dist/test/function-type.test.js +122 -0
- package/dist/test/if-statement.test.js +25 -0
- package/dist/test/imports.test.js +434 -0
- package/dist/test/interface-jsdoc.test.js +178 -0
- package/dist/test/interface.test.d.ts.map +1 -1
- package/dist/test/interface.test.js +490 -0
- package/dist/test/jscomment.test.js +70 -0
- package/dist/test/jsdoc.test.js +134 -0
- package/dist/test/jsdocparam.test.js +164 -0
- package/dist/test/member-chain.test.js +141 -0
- package/dist/test/member-expression.test.js +359 -0
- package/dist/test/name-conflict.test.js +108 -0
- package/dist/test/name-policy.test.js +122 -0
- package/dist/test/package-external.test.js +196 -0
- package/dist/test/package-json.test.js +93 -0
- package/dist/test/package.test.js +136 -0
- package/dist/test/reference.test.js +81 -0
- package/dist/test/source-file.test.js +36 -0
- package/dist/test/switch-statement.test.js +61 -0
- package/dist/test/utils.js +45 -0
- package/dist/test/value-expression.test.js +30 -0
- package/dist/test/values.test.js +351 -0
- package/dist/test/var-declaration-jsdoc.test.js +50 -0
- package/dist/test/var-declaration.test.js +63 -0
- package/dist/test/vitest.d.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -17
- package/src/components/ArrowFunction.tsx +87 -0
- package/src/components/Declaration.tsx +1 -1
- package/src/components/FunctionBase.tsx +271 -0
- package/src/components/FunctionDeclaration.tsx +13 -195
- package/src/components/FunctionExpression.tsx +86 -0
- package/src/components/FunctionType.tsx +88 -0
- package/src/components/Interface.tsx +33 -5
- package/src/components/InterfaceMethod.tsx +96 -0
- package/src/components/MemberDeclaration.tsx +70 -0
- package/src/components/MemberExpression.tsx +1 -1
- package/src/components/index.ts +11 -0
- package/src/components/stc/index.ts +8 -0
- package/src/parameter-descriptor.ts +29 -18
- package/src/symbols/reference.ts +4 -1
- package/temp/api.json +3099 -863
- package/test/arrow-function.test.tsx +188 -0
- package/test/class.test.tsx +1 -2
- package/test/function-call-expression.test.tsx +1 -2
- package/test/function-declaration.test.tsx +1 -2
- package/test/function-expression.test.tsx +195 -0
- package/test/function-type.test.tsx +118 -0
- package/test/interface.test.tsx +256 -6
- package/tsdoc-metadata.json +1 -1
- package/babel.config.cjs +0 -4
- package/dist/src/builtins/index.js.map +0 -1
- package/dist/src/builtins/node.js.map +0 -1
- package/dist/src/components/ArrayExpression.js.map +0 -1
- package/dist/src/components/BarrelFile.js.map +0 -1
- package/dist/src/components/BlockScope.js.map +0 -1
- package/dist/src/components/CallSignature.js.map +0 -1
- package/dist/src/components/ClassDeclaration.js.map +0 -1
- package/dist/src/components/CommaList.js.map +0 -1
- package/dist/src/components/Declaration.js.map +0 -1
- package/dist/src/components/EnumDeclaration.js.map +0 -1
- package/dist/src/components/EnumMember.js.map +0 -1
- package/dist/src/components/ExportStatement.js.map +0 -1
- package/dist/src/components/FunctionCallExpression.js.map +0 -1
- package/dist/src/components/FunctionDeclaration.js.map +0 -1
- package/dist/src/components/IfStatement.js.map +0 -1
- package/dist/src/components/ImportStatement.js.map +0 -1
- package/dist/src/components/Interface.js.map +0 -1
- package/dist/src/components/JSDoc.js.map +0 -1
- package/dist/src/components/JSDocComment.js.map +0 -1
- package/dist/src/components/JSDocExample.js.map +0 -1
- package/dist/src/components/JSDocParam.js.map +0 -1
- package/dist/src/components/MemberChainExpression.js.map +0 -1
- package/dist/src/components/MemberExpression.js.map +0 -1
- package/dist/src/components/ObjectExpression.js.map +0 -1
- package/dist/src/components/PackageDirectory.js.map +0 -1
- package/dist/src/components/PackageJson.js.map +0 -1
- package/dist/src/components/PropertyName.js.map +0 -1
- package/dist/src/components/Reference.js.map +0 -1
- package/dist/src/components/SingleLineCommentBlock.js.map +0 -1
- package/dist/src/components/SourceFile.js.map +0 -1
- package/dist/src/components/SwitchStatement.js.map +0 -1
- package/dist/src/components/TsConfigJson.js.map +0 -1
- package/dist/src/components/TypeDeclaration.js.map +0 -1
- package/dist/src/components/ValueExpression.js.map +0 -1
- package/dist/src/components/VarDeclaration.js.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/components/stc/index.js.map +0 -1
- package/dist/src/context/index.js.map +0 -1
- package/dist/src/context/private-scope.js.map +0 -1
- package/dist/src/create-package.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/name-conflict-resolver.js.map +0 -1
- package/dist/src/name-policy.js.map +0 -1
- package/dist/src/parameter-descriptor.js.map +0 -1
- package/dist/src/source-directory-data.js.map +0 -1
- package/dist/src/symbols/index.js.map +0 -1
- package/dist/src/symbols/reference.js.map +0 -1
- package/dist/src/symbols/scopes.js.map +0 -1
- package/dist/src/symbols/ts-member-scope.js.map +0 -1
- package/dist/src/symbols/ts-module-scope.js.map +0 -1
- package/dist/src/symbols/ts-output-symbol.js.map +0 -1
- package/dist/src/symbols/ts-package-scope.js.map +0 -1
- package/dist/src/utils.js.map +0 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List, refkey, StatementList } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { d } from "@alloy-js/core/testing";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import * as ts from "../src/components/index.js";
|
|
7
|
+
import { toSourceText } from "./utils.js";
|
|
8
|
+
it("declares classes", () => {
|
|
9
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
10
|
+
name: "Foo"
|
|
11
|
+
}));
|
|
12
|
+
expect(res).toEqual(d`
|
|
13
|
+
class Foo {}
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
16
|
+
it("accepts export and default", () => {
|
|
17
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
18
|
+
name: "Foo",
|
|
19
|
+
"export": true,
|
|
20
|
+
"default": true
|
|
21
|
+
}));
|
|
22
|
+
expect(res).toEqual(d`
|
|
23
|
+
export default class Foo {}
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
it("creates extends", () => {
|
|
27
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
28
|
+
name: "Foo",
|
|
29
|
+
"extends": "string"
|
|
30
|
+
}));
|
|
31
|
+
expect(res).toEqual(d`
|
|
32
|
+
class Foo extends string {}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
describe("instance members", () => {
|
|
36
|
+
it("can be created", () => {
|
|
37
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
38
|
+
name: "Foo",
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(StatementList, {
|
|
41
|
+
get children() {
|
|
42
|
+
return [_$createComponent(ts.ClassField, {
|
|
43
|
+
name: "one"
|
|
44
|
+
}), _$createComponent(ts.ClassField, {
|
|
45
|
+
name: "two",
|
|
46
|
+
"public": true
|
|
47
|
+
}), _$createComponent(ts.ClassField, {
|
|
48
|
+
name: "three",
|
|
49
|
+
"private": true
|
|
50
|
+
}), _$createComponent(ts.ClassField, {
|
|
51
|
+
name: "four",
|
|
52
|
+
"protected": true
|
|
53
|
+
}), _$createComponent(ts.ClassField, {
|
|
54
|
+
name: "five",
|
|
55
|
+
type: "number"
|
|
56
|
+
}), _$createComponent(ts.ClassField, {
|
|
57
|
+
name: "six",
|
|
58
|
+
type: "number",
|
|
59
|
+
children: "12"
|
|
60
|
+
}), _$createComponent(ts.ClassField, {
|
|
61
|
+
name: "seven",
|
|
62
|
+
jsPrivate: true
|
|
63
|
+
})];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
expect(res).toEqual(d`
|
|
69
|
+
class Foo {
|
|
70
|
+
one;
|
|
71
|
+
public two;
|
|
72
|
+
private three;
|
|
73
|
+
protected four;
|
|
74
|
+
five: number;
|
|
75
|
+
six: number = 12;
|
|
76
|
+
#seven;
|
|
77
|
+
}
|
|
78
|
+
`);
|
|
79
|
+
});
|
|
80
|
+
it("can be referenced", () => {
|
|
81
|
+
const one = refkey();
|
|
82
|
+
const privateOne = refkey();
|
|
83
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
84
|
+
name: "Foo",
|
|
85
|
+
get children() {
|
|
86
|
+
return _$createComponent(StatementList, {
|
|
87
|
+
get children() {
|
|
88
|
+
return [_$createComponent(ts.ClassField, {
|
|
89
|
+
name: "one",
|
|
90
|
+
refkey: one,
|
|
91
|
+
children: "1"
|
|
92
|
+
}), _$createComponent(ts.ClassField, {
|
|
93
|
+
name: "two",
|
|
94
|
+
get children() {
|
|
95
|
+
return [one, " + 1"];
|
|
96
|
+
}
|
|
97
|
+
}), _$createComponent(ts.ClassField, {
|
|
98
|
+
name: "one",
|
|
99
|
+
refkey: privateOne,
|
|
100
|
+
jsPrivate: true,
|
|
101
|
+
children: "1"
|
|
102
|
+
}), _$createComponent(ts.ClassField, {
|
|
103
|
+
name: "three",
|
|
104
|
+
get children() {
|
|
105
|
+
return [privateOne, " + 1"];
|
|
106
|
+
}
|
|
107
|
+
})];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
expect(res).toEqual(d`
|
|
113
|
+
class Foo {
|
|
114
|
+
one = 1;
|
|
115
|
+
two = this.one + 1;
|
|
116
|
+
#one = 1;
|
|
117
|
+
three = this.#one + 1;
|
|
118
|
+
}
|
|
119
|
+
`);
|
|
120
|
+
});
|
|
121
|
+
it("cannot be referenced outside the class", () => {
|
|
122
|
+
const one = refkey();
|
|
123
|
+
expect(() => {
|
|
124
|
+
toSourceText([_$createComponent(ts.ClassDeclaration, {
|
|
125
|
+
name: "Foo",
|
|
126
|
+
get children() {
|
|
127
|
+
return _$createComponent(StatementList, {
|
|
128
|
+
get children() {
|
|
129
|
+
return _$createComponent(ts.ClassField, {
|
|
130
|
+
name: "one",
|
|
131
|
+
refkey: one,
|
|
132
|
+
children: "1"
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}), one]);
|
|
138
|
+
}).toThrow(/Cannot resolve member symbols/);
|
|
139
|
+
});
|
|
140
|
+
it("cannot be referenced outside the class when protected", () => {
|
|
141
|
+
const one = refkey();
|
|
142
|
+
expect(() => {
|
|
143
|
+
toSourceText([_$createComponent(ts.ClassDeclaration, {
|
|
144
|
+
name: "Foo",
|
|
145
|
+
get children() {
|
|
146
|
+
return _$createComponent(StatementList, {
|
|
147
|
+
get children() {
|
|
148
|
+
return _$createComponent(ts.ClassField, {
|
|
149
|
+
name: "one",
|
|
150
|
+
refkey: one,
|
|
151
|
+
"protected": true,
|
|
152
|
+
children: "1"
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}), one]);
|
|
158
|
+
}).toThrow(/Cannot resolve member symbols/);
|
|
159
|
+
});
|
|
160
|
+
it("cannot be referenced outside the class when private", () => {
|
|
161
|
+
const one = refkey();
|
|
162
|
+
expect(() => {
|
|
163
|
+
toSourceText([_$createComponent(ts.ClassDeclaration, {
|
|
164
|
+
name: "Foo",
|
|
165
|
+
get children() {
|
|
166
|
+
return _$createComponent(StatementList, {
|
|
167
|
+
get children() {
|
|
168
|
+
return _$createComponent(ts.ClassField, {
|
|
169
|
+
name: "one",
|
|
170
|
+
refkey: one,
|
|
171
|
+
jsPrivate: true,
|
|
172
|
+
children: "1"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}), one]);
|
|
178
|
+
}).toThrow(/Cannot resolve private member symbols/);
|
|
179
|
+
});
|
|
180
|
+
it("works with invalid identifier names", () => {
|
|
181
|
+
const one = refkey();
|
|
182
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
183
|
+
name: "Foo",
|
|
184
|
+
get children() {
|
|
185
|
+
return _$createComponent(StatementList, {
|
|
186
|
+
get children() {
|
|
187
|
+
return [_$createComponent(ts.ClassField, {
|
|
188
|
+
name: "o-n-e",
|
|
189
|
+
refkey: one,
|
|
190
|
+
children: "1"
|
|
191
|
+
}), _$createComponent(ts.ClassField, {
|
|
192
|
+
name: "t-w-o",
|
|
193
|
+
get children() {
|
|
194
|
+
return [one, " + 1"];
|
|
195
|
+
}
|
|
196
|
+
})];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}));
|
|
201
|
+
expect(res).toEqual(d`
|
|
202
|
+
class Foo {
|
|
203
|
+
"o-n-e" = 1;
|
|
204
|
+
"t-w-o" = this["o-n-e"] + 1;
|
|
205
|
+
}
|
|
206
|
+
`);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
describe("static members", () => {
|
|
210
|
+
it("renders", () => {
|
|
211
|
+
const one = refkey();
|
|
212
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
213
|
+
name: "Foo",
|
|
214
|
+
get children() {
|
|
215
|
+
return _$createComponent(StatementList, {
|
|
216
|
+
get children() {
|
|
217
|
+
return [_$createComponent(ts.ClassField, {
|
|
218
|
+
"static": true,
|
|
219
|
+
name: "one",
|
|
220
|
+
refkey: one,
|
|
221
|
+
children: "1"
|
|
222
|
+
}), _$createComponent(ts.ClassField, {
|
|
223
|
+
"static": true,
|
|
224
|
+
name: "two",
|
|
225
|
+
jsPrivate: true,
|
|
226
|
+
children: "2"
|
|
227
|
+
})];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
232
|
+
expect(res).toBe(d`
|
|
233
|
+
class Foo {
|
|
234
|
+
static one = 1;
|
|
235
|
+
static #two = 2;
|
|
236
|
+
}
|
|
237
|
+
`);
|
|
238
|
+
});
|
|
239
|
+
it("can be referenced", () => {
|
|
240
|
+
const one = refkey();
|
|
241
|
+
const two = refkey();
|
|
242
|
+
const res = toSourceText([_$createComponent(ts.ClassDeclaration, {
|
|
243
|
+
name: "Foo",
|
|
244
|
+
get children() {
|
|
245
|
+
return _$createComponent(StatementList, {
|
|
246
|
+
get children() {
|
|
247
|
+
return [_$createComponent(ts.ClassField, {
|
|
248
|
+
"static": true,
|
|
249
|
+
name: "one",
|
|
250
|
+
refkey: one,
|
|
251
|
+
children: "1"
|
|
252
|
+
}), _$createComponent(ts.ClassField, {
|
|
253
|
+
"static": true,
|
|
254
|
+
name: "two",
|
|
255
|
+
refkey: two,
|
|
256
|
+
jsPrivate: true,
|
|
257
|
+
children: "2"
|
|
258
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
259
|
+
name: "getTwo",
|
|
260
|
+
get children() {
|
|
261
|
+
return ["return ", two, ";"];
|
|
262
|
+
}
|
|
263
|
+
})];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}), _$createIntrinsic("hbr", {}), one, ";"]);
|
|
268
|
+
expect(res).toBe(d`
|
|
269
|
+
class Foo {
|
|
270
|
+
static one = 1;
|
|
271
|
+
static #two = 2;
|
|
272
|
+
getTwo() {
|
|
273
|
+
return Foo.#two;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
Foo.one;
|
|
277
|
+
`);
|
|
278
|
+
});
|
|
279
|
+
it("cannot be referenced outside the class when private", () => {
|
|
280
|
+
const two = refkey();
|
|
281
|
+
expect(() => toSourceText([_$createComponent(ts.ClassDeclaration, {
|
|
282
|
+
name: "Foo",
|
|
283
|
+
get children() {
|
|
284
|
+
return _$createComponent(StatementList, {
|
|
285
|
+
get children() {
|
|
286
|
+
return _$createComponent(ts.ClassField, {
|
|
287
|
+
"static": true,
|
|
288
|
+
name: "two",
|
|
289
|
+
refkey: two,
|
|
290
|
+
jsPrivate: true,
|
|
291
|
+
children: "2"
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}), _$createIntrinsic("hbr", {}), two, ";"])).toThrow(/Cannot resolve/);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
describe("instance methods", () => {
|
|
300
|
+
it("renders", () => {
|
|
301
|
+
const one = refkey();
|
|
302
|
+
const a = refkey();
|
|
303
|
+
const b = refkey();
|
|
304
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
305
|
+
name: "Foo",
|
|
306
|
+
get children() {
|
|
307
|
+
return _$createComponent(List, {
|
|
308
|
+
hardline: true,
|
|
309
|
+
get children() {
|
|
310
|
+
return [_$createComponent(ts.ClassMethod, {
|
|
311
|
+
name: "one",
|
|
312
|
+
refkey: one
|
|
313
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
314
|
+
name: "two",
|
|
315
|
+
"public": true
|
|
316
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
317
|
+
name: "three",
|
|
318
|
+
"private": true
|
|
319
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
320
|
+
name: "four",
|
|
321
|
+
"protected": true
|
|
322
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
323
|
+
name: "five",
|
|
324
|
+
parameters: [{
|
|
325
|
+
name: "a",
|
|
326
|
+
type: "string"
|
|
327
|
+
}, {
|
|
328
|
+
name: "b",
|
|
329
|
+
type: "string"
|
|
330
|
+
}]
|
|
331
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
332
|
+
name: "six",
|
|
333
|
+
parameters: [{
|
|
334
|
+
name: "a",
|
|
335
|
+
type: "number",
|
|
336
|
+
refkey: a
|
|
337
|
+
}, {
|
|
338
|
+
name: "b",
|
|
339
|
+
type: "number",
|
|
340
|
+
refkey: b
|
|
341
|
+
}],
|
|
342
|
+
returnType: "number",
|
|
343
|
+
get children() {
|
|
344
|
+
return [one, " = ", a, " + ", b, ";"];
|
|
345
|
+
}
|
|
346
|
+
}), _$createComponent(ts.ClassMethod, {
|
|
347
|
+
name: "seven",
|
|
348
|
+
jsPrivate: true
|
|
349
|
+
})];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}));
|
|
354
|
+
expect(res).toEqual(d`
|
|
355
|
+
class Foo {
|
|
356
|
+
one() {}
|
|
357
|
+
public two() {}
|
|
358
|
+
private three() {}
|
|
359
|
+
protected four() {}
|
|
360
|
+
five(a: string, b: string) {}
|
|
361
|
+
six(a: number, b: number): number {
|
|
362
|
+
this.one = a + b;
|
|
363
|
+
}
|
|
364
|
+
#seven() {}
|
|
365
|
+
}
|
|
366
|
+
`);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
it("renders a class with docs for the class and its members", () => {
|
|
370
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
371
|
+
name: "Foo",
|
|
372
|
+
doc: "This is a class documentation",
|
|
373
|
+
get children() {
|
|
374
|
+
return [_$createComponent(ts.ClassField, {
|
|
375
|
+
name: "bar",
|
|
376
|
+
doc: "This is a field documentation",
|
|
377
|
+
children: "123"
|
|
378
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.ClassMethod, {
|
|
379
|
+
name: "baz",
|
|
380
|
+
doc: "This is a method documentation",
|
|
381
|
+
children: "return 123;"
|
|
382
|
+
})];
|
|
383
|
+
}
|
|
384
|
+
}));
|
|
385
|
+
expect(res).toEqual(d`
|
|
386
|
+
/**
|
|
387
|
+
* This is a class documentation
|
|
388
|
+
**/
|
|
389
|
+
class Foo {
|
|
390
|
+
/**
|
|
391
|
+
* This is a field documentation
|
|
392
|
+
**/
|
|
393
|
+
bar = 123;
|
|
394
|
+
/**
|
|
395
|
+
* This is a method documentation
|
|
396
|
+
**/
|
|
397
|
+
baz() {
|
|
398
|
+
return 123;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
`);
|
|
402
|
+
});
|
|
403
|
+
it("renders a method with parameter docs", () => {
|
|
404
|
+
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
405
|
+
name: "Foo",
|
|
406
|
+
get children() {
|
|
407
|
+
return _$createComponent(ts.ClassMethod, {
|
|
408
|
+
name: "bar",
|
|
409
|
+
doc: "Method documentation",
|
|
410
|
+
returnType: "void",
|
|
411
|
+
parameters: [{
|
|
412
|
+
name: "a",
|
|
413
|
+
type: "number",
|
|
414
|
+
doc: "Parameter a doc"
|
|
415
|
+
}, {
|
|
416
|
+
name: "b",
|
|
417
|
+
type: "string",
|
|
418
|
+
doc: "Line 1 for b. This is a long description that should continue in the next line."
|
|
419
|
+
}]
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}), {
|
|
423
|
+
printWidth: 40
|
|
424
|
+
});
|
|
425
|
+
expect(res).toEqual(d`
|
|
426
|
+
class Foo {
|
|
427
|
+
/**
|
|
428
|
+
* Method documentation
|
|
429
|
+
*
|
|
430
|
+
* @param {number} a - Parameter a doc
|
|
431
|
+
* @param {string} b - Line 1 for b.
|
|
432
|
+
* This is a long description that
|
|
433
|
+
* should continue in the next line.
|
|
434
|
+
**/
|
|
435
|
+
bar(a: number, b: string): void {}
|
|
436
|
+
}
|
|
437
|
+
`);
|
|
438
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
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
|
+
it("renders an enum declaration with documentation", () => {
|
|
7
|
+
const res = toSourceText(_$createComponent(ts.EnumDeclaration, {
|
|
8
|
+
name: "Color",
|
|
9
|
+
doc: "Color enumeration for the application",
|
|
10
|
+
get children() {
|
|
11
|
+
return _$createComponent(ts.CommaList, {
|
|
12
|
+
get children() {
|
|
13
|
+
return [_$createComponent(ts.EnumMember, {
|
|
14
|
+
name: "Red"
|
|
15
|
+
}), _$createComponent(ts.EnumMember, {
|
|
16
|
+
name: "Green"
|
|
17
|
+
}), _$createComponent(ts.EnumMember, {
|
|
18
|
+
name: "Blue"
|
|
19
|
+
})];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
expect(res).toEqual(d`
|
|
25
|
+
/**
|
|
26
|
+
* Color enumeration for the application
|
|
27
|
+
**/
|
|
28
|
+
enum Color {
|
|
29
|
+
Red,
|
|
30
|
+
Green,
|
|
31
|
+
Blue,
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
it("renders an enum declaration with documented members", () => {
|
|
36
|
+
const res = toSourceText(_$createComponent(ts.EnumDeclaration, {
|
|
37
|
+
name: "Direction",
|
|
38
|
+
doc: "Represents cardinal directions. Used for navigation purposes",
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(ts.CommaList, {
|
|
41
|
+
get children() {
|
|
42
|
+
return [_$createComponent(ts.EnumMember, {
|
|
43
|
+
name: "North",
|
|
44
|
+
jsValue: 0,
|
|
45
|
+
doc: ["Bound to the north"]
|
|
46
|
+
}), _$createComponent(ts.EnumMember, {
|
|
47
|
+
name: "East",
|
|
48
|
+
jsValue: 1,
|
|
49
|
+
doc: ["Bound to the East", "A second doc paragraph"]
|
|
50
|
+
}), _$createComponent(ts.EnumMember, {
|
|
51
|
+
name: "South",
|
|
52
|
+
jsValue: 2,
|
|
53
|
+
doc: "Opposite to North"
|
|
54
|
+
}), _$createComponent(ts.EnumMember, {
|
|
55
|
+
name: "West",
|
|
56
|
+
jsValue: 3,
|
|
57
|
+
doc: "Going west!"
|
|
58
|
+
})];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
expect(res).toEqual(d`
|
|
64
|
+
/**
|
|
65
|
+
* Represents cardinal directions. Used for navigation purposes
|
|
66
|
+
**/
|
|
67
|
+
enum Direction {
|
|
68
|
+
/**
|
|
69
|
+
* Bound to the north
|
|
70
|
+
**/
|
|
71
|
+
North = 0,
|
|
72
|
+
/**
|
|
73
|
+
* Bound to the East
|
|
74
|
+
*
|
|
75
|
+
* A second doc paragraph
|
|
76
|
+
**/
|
|
77
|
+
East = 1,
|
|
78
|
+
/**
|
|
79
|
+
* Opposite to North
|
|
80
|
+
**/
|
|
81
|
+
South = 2,
|
|
82
|
+
/**
|
|
83
|
+
* Going west!
|
|
84
|
+
**/
|
|
85
|
+
West = 3,
|
|
86
|
+
}
|
|
87
|
+
`);
|
|
88
|
+
});
|