@alloy-js/typescript 0.4.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.
Files changed (170) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/src/components/ArrayExpression.d.ts +1 -1
  3. package/dist/src/components/ArrayExpression.d.ts.map +1 -1
  4. package/dist/src/components/ArrayExpression.js +18 -28
  5. package/dist/src/components/ArrayExpression.js.map +1 -1
  6. package/dist/src/components/BarrelFile.d.ts +1 -1
  7. package/dist/src/components/BarrelFile.d.ts.map +1 -1
  8. package/dist/src/components/BarrelFile.js +11 -9
  9. package/dist/src/components/BarrelFile.js.map +1 -1
  10. package/dist/src/components/ClassDeclaration.d.ts +4 -4
  11. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  12. package/dist/src/components/ClassDeclaration.js +8 -9
  13. package/dist/src/components/ClassDeclaration.js.map +1 -1
  14. package/dist/src/components/CommaList.d.ts +12 -0
  15. package/dist/src/components/CommaList.d.ts.map +1 -0
  16. package/dist/src/components/CommaList.js +19 -0
  17. package/dist/src/components/CommaList.js.map +1 -0
  18. package/dist/src/components/Declaration.d.ts +1 -1
  19. package/dist/src/components/Declaration.d.ts.map +1 -1
  20. package/dist/src/components/Declaration.js.map +1 -1
  21. package/dist/src/components/EnumDeclaration.d.ts +1 -1
  22. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  23. package/dist/src/components/EnumDeclaration.js +19 -17
  24. package/dist/src/components/EnumDeclaration.js.map +1 -1
  25. package/dist/src/components/EnumMember.d.ts +1 -1
  26. package/dist/src/components/EnumMember.d.ts.map +1 -1
  27. package/dist/src/components/EnumMember.js.map +1 -1
  28. package/dist/src/components/ExportStatement.d.ts +1 -1
  29. package/dist/src/components/ExportStatement.d.ts.map +1 -1
  30. package/dist/src/components/ExportStatement.js.map +1 -1
  31. package/dist/src/components/FunctionCallExpression.d.ts +3 -3
  32. package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
  33. package/dist/src/components/FunctionCallExpression.js +26 -9
  34. package/dist/src/components/FunctionCallExpression.js.map +1 -1
  35. package/dist/src/components/FunctionDeclaration.d.ts +9 -2
  36. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  37. package/dist/src/components/FunctionDeclaration.js +135 -33
  38. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  39. package/dist/src/components/ImportStatement.d.ts +1 -1
  40. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  41. package/dist/src/components/ImportStatement.js +25 -31
  42. package/dist/src/components/ImportStatement.js.map +1 -1
  43. package/dist/src/components/Interface.d.ts +3 -3
  44. package/dist/src/components/Interface.d.ts.map +1 -1
  45. package/dist/src/components/Interface.js +5 -5
  46. package/dist/src/components/Interface.js.map +1 -1
  47. package/dist/src/components/JSDoc.d.ts +10 -0
  48. package/dist/src/components/JSDoc.d.ts.map +1 -0
  49. package/dist/src/components/JSDoc.js +24 -0
  50. package/dist/src/components/JSDoc.js.map +1 -0
  51. package/dist/src/components/JSDocComment.d.ts +11 -0
  52. package/dist/src/components/JSDocComment.d.ts.map +1 -0
  53. package/dist/src/components/JSDocComment.js +16 -0
  54. package/dist/src/components/JSDocComment.js.map +1 -0
  55. package/dist/src/components/JSDocExample.d.ts +12 -0
  56. package/dist/src/components/JSDocExample.d.ts.map +1 -0
  57. package/dist/src/components/JSDocExample.js +26 -0
  58. package/dist/src/components/JSDocExample.js.map +1 -0
  59. package/dist/src/components/JSDocParagraph.d.ts +10 -0
  60. package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
  61. package/dist/src/components/JSDocParagraph.js +23 -0
  62. package/dist/src/components/JSDocParagraph.js.map +1 -0
  63. package/dist/src/components/MemberChainExpression.d.ts +11 -0
  64. package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
  65. package/dist/src/components/MemberChainExpression.js +64 -0
  66. package/dist/src/components/MemberChainExpression.js.map +1 -0
  67. package/dist/src/components/ObjectExpression.d.ts +2 -2
  68. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  69. package/dist/src/components/ObjectExpression.js +45 -42
  70. package/dist/src/components/ObjectExpression.js.map +1 -1
  71. package/dist/src/components/PackageDirectory.d.ts +1 -1
  72. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  73. package/dist/src/components/PackageDirectory.js +1 -1
  74. package/dist/src/components/PackageDirectory.js.map +1 -1
  75. package/dist/src/components/PackageJson.d.ts +1 -1
  76. package/dist/src/components/PackageJson.d.ts.map +1 -1
  77. package/dist/src/components/PackageJson.js.map +1 -1
  78. package/dist/src/components/Reference.d.ts +1 -1
  79. package/dist/src/components/Reference.d.ts.map +1 -1
  80. package/dist/src/components/Reference.js +1 -1
  81. package/dist/src/components/Reference.js.map +1 -1
  82. package/dist/src/components/SourceFile.d.ts +1 -1
  83. package/dist/src/components/SourceFile.d.ts.map +1 -1
  84. package/dist/src/components/SourceFile.js +13 -6
  85. package/dist/src/components/SourceFile.js.map +1 -1
  86. package/dist/src/components/TsConfigJson.d.ts +1 -1
  87. package/dist/src/components/TsConfigJson.d.ts.map +1 -1
  88. package/dist/src/components/TsConfigJson.js.map +1 -1
  89. package/dist/src/components/TypeDeclaration.d.ts +1 -1
  90. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  91. package/dist/src/components/TypeDeclaration.js.map +1 -1
  92. package/dist/src/components/ValueExpression.d.ts +2 -1
  93. package/dist/src/components/ValueExpression.d.ts.map +1 -1
  94. package/dist/src/components/ValueExpression.js.map +1 -1
  95. package/dist/src/components/VarDeclaration.d.ts +1 -1
  96. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  97. package/dist/src/components/VarDeclaration.js +2 -2
  98. package/dist/src/components/VarDeclaration.js.map +1 -1
  99. package/dist/src/components/index.d.ts +2 -1
  100. package/dist/src/components/index.d.ts.map +1 -1
  101. package/dist/src/components/index.js +2 -1
  102. package/dist/src/components/index.js.map +1 -1
  103. package/dist/src/components/stc/index.d.ts +21 -21
  104. package/dist/src/components/stc/index.d.ts.map +1 -1
  105. package/dist/src/components/stc/index.js +1 -1
  106. package/dist/src/components/stc/index.js.map +1 -1
  107. package/dist/test/imports.test.d.ts.map +1 -1
  108. package/dist/test/jsdoc.test.d.ts +2 -0
  109. package/dist/test/jsdoc.test.d.ts.map +1 -0
  110. package/dist/test/member-chain.test.d.ts +2 -0
  111. package/dist/test/member-chain.test.d.ts.map +1 -0
  112. package/dist/test/utils.d.ts +2 -2
  113. package/dist/test/utils.d.ts.map +1 -1
  114. package/dist/test/values.test.d.ts.map +1 -1
  115. package/dist/tsconfig.tsbuildinfo +1 -1
  116. package/package.json +4 -6
  117. package/src/components/ArrayExpression.tsx +18 -32
  118. package/src/components/BarrelFile.tsx +7 -13
  119. package/src/components/ClassDeclaration.tsx +33 -28
  120. package/src/components/CommaList.tsx +23 -0
  121. package/src/components/Declaration.tsx +7 -3
  122. package/src/components/EnumDeclaration.tsx +21 -14
  123. package/src/components/EnumMember.tsx +7 -4
  124. package/src/components/ExportStatement.tsx +6 -1
  125. package/src/components/FunctionCallExpression.tsx +18 -9
  126. package/src/components/FunctionDeclaration.tsx +170 -55
  127. package/src/components/ImportStatement.tsx +6 -9
  128. package/src/components/Interface.tsx +20 -13
  129. package/src/components/JSDoc.tsx +28 -0
  130. package/src/components/JSDocComment.tsx +23 -0
  131. package/src/components/JSDocExample.tsx +30 -0
  132. package/src/components/JSDocParagraph.tsx +35 -0
  133. package/src/components/MemberChainExpression.tsx +59 -0
  134. package/src/components/ObjectExpression.tsx +53 -48
  135. package/src/components/PackageDirectory.tsx +11 -9
  136. package/src/components/PackageJson.tsx +9 -6
  137. package/src/components/SourceFile.tsx +15 -8
  138. package/src/components/TsConfigJson.tsx +5 -3
  139. package/src/components/TypeDeclaration.tsx +5 -3
  140. package/src/components/ValueExpression.tsx +7 -5
  141. package/src/components/VarDeclaration.tsx +11 -5
  142. package/src/components/index.ts +2 -1
  143. package/src/components/stc/index.ts +1 -1
  144. package/temp/api.json +618 -208
  145. package/test/array.test.tsx +28 -7
  146. package/test/basic.test.tsx +26 -21
  147. package/test/class.test.tsx +65 -53
  148. package/test/enum.test.tsx +18 -13
  149. package/test/externals.test.tsx +6 -7
  150. package/test/function-call-expression.test.tsx +39 -17
  151. package/test/function-declaration.test.tsx +96 -78
  152. package/test/imports.test.tsx +90 -65
  153. package/test/interface.test.tsx +29 -19
  154. package/test/jsdoc.test.tsx +154 -0
  155. package/test/member-chain.test.tsx +47 -0
  156. package/test/name-policy.test.tsx +33 -26
  157. package/test/package-external.test.tsx +8 -4
  158. package/test/package.test.tsx +1 -2
  159. package/test/reference.test.tsx +2 -6
  160. package/test/utils.tsx +3 -1
  161. package/test/value-expression.test.tsx +2 -6
  162. package/test/values.test.tsx +67 -73
  163. package/test/var-declaration.test.tsx +11 -5
  164. package/test/vitest.d.ts +6 -1
  165. package/tsconfig.json +8 -1
  166. package/dist/src/components/Block.d.ts +0 -6
  167. package/dist/src/components/Block.d.ts.map +0 -1
  168. package/dist/src/components/Block.js +0 -11
  169. package/dist/src/components/Block.js.map +0 -1
  170. package/src/components/Block.tsx +0 -12
@@ -1,6 +1,7 @@
1
1
  import { Props, refkey } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { describe, expect, it } from "vitest";
4
+ import { StatementList } from "../../core/src/components/StatementList.jsx";
4
5
  import {
5
6
  FunctionDeclaration,
6
7
  ParameterDescriptor,
@@ -10,55 +11,36 @@ import { toSourceText } from "./utils.js";
10
11
 
11
12
  it("works", () => {
12
13
  expect(toSourceText(<FunctionDeclaration name="foo" />)).toBe(d`
13
- function foo() {
14
-
15
- }
14
+ function foo() {}
16
15
  `);
17
16
  });
18
17
 
19
18
  it("can be exported", () => {
20
19
  expect(toSourceText(<FunctionDeclaration export name="foo" />)).toBe(d`
21
- export function foo() {
22
-
23
- }
24
- `);
25
- });
26
-
27
- it("can be a default export", () => {
28
- expect(toSourceText(<FunctionDeclaration export default name="foo" />))
29
- .toBe(d`
30
- export default function foo() {
31
-
32
- }
20
+ export function foo() {}
33
21
  `);
34
22
  });
35
23
 
36
24
  it("can be a default export", () => {
37
25
  expect(toSourceText(<FunctionDeclaration export default name="foo" />))
38
26
  .toBe(d`
39
- export default function foo() {
40
-
41
- }
27
+ export default function foo() {}
42
28
  `);
43
29
  });
44
30
 
45
31
  it("can be an async function", () => {
46
32
  expect(toSourceText(<FunctionDeclaration async export name="foo" />)).toBe(d`
47
- export async function foo() {
48
-
49
- }
33
+ export async function foo() {}
50
34
  `);
51
35
  });
52
36
 
53
37
  it("can be an async function with returnType", () => {
54
38
  expect(
55
39
  toSourceText(
56
- <FunctionDeclaration async export name="foo" returnType="Foo"/>,
40
+ <FunctionDeclaration async export name="foo" returnType="Foo" />,
57
41
  ),
58
42
  ).toBe(d`
59
- export async function foo(): Promise<Foo> {
60
-
61
- }
43
+ export async function foo(): Promise<Foo> {}
62
44
  `);
63
45
  });
64
46
 
@@ -68,92 +50,126 @@ it("can be an async function with returnType element", () => {
68
50
  }
69
51
  expect(
70
52
  toSourceText(
71
- <FunctionDeclaration async export name="foo" returnType={<Foo />}/>,
53
+ <FunctionDeclaration async export name="foo" returnType={<Foo />} />,
72
54
  ),
73
55
  ).toBe(d`
74
- export async function foo(): Promise<Foo> {
75
-
76
- }
56
+ export async function foo(): Promise<Foo> {}
77
57
  `);
78
58
  });
79
59
 
80
60
  it("supports parameters by element", () => {
81
- const decl =
61
+ const decl = (
82
62
  <FunctionDeclaration name="foo">
83
- return a + b;
84
- <FunctionDeclaration.Parameters>a, b</FunctionDeclaration.Parameters>
85
- </FunctionDeclaration>;
86
-
87
- // there is an extra line break here because the return statement ends in a
88
- // line break, which is not significant but we don't know that at transform
89
- // time. Ideally the renderer would take care of this - I think it's the same
90
- // problem as handling removal of linebreaks when the only contents of a line
91
- // are something undefined, e.g. how
92
- //
93
- // <>a
94
- // {undefined}
95
- // b</>
96
- //
97
- // should render to
98
- //
99
- // a
100
- // b
101
- //
102
- // so in principle this can be fixed later.
63
+ return a + b;
64
+ <FunctionDeclaration.Parameters>a, b</FunctionDeclaration.Parameters>
65
+ </FunctionDeclaration>
66
+ );
67
+
103
68
  expect(toSourceText(decl)).toBe(d`
104
69
  function foo(a, b) {
105
70
  return a + b;
106
-
107
71
  }
108
72
  `);
109
73
  });
110
74
 
75
+ it("supports type parameters by descriptor object", () => {
76
+ const decl = (
77
+ <FunctionDeclaration
78
+ name="foo"
79
+ typeParameters={{ a: "any", b: "any" }}
80
+ ></FunctionDeclaration>
81
+ );
82
+
83
+ expect(toSourceText(decl)).toBe(d`
84
+ function foo<a extends any, b extends any>() {}
85
+ `);
86
+ });
87
+
88
+ it("supports type parameters by descriptor array", () => {
89
+ const decl = (
90
+ <FunctionDeclaration
91
+ name="foo"
92
+ typeParameters={["a", "b"]}
93
+ ></FunctionDeclaration>
94
+ );
95
+
96
+ expect(toSourceText(decl)).toBe(d`
97
+ function foo<a, b>() {}
98
+ `);
99
+ });
100
+
101
+ it("supports type parameters by element", () => {
102
+ const decl = (
103
+ <FunctionDeclaration name="foo">
104
+ <FunctionDeclaration.TypeParameters>
105
+ a, b
106
+ </FunctionDeclaration.TypeParameters>
107
+ </FunctionDeclaration>
108
+ );
109
+
110
+ expect(toSourceText(decl)).toBe(d`
111
+ function foo<a, b>() {}
112
+ `);
113
+ });
114
+
111
115
  describe("symbols", () => {
112
116
  it("creates a nested scope", () => {
113
117
  const innerRefkey = refkey();
114
118
  const outerRefkey = refkey();
115
- const decl =
116
- <>
119
+ const decl = (
120
+ <StatementList>
117
121
  <FunctionDeclaration name="foo">
118
- {innerRefkey}
119
- <VarDeclaration name="refme" refkey={innerRefkey}>1</VarDeclaration>
120
- </FunctionDeclaration>;
121
- <VarDeclaration name="refme" refkey={outerRefkey}>2</VarDeclaration>
122
+ <StatementList>
123
+ {innerRefkey}
124
+ <VarDeclaration name="refme" refkey={innerRefkey}>
125
+ 1
126
+ </VarDeclaration>
127
+ </StatementList>
128
+ </FunctionDeclaration>
129
+ <VarDeclaration name="refme" refkey={outerRefkey}>
130
+ 2
131
+ </VarDeclaration>
122
132
  {outerRefkey}
123
- </>;
133
+ </StatementList>
134
+ );
124
135
  expect(toSourceText(decl)).toBe(d`
125
136
  function foo() {
126
- refme
137
+ refme;
127
138
  const refme = 1;
128
139
  };
129
140
  const refme = 2;
130
- refme
141
+ refme;
131
142
  `);
132
143
  });
133
144
 
134
145
  it("throws an error when trying to access a symbol in a nested function scope", () => {
135
146
  const innerRefkey = refkey();
136
- const decl =
147
+ const decl = (
137
148
  <>
138
149
  <FunctionDeclaration name="foo">
139
- <VarDeclaration name="refme" refkey={innerRefkey}>1</VarDeclaration>
140
- </FunctionDeclaration>;
141
- {innerRefkey}
142
- </>;
150
+ <VarDeclaration name="refme" refkey={innerRefkey}>
151
+ 1
152
+ </VarDeclaration>
153
+ </FunctionDeclaration>
154
+ ;{innerRefkey}
155
+ </>
156
+ );
143
157
  expect(() => toSourceText(decl)).toThrow(/Cannot reference a symbol/);
144
158
  });
145
159
 
146
160
  it("creates symbols for parameters", () => {
147
161
  const rk = refkey();
148
162
 
149
- const decl =
163
+ const decl = (
150
164
  <>
151
- <FunctionDeclaration name="foo" parameters={{sym: { type: "any", refkey: rk }}}>
152
- <FunctionDeclaration name="bar">
153
- {rk}
154
- </FunctionDeclaration>
165
+ <FunctionDeclaration
166
+ name="foo"
167
+ parameters={{ sym: { type: "any", refkey: rk } }}
168
+ >
169
+ <FunctionDeclaration name="bar">{rk}</FunctionDeclaration>
155
170
  </FunctionDeclaration>
156
- </>;
171
+ </>
172
+ );
157
173
 
158
174
  expect(toSourceText(decl)).toBe(d`
159
175
  function foo(sym: any) {
@@ -165,12 +181,13 @@ describe("symbols", () => {
165
181
  });
166
182
 
167
183
  it("creates symbols for parameters and addresses conflicts", () => {
168
- const decl =
184
+ const decl = (
169
185
  <>
170
- <FunctionDeclaration name="foo" parameters={{conflict: "any"}}>
171
- <VarDeclaration name="conflict">1</VarDeclaration>
186
+ <FunctionDeclaration name="foo" parameters={{ conflict: "any" }}>
187
+ <VarDeclaration name="conflict">1</VarDeclaration>;
172
188
  </FunctionDeclaration>
173
- </>;
189
+ </>
190
+ );
174
191
 
175
192
  expect(toSourceText(decl)).toBe(d`
176
193
  function foo(conflict: any) {
@@ -185,12 +202,13 @@ describe("symbols", () => {
185
202
  type: "any",
186
203
  optional: true,
187
204
  };
188
- const decl =
205
+ const decl = (
189
206
  <>
190
- <FunctionDeclaration name="foo" parameters={{foo: paramDesc}}>
207
+ <FunctionDeclaration name="foo" parameters={{ foo: paramDesc }}>
191
208
  console.log(foo);
192
209
  </FunctionDeclaration>
193
- </>;
210
+ </>
211
+ );
194
212
 
195
213
  expect(toSourceText(decl)).toBe(d`
196
214
  function foo(foo?: any) {
@@ -1,4 +1,10 @@
1
- import { Output, SourceDirectory, refkey, render } from "@alloy-js/core";
1
+ import {
2
+ Output,
3
+ SourceDirectory,
4
+ StatementList,
5
+ refkey,
6
+ render,
7
+ } from "@alloy-js/core";
2
8
  import "@alloy-js/core/testing";
3
9
  import { it } from "vitest";
4
10
  import * as ts from "../src/components/index.js";
@@ -10,7 +16,12 @@ it("works with default imports", () => {
10
16
  const res = render(
11
17
  <Output>
12
18
  <ts.SourceFile path="test1.ts">
13
- <ts.FunctionDeclaration export default name="asdf" refkey={refkey("test")} />
19
+ <ts.FunctionDeclaration
20
+ export
21
+ default
22
+ name="asdf"
23
+ refkey={refkey("test")}
24
+ />
14
25
  </ts.SourceFile>
15
26
 
16
27
  <ts.SourceFile path="test2.ts">
@@ -21,9 +32,7 @@ it("works with default imports", () => {
21
32
 
22
33
  assertFileContents(res, {
23
34
  "test1.ts": `
24
- export default function asdf() {
25
-
26
- }
35
+ export default function asdf() {}
27
36
  `,
28
37
  "test2.ts": `
29
38
  import asdf from "./test1.js";
@@ -48,9 +57,7 @@ it("works with named imports", () => {
48
57
 
49
58
  assertFileContents(res, {
50
59
  "test1.ts": `
51
- export function test() {
52
-
53
- }
60
+ export function test() {}
54
61
  `,
55
62
  "test2.ts": `
56
63
  import { test } from "./test1.js";
@@ -65,11 +72,12 @@ it("works with default and named imports", () => {
65
72
  <Output>
66
73
  <ts.SourceFile path="test1.ts">
67
74
  <ts.FunctionDeclaration export default name="test1" />
75
+ <hbr />
68
76
  <ts.FunctionDeclaration export name="test2" />
69
77
  </ts.SourceFile>
70
78
 
71
79
  <ts.SourceFile path="test2.ts">
72
- const v1 = <Reference refkey={refkey("test1")} />;
80
+ const v1 = <Reference refkey={refkey("test1")} />;<hbr />
73
81
  const v2 = <Reference refkey={refkey("test2")} />;
74
82
  </ts.SourceFile>
75
83
  </Output>,
@@ -77,12 +85,8 @@ it("works with default and named imports", () => {
77
85
 
78
86
  assertFileContents(res, {
79
87
  "test1.ts": `
80
- export default function test1() {
81
-
82
- }
83
- export function test2() {
84
-
85
- }
88
+ export default function test1() {}
89
+ export function test2() {}
86
90
  `,
87
91
  "test2.ts": `
88
92
  import test1, { test2 } from "./test1.js";
@@ -98,40 +102,51 @@ it("works with default and named imports and name conflicts", () => {
98
102
  <Output nameConflictResolver={tsNameConflictResolver}>
99
103
  <ts.SourceFile path="test1.ts">
100
104
  <ts.FunctionDeclaration export default name="test1" />
105
+ <br />
101
106
  <ts.FunctionDeclaration export name="test2" />
102
107
  </ts.SourceFile>
103
108
 
104
109
  <ts.SourceFile path="test2.ts">
105
- <ts.FunctionDeclaration export default name="test1" refkey={refkey("test3")} />
110
+ <ts.FunctionDeclaration
111
+ export
112
+ default
113
+ name="test1"
114
+ refkey={refkey("test3")}
115
+ />
116
+ <br />
106
117
  <ts.FunctionDeclaration export name="test2" refkey={refkey("test4")} />
107
118
  </ts.SourceFile>
108
119
 
109
120
  <ts.SourceFile path="test3.ts">
110
- const v1 = <Reference refkey={refkey("test1")} />;
111
- const v1_1 = <Reference refkey={refkey("test2")}/>;
112
- const v2 = <Reference refkey={refkey("test3")} />;
113
- const v3 = <Reference refkey={refkey("test3")}/>;
114
- const v4 = <Reference refkey={refkey("test4")} />;
121
+ <StatementList>
122
+ <>
123
+ const v1 = <Reference refkey={refkey("test1")} />
124
+ </>
125
+ <>
126
+ const v1_1 = <Reference refkey={refkey("test2")} />
127
+ </>
128
+ <>
129
+ const v2 = <Reference refkey={refkey("test3")} />
130
+ </>
131
+ <>
132
+ const v3 = <Reference refkey={refkey("test3")} />
133
+ </>
134
+ <>
135
+ const v4 = <Reference refkey={refkey("test4")} />
136
+ </>
137
+ </StatementList>
115
138
  </ts.SourceFile>
116
139
  </Output>,
117
140
  );
118
141
 
119
142
  assertFileContents(res, {
120
143
  "test1.ts": `
121
- export default function test1() {
122
-
123
- }
124
- export function test2() {
125
-
126
- }
144
+ export default function test1() {}
145
+ export function test2() {}
127
146
  `,
128
147
  "test2.ts": `
129
- export default function test1() {
130
-
131
- }
132
- export function test2() {
133
-
134
- }
148
+ export default function test1() {}
149
+ export function test2() {}
135
150
  `,
136
151
  "test3.ts": `
137
152
  import test1_1, { test2 as test2_1 } from "./test1.js";
@@ -151,21 +166,43 @@ it("works with default and named imports and name conflicts and references in ne
151
166
  <Output nameConflictResolver={tsNameConflictResolver}>
152
167
  <ts.SourceFile path="test1.ts">
153
168
  <ts.FunctionDeclaration export default name="test1" />
169
+ <hbr />
154
170
  <ts.FunctionDeclaration export name="test2" />
155
171
  </ts.SourceFile>
156
172
 
157
173
  <ts.SourceFile path="test2.ts">
158
- <ts.FunctionDeclaration export default name="test1" refkey={refkey("test3")} />
174
+ <ts.FunctionDeclaration
175
+ export
176
+ default
177
+ name="test1"
178
+ refkey={refkey("test3")}
179
+ />
180
+ <hbr />
159
181
  <ts.FunctionDeclaration export name="test2" refkey={refkey("test4")} />
160
182
  </ts.SourceFile>
161
183
 
162
184
  <ts.SourceFile path="test3.ts">
163
- const v1 = <Reference refkey={refkey("test1")} />;
164
- const v1_1 = <Reference refkey={refkey("test2")}/>;
185
+ <StatementList>
186
+ <>
187
+ const v1 = <Reference refkey={refkey("test1")} />
188
+ </>
189
+ <>
190
+ const v1_1 = <Reference refkey={refkey("test2")} />
191
+ </>
192
+ </StatementList>
193
+ <hbr />
165
194
  <ts.FunctionDeclaration name="foo">
166
- const v2 = <Reference refkey={refkey("test3")} />;
167
- const v3 = <Reference refkey={refkey("test3")}/>;
168
- const v4 = <Reference refkey={refkey("test4")} />;
195
+ <StatementList>
196
+ <>
197
+ const v2 = <Reference refkey={refkey("test3")} />
198
+ </>
199
+ <>
200
+ const v3 = <Reference refkey={refkey("test3")} />
201
+ </>
202
+ <>
203
+ const v4 = <Reference refkey={refkey("test4")} />
204
+ </>
205
+ </StatementList>
169
206
  </ts.FunctionDeclaration>
170
207
  </ts.SourceFile>
171
208
  </Output>,
@@ -173,20 +210,12 @@ it("works with default and named imports and name conflicts and references in ne
173
210
 
174
211
  assertFileContents(res, {
175
212
  "test1.ts": `
176
- export default function test1() {
177
-
178
- }
179
- export function test2() {
180
-
181
- }
213
+ export default function test1() {}
214
+ export function test2() {}
182
215
  `,
183
216
  "test2.ts": `
184
- export default function test1() {
185
-
186
- }
187
- export function test2() {
188
-
189
- }
217
+ export default function test1() {}
218
+ export function test2() {}
190
219
  `,
191
220
  "test3.ts": `
192
221
  import test1_1, { test2 as test2_1 } from "./test1.js";
@@ -209,12 +238,13 @@ it("works with imports from different directories", () => {
209
238
  <SourceDirectory path="src">
210
239
  <ts.SourceFile path="test1.ts">
211
240
  <ts.FunctionDeclaration export name="test" />
212
- const v = <Reference refkey={refkey("test2")} />
241
+ <hbr />
242
+ const v = <Reference refkey={refkey("test2")} />;
213
243
  </ts.SourceFile>
214
244
  </SourceDirectory>
215
245
 
216
246
  <ts.SourceFile path="test2.ts">
217
- const v = <Reference refkey={refkey("test")} />;
247
+ const v = <Reference refkey={refkey("test")} />;<hbr />
218
248
  <ts.FunctionDeclaration export name="test2" />
219
249
  </ts.SourceFile>
220
250
  </Output>,
@@ -224,18 +254,14 @@ it("works with imports from different directories", () => {
224
254
  "src/test1.ts": `
225
255
  import { test2 } from "../test2.js";
226
256
 
227
- export function test() {
228
-
229
- }
230
- const v = test2
257
+ export function test() {}
258
+ const v = test2;
231
259
  `,
232
260
  "test2.ts": `
233
261
  import { test } from "./src/test1.js";
234
262
 
235
263
  const v = test;
236
- export function test2() {
237
-
238
- }
264
+ export function test2() {}
239
265
  `,
240
266
  });
241
267
  });
@@ -246,12 +272,13 @@ it("handles conflicts with local declarations", () => {
246
272
  <SourceDirectory path="src">
247
273
  <ts.SourceFile path="test1.ts">
248
274
  <ts.FunctionDeclaration export name="test" />
249
- const v = <Reference refkey={refkey("test2")} />
275
+ <hbr />
276
+ const v = <Reference refkey={refkey("test2")} />;
250
277
  </ts.SourceFile>
251
278
  </SourceDirectory>
252
279
 
253
280
  <ts.SourceFile path="test2.ts">
254
- const v = <Reference refkey={refkey("test")} />;
281
+ const v = <Reference refkey={refkey("test")} />;<hbr />
255
282
  <ts.FunctionDeclaration export name="test" />
256
283
  </ts.SourceFile>
257
284
  </Output>,
@@ -262,9 +289,7 @@ it("handles conflicts with local declarations", () => {
262
289
  import { test as test_1 } from "./src/test1.js";
263
290
 
264
291
  const v = test_1;
265
- export function test() {
266
-
267
- }
292
+ export function test() {}
268
293
  `,
269
294
  });
270
295
  });
@@ -1,4 +1,4 @@
1
- import { NamePolicyContext, refkey } from "@alloy-js/core";
1
+ import { NamePolicyContext, refkey, 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";
@@ -10,9 +10,7 @@ import { toSourceText } from "./utils.js";
10
10
  it("declares interfaces", () => {
11
11
  const res = toSourceText(<ts.InterfaceDeclaration name="Foo" />);
12
12
  expect(res).toEqual(d`
13
- interface Foo {
14
-
15
- }
13
+ interface Foo {}
16
14
  `);
17
15
  });
18
16
 
@@ -21,9 +19,7 @@ it("accepts export and default", () => {
21
19
  <ts.InterfaceDeclaration name="Foo" export default />,
22
20
  );
23
21
  expect(res).toEqual(d`
24
- export default interface Foo {
25
-
26
- }
22
+ export default interface Foo {}
27
23
  `);
28
24
  });
29
25
 
@@ -33,18 +29,21 @@ it("creates extends", () => {
33
29
  );
34
30
 
35
31
  expect(res).toEqual(d`
36
- interface Foo extends string {
37
-
38
- }
32
+ interface Foo extends string {}
39
33
  `);
40
34
  });
41
35
 
42
36
  it("can create members", () => {
43
37
  const res = toSourceText(
44
38
  <ts.InterfaceDeclaration name="Foo">
45
- <ts.InterfaceMember name="member" type="string" />;
46
- <ts.InterfaceMember name="circular" type={<Reference refkey={refkey("Foo")} />} />;
47
- <ts.InterfaceMember indexer="str: string" type="number" />;
39
+ <StatementList>
40
+ <ts.InterfaceMember name="member" type="string" />
41
+ <ts.InterfaceMember
42
+ name="circular"
43
+ type={<Reference refkey={refkey("Foo")} />}
44
+ />
45
+ <ts.InterfaceMember indexer="str: string" type="number" />
46
+ </StatementList>
48
47
  </ts.InterfaceDeclaration>,
49
48
  );
50
49
 
@@ -60,9 +59,15 @@ it("can create members", () => {
60
59
  it("can create optional members", () => {
61
60
  const res = toSourceText(
62
61
  <ts.InterfaceDeclaration name="Foo">
63
- <ts.InterfaceMember name="member" type="string" />;
64
- <ts.InterfaceMember optional name="circular" type={<Reference refkey={refkey("Foo")} />} />;
65
- <ts.InterfaceMember indexer="str: string" type="number" />;
62
+ <StatementList>
63
+ <ts.InterfaceMember name="member" type="string" />
64
+ <ts.InterfaceMember
65
+ optional
66
+ name="circular"
67
+ type={<Reference refkey={refkey("Foo")} />}
68
+ />
69
+ <ts.InterfaceMember indexer="str: string" type="number" />
70
+ </StatementList>
66
71
  </ts.InterfaceDeclaration>,
67
72
  );
68
73
 
@@ -78,9 +83,14 @@ it("can create optional members", () => {
78
83
  it("can create readonly members", () => {
79
84
  const res = toSourceText(
80
85
  <ts.InterfaceDeclaration name="Foo">
81
- <ts.InterfaceMember readonly name="member" type="string" />;
82
- <ts.InterfaceMember name="circular" type={<Reference refkey={refkey("Foo")} />} />;
83
- <ts.InterfaceMember indexer="str: string" type="number" />;
86
+ <StatementList>
87
+ <ts.InterfaceMember readonly name="member" type="string" />
88
+ <ts.InterfaceMember
89
+ name="circular"
90
+ type={<Reference refkey={refkey("Foo")} />}
91
+ />
92
+ <ts.InterfaceMember indexer="str: string" type="number" />
93
+ </StatementList>
84
94
  </ts.InterfaceDeclaration>,
85
95
  );
86
96