@alloy-js/typescript 0.10.0 → 0.12.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/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.d.ts +2 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +16 -8
- 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 +217 -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 +38 -0
- package/dist/src/components/FunctionType.d.ts.map +1 -0
- package/dist/src/components/FunctionType.js +77 -0
- package/dist/src/components/IfStatement.js +2 -4
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +10 -4
- 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 +40 -15
- 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 +3 -5
- 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 +34 -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.map +1 -1
- package/dist/src/components/MemberExpression.js +5 -7
- 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.d.ts +8 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +8 -4
- 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.d.ts +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js +4 -7
- 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/ValueExpression.js +1 -2
- 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 +11 -8
- 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/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/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 +33 -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.d.ts +4 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +13 -8
- 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.d.ts +4 -1
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +11 -5
- 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 +2 -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.d.ts.map +1 -1
- package/dist/test/imports.test.js +640 -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 +575 -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 +13 -18
- package/src/components/ArrowFunction.tsx +87 -0
- package/src/components/ClassDeclaration.tsx +19 -3
- package/src/components/Declaration.tsx +1 -1
- package/src/components/FunctionBase.tsx +282 -0
- package/src/components/FunctionDeclaration.tsx +13 -195
- package/src/components/FunctionExpression.tsx +86 -0
- package/src/components/FunctionType.tsx +93 -0
- package/src/components/ImportStatement.tsx +30 -3
- package/src/components/Interface.tsx +58 -23
- package/src/components/InterfaceMethod.tsx +96 -0
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +76 -0
- 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 +11 -0
- package/src/components/stc/index.ts +8 -0
- package/src/context/type-ref-context.tsx +19 -0
- package/src/parameter-descriptor.ts +35 -17
- package/src/symbols/reference.ts +21 -6
- package/src/symbols/ts-module-scope.ts +19 -4
- package/src/symbols/ts-output-symbol.ts +1 -0
- package/temp/api.json +4999 -2681
- package/test/arrow-function.test.tsx +188 -0
- package/test/class.test.tsx +5 -6
- package/test/enum-jsdoc.test.tsx +6 -6
- package/test/function-call-expression.test.tsx +1 -2
- package/test/function-declaration-jsdoc.test.tsx +3 -3
- 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/imports.test.tsx +165 -1
- package/test/interface-jsdoc.test.tsx +9 -9
- package/test/interface.test.tsx +256 -6
- 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
- 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
package/test/imports.test.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
List,
|
|
2
3
|
Output,
|
|
3
4
|
SourceDirectory,
|
|
4
5
|
StatementList,
|
|
@@ -6,9 +7,10 @@ import {
|
|
|
6
7
|
render,
|
|
7
8
|
} from "@alloy-js/core";
|
|
8
9
|
import "@alloy-js/core/testing";
|
|
9
|
-
import { it } from "vitest";
|
|
10
|
+
import { describe, it } from "vitest";
|
|
10
11
|
import * as ts from "../src/components/index.js";
|
|
11
12
|
import { Reference } from "../src/components/Reference.js";
|
|
13
|
+
import { TypeRefContext } from "../src/context/type-ref-context.js";
|
|
12
14
|
import { tsNameConflictResolver } from "../src/name-conflict-resolver.js";
|
|
13
15
|
import { assertFileContents } from "./utils.js";
|
|
14
16
|
|
|
@@ -308,3 +310,165 @@ it("handles conflicts with local declarations", () => {
|
|
|
308
310
|
`,
|
|
309
311
|
});
|
|
310
312
|
});
|
|
313
|
+
|
|
314
|
+
describe("type imports", () => {
|
|
315
|
+
function mkTestFile(name: string) {
|
|
316
|
+
const TypeA = refkey("TypeA");
|
|
317
|
+
const TypeB = refkey("TypeB");
|
|
318
|
+
const ClassA = refkey("ClassA");
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
component: (
|
|
322
|
+
<ts.SourceFile path="test1.ts">
|
|
323
|
+
<ts.InterfaceDeclaration export name="TypeA" refkey={TypeA} />
|
|
324
|
+
<ts.InterfaceDeclaration export name="TypeB" refkey={TypeB} />
|
|
325
|
+
<ts.ClassDeclaration export name="ClassA" refkey={ClassA} />
|
|
326
|
+
</ts.SourceFile>
|
|
327
|
+
),
|
|
328
|
+
TypeA,
|
|
329
|
+
TypeB,
|
|
330
|
+
ClassA,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
it("adds type keyword only to type imports", () => {
|
|
335
|
+
const { component, TypeA, ClassA } = mkTestFile("test1.ts");
|
|
336
|
+
const res = render(
|
|
337
|
+
<Output>
|
|
338
|
+
{component}
|
|
339
|
+
<ts.SourceFile path="test2.ts">
|
|
340
|
+
<List>
|
|
341
|
+
<>
|
|
342
|
+
type A = <Reference refkey={TypeA} type />
|
|
343
|
+
</>
|
|
344
|
+
<>
|
|
345
|
+
class B extends <Reference refkey={ClassA} /> {"{}"}
|
|
346
|
+
</>
|
|
347
|
+
</List>
|
|
348
|
+
</ts.SourceFile>
|
|
349
|
+
</Output>,
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
assertFileContents(res, {
|
|
353
|
+
"test2.ts": `
|
|
354
|
+
import { type TypeA, ClassA } from "./test1.js";
|
|
355
|
+
|
|
356
|
+
type A = TypeA
|
|
357
|
+
class B extends ClassA {}
|
|
358
|
+
`,
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("add type keyword for whole import if all are types", () => {
|
|
363
|
+
const { component, TypeA, TypeB } = mkTestFile("test1.ts");
|
|
364
|
+
const res = render(
|
|
365
|
+
<Output>
|
|
366
|
+
{component}
|
|
367
|
+
<ts.SourceFile path="test2.ts">
|
|
368
|
+
<List>
|
|
369
|
+
<>
|
|
370
|
+
type A = <Reference refkey={TypeA} type />
|
|
371
|
+
</>
|
|
372
|
+
<>
|
|
373
|
+
type B = <Reference refkey={TypeB} type />
|
|
374
|
+
</>
|
|
375
|
+
</List>
|
|
376
|
+
</ts.SourceFile>
|
|
377
|
+
</Output>,
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
assertFileContents(res, {
|
|
381
|
+
"test2.ts": `
|
|
382
|
+
import type { TypeA, TypeB } from "./test1.js";
|
|
383
|
+
|
|
384
|
+
type A = TypeA
|
|
385
|
+
type B = TypeB
|
|
386
|
+
`,
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
it("reference same type multiple times", () => {
|
|
390
|
+
const { component, TypeA } = mkTestFile("test1.ts");
|
|
391
|
+
const res = render(
|
|
392
|
+
<Output>
|
|
393
|
+
{component}
|
|
394
|
+
<ts.SourceFile path="test2.ts">
|
|
395
|
+
<List>
|
|
396
|
+
<>
|
|
397
|
+
type A = <Reference refkey={TypeA} type />
|
|
398
|
+
</>
|
|
399
|
+
<>
|
|
400
|
+
type B = <Reference refkey={TypeA} type />
|
|
401
|
+
</>
|
|
402
|
+
</List>
|
|
403
|
+
</ts.SourceFile>
|
|
404
|
+
</Output>,
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
assertFileContents(res, {
|
|
408
|
+
"test2.ts": `
|
|
409
|
+
import type { TypeA } from "./test1.js";
|
|
410
|
+
|
|
411
|
+
type A = TypeA
|
|
412
|
+
type B = TypeA
|
|
413
|
+
`,
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("same reference used as both type and non type doesn't include type", () => {
|
|
418
|
+
const { component, ClassA } = mkTestFile("test1.ts");
|
|
419
|
+
const res = render(
|
|
420
|
+
<Output>
|
|
421
|
+
{component}
|
|
422
|
+
<ts.SourceFile path="test2.ts">
|
|
423
|
+
<List>
|
|
424
|
+
<>
|
|
425
|
+
type A = <Reference refkey={ClassA} type />
|
|
426
|
+
</>
|
|
427
|
+
<>
|
|
428
|
+
class B extends <Reference refkey={ClassA} /> {"{}"}
|
|
429
|
+
</>
|
|
430
|
+
</List>
|
|
431
|
+
</ts.SourceFile>
|
|
432
|
+
</Output>,
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
assertFileContents(res, {
|
|
436
|
+
"test2.ts": `
|
|
437
|
+
import { ClassA } from "./test1.js";
|
|
438
|
+
|
|
439
|
+
type A = ClassA
|
|
440
|
+
class B extends ClassA {}
|
|
441
|
+
`,
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("infer if a type reference from the typescript context", () => {
|
|
446
|
+
const { component, TypeA } = mkTestFile("test1.ts");
|
|
447
|
+
const res = render(
|
|
448
|
+
<Output>
|
|
449
|
+
{component}
|
|
450
|
+
<ts.SourceFile path="test2.ts">
|
|
451
|
+
<TypeRefContext.Provider value={{ type: true }}>
|
|
452
|
+
<List>
|
|
453
|
+
<>
|
|
454
|
+
type A = <Reference refkey={TypeA} />
|
|
455
|
+
</>
|
|
456
|
+
<>
|
|
457
|
+
type B = <Reference refkey={TypeA} />
|
|
458
|
+
</>
|
|
459
|
+
</List>
|
|
460
|
+
</TypeRefContext.Provider>
|
|
461
|
+
</ts.SourceFile>
|
|
462
|
+
</Output>,
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
assertFileContents(res, {
|
|
466
|
+
"test2.ts": `
|
|
467
|
+
import type { TypeA } from "./test1.js";
|
|
468
|
+
|
|
469
|
+
type A = TypeA
|
|
470
|
+
type B = TypeA
|
|
471
|
+
`,
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
});
|
|
@@ -19,7 +19,7 @@ it("renders an interface declaration with documentation", () => {
|
|
|
19
19
|
expect(res).toEqual(d`
|
|
20
20
|
/**
|
|
21
21
|
* Interface representing a person
|
|
22
|
-
|
|
22
|
+
*/
|
|
23
23
|
interface Person {
|
|
24
24
|
name: string;
|
|
25
25
|
age: number;
|
|
@@ -42,7 +42,7 @@ it("renders an interface declaration with docs from a string array with single e
|
|
|
42
42
|
expect(res).toEqual(d`
|
|
43
43
|
/**
|
|
44
44
|
* Interface representing a person
|
|
45
|
-
|
|
45
|
+
*/
|
|
46
46
|
interface Person {
|
|
47
47
|
name: string;
|
|
48
48
|
age: number;
|
|
@@ -70,7 +70,7 @@ it("renders an interface declaration with docs from a string array", () => {
|
|
|
70
70
|
* Interface representing a person
|
|
71
71
|
*
|
|
72
72
|
* This should be another paragraph
|
|
73
|
-
|
|
73
|
+
*/
|
|
74
74
|
interface Person {
|
|
75
75
|
name: string;
|
|
76
76
|
age: number;
|
|
@@ -103,15 +103,15 @@ it("renders an interface declaration with documented properties", () => {
|
|
|
103
103
|
expect(res).toEqual(d`
|
|
104
104
|
/**
|
|
105
105
|
* Standard API response format
|
|
106
|
-
|
|
106
|
+
*/
|
|
107
107
|
export interface APIResponse {
|
|
108
108
|
/**
|
|
109
109
|
* Wether or not the request completed successfully
|
|
110
|
-
|
|
110
|
+
*/
|
|
111
111
|
success: boolean;
|
|
112
112
|
/**
|
|
113
113
|
* the response payload
|
|
114
|
-
|
|
114
|
+
*/
|
|
115
115
|
data: unknown;
|
|
116
116
|
error?: string;
|
|
117
117
|
}
|
|
@@ -146,17 +146,17 @@ it("renders an interface declaration with array documented properties ", () => {
|
|
|
146
146
|
expect(res).toEqual(d`
|
|
147
147
|
/**
|
|
148
148
|
* Standard API response format
|
|
149
|
-
|
|
149
|
+
*/
|
|
150
150
|
export interface APIResponse {
|
|
151
151
|
/**
|
|
152
152
|
* Wether or not the request completed successfully
|
|
153
153
|
*
|
|
154
154
|
* This is another paragraph
|
|
155
|
-
|
|
155
|
+
*/
|
|
156
156
|
success: boolean;
|
|
157
157
|
/**
|
|
158
158
|
* the response payload
|
|
159
|
-
|
|
159
|
+
*/
|
|
160
160
|
data: unknown;
|
|
161
161
|
error?: string;
|
|
162
162
|
}
|
package/test/interface.test.tsx
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NamePolicyContext,
|
|
3
|
+
Props,
|
|
4
|
+
refkey,
|
|
5
|
+
StatementList,
|
|
6
|
+
} from "@alloy-js/core";
|
|
2
7
|
import "@alloy-js/core/testing";
|
|
3
8
|
import { d } from "@alloy-js/core/testing";
|
|
4
|
-
import { expect, it } from "vitest";
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
5
10
|
import * as ts from "../src/components/index.js";
|
|
11
|
+
import { ParameterDescriptor } from "../src/components/index.js";
|
|
6
12
|
import { Reference } from "../src/components/Reference.js";
|
|
7
13
|
import { createTSNamePolicy } from "../src/name-policy.js";
|
|
8
14
|
import { toSourceText } from "./utils.js";
|
|
@@ -103,18 +109,94 @@ it("can create readonly members", () => {
|
|
|
103
109
|
`);
|
|
104
110
|
});
|
|
105
111
|
|
|
106
|
-
it("
|
|
112
|
+
it("can reference member", () => {
|
|
113
|
+
const ref = refkey("Foo");
|
|
107
114
|
const res = toSourceText(
|
|
108
|
-
|
|
109
|
-
<ts.
|
|
110
|
-
|
|
115
|
+
<>
|
|
116
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
117
|
+
<ts.InterfaceMember name="prop" type="string" refkey={ref} />
|
|
118
|
+
</ts.InterfaceDeclaration>
|
|
119
|
+
<line />
|
|
120
|
+
<ts.InterfaceDeclaration name="Bar">
|
|
121
|
+
<ts.InterfaceMember name="ref" type={<Reference refkey={ref} />} />
|
|
122
|
+
</ts.InterfaceDeclaration>
|
|
123
|
+
</>,
|
|
111
124
|
);
|
|
112
125
|
|
|
113
126
|
expect(res).toEqual(d`
|
|
127
|
+
interface Foo {
|
|
128
|
+
prop: string
|
|
129
|
+
}
|
|
130
|
+
interface Bar {
|
|
131
|
+
ref: Foo["prop"]
|
|
132
|
+
}
|
|
133
|
+
`);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("interface expressions", () => {
|
|
137
|
+
it("basic", () => {
|
|
138
|
+
const res = toSourceText(
|
|
139
|
+
<ts.InterfaceExpression>
|
|
140
|
+
<ts.InterfaceMember name="member" type="string" />;
|
|
141
|
+
</ts.InterfaceExpression>,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(res).toEqual(d`
|
|
114
145
|
{
|
|
115
146
|
member: string;
|
|
116
147
|
}
|
|
117
148
|
`);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("nested", () => {
|
|
152
|
+
const res = toSourceText(
|
|
153
|
+
<ts.InterfaceExpression>
|
|
154
|
+
<ts.InterfaceMember name="outer">
|
|
155
|
+
<ts.InterfaceExpression>
|
|
156
|
+
<ts.InterfaceMember name="inner" type="string" />;
|
|
157
|
+
</ts.InterfaceExpression>
|
|
158
|
+
</ts.InterfaceMember>
|
|
159
|
+
</ts.InterfaceExpression>,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
expect(res).toEqual(d`
|
|
163
|
+
{
|
|
164
|
+
outer: {
|
|
165
|
+
inner: string;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
`);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("can reference member when nested in a declaration", () => {
|
|
172
|
+
const ref = refkey("Foo");
|
|
173
|
+
const res = toSourceText(
|
|
174
|
+
<>
|
|
175
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
176
|
+
<ts.InterfaceMember name="outer">
|
|
177
|
+
<ts.InterfaceExpression>
|
|
178
|
+
<ts.InterfaceMember name="inner" type="string" refkey={ref} />
|
|
179
|
+
</ts.InterfaceExpression>
|
|
180
|
+
</ts.InterfaceMember>
|
|
181
|
+
</ts.InterfaceDeclaration>
|
|
182
|
+
<line />
|
|
183
|
+
<ts.InterfaceDeclaration name="Bar">
|
|
184
|
+
<ts.InterfaceMember name="ref" type={<Reference refkey={ref} />} />
|
|
185
|
+
</ts.InterfaceDeclaration>
|
|
186
|
+
</>,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
expect(res).toEqual(d`
|
|
190
|
+
interface Foo {
|
|
191
|
+
outer: {
|
|
192
|
+
inner: string
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
interface Bar {
|
|
196
|
+
ref: Foo["outer"]["inner"]
|
|
197
|
+
}
|
|
198
|
+
`);
|
|
199
|
+
});
|
|
118
200
|
});
|
|
119
201
|
|
|
120
202
|
it("supports the naming policy", () => {
|
|
@@ -146,3 +228,171 @@ it("handles invalid identifier names", () => {
|
|
|
146
228
|
}
|
|
147
229
|
`);
|
|
148
230
|
});
|
|
231
|
+
|
|
232
|
+
describe("method members", () => {
|
|
233
|
+
it("render basic", () => {
|
|
234
|
+
expect(
|
|
235
|
+
toSourceText(
|
|
236
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
237
|
+
<ts.InterfaceMethod name="foo" />
|
|
238
|
+
</ts.InterfaceDeclaration>,
|
|
239
|
+
),
|
|
240
|
+
).toBe(d`
|
|
241
|
+
interface Foo {
|
|
242
|
+
foo(): void
|
|
243
|
+
}
|
|
244
|
+
`);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("render in interface", () => {
|
|
248
|
+
expect(
|
|
249
|
+
toSourceText(
|
|
250
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
251
|
+
<ts.InterfaceMethod name="foo" />
|
|
252
|
+
</ts.InterfaceDeclaration>,
|
|
253
|
+
),
|
|
254
|
+
).toBe(d`
|
|
255
|
+
interface Foo {
|
|
256
|
+
foo(): void
|
|
257
|
+
}
|
|
258
|
+
`);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("can be an async function", () => {
|
|
262
|
+
expect(
|
|
263
|
+
toSourceText(
|
|
264
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
265
|
+
<ts.InterfaceMethod async name="foo" />
|
|
266
|
+
</ts.InterfaceDeclaration>,
|
|
267
|
+
),
|
|
268
|
+
).toBe(d`
|
|
269
|
+
interface Foo {
|
|
270
|
+
foo(): Promise<void>
|
|
271
|
+
}
|
|
272
|
+
`);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("can be an async function with returnType", () => {
|
|
276
|
+
expect(
|
|
277
|
+
toSourceText(
|
|
278
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
279
|
+
<ts.InterfaceMethod async name="foo" returnType="Foo" />
|
|
280
|
+
</ts.InterfaceDeclaration>,
|
|
281
|
+
),
|
|
282
|
+
).toBe(d`
|
|
283
|
+
interface Foo {
|
|
284
|
+
foo(): Promise<Foo>
|
|
285
|
+
}
|
|
286
|
+
`);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("can be an async function with returnType element", () => {
|
|
290
|
+
function Foo(_props?: Props) {
|
|
291
|
+
return <>Foo</>;
|
|
292
|
+
}
|
|
293
|
+
expect(
|
|
294
|
+
toSourceText(
|
|
295
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
296
|
+
<ts.InterfaceMethod async name="foo" returnType={<Foo />} />
|
|
297
|
+
</ts.InterfaceDeclaration>,
|
|
298
|
+
),
|
|
299
|
+
).toBe(d`
|
|
300
|
+
interface Foo {
|
|
301
|
+
foo(): Promise<Foo>
|
|
302
|
+
}
|
|
303
|
+
`);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("supports parameters by element", () => {
|
|
307
|
+
const decl = (
|
|
308
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
309
|
+
<ts.InterfaceMethod name="foo">
|
|
310
|
+
<ts.InterfaceMethod.Parameters>a, b</ts.InterfaceMethod.Parameters>
|
|
311
|
+
</ts.InterfaceMethod>
|
|
312
|
+
</ts.InterfaceDeclaration>
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
expect(toSourceText(decl)).toBe(d`
|
|
316
|
+
interface Foo {
|
|
317
|
+
foo(a, b): void
|
|
318
|
+
}
|
|
319
|
+
`);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("supports type parameters by descriptor object", () => {
|
|
323
|
+
const decl = (
|
|
324
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
325
|
+
<ts.InterfaceMethod
|
|
326
|
+
name="foo"
|
|
327
|
+
typeParameters={[
|
|
328
|
+
{ name: "a", extends: "any" },
|
|
329
|
+
{ name: "b", extends: "any" },
|
|
330
|
+
]}
|
|
331
|
+
/>
|
|
332
|
+
</ts.InterfaceDeclaration>
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
expect(toSourceText(decl)).toBe(d`
|
|
336
|
+
interface Foo {
|
|
337
|
+
foo<a extends any, b extends any>(): void
|
|
338
|
+
}
|
|
339
|
+
`);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("supports type parameters by descriptor array", () => {
|
|
343
|
+
const decl = (
|
|
344
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
345
|
+
<ts.InterfaceMethod
|
|
346
|
+
name="foo"
|
|
347
|
+
typeParameters={["a", "b"]}
|
|
348
|
+
></ts.InterfaceMethod>
|
|
349
|
+
</ts.InterfaceDeclaration>
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
expect(toSourceText(decl)).toBe(d`
|
|
353
|
+
interface Foo {
|
|
354
|
+
foo<a, b>(): void
|
|
355
|
+
}
|
|
356
|
+
`);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("supports type parameters by element", () => {
|
|
360
|
+
const decl = (
|
|
361
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
362
|
+
<ts.InterfaceMethod name="foo">
|
|
363
|
+
<ts.InterfaceMethod.TypeParameters>
|
|
364
|
+
a, b
|
|
365
|
+
</ts.InterfaceMethod.TypeParameters>
|
|
366
|
+
</ts.InterfaceMethod>
|
|
367
|
+
</ts.InterfaceDeclaration>
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
expect(toSourceText(decl)).toBe(d`
|
|
371
|
+
interface Foo {
|
|
372
|
+
foo<a, b>(): void
|
|
373
|
+
}
|
|
374
|
+
`);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
describe("symbols", () => {
|
|
378
|
+
it("create optional parameters", () => {
|
|
379
|
+
const paramDesc: ParameterDescriptor = {
|
|
380
|
+
name: "foo",
|
|
381
|
+
refkey: refkey(),
|
|
382
|
+
type: "any",
|
|
383
|
+
optional: true,
|
|
384
|
+
};
|
|
385
|
+
const decl = (
|
|
386
|
+
<ts.InterfaceDeclaration name="Foo">
|
|
387
|
+
<ts.InterfaceMethod name="foo" parameters={[paramDesc]} />
|
|
388
|
+
</ts.InterfaceDeclaration>
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
expect(toSourceText(decl)).toBe(d`
|
|
392
|
+
interface Foo {
|
|
393
|
+
foo(foo?: any): void
|
|
394
|
+
}
|
|
395
|
+
`);
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
});
|
package/test/jsdoc.test.tsx
CHANGED
|
@@ -24,7 +24,7 @@ describe("JSDoc", () => {
|
|
|
24
24
|
* Hello!
|
|
25
25
|
*
|
|
26
26
|
* This is another line
|
|
27
|
-
|
|
27
|
+
*/
|
|
28
28
|
`,
|
|
29
29
|
{ printWidth: 40 },
|
|
30
30
|
);
|
|
@@ -59,7 +59,7 @@ describe("Prose", () => {
|
|
|
59
59
|
* This is another paragraph. There
|
|
60
60
|
* should be a couple breaks in front of
|
|
61
61
|
* it.
|
|
62
|
-
|
|
62
|
+
*/
|
|
63
63
|
`,
|
|
64
64
|
{ printWidth: 40 },
|
|
65
65
|
);
|
|
@@ -83,7 +83,7 @@ describe("JSDocExample", () => {
|
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
85
85
|
* console.log("Hello world!")
|
|
86
|
-
|
|
86
|
+
*/
|
|
87
87
|
`,
|
|
88
88
|
{ printWidth: 40 },
|
|
89
89
|
);
|
|
@@ -109,7 +109,7 @@ describe("JSDocExample", () => {
|
|
|
109
109
|
* \`\`\`ts
|
|
110
110
|
* console.log("Hello world!")
|
|
111
111
|
* \`\`\`
|
|
112
|
-
|
|
112
|
+
*/
|
|
113
113
|
`,
|
|
114
114
|
{ printWidth: 40 },
|
|
115
115
|
);
|
|
@@ -140,7 +140,7 @@ describe("JSDocExample", () => {
|
|
|
140
140
|
* @example
|
|
141
141
|
* // make a function call.
|
|
142
142
|
* console.log(arg1, arg2);
|
|
143
|
-
|
|
143
|
+
*/
|
|
144
144
|
`,
|
|
145
145
|
{ printWidth: 40 },
|
|
146
146
|
);
|
package/test/jsdocparam.test.tsx
CHANGED
|
@@ -14,7 +14,7 @@ it("name only", () => {
|
|
|
14
14
|
d`
|
|
15
15
|
/**
|
|
16
16
|
* @param somebody
|
|
17
|
-
|
|
17
|
+
*/
|
|
18
18
|
`,
|
|
19
19
|
);
|
|
20
20
|
});
|
|
@@ -30,7 +30,7 @@ it("name and type", () => {
|
|
|
30
30
|
d`
|
|
31
31
|
/**
|
|
32
32
|
* @param {string} somebody
|
|
33
|
-
|
|
33
|
+
*/
|
|
34
34
|
`,
|
|
35
35
|
);
|
|
36
36
|
});
|
|
@@ -48,7 +48,7 @@ it("name, type and description", () => {
|
|
|
48
48
|
d`
|
|
49
49
|
/**
|
|
50
50
|
* @param {string} somebody Somebody's name.
|
|
51
|
-
|
|
51
|
+
*/
|
|
52
52
|
`,
|
|
53
53
|
);
|
|
54
54
|
});
|
|
@@ -66,7 +66,7 @@ it("name, type and description with hyphen", () => {
|
|
|
66
66
|
d`
|
|
67
67
|
/**
|
|
68
68
|
* @param {string} somebody - Somebody's name.
|
|
69
|
-
|
|
69
|
+
*/
|
|
70
70
|
`,
|
|
71
71
|
);
|
|
72
72
|
});
|
|
@@ -84,7 +84,7 @@ it("name, type, description, hyphen and optional", () => {
|
|
|
84
84
|
d`
|
|
85
85
|
/**
|
|
86
86
|
* @param {string} [somebody] - Somebody's name.
|
|
87
|
-
|
|
87
|
+
*/
|
|
88
88
|
`,
|
|
89
89
|
);
|
|
90
90
|
});
|
|
@@ -108,7 +108,7 @@ it("name, type, description, hyphen and optional with default value", () => {
|
|
|
108
108
|
d`
|
|
109
109
|
/**
|
|
110
110
|
* @param {string} [somebody=John Doe] - Somebody's name.
|
|
111
|
-
|
|
111
|
+
*/
|
|
112
112
|
`,
|
|
113
113
|
);
|
|
114
114
|
});
|
|
@@ -153,7 +153,7 @@ it("name, type, description, hyphen and optional with default value with a very
|
|
|
153
153
|
* even a codename (e.g., "Agent X"). It's used primarily for display
|
|
154
154
|
* purposes, logging, or greeting messages and is not required to be unique or
|
|
155
155
|
* validated unless specified by the caller.
|
|
156
|
-
|
|
156
|
+
*/
|
|
157
157
|
`,
|
|
158
158
|
{ printWidth: 80 },
|
|
159
159
|
);
|
|
@@ -181,7 +181,7 @@ it("name, type, description, hyphen and optional with default value with a descr
|
|
|
181
181
|
/**
|
|
182
182
|
* @param {string} [somebody=John Doe] - Somebody's name. This is one line
|
|
183
183
|
* This is another line
|
|
184
|
-
|
|
184
|
+
*/
|
|
185
185
|
`,
|
|
186
186
|
{ printWidth: 80 },
|
|
187
187
|
);
|