@alloy-js/typescript 0.11.0 → 0.13.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 +17 -0
- package/dist/src/components/ClassDeclaration.d.ts +2 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +14 -2
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +13 -3
- package/dist/src/components/FunctionType.d.ts +7 -8
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +29 -25
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +9 -2
- package/dist/src/components/Interface.d.ts +3 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +8 -4
- package/dist/src/components/JSDocComment.js +1 -1
- package/dist/src/components/MemberDeclaration.d.ts +4 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +1 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +3 -2
- package/dist/src/components/Reference.d.ts +8 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +7 -2
- 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 +3 -2
- package/dist/src/components/TypeRefContext.d.ts +22 -0
- package/dist/src/components/TypeRefContext.d.ts.map +1 -0
- package/dist/src/components/TypeRefContext.js +41 -0
- package/dist/src/components/VarDeclaration.d.ts +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +9 -3
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/stc/index.d.ts +1 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -0
- package/dist/src/context/type-ref-context.d.ts +15 -0
- package/dist/src/context/type-ref-context.d.ts.map +1 -0
- package/dist/src/context/type-ref-context.js +12 -0
- package/dist/src/parameter-descriptor.d.ts +6 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/symbols/reference.d.ts +4 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +11 -5
- package/dist/src/symbols/ts-module-scope.d.ts +4 -1
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +10 -3
- 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 +1 -0
- package/dist/test/class.test.js +108 -5
- package/dist/test/enum-jsdoc.test.js +6 -6
- package/dist/test/function-declaration-jsdoc.test.js +3 -3
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +293 -2
- package/dist/test/interface-jsdoc.test.js +9 -9
- package/dist/test/jsdoc.test.js +5 -5
- package/dist/test/jsdocparam.test.js +8 -8
- package/dist/test/member-expression.test.js +218 -2
- package/dist/test/var-declaration-jsdoc.test.js +3 -3
- package/dist/test/var-declaration.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/ClassDeclaration.tsx +19 -3
- package/src/components/FunctionBase.tsx +14 -3
- package/src/components/FunctionType.tsx +45 -40
- package/src/components/ImportStatement.tsx +30 -3
- package/src/components/Interface.tsx +41 -34
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +7 -1
- package/src/components/MemberExpression.tsx +7 -2
- package/src/components/Reference.tsx +12 -2
- package/src/components/TypeDeclaration.tsx +16 -13
- package/src/components/TypeRefContext.tsx +49 -0
- package/src/components/VarDeclaration.tsx +6 -2
- package/src/components/index.ts +1 -0
- package/src/components/stc/index.ts +1 -0
- package/src/context/type-ref-context.tsx +19 -0
- package/src/parameter-descriptor.ts +7 -0
- package/src/symbols/reference.ts +17 -5
- package/src/symbols/ts-module-scope.ts +19 -4
- package/src/symbols/ts-output-symbol.ts +1 -0
- package/temp/api.json +613 -220
- package/test/class.test.tsx +75 -5
- package/test/enum-jsdoc.test.tsx +6 -6
- package/test/function-declaration-jsdoc.test.tsx +3 -3
- package/test/imports.test.tsx +215 -1
- package/test/interface-jsdoc.test.tsx +9 -9
- package/test/jsdoc.test.tsx +5 -5
- package/test/jsdocparam.test.tsx +8 -8
- package/test/member-expression.test.tsx +171 -2
- package/test/var-declaration-jsdoc.test.tsx +3 -3
- package/test/var-declaration.test.tsx +1 -1
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { refkey, StatementList } from "@alloy-js/core";
|
|
1
|
+
import { code, List, refkey, StatementList } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { MemberExpression } from "../src/components/MemberExpression.jsx";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
InterfaceMember,
|
|
7
|
+
ObjectExpression,
|
|
8
|
+
} from "../src/components/stc/index.js";
|
|
6
9
|
import { VarDeclaration } from "../src/components/VarDeclaration.jsx";
|
|
10
|
+
import {
|
|
11
|
+
ClassDeclaration,
|
|
12
|
+
ClassField,
|
|
13
|
+
FunctionDeclaration,
|
|
14
|
+
InterfaceDeclaration,
|
|
15
|
+
ParameterDescriptor,
|
|
16
|
+
} from "../src/index.js";
|
|
7
17
|
import { toSourceText } from "./utils.js";
|
|
8
18
|
|
|
9
19
|
it("renders basic member expression with dot notation", () => {
|
|
@@ -143,6 +153,165 @@ describe("with refkeys", () => {
|
|
|
143
153
|
`);
|
|
144
154
|
});
|
|
145
155
|
|
|
156
|
+
it("handles nullish symbols correctly", () => {
|
|
157
|
+
// Note that this is deliberately producing invalid references (it's just easiest to test with VarDeclaration).
|
|
158
|
+
const rk1 = refkey();
|
|
159
|
+
const rk2 = refkey();
|
|
160
|
+
expect(
|
|
161
|
+
toSourceText(
|
|
162
|
+
<StatementList>
|
|
163
|
+
<VarDeclaration name="test1" refkey={rk1} initializer={1} nullish />
|
|
164
|
+
<VarDeclaration name="test1" refkey={rk2} initializer={2} nullish />
|
|
165
|
+
<MemberExpression>
|
|
166
|
+
<MemberExpression.Part refkey={rk1} />
|
|
167
|
+
<MemberExpression.Part refkey={rk2} />
|
|
168
|
+
</MemberExpression>
|
|
169
|
+
</StatementList>,
|
|
170
|
+
),
|
|
171
|
+
).toBe(d`
|
|
172
|
+
const test1 = 1;
|
|
173
|
+
const test1_2 = 2;
|
|
174
|
+
test1?.test1_2;
|
|
175
|
+
`);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("handles optional parameters correctly", () => {
|
|
179
|
+
const fooRef = refkey();
|
|
180
|
+
const modelRef = refkey();
|
|
181
|
+
const parameters: ParameterDescriptor[] = [
|
|
182
|
+
{ name: "foo", optional: true, refkey: fooRef, type: modelRef },
|
|
183
|
+
];
|
|
184
|
+
const messageRef = refkey();
|
|
185
|
+
const template = (
|
|
186
|
+
<List hardline>
|
|
187
|
+
<InterfaceDeclaration name="Model" refkey={modelRef}>
|
|
188
|
+
<InterfaceMember name="bar" refkey={refkey()} type="string" />
|
|
189
|
+
</InterfaceDeclaration>
|
|
190
|
+
<FunctionDeclaration name="fooFunction" parameters={parameters}>
|
|
191
|
+
<StatementList>
|
|
192
|
+
<VarDeclaration
|
|
193
|
+
name="message"
|
|
194
|
+
const
|
|
195
|
+
refkey={messageRef}
|
|
196
|
+
initializer={
|
|
197
|
+
<MemberExpression>
|
|
198
|
+
<MemberExpression.Part refkey={fooRef} />
|
|
199
|
+
<MemberExpression.Part id="bar" />
|
|
200
|
+
</MemberExpression>
|
|
201
|
+
}
|
|
202
|
+
/>
|
|
203
|
+
<>console.log({messageRef})</>
|
|
204
|
+
</StatementList>
|
|
205
|
+
</FunctionDeclaration>
|
|
206
|
+
</List>
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
expect(toSourceText(template)).toBe(d`
|
|
210
|
+
interface Model {
|
|
211
|
+
bar: string
|
|
212
|
+
}
|
|
213
|
+
function fooFunction(foo?: Model) {
|
|
214
|
+
const message = foo?.bar;
|
|
215
|
+
console.log(message);
|
|
216
|
+
}
|
|
217
|
+
`);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("handles nullish parameters correctly", () => {
|
|
221
|
+
const fooRef = refkey();
|
|
222
|
+
const modelRef = refkey();
|
|
223
|
+
const parameters: ParameterDescriptor[] = [
|
|
224
|
+
{
|
|
225
|
+
name: "foo",
|
|
226
|
+
nullish: true,
|
|
227
|
+
refkey: fooRef,
|
|
228
|
+
type: <>{modelRef} | null</>,
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
const messageRef = refkey();
|
|
232
|
+
const template = (
|
|
233
|
+
<List hardline>
|
|
234
|
+
<InterfaceDeclaration name="Model" refkey={modelRef}>
|
|
235
|
+
<InterfaceMember name="bar" refkey={refkey()} type="string" />
|
|
236
|
+
</InterfaceDeclaration>
|
|
237
|
+
<FunctionDeclaration name="fooFunction" parameters={parameters}>
|
|
238
|
+
<StatementList>
|
|
239
|
+
<VarDeclaration
|
|
240
|
+
name="message"
|
|
241
|
+
const
|
|
242
|
+
refkey={messageRef}
|
|
243
|
+
initializer={
|
|
244
|
+
<MemberExpression>
|
|
245
|
+
<MemberExpression.Part refkey={fooRef} />
|
|
246
|
+
<MemberExpression.Part id="bar" />
|
|
247
|
+
</MemberExpression>
|
|
248
|
+
}
|
|
249
|
+
/>
|
|
250
|
+
<>console.log({messageRef})</>
|
|
251
|
+
</StatementList>
|
|
252
|
+
</FunctionDeclaration>
|
|
253
|
+
</List>
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
expect(toSourceText(template)).toBe(d`
|
|
257
|
+
interface Model {
|
|
258
|
+
bar: string
|
|
259
|
+
}
|
|
260
|
+
function fooFunction(foo: Model | null) {
|
|
261
|
+
const message = foo?.bar;
|
|
262
|
+
console.log(message);
|
|
263
|
+
}
|
|
264
|
+
`);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("handles nullish class member correctly", () => {
|
|
268
|
+
const classRefkey = refkey();
|
|
269
|
+
const interfaceRefkey = refkey();
|
|
270
|
+
const interfaceMemberRefkey = refkey();
|
|
271
|
+
const classMemberRefkey = refkey();
|
|
272
|
+
const instanceRefkey = refkey();
|
|
273
|
+
expect(
|
|
274
|
+
toSourceText(
|
|
275
|
+
<List hardline>
|
|
276
|
+
<InterfaceDeclaration name="Bar" refkey={interfaceRefkey}>
|
|
277
|
+
<InterfaceMember
|
|
278
|
+
name="prop1"
|
|
279
|
+
refkey={interfaceMemberRefkey}
|
|
280
|
+
type={"string"}
|
|
281
|
+
/>
|
|
282
|
+
</InterfaceDeclaration>
|
|
283
|
+
<ClassDeclaration name="Foo" refkey={classRefkey}>
|
|
284
|
+
<ClassField
|
|
285
|
+
name="test1"
|
|
286
|
+
refkey={classMemberRefkey}
|
|
287
|
+
nullish
|
|
288
|
+
type={interfaceRefkey}
|
|
289
|
+
/>
|
|
290
|
+
</ClassDeclaration>
|
|
291
|
+
<VarDeclaration
|
|
292
|
+
name="inst"
|
|
293
|
+
refkey={instanceRefkey}
|
|
294
|
+
initializer={code`new ${classRefkey}();`}
|
|
295
|
+
/>
|
|
296
|
+
<MemberExpression>
|
|
297
|
+
<MemberExpression.Part refkey={instanceRefkey} />
|
|
298
|
+
<MemberExpression.Part refkey={classMemberRefkey} />
|
|
299
|
+
<MemberExpression.Part refkey={interfaceMemberRefkey} />
|
|
300
|
+
</MemberExpression>
|
|
301
|
+
</List>,
|
|
302
|
+
),
|
|
303
|
+
).toBe(d`
|
|
304
|
+
interface Bar {
|
|
305
|
+
prop1: string
|
|
306
|
+
}
|
|
307
|
+
class Foo {
|
|
308
|
+
test1: Bar
|
|
309
|
+
}
|
|
310
|
+
const inst = new Foo();
|
|
311
|
+
inst.test1?.prop1
|
|
312
|
+
`);
|
|
313
|
+
});
|
|
314
|
+
|
|
146
315
|
it("handles late resolved refkeys correctly", () => {
|
|
147
316
|
const rk1 = refkey();
|
|
148
317
|
const rk2 = refkey();
|
|
@@ -19,7 +19,7 @@ it("renders a variable declaration with documentation", () => {
|
|
|
19
19
|
expect(res).toEqual(d`
|
|
20
20
|
/**
|
|
21
21
|
* This is a variable documentation
|
|
22
|
-
|
|
22
|
+
*/
|
|
23
23
|
const myVar = 123;
|
|
24
24
|
`);
|
|
25
25
|
});
|
|
@@ -41,7 +41,7 @@ it("renders a let declaration with documentation", () => {
|
|
|
41
41
|
expect(res).toEqual(d`
|
|
42
42
|
/**
|
|
43
43
|
* A counter variable that can be changed
|
|
44
|
-
|
|
44
|
+
*/
|
|
45
45
|
let counter: number = 0;
|
|
46
46
|
`);
|
|
47
47
|
});
|
|
@@ -64,7 +64,7 @@ it("renders an exported variable declaration with documentation", () => {
|
|
|
64
64
|
expect(res).toEqual(d`
|
|
65
65
|
/**
|
|
66
66
|
* The base URL for API calls
|
|
67
|
-
|
|
67
|
+
*/
|
|
68
68
|
export const API_URL: string = "https://api.example.com";
|
|
69
69
|
`);
|
|
70
70
|
});
|