@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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List } 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 { SingleLineCommentBlock } from "../src/components/SingleLineCommentBlock.js";
|
|
7
|
+
describe("JSComment", () => {
|
|
8
|
+
it("formats properly a simple comment", () => {
|
|
9
|
+
const template = [_$createComponent(SingleLineCommentBlock, {
|
|
10
|
+
children: "Hello!"
|
|
11
|
+
}), _$createIntrinsic("hbr", {}), "Should not be part of the comment"];
|
|
12
|
+
expect(template).toRenderTo(d`
|
|
13
|
+
// Hello!
|
|
14
|
+
Should not be part of the comment
|
|
15
|
+
`, {
|
|
16
|
+
printWidth: 40
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it("should not add extra line breaks", () => {
|
|
20
|
+
const template = [_$createComponent(List, {
|
|
21
|
+
hardline: true,
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(SingleLineCommentBlock, {
|
|
24
|
+
get children() {
|
|
25
|
+
return ["Hello!", _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {}), "This is another line"];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}), _$createIntrinsic("hbr", {}), "Hello"];
|
|
30
|
+
expect(template).toRenderTo(d`
|
|
31
|
+
// Hello!
|
|
32
|
+
//
|
|
33
|
+
// This is another line
|
|
34
|
+
Hello
|
|
35
|
+
`, {
|
|
36
|
+
printWidth: 40
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it("formats properly multiple children", () => {
|
|
40
|
+
const template = [_$createComponent(SingleLineCommentBlock, {
|
|
41
|
+
get children() {
|
|
42
|
+
return ["Hello!", _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {}), "This is another line"];
|
|
43
|
+
}
|
|
44
|
+
}), _$createIntrinsic("hbr", {}), "foo should be outside the comment"];
|
|
45
|
+
expect(template).toRenderTo(d`
|
|
46
|
+
// Hello!
|
|
47
|
+
//
|
|
48
|
+
// This is another line
|
|
49
|
+
foo should be outside the comment
|
|
50
|
+
`, {
|
|
51
|
+
printWidth: 40
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it("It correctly do word wrapping", () => {
|
|
55
|
+
const template = [_$createComponent(SingleLineCommentBlock, {
|
|
56
|
+
children: "This is a very long line that should be broken into multiple lines. It should also be aligned properly. The line breaks in this paragraph should not be carried over into the JSDoc comment."
|
|
57
|
+
}), _$createIntrinsic("hbr", {}), ["This should not be part of the comment"]];
|
|
58
|
+
expect(template).toRenderTo(d`
|
|
59
|
+
// This is a very long line that should
|
|
60
|
+
// be broken into multiple lines. It
|
|
61
|
+
// should also be aligned properly. The
|
|
62
|
+
// line breaks in this paragraph should
|
|
63
|
+
// not be carried over into the JSDoc
|
|
64
|
+
// comment.
|
|
65
|
+
This should not be part of the comment
|
|
66
|
+
`, {
|
|
67
|
+
printWidth: 40
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Prose } 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 { JSDoc } from "../src/components/JSDoc.js";
|
|
7
|
+
import { JSDocComment } from "../src/components/JSDocComment.js";
|
|
8
|
+
import { JSDocExample } from "../src/components/JSDocExample.js";
|
|
9
|
+
import { FunctionCallExpression } from "../src/index.js";
|
|
10
|
+
describe("JSDoc", () => {
|
|
11
|
+
it("formats properly", () => {
|
|
12
|
+
const template = _$createComponent(JSDocComment, {
|
|
13
|
+
get children() {
|
|
14
|
+
return ["Hello!", _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {}), "This is another line"];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
expect(template).toRenderTo(d`
|
|
18
|
+
/**
|
|
19
|
+
* Hello!
|
|
20
|
+
*
|
|
21
|
+
* This is another line
|
|
22
|
+
*/
|
|
23
|
+
`, {
|
|
24
|
+
printWidth: 40
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe("Prose", () => {
|
|
29
|
+
it("formats properly", () => {
|
|
30
|
+
const template = _$createComponent(JSDoc, {
|
|
31
|
+
get children() {
|
|
32
|
+
return [_$createComponent(Prose, {
|
|
33
|
+
children: "This is a long paragraph that should end up being broken into multiple paragraphs. Moreover, the line breaks in this paragraph should not be carried over into the JSDoc comment."
|
|
34
|
+
}), _$createComponent(Prose, {
|
|
35
|
+
children: "This is another paragraph. There should be a couple breaks in front of it."
|
|
36
|
+
})];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
expect(template).toRenderTo(d`
|
|
40
|
+
/**
|
|
41
|
+
* This is a long paragraph that should
|
|
42
|
+
* end up being broken into multiple
|
|
43
|
+
* paragraphs. Moreover, the line breaks
|
|
44
|
+
* in this paragraph should not be
|
|
45
|
+
* carried over into the JSDoc comment.
|
|
46
|
+
*
|
|
47
|
+
* This is another paragraph. There
|
|
48
|
+
* should be a couple breaks in front of
|
|
49
|
+
* it.
|
|
50
|
+
*/
|
|
51
|
+
`, {
|
|
52
|
+
printWidth: 40
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe("JSDocExample", () => {
|
|
57
|
+
it("creates unfenced code samples", () => {
|
|
58
|
+
const template = _$createComponent(JSDoc, {
|
|
59
|
+
get children() {
|
|
60
|
+
return [_$createComponent(Prose, {
|
|
61
|
+
children: "This API is awesome, and it comes with an example!"
|
|
62
|
+
}), _$createComponent(JSDocExample, {
|
|
63
|
+
children: "console.log(\"Hello world!\")"
|
|
64
|
+
})];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
expect(template).toRenderTo(d`
|
|
68
|
+
/**
|
|
69
|
+
* This API is awesome, and it comes
|
|
70
|
+
* with an example!
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* console.log("Hello world!")
|
|
74
|
+
*/
|
|
75
|
+
`, {
|
|
76
|
+
printWidth: 40
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("creates fenced code samples", () => {
|
|
80
|
+
const template = _$createComponent(JSDoc, {
|
|
81
|
+
get children() {
|
|
82
|
+
return [_$createComponent(Prose, {
|
|
83
|
+
children: "This API is awesome, and it comes with an example!"
|
|
84
|
+
}), _$createComponent(JSDocExample, {
|
|
85
|
+
fenced: true,
|
|
86
|
+
language: "ts",
|
|
87
|
+
children: "console.log(\"Hello world!\")"
|
|
88
|
+
})];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
expect(template).toRenderTo(d`
|
|
92
|
+
/**
|
|
93
|
+
* This API is awesome, and it comes
|
|
94
|
+
* with an example!
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* \`\`\`ts
|
|
98
|
+
* console.log("Hello world!")
|
|
99
|
+
* \`\`\`
|
|
100
|
+
*/
|
|
101
|
+
`, {
|
|
102
|
+
printWidth: 40
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it("creates code samples using other components", () => {
|
|
106
|
+
const template = _$createComponent(JSDoc, {
|
|
107
|
+
get children() {
|
|
108
|
+
return [_$createComponent(Prose, {
|
|
109
|
+
children: "This API is awesome, and it comes with an example!"
|
|
110
|
+
}), _$createComponent(JSDocExample, {
|
|
111
|
+
language: "ts",
|
|
112
|
+
get children() {
|
|
113
|
+
return ["// make a function call.", _$createIntrinsic("hbr", {}), _$createComponent(FunctionCallExpression, {
|
|
114
|
+
target: "console.log",
|
|
115
|
+
args: ["arg1", "arg2"]
|
|
116
|
+
}), ";"];
|
|
117
|
+
}
|
|
118
|
+
})];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
expect(template).toRenderTo(d`
|
|
122
|
+
/**
|
|
123
|
+
* This API is awesome, and it comes
|
|
124
|
+
* with an example!
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* // make a function call.
|
|
128
|
+
* console.log(arg1, arg2);
|
|
129
|
+
*/
|
|
130
|
+
`, {
|
|
131
|
+
printWidth: 40
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { JSDocParam } from "../src/components/JSDocParam.js";
|
|
5
|
+
import { JSDoc } from "../src/index.js";
|
|
6
|
+
it("name only", () => {
|
|
7
|
+
const template = _$createComponent(JSDoc, {
|
|
8
|
+
get children() {
|
|
9
|
+
return _$createComponent(JSDocParam, {
|
|
10
|
+
name: "somebody"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
expect(template).toRenderTo(d`
|
|
15
|
+
/**
|
|
16
|
+
* @param somebody
|
|
17
|
+
*/
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
it("name and type", () => {
|
|
21
|
+
const template = _$createComponent(JSDoc, {
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(JSDocParam, {
|
|
24
|
+
name: "somebody",
|
|
25
|
+
type: "string"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
expect(template).toRenderTo(d`
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} somebody
|
|
32
|
+
*/
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
it("name, type and description", () => {
|
|
36
|
+
const template = _$createComponent(JSDoc, {
|
|
37
|
+
get children() {
|
|
38
|
+
return _$createComponent(JSDocParam, {
|
|
39
|
+
name: "somebody",
|
|
40
|
+
type: "string",
|
|
41
|
+
children: "Somebody's name."
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
expect(template).toRenderTo(d`
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} somebody Somebody's name.
|
|
48
|
+
*/
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
it("name, type and description with hyphen", () => {
|
|
52
|
+
const template = _$createComponent(JSDoc, {
|
|
53
|
+
get children() {
|
|
54
|
+
return _$createComponent(JSDocParam, {
|
|
55
|
+
name: "somebody",
|
|
56
|
+
type: "string",
|
|
57
|
+
hyphen: true,
|
|
58
|
+
children: "Somebody's name."
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
expect(template).toRenderTo(d`
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} somebody - Somebody's name.
|
|
65
|
+
*/
|
|
66
|
+
`);
|
|
67
|
+
});
|
|
68
|
+
it("name, type, description, hyphen and optional", () => {
|
|
69
|
+
const template = _$createComponent(JSDoc, {
|
|
70
|
+
get children() {
|
|
71
|
+
return _$createComponent(JSDocParam, {
|
|
72
|
+
name: "somebody",
|
|
73
|
+
type: "string",
|
|
74
|
+
optional: true,
|
|
75
|
+
hyphen: true,
|
|
76
|
+
children: "Somebody's name."
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
expect(template).toRenderTo(d`
|
|
81
|
+
/**
|
|
82
|
+
* @param {string} [somebody] - Somebody's name.
|
|
83
|
+
*/
|
|
84
|
+
`);
|
|
85
|
+
});
|
|
86
|
+
it("name, type, description, hyphen and optional with default value", () => {
|
|
87
|
+
const template = _$createComponent(JSDoc, {
|
|
88
|
+
get children() {
|
|
89
|
+
return _$createComponent(JSDocParam, {
|
|
90
|
+
name: "somebody",
|
|
91
|
+
type: "string",
|
|
92
|
+
optional: true,
|
|
93
|
+
defaultValue: "John Doe",
|
|
94
|
+
hyphen: true,
|
|
95
|
+
children: "Somebody's name."
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
expect(template).toRenderTo(d`
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} [somebody=John Doe] - Somebody's name.
|
|
102
|
+
*/
|
|
103
|
+
`);
|
|
104
|
+
});
|
|
105
|
+
it("name, type, description, hyphen and optional with default value with a very lon description", () => {
|
|
106
|
+
const template = _$createComponent(JSDoc, {
|
|
107
|
+
get children() {
|
|
108
|
+
return [_$createComponent(JSDocParam, {
|
|
109
|
+
name: "somebody",
|
|
110
|
+
type: "string",
|
|
111
|
+
optional: true,
|
|
112
|
+
defaultValue: "John Doe",
|
|
113
|
+
hyphen: true,
|
|
114
|
+
children: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., \"Agent X\"). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller."
|
|
115
|
+
}), _$createComponent(JSDocParam, {
|
|
116
|
+
name: "somebody2",
|
|
117
|
+
type: "string",
|
|
118
|
+
hyphen: true,
|
|
119
|
+
children: "Somebody's name. This can be any string representing a person, whether it's a first name, full name, nickname, or even a codename (e.g., \"Agent X\"). It's used primarily for display purposes, logging, or greeting messages and is not required to be unique or validated unless specified by the caller."
|
|
120
|
+
})];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
expect(template).toRenderTo(d`
|
|
124
|
+
/**
|
|
125
|
+
* @param {string} [somebody=John Doe] - Somebody's name. This can be any string
|
|
126
|
+
* representing a person, whether it's a first name, full name, nickname, or
|
|
127
|
+
* even a codename (e.g., "Agent X"). It's used primarily for display
|
|
128
|
+
* purposes, logging, or greeting messages and is not required to be unique or
|
|
129
|
+
* validated unless specified by the caller.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} somebody2 - Somebody's name. This can be any string
|
|
132
|
+
* representing a person, whether it's a first name, full name, nickname, or
|
|
133
|
+
* even a codename (e.g., "Agent X"). It's used primarily for display
|
|
134
|
+
* purposes, logging, or greeting messages and is not required to be unique or
|
|
135
|
+
* validated unless specified by the caller.
|
|
136
|
+
*/
|
|
137
|
+
`, {
|
|
138
|
+
printWidth: 80
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
it("name, type, description, hyphen and optional with default value with a description containing a linebreak", () => {
|
|
142
|
+
const template = _$createComponent(JSDoc, {
|
|
143
|
+
get children() {
|
|
144
|
+
return _$createComponent(JSDocParam, {
|
|
145
|
+
name: "somebody",
|
|
146
|
+
type: "string",
|
|
147
|
+
optional: true,
|
|
148
|
+
defaultValue: "John Doe",
|
|
149
|
+
hyphen: true,
|
|
150
|
+
get children() {
|
|
151
|
+
return ["Somebody's name. This is one line", _$createIntrinsic("hbr", {}), "This is another line"];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
expect(template).toRenderTo(d`
|
|
157
|
+
/**
|
|
158
|
+
* @param {string} [somebody=John Doe] - Somebody's name. This is one line
|
|
159
|
+
* This is another line
|
|
160
|
+
*/
|
|
161
|
+
`, {
|
|
162
|
+
printWidth: 80
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
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 { MemberChainExpression } from "../src/components/MemberChainExpression.js";
|
|
5
|
+
import { FunctionCallExpression, ValueExpression } from "../src/index.js";
|
|
6
|
+
import { toSourceText } from "./utils.js";
|
|
7
|
+
it("works", () => {
|
|
8
|
+
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
9
|
+
get children() {
|
|
10
|
+
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
11
|
+
target: "string"
|
|
12
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
13
|
+
target: "array"
|
|
14
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
15
|
+
target: "min",
|
|
16
|
+
args: [5]
|
|
17
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
18
|
+
target: "max",
|
|
19
|
+
args: [10]
|
|
20
|
+
})];
|
|
21
|
+
}
|
|
22
|
+
}), {
|
|
23
|
+
printWidth: 10
|
|
24
|
+
})).toBe(d`
|
|
25
|
+
z.string()
|
|
26
|
+
.array()
|
|
27
|
+
.min(5)
|
|
28
|
+
.max(10)
|
|
29
|
+
`);
|
|
30
|
+
});
|
|
31
|
+
it("works with args which break", () => {
|
|
32
|
+
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
33
|
+
get children() {
|
|
34
|
+
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
35
|
+
target: "object",
|
|
36
|
+
get args() {
|
|
37
|
+
return [_$createComponent(ValueExpression, {
|
|
38
|
+
jsValue: {
|
|
39
|
+
a: 1,
|
|
40
|
+
b: 2
|
|
41
|
+
}
|
|
42
|
+
})];
|
|
43
|
+
}
|
|
44
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
45
|
+
target: "array"
|
|
46
|
+
})];
|
|
47
|
+
}
|
|
48
|
+
}), {
|
|
49
|
+
printWidth: 10
|
|
50
|
+
})).toBe(d`
|
|
51
|
+
z.object({
|
|
52
|
+
a: 1,
|
|
53
|
+
b: 2,
|
|
54
|
+
})
|
|
55
|
+
.array()
|
|
56
|
+
`);
|
|
57
|
+
});
|
|
58
|
+
it("works with args when it doesn't break", () => {
|
|
59
|
+
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
60
|
+
get children() {
|
|
61
|
+
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
62
|
+
target: "object",
|
|
63
|
+
get args() {
|
|
64
|
+
return [_$createComponent(ValueExpression, {
|
|
65
|
+
jsValue: {
|
|
66
|
+
a: 1,
|
|
67
|
+
b: 2
|
|
68
|
+
}
|
|
69
|
+
})];
|
|
70
|
+
}
|
|
71
|
+
})];
|
|
72
|
+
}
|
|
73
|
+
}))).toBe(d`
|
|
74
|
+
z.object({
|
|
75
|
+
a: 1,
|
|
76
|
+
b: 2,
|
|
77
|
+
})
|
|
78
|
+
`);
|
|
79
|
+
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
80
|
+
get children() {
|
|
81
|
+
return [["z"], ["z2"], ["z3"], _$createComponent(FunctionCallExpression, {
|
|
82
|
+
target: "object",
|
|
83
|
+
get args() {
|
|
84
|
+
return [_$createComponent(ValueExpression, {
|
|
85
|
+
jsValue: {
|
|
86
|
+
a: 1,
|
|
87
|
+
b: 2
|
|
88
|
+
}
|
|
89
|
+
})];
|
|
90
|
+
}
|
|
91
|
+
})];
|
|
92
|
+
}
|
|
93
|
+
}))).toBe(d`
|
|
94
|
+
z.z2.z3.object({
|
|
95
|
+
a: 1,
|
|
96
|
+
b: 2,
|
|
97
|
+
})
|
|
98
|
+
`);
|
|
99
|
+
});
|
|
100
|
+
it("works with nested call member chains", () => {
|
|
101
|
+
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
102
|
+
get children() {
|
|
103
|
+
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
104
|
+
target: "string"
|
|
105
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
106
|
+
target: "array"
|
|
107
|
+
}), _$createComponent(MemberChainExpression, {
|
|
108
|
+
get children() {
|
|
109
|
+
return [_$createComponent(FunctionCallExpression, {
|
|
110
|
+
target: "min",
|
|
111
|
+
args: [5]
|
|
112
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
113
|
+
target: "max",
|
|
114
|
+
args: [10]
|
|
115
|
+
})];
|
|
116
|
+
}
|
|
117
|
+
}), _$createComponent(FunctionCallExpression, {
|
|
118
|
+
target: "array"
|
|
119
|
+
})];
|
|
120
|
+
}
|
|
121
|
+
}), {
|
|
122
|
+
printWidth: 10
|
|
123
|
+
})).toBe(d`
|
|
124
|
+
z.string()
|
|
125
|
+
.array()
|
|
126
|
+
.min(5)
|
|
127
|
+
.max(10)
|
|
128
|
+
.array()
|
|
129
|
+
`);
|
|
130
|
+
});
|
|
131
|
+
it("works without function call expressions", () => {
|
|
132
|
+
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
133
|
+
get children() {
|
|
134
|
+
return [["z"], ["string"], ["min"]];
|
|
135
|
+
}
|
|
136
|
+
}), {
|
|
137
|
+
printWidth: 5
|
|
138
|
+
})).toBe(d`
|
|
139
|
+
z.string.min
|
|
140
|
+
`);
|
|
141
|
+
});
|