@alloy-js/typescript 0.5.0 → 0.6.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 +15 -0
- package/dist/src/components/ArrayExpression.d.ts +1 -1
- package/dist/src/components/ArrayExpression.d.ts.map +1 -1
- package/dist/src/components/ArrayExpression.js +18 -28
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BarrelFile.d.ts.map +1 -1
- package/dist/src/components/BarrelFile.js +11 -9
- package/dist/src/components/BarrelFile.js.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +8 -9
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/CommaList.d.ts +12 -0
- package/dist/src/components/CommaList.d.ts.map +1 -0
- package/dist/src/components/CommaList.js +19 -0
- package/dist/src/components/CommaList.js.map +1 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +19 -17
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.d.ts +2 -2
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionCallExpression.js +26 -9
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +8 -1
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +135 -33
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +25 -31
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/components/Interface.d.ts +1 -1
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +5 -5
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts +10 -0
- package/dist/src/components/JSDoc.d.ts.map +1 -0
- package/dist/src/components/JSDoc.js +24 -0
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.d.ts +11 -0
- package/dist/src/components/JSDocComment.d.ts.map +1 -0
- package/dist/src/components/JSDocComment.js +16 -0
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.d.ts +12 -0
- package/dist/src/components/JSDocExample.d.ts.map +1 -0
- package/dist/src/components/JSDocExample.js +26 -0
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParagraph.d.ts +10 -0
- package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
- package/dist/src/components/JSDocParagraph.js +23 -0
- package/dist/src/components/JSDocParagraph.js.map +1 -0
- package/dist/src/components/MemberChainExpression.d.ts +11 -0
- package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
- package/dist/src/components/MemberChainExpression.js +64 -0
- package/dist/src/components/MemberChainExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +1 -1
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +45 -42
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +1 -1
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js.map +1 -1
- package/dist/src/components/Reference.js +1 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +13 -6
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TsConfigJson.js.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/ValueExpression.d.ts.map +1 -1
- package/dist/src/components/ValueExpression.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +2 -2
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +21 -21
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/jsdoc.test.d.ts +2 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -0
- package/dist/test/member-chain.test.d.ts +2 -0
- package/dist/test/member-chain.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/ArrayExpression.tsx +18 -32
- package/src/components/BarrelFile.tsx +7 -13
- package/src/components/ClassDeclaration.tsx +33 -28
- package/src/components/CommaList.tsx +23 -0
- package/src/components/Declaration.tsx +7 -3
- package/src/components/EnumDeclaration.tsx +21 -14
- package/src/components/EnumMember.tsx +7 -4
- package/src/components/ExportStatement.tsx +6 -1
- package/src/components/FunctionCallExpression.tsx +18 -9
- package/src/components/FunctionDeclaration.tsx +170 -55
- package/src/components/ImportStatement.tsx +6 -9
- package/src/components/Interface.tsx +20 -13
- package/src/components/JSDoc.tsx +28 -0
- package/src/components/JSDocComment.tsx +23 -0
- package/src/components/JSDocExample.tsx +30 -0
- package/src/components/JSDocParagraph.tsx +35 -0
- package/src/components/MemberChainExpression.tsx +59 -0
- package/src/components/ObjectExpression.tsx +53 -48
- package/src/components/PackageDirectory.tsx +11 -9
- package/src/components/PackageJson.tsx +9 -6
- package/src/components/SourceFile.tsx +15 -8
- package/src/components/TsConfigJson.tsx +5 -3
- package/src/components/TypeDeclaration.tsx +5 -3
- package/src/components/ValueExpression.tsx +3 -1
- package/src/components/VarDeclaration.tsx +11 -5
- package/src/components/index.ts +2 -1
- package/src/components/stc/index.ts +1 -1
- package/temp/api.json +461 -125
- package/test/array.test.tsx +28 -7
- package/test/basic.test.tsx +26 -21
- package/test/class.test.tsx +65 -53
- package/test/enum.test.tsx +18 -13
- package/test/externals.test.tsx +6 -7
- package/test/function-call-expression.test.tsx +39 -17
- package/test/function-declaration.test.tsx +96 -78
- package/test/imports.test.tsx +90 -65
- package/test/interface.test.tsx +29 -19
- package/test/jsdoc.test.tsx +154 -0
- package/test/member-chain.test.tsx +47 -0
- package/test/name-policy.test.tsx +33 -26
- package/test/package-external.test.tsx +8 -4
- package/test/package.test.tsx +1 -2
- package/test/reference.test.tsx +2 -6
- package/test/utils.tsx +3 -1
- package/test/value-expression.test.tsx +2 -6
- package/test/values.test.tsx +67 -73
- package/test/var-declaration.test.tsx +11 -5
- package/test/vitest.d.ts +6 -1
- package/tsconfig.json +8 -1
- package/dist/src/components/Block.d.ts +0 -6
- package/dist/src/components/Block.d.ts.map +0 -1
- package/dist/src/components/Block.js +0 -11
- package/dist/src/components/Block.js.map +0 -1
- package/src/components/Block.tsx +0 -12
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { JSDoc } from "../src/components/JSDoc.jsx";
|
|
5
|
+
import { JSDocComment } from "../src/components/JSDocComment.jsx";
|
|
6
|
+
import { JSDocExample } from "../src/components/JSDocExample.jsx";
|
|
7
|
+
import { JSDocParagraph } from "../src/components/JSDocParagraph.jsx";
|
|
8
|
+
import { FunctionCallExpression } from "../src/index.js";
|
|
9
|
+
|
|
10
|
+
describe("JSDoc", () => {
|
|
11
|
+
it("formats properly", () => {
|
|
12
|
+
const template = (
|
|
13
|
+
<JSDocComment>
|
|
14
|
+
Hello!
|
|
15
|
+
<hbr />
|
|
16
|
+
<hbr />
|
|
17
|
+
This is another line
|
|
18
|
+
</JSDocComment>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(template).toRenderTo(
|
|
22
|
+
d`
|
|
23
|
+
/**
|
|
24
|
+
* Hello!
|
|
25
|
+
*
|
|
26
|
+
* This is another line
|
|
27
|
+
**/
|
|
28
|
+
`,
|
|
29
|
+
{ printWidth: 40 },
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("JSDocParagraph", () => {
|
|
35
|
+
it("formats properly", () => {
|
|
36
|
+
const template = (
|
|
37
|
+
<JSDoc>
|
|
38
|
+
<JSDocParagraph>
|
|
39
|
+
This is a long paragraph that should end up being broken into multiple
|
|
40
|
+
paragraphs. Moreover, the line breaks in this paragraph should not be
|
|
41
|
+
carried over into the JSDoc comment.
|
|
42
|
+
</JSDocParagraph>
|
|
43
|
+
<JSDocParagraph>
|
|
44
|
+
This is another paragraph. There should be a couple breaks in front of
|
|
45
|
+
it.
|
|
46
|
+
</JSDocParagraph>
|
|
47
|
+
</JSDoc>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(template).toRenderTo(
|
|
51
|
+
d`
|
|
52
|
+
/**
|
|
53
|
+
* This is a long paragraph that should
|
|
54
|
+
* end up being broken into multiple
|
|
55
|
+
* paragraphs. Moreover, the line breaks
|
|
56
|
+
* in this paragraph should not be
|
|
57
|
+
* carried over into the JSDoc comment.
|
|
58
|
+
*
|
|
59
|
+
* This is another paragraph. There
|
|
60
|
+
* should be a couple breaks in front of
|
|
61
|
+
* it.
|
|
62
|
+
**/
|
|
63
|
+
`,
|
|
64
|
+
{ printWidth: 40 },
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("JSDocExample", () => {
|
|
70
|
+
it("creates unfenced code samples", () => {
|
|
71
|
+
const template = (
|
|
72
|
+
<JSDoc>
|
|
73
|
+
<JSDocParagraph>
|
|
74
|
+
This API is awesome, and it comes with an example!
|
|
75
|
+
</JSDocParagraph>
|
|
76
|
+
<JSDocExample>console.log("Hello world!")</JSDocExample>
|
|
77
|
+
</JSDoc>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(template).toRenderTo(
|
|
81
|
+
d`
|
|
82
|
+
/**
|
|
83
|
+
* This API is awesome, and it comes
|
|
84
|
+
* with an example!
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* console.log("Hello world!")
|
|
88
|
+
**/
|
|
89
|
+
`,
|
|
90
|
+
{ printWidth: 40 },
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("creates fenced code samples", () => {
|
|
95
|
+
const template = (
|
|
96
|
+
<JSDoc>
|
|
97
|
+
<JSDocParagraph>
|
|
98
|
+
This API is awesome, and it comes with an example!
|
|
99
|
+
</JSDocParagraph>
|
|
100
|
+
<JSDocExample fenced language="ts">
|
|
101
|
+
console.log("Hello world!")
|
|
102
|
+
</JSDocExample>
|
|
103
|
+
</JSDoc>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(template).toRenderTo(
|
|
107
|
+
d`
|
|
108
|
+
/**
|
|
109
|
+
* This API is awesome, and it comes
|
|
110
|
+
* with an example!
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* \`\`\`ts
|
|
114
|
+
* console.log("Hello world!")
|
|
115
|
+
* \`\`\`
|
|
116
|
+
**/
|
|
117
|
+
`,
|
|
118
|
+
{ printWidth: 40 },
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("creates code samples using other components", () => {
|
|
123
|
+
const template = (
|
|
124
|
+
<JSDoc>
|
|
125
|
+
<JSDocParagraph>
|
|
126
|
+
This API is awesome, and it comes with an example!
|
|
127
|
+
</JSDocParagraph>
|
|
128
|
+
<JSDocExample language="ts">
|
|
129
|
+
// make a function call.
|
|
130
|
+
<hbr />
|
|
131
|
+
<FunctionCallExpression
|
|
132
|
+
target="console.log"
|
|
133
|
+
args={["arg1", "arg2"]}
|
|
134
|
+
/>
|
|
135
|
+
;
|
|
136
|
+
</JSDocExample>
|
|
137
|
+
</JSDoc>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(template).toRenderTo(
|
|
141
|
+
d`
|
|
142
|
+
/**
|
|
143
|
+
* This API is awesome, and it comes
|
|
144
|
+
* with an example!
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // make a function call.
|
|
148
|
+
* console.log(arg1, arg2);
|
|
149
|
+
**/
|
|
150
|
+
`,
|
|
151
|
+
{ printWidth: 40 },
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { MemberChainExpression } from "../src/components/MemberChainExpression.jsx";
|
|
4
|
+
import { FunctionCallExpression, ValueExpression } from "../src/index.js";
|
|
5
|
+
import { toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("works", () => {
|
|
8
|
+
expect(
|
|
9
|
+
toSourceText(
|
|
10
|
+
<MemberChainExpression>
|
|
11
|
+
<>z</>
|
|
12
|
+
<FunctionCallExpression target="string" />
|
|
13
|
+
<FunctionCallExpression target="array" />
|
|
14
|
+
<FunctionCallExpression target="min" args={[5]} />
|
|
15
|
+
<FunctionCallExpression target="max" args={[10]} />
|
|
16
|
+
</MemberChainExpression>,
|
|
17
|
+
{ printWidth: 10 },
|
|
18
|
+
),
|
|
19
|
+
).toBe(d`
|
|
20
|
+
z.string()
|
|
21
|
+
.array()
|
|
22
|
+
.min(5)
|
|
23
|
+
.max(10)
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("works with args which break", () => {
|
|
28
|
+
expect(
|
|
29
|
+
toSourceText(
|
|
30
|
+
<MemberChainExpression>
|
|
31
|
+
<>z</>
|
|
32
|
+
<FunctionCallExpression
|
|
33
|
+
target="object"
|
|
34
|
+
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
35
|
+
/>
|
|
36
|
+
<FunctionCallExpression target="array" />
|
|
37
|
+
</MemberChainExpression>,
|
|
38
|
+
{ printWidth: 10 },
|
|
39
|
+
),
|
|
40
|
+
).toBe(d`
|
|
41
|
+
z.object({
|
|
42
|
+
a: 1,
|
|
43
|
+
b: 2,
|
|
44
|
+
})
|
|
45
|
+
.array()
|
|
46
|
+
`);
|
|
47
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output, refkey, render } from "@alloy-js/core";
|
|
1
|
+
import { Output, refkey, render, StatementList } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
@@ -14,19 +14,20 @@ it("applies to functions and variables", () => {
|
|
|
14
14
|
<Output namePolicy={namePolicy}>
|
|
15
15
|
<ts.SourceFile path="test.ts">
|
|
16
16
|
<ts.FunctionDeclaration name="foo-bar" refkey={ref1} />
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
<hbr />
|
|
18
|
+
<StatementList>
|
|
19
|
+
<ts.VarDeclaration name="one-two" refkey={ref2}>
|
|
20
|
+
"hello"
|
|
21
|
+
</ts.VarDeclaration>
|
|
22
|
+
<ts.Reference refkey={ref1} />
|
|
23
|
+
<ts.Reference refkey={ref2} />
|
|
24
|
+
</StatementList>
|
|
22
25
|
</ts.SourceFile>
|
|
23
26
|
</Output>,
|
|
24
27
|
);
|
|
25
28
|
|
|
26
29
|
expect(res.contents[0].contents).toEqual(d`
|
|
27
|
-
function fooBar() {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
+
function fooBar() {}
|
|
30
31
|
const oneTwo = "hello";
|
|
31
32
|
fooBar;
|
|
32
33
|
oneTwo;
|
|
@@ -42,19 +43,20 @@ it("keeps _ and $ prefix", () => {
|
|
|
42
43
|
<Output namePolicy={namePolicy}>
|
|
43
44
|
<ts.SourceFile path="test.ts">
|
|
44
45
|
<ts.FunctionDeclaration name="_foo-bar" refkey={ref1} />
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
<hbr />
|
|
47
|
+
<StatementList>
|
|
48
|
+
<ts.VarDeclaration name="$one-two" refkey={ref2}>
|
|
49
|
+
"hello"
|
|
50
|
+
</ts.VarDeclaration>
|
|
51
|
+
<ts.Reference refkey={ref1} />
|
|
52
|
+
<ts.Reference refkey={ref2} />
|
|
53
|
+
</StatementList>
|
|
50
54
|
</ts.SourceFile>
|
|
51
55
|
</Output>,
|
|
52
56
|
);
|
|
53
57
|
|
|
54
58
|
expect(res.contents[0].contents).toEqual(d`
|
|
55
|
-
function _fooBar() {
|
|
56
|
-
|
|
57
|
-
}
|
|
59
|
+
function _fooBar() {}
|
|
58
60
|
const $oneTwo = "hello";
|
|
59
61
|
_fooBar;
|
|
60
62
|
$oneTwo;
|
|
@@ -69,20 +71,25 @@ it("appends _ to reserved words", () => {
|
|
|
69
71
|
const res = render(
|
|
70
72
|
<Output namePolicy={namePolicy}>
|
|
71
73
|
<ts.SourceFile path="test.ts">
|
|
72
|
-
<ts.FunctionDeclaration
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
<
|
|
74
|
+
<ts.FunctionDeclaration
|
|
75
|
+
name="default"
|
|
76
|
+
refkey={ref1}
|
|
77
|
+
parameters={{ await: "any" }}
|
|
78
|
+
/>
|
|
79
|
+
<hbr />
|
|
80
|
+
<StatementList>
|
|
81
|
+
<ts.VarDeclaration name="super" refkey={ref2}>
|
|
82
|
+
"hello"
|
|
83
|
+
</ts.VarDeclaration>
|
|
84
|
+
<ts.Reference refkey={ref1} />
|
|
85
|
+
<ts.Reference refkey={ref2} />
|
|
86
|
+
</StatementList>
|
|
78
87
|
</ts.SourceFile>
|
|
79
88
|
</Output>,
|
|
80
89
|
);
|
|
81
90
|
|
|
82
91
|
expect(res.contents[0].contents).toEqual(d`
|
|
83
|
-
function default_(await_: any) {
|
|
84
|
-
|
|
85
|
-
}
|
|
92
|
+
function default_(await_: any) {}
|
|
86
93
|
const super_ = "hello";
|
|
87
94
|
default_;
|
|
88
95
|
super_;
|
|
@@ -5,10 +5,13 @@ import * as ts from "../src/index.js";
|
|
|
5
5
|
import { findFile } from "./utils.js";
|
|
6
6
|
|
|
7
7
|
it("imports external packages", () => {
|
|
8
|
-
debug.component.tree();
|
|
9
8
|
const res = render(
|
|
10
9
|
<Output>
|
|
11
|
-
<ts.PackageDirectory
|
|
10
|
+
<ts.PackageDirectory
|
|
11
|
+
name="greeting-lib"
|
|
12
|
+
path="greeting-lib"
|
|
13
|
+
version="1.0.0"
|
|
14
|
+
>
|
|
12
15
|
<ts.SourceFile path="greetings.ts">
|
|
13
16
|
<ts.FunctionDeclaration name="getGreeting">
|
|
14
17
|
return "Hello world!";
|
|
@@ -20,13 +23,14 @@ it("imports external packages", () => {
|
|
|
20
23
|
console.log("Hello world!");
|
|
21
24
|
</ts.FunctionDeclaration>
|
|
22
25
|
</ts.SourceFile>
|
|
23
|
-
|
|
26
|
+
|
|
24
27
|
<ts.BarrelFile export="." />
|
|
25
28
|
</ts.PackageDirectory>
|
|
26
29
|
|
|
27
30
|
<ts.PackageDirectory name="consumer" path="consumer" version="1.0.0">
|
|
28
31
|
<ts.SourceFile export="." path="ref.ts">
|
|
29
|
-
<ts.Reference refkey={refkey("getGreeting")} />
|
|
32
|
+
<ts.Reference refkey={refkey("getGreeting")} />
|
|
33
|
+
();
|
|
30
34
|
</ts.SourceFile>
|
|
31
35
|
</ts.PackageDirectory>
|
|
32
36
|
</Output>,
|
package/test/package.test.tsx
CHANGED
|
@@ -9,7 +9,6 @@ it("exports source files", () => {
|
|
|
9
9
|
const res = render(
|
|
10
10
|
<Output>
|
|
11
11
|
<PackageDirectory name="greeting-js" path="." version="1.0.0">
|
|
12
|
-
|
|
13
12
|
<ts.SourceFile path="greeting.ts">
|
|
14
13
|
<ts.FunctionDeclaration name="getGreeting">
|
|
15
14
|
return "Hello world!";
|
|
@@ -20,13 +19,13 @@ it("exports source files", () => {
|
|
|
20
19
|
<ts.VarDeclaration name="greeting">
|
|
21
20
|
{refkey("getGreeting")}()
|
|
22
21
|
</ts.VarDeclaration>
|
|
22
|
+
;<hbr />
|
|
23
23
|
<ts.FunctionDeclaration export name="printGreeting">
|
|
24
24
|
console.log(greeting);
|
|
25
25
|
</ts.FunctionDeclaration>
|
|
26
26
|
</ts.SourceFile>
|
|
27
27
|
|
|
28
28
|
<ts.BarrelFile export="." />
|
|
29
|
-
|
|
30
29
|
</PackageDirectory>
|
|
31
30
|
</Output>,
|
|
32
31
|
);
|
package/test/reference.test.tsx
CHANGED
|
@@ -9,9 +9,7 @@ it("works with back references", () => {
|
|
|
9
9
|
const res = render(
|
|
10
10
|
<Output>
|
|
11
11
|
<ts.SourceFile path="test1.ts">
|
|
12
|
-
<Declaration name="foo">
|
|
13
|
-
const foo = 1;
|
|
14
|
-
</Declaration>
|
|
12
|
+
<Declaration name="foo">const foo = 1;</Declaration>
|
|
15
13
|
</ts.SourceFile>
|
|
16
14
|
|
|
17
15
|
<ts.SourceFile path="test2.ts">
|
|
@@ -39,9 +37,7 @@ it("works with forward references", () => {
|
|
|
39
37
|
const v = <Reference refkey={refkey("foo")} />;
|
|
40
38
|
</ts.SourceFile>
|
|
41
39
|
<ts.SourceFile path="test1.ts">
|
|
42
|
-
<Declaration name="foo">
|
|
43
|
-
const foo = 1;
|
|
44
|
-
</Declaration>
|
|
40
|
+
<Declaration name="foo">const foo = 1;</Declaration>
|
|
45
41
|
</ts.SourceFile>
|
|
46
42
|
</Output>,
|
|
47
43
|
);
|
package/test/utils.tsx
CHANGED
|
@@ -3,17 +3,19 @@ import {
|
|
|
3
3
|
Output,
|
|
4
4
|
OutputDirectory,
|
|
5
5
|
OutputFile,
|
|
6
|
+
PrintTreeOptions,
|
|
6
7
|
render,
|
|
7
8
|
} from "@alloy-js/core";
|
|
8
9
|
import { dedent } from "@alloy-js/core/testing";
|
|
9
10
|
import { expect } from "vitest";
|
|
10
11
|
import * as ts from "../src/index.js";
|
|
11
12
|
|
|
12
|
-
export function toSourceText(c: Children): string {
|
|
13
|
+
export function toSourceText(c: Children, options?: PrintTreeOptions): string {
|
|
13
14
|
const res = render(
|
|
14
15
|
<Output>
|
|
15
16
|
<ts.SourceFile path="test.ts">{c}</ts.SourceFile>
|
|
16
17
|
</Output>,
|
|
18
|
+
options,
|
|
17
19
|
);
|
|
18
20
|
|
|
19
21
|
return res.contents[0].contents as string;
|