@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,10 +1,11 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey, StatementList } from "@alloy-js/core";
|
|
2
|
+
import { code, List, refkey, StatementList } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { MemberExpression } from "../src/components/MemberExpression.js";
|
|
6
|
-
import { ObjectExpression } from "../src/components/stc/index.js";
|
|
6
|
+
import { InterfaceMember, ObjectExpression } from "../src/components/stc/index.js";
|
|
7
7
|
import { VarDeclaration } from "../src/components/VarDeclaration.js";
|
|
8
|
+
import { ClassDeclaration, ClassField, FunctionDeclaration, InterfaceDeclaration } from "../src/index.js";
|
|
8
9
|
import { toSourceText } from "./utils.js";
|
|
9
10
|
it("renders basic member expression with dot notation", () => {
|
|
10
11
|
expect(toSourceText(_$createComponent(MemberExpression, {
|
|
@@ -165,6 +166,221 @@ describe("with refkeys", () => {
|
|
|
165
166
|
test1.test1_2;
|
|
166
167
|
`);
|
|
167
168
|
});
|
|
169
|
+
it("handles nullish symbols correctly", () => {
|
|
170
|
+
// Note that this is deliberately producing invalid references (it's just easiest to test with VarDeclaration).
|
|
171
|
+
const rk1 = refkey();
|
|
172
|
+
const rk2 = refkey();
|
|
173
|
+
expect(toSourceText(_$createComponent(StatementList, {
|
|
174
|
+
get children() {
|
|
175
|
+
return [_$createComponent(VarDeclaration, {
|
|
176
|
+
name: "test1",
|
|
177
|
+
refkey: rk1,
|
|
178
|
+
initializer: 1,
|
|
179
|
+
nullish: true
|
|
180
|
+
}), _$createComponent(VarDeclaration, {
|
|
181
|
+
name: "test1",
|
|
182
|
+
refkey: rk2,
|
|
183
|
+
initializer: 2,
|
|
184
|
+
nullish: true
|
|
185
|
+
}), _$createComponent(MemberExpression, {
|
|
186
|
+
get children() {
|
|
187
|
+
return [_$createComponent(MemberExpression.Part, {
|
|
188
|
+
refkey: rk1
|
|
189
|
+
}), _$createComponent(MemberExpression.Part, {
|
|
190
|
+
refkey: rk2
|
|
191
|
+
})];
|
|
192
|
+
}
|
|
193
|
+
})];
|
|
194
|
+
}
|
|
195
|
+
}))).toBe(d`
|
|
196
|
+
const test1 = 1;
|
|
197
|
+
const test1_2 = 2;
|
|
198
|
+
test1?.test1_2;
|
|
199
|
+
`);
|
|
200
|
+
});
|
|
201
|
+
it("handles optional parameters correctly", () => {
|
|
202
|
+
const fooRef = refkey();
|
|
203
|
+
const modelRef = refkey();
|
|
204
|
+
const parameters = [{
|
|
205
|
+
name: "foo",
|
|
206
|
+
optional: true,
|
|
207
|
+
refkey: fooRef,
|
|
208
|
+
type: modelRef
|
|
209
|
+
}];
|
|
210
|
+
const messageRef = refkey();
|
|
211
|
+
const template = _$createComponent(List, {
|
|
212
|
+
hardline: true,
|
|
213
|
+
get children() {
|
|
214
|
+
return [_$createComponent(InterfaceDeclaration, {
|
|
215
|
+
name: "Model",
|
|
216
|
+
refkey: modelRef,
|
|
217
|
+
get children() {
|
|
218
|
+
return _$createComponent(InterfaceMember, {
|
|
219
|
+
name: "bar",
|
|
220
|
+
get refkey() {
|
|
221
|
+
return refkey();
|
|
222
|
+
},
|
|
223
|
+
type: "string"
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}), _$createComponent(FunctionDeclaration, {
|
|
227
|
+
name: "fooFunction",
|
|
228
|
+
parameters: parameters,
|
|
229
|
+
get children() {
|
|
230
|
+
return _$createComponent(StatementList, {
|
|
231
|
+
get children() {
|
|
232
|
+
return [_$createComponent(VarDeclaration, {
|
|
233
|
+
name: "message",
|
|
234
|
+
"const": true,
|
|
235
|
+
refkey: messageRef,
|
|
236
|
+
get initializer() {
|
|
237
|
+
return _$createComponent(MemberExpression, {
|
|
238
|
+
get children() {
|
|
239
|
+
return [_$createComponent(MemberExpression.Part, {
|
|
240
|
+
refkey: fooRef
|
|
241
|
+
}), _$createComponent(MemberExpression.Part, {
|
|
242
|
+
id: "bar"
|
|
243
|
+
})];
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}), ["console.log(", messageRef, ")"]];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
})];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
expect(toSourceText(template)).toBe(d`
|
|
255
|
+
interface Model {
|
|
256
|
+
bar: string
|
|
257
|
+
}
|
|
258
|
+
function fooFunction(foo?: Model) {
|
|
259
|
+
const message = foo?.bar;
|
|
260
|
+
console.log(message);
|
|
261
|
+
}
|
|
262
|
+
`);
|
|
263
|
+
});
|
|
264
|
+
it("handles nullish parameters correctly", () => {
|
|
265
|
+
const fooRef = refkey();
|
|
266
|
+
const modelRef = refkey();
|
|
267
|
+
const parameters = [{
|
|
268
|
+
name: "foo",
|
|
269
|
+
nullish: true,
|
|
270
|
+
refkey: fooRef,
|
|
271
|
+
type: [modelRef, " | null"]
|
|
272
|
+
}];
|
|
273
|
+
const messageRef = refkey();
|
|
274
|
+
const template = _$createComponent(List, {
|
|
275
|
+
hardline: true,
|
|
276
|
+
get children() {
|
|
277
|
+
return [_$createComponent(InterfaceDeclaration, {
|
|
278
|
+
name: "Model",
|
|
279
|
+
refkey: modelRef,
|
|
280
|
+
get children() {
|
|
281
|
+
return _$createComponent(InterfaceMember, {
|
|
282
|
+
name: "bar",
|
|
283
|
+
get refkey() {
|
|
284
|
+
return refkey();
|
|
285
|
+
},
|
|
286
|
+
type: "string"
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}), _$createComponent(FunctionDeclaration, {
|
|
290
|
+
name: "fooFunction",
|
|
291
|
+
parameters: parameters,
|
|
292
|
+
get children() {
|
|
293
|
+
return _$createComponent(StatementList, {
|
|
294
|
+
get children() {
|
|
295
|
+
return [_$createComponent(VarDeclaration, {
|
|
296
|
+
name: "message",
|
|
297
|
+
"const": true,
|
|
298
|
+
refkey: messageRef,
|
|
299
|
+
get initializer() {
|
|
300
|
+
return _$createComponent(MemberExpression, {
|
|
301
|
+
get children() {
|
|
302
|
+
return [_$createComponent(MemberExpression.Part, {
|
|
303
|
+
refkey: fooRef
|
|
304
|
+
}), _$createComponent(MemberExpression.Part, {
|
|
305
|
+
id: "bar"
|
|
306
|
+
})];
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}), ["console.log(", messageRef, ")"]];
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
})];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
expect(toSourceText(template)).toBe(d`
|
|
318
|
+
interface Model {
|
|
319
|
+
bar: string
|
|
320
|
+
}
|
|
321
|
+
function fooFunction(foo: Model | null) {
|
|
322
|
+
const message = foo?.bar;
|
|
323
|
+
console.log(message);
|
|
324
|
+
}
|
|
325
|
+
`);
|
|
326
|
+
});
|
|
327
|
+
it("handles nullish class member correctly", () => {
|
|
328
|
+
const classRefkey = refkey();
|
|
329
|
+
const interfaceRefkey = refkey();
|
|
330
|
+
const interfaceMemberRefkey = refkey();
|
|
331
|
+
const classMemberRefkey = refkey();
|
|
332
|
+
const instanceRefkey = refkey();
|
|
333
|
+
expect(toSourceText(_$createComponent(List, {
|
|
334
|
+
hardline: true,
|
|
335
|
+
get children() {
|
|
336
|
+
return [_$createComponent(InterfaceDeclaration, {
|
|
337
|
+
name: "Bar",
|
|
338
|
+
refkey: interfaceRefkey,
|
|
339
|
+
get children() {
|
|
340
|
+
return _$createComponent(InterfaceMember, {
|
|
341
|
+
name: "prop1",
|
|
342
|
+
refkey: interfaceMemberRefkey,
|
|
343
|
+
type: "string"
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}), _$createComponent(ClassDeclaration, {
|
|
347
|
+
name: "Foo",
|
|
348
|
+
refkey: classRefkey,
|
|
349
|
+
get children() {
|
|
350
|
+
return _$createComponent(ClassField, {
|
|
351
|
+
name: "test1",
|
|
352
|
+
refkey: classMemberRefkey,
|
|
353
|
+
nullish: true,
|
|
354
|
+
type: interfaceRefkey
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}), _$createComponent(VarDeclaration, {
|
|
358
|
+
name: "inst",
|
|
359
|
+
refkey: instanceRefkey,
|
|
360
|
+
initializer: code`new ${classRefkey}();`
|
|
361
|
+
}), _$createComponent(MemberExpression, {
|
|
362
|
+
get children() {
|
|
363
|
+
return [_$createComponent(MemberExpression.Part, {
|
|
364
|
+
refkey: instanceRefkey
|
|
365
|
+
}), _$createComponent(MemberExpression.Part, {
|
|
366
|
+
refkey: classMemberRefkey
|
|
367
|
+
}), _$createComponent(MemberExpression.Part, {
|
|
368
|
+
refkey: interfaceMemberRefkey
|
|
369
|
+
})];
|
|
370
|
+
}
|
|
371
|
+
})];
|
|
372
|
+
}
|
|
373
|
+
}))).toBe(d`
|
|
374
|
+
interface Bar {
|
|
375
|
+
prop1: string
|
|
376
|
+
}
|
|
377
|
+
class Foo {
|
|
378
|
+
test1: Bar
|
|
379
|
+
}
|
|
380
|
+
const inst = new Foo();
|
|
381
|
+
inst.test1?.prop1
|
|
382
|
+
`);
|
|
383
|
+
});
|
|
168
384
|
it("handles late resolved refkeys correctly", () => {
|
|
169
385
|
const rk1 = refkey();
|
|
170
386
|
const rk2 = refkey();
|
|
@@ -13,7 +13,7 @@ it("renders a variable declaration with documentation", () => {
|
|
|
13
13
|
expect(res).toEqual(d`
|
|
14
14
|
/**
|
|
15
15
|
* This is a variable documentation
|
|
16
|
-
|
|
16
|
+
*/
|
|
17
17
|
const myVar = 123;
|
|
18
18
|
`);
|
|
19
19
|
});
|
|
@@ -28,7 +28,7 @@ it("renders a let declaration with documentation", () => {
|
|
|
28
28
|
expect(res).toEqual(d`
|
|
29
29
|
/**
|
|
30
30
|
* A counter variable that can be changed
|
|
31
|
-
|
|
31
|
+
*/
|
|
32
32
|
let counter: number = 0;
|
|
33
33
|
`);
|
|
34
34
|
});
|
|
@@ -44,7 +44,7 @@ it("renders an exported variable declaration with documentation", () => {
|
|
|
44
44
|
expect(res).toEqual(d`
|
|
45
45
|
/**
|
|
46
46
|
* The base URL for API calls
|
|
47
|
-
|
|
47
|
+
*/
|
|
48
48
|
export const API_URL: string = "https://api.example.com";
|
|
49
49
|
`);
|
|
50
50
|
});
|