@typespec/emitter-framework 0.3.0-dev.2 → 0.3.0-dev.4

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 (64) hide show
  1. package/dist/src/testing/scenario-test/snippet-extractor.d.ts +2 -2
  2. package/dist/src/testing/scenario-test/snippet-extractor.d.ts.map +1 -1
  3. package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
  4. package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -1
  5. package/dist/src/typescript/components/array-expression.d.ts +2 -1
  6. package/dist/src/typescript/components/array-expression.d.ts.map +1 -1
  7. package/dist/src/typescript/components/array-expression.js +3 -2
  8. package/dist/src/typescript/components/array-expression.js.map +1 -1
  9. package/dist/src/typescript/components/class-method.d.ts.map +1 -1
  10. package/dist/src/typescript/components/class-method.js.map +1 -1
  11. package/dist/src/typescript/components/enum-declaration.d.ts +4 -4
  12. package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
  13. package/dist/src/typescript/components/enum-declaration.js +19 -15
  14. package/dist/src/typescript/components/enum-declaration.js.map +1 -1
  15. package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
  16. package/dist/src/typescript/components/function-declaration.js +1 -1
  17. package/dist/src/typescript/components/function-declaration.js.map +1 -1
  18. package/dist/src/typescript/components/interface-declaration.d.ts +3 -3
  19. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  20. package/dist/src/typescript/components/interface-declaration.js +14 -7
  21. package/dist/src/typescript/components/interface-declaration.js.map +1 -1
  22. package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
  23. package/dist/src/typescript/components/interface-member.js.map +1 -1
  24. package/dist/src/typescript/components/record-expression.js.map +1 -1
  25. package/dist/src/typescript/components/static-serializers.d.ts.map +1 -1
  26. package/dist/src/typescript/components/static-serializers.js +8 -8
  27. package/dist/src/typescript/components/static-serializers.js.map +1 -1
  28. package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
  29. package/dist/src/typescript/components/type-alias-declaration.js +1 -1
  30. package/dist/src/typescript/components/type-alias-declaration.js.map +1 -1
  31. package/dist/src/typescript/components/type-declaration.js.map +1 -1
  32. package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
  33. package/dist/src/typescript/components/type-expression.js +12 -5
  34. package/dist/src/typescript/components/type-expression.js.map +1 -1
  35. package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
  36. package/dist/src/typescript/components/type-transform.js +29 -27
  37. package/dist/src/typescript/components/type-transform.js.map +1 -1
  38. package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
  39. package/dist/src/typescript/components/union-declaration.js.map +1 -1
  40. package/dist/src/typescript/components/union-expression.d.ts +2 -1
  41. package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
  42. package/dist/src/typescript/components/union-expression.js +23 -24
  43. package/dist/src/typescript/components/union-expression.js.map +1 -1
  44. package/package.json +7 -7
  45. package/src/testing/scenario-test/snippet-extractor.ts +4 -3
  46. package/src/typescript/components/array-expression.tsx +2 -3
  47. package/src/typescript/components/class-method.tsx +14 -9
  48. package/src/typescript/components/enum-declaration.tsx +31 -28
  49. package/src/typescript/components/function-declaration.tsx +8 -4
  50. package/src/typescript/components/interface-declaration.tsx +23 -10
  51. package/src/typescript/components/interface-member.tsx +8 -4
  52. package/src/typescript/components/record-expression.tsx +1 -1
  53. package/src/typescript/components/static-serializers.tsx +78 -18
  54. package/src/typescript/components/type-alias-declaration.tsx +6 -4
  55. package/src/typescript/components/type-declaration.tsx +1 -1
  56. package/src/typescript/components/type-expression.tsx +10 -8
  57. package/src/typescript/components/type-transform.tsx +83 -46
  58. package/src/typescript/components/union-declaration.tsx +4 -2
  59. package/src/typescript/components/union-expression.tsx +25 -22
  60. package/test/typescript/components/enum-declaration.test.tsx +19 -11
  61. package/test/typescript/components/interface-declaration.test.tsx +41 -40
  62. package/test/typescript/components/member-expression.test.tsx +25 -16
  63. package/test/typescript/components/type-transform.test.tsx +21 -6
  64. package/test/typescript/components/union-declaration.test.tsx +6 -10
@@ -1,4 +1,4 @@
1
- import { refkey } from "@alloy-js/core";
1
+ import { List, refkey, StatementList } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { Enum, Union } from "@typespec/compiler";
4
4
  import { describe, expect, it } from "vitest";
@@ -61,11 +61,15 @@ describe("Typescript Enum Declaration", () => {
61
61
 
62
62
  const output = await getEmitOutput(code, (program) => {
63
63
  const Foo = program.resolveTypeReference("Foo")[0]! as Enum;
64
- return <>
65
- <EnumDeclaration type={Foo} />
66
- {refkey(Foo)};
67
- {refkey(Foo.members.get("one"))};
68
- </>;
64
+ return (
65
+ <List hardline>
66
+ <EnumDeclaration type={Foo} />
67
+ <StatementList>
68
+ {refkey(Foo)}
69
+ {refkey(Foo.members.get("one"))}
70
+ </StatementList>
71
+ </List>
72
+ );
69
73
  });
70
74
 
71
75
  expect(output).toBe(d`
@@ -90,11 +94,15 @@ describe("Typescript Enum Declaration", () => {
90
94
 
91
95
  const output = await getEmitOutput(code, (program) => {
92
96
  const Foo = program.resolveTypeReference("Foo")[0]! as Union;
93
- return <>
94
- <EnumDeclaration type={Foo} />
95
- {refkey(Foo)};
96
- {refkey(Foo.variants.get("one"))};
97
- </>;
97
+ return (
98
+ <List hardline>
99
+ <EnumDeclaration type={Foo} />
100
+ <StatementList>
101
+ {refkey(Foo)}
102
+ {refkey(Foo.variants.get("one"))}
103
+ </StatementList>
104
+ </List>
105
+ );
98
106
  });
99
107
 
100
108
  expect(output).toBe(d`
@@ -1,6 +1,6 @@
1
1
  import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
2
2
 
3
- import { mapJoin, Output, render } from "@alloy-js/core";
3
+ import { For, List, Output, render } from "@alloy-js/core";
4
4
  import { SourceFile } from "@alloy-js/typescript";
5
5
  import { Namespace } from "@typespec/compiler";
6
6
  import { format } from "prettier";
@@ -25,12 +25,14 @@ describe("Typescript Interface", () => {
25
25
 
26
26
  const res = render(
27
27
  <Output>
28
- <SourceFile path="test.ts">
28
+ <SourceFile path="test.ts">
29
+ <List hardline>
29
30
  {models.map((model) => (
30
31
  <InterfaceDeclaration export type={model} />
31
32
  ))}
32
- </SourceFile>
33
- </Output>,
33
+ </List>
34
+ </SourceFile>
35
+ </Output>,
34
36
  );
35
37
 
36
38
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -62,12 +64,12 @@ describe("Typescript Interface", () => {
62
64
 
63
65
  const res = render(
64
66
  <Output>
65
- <SourceFile path="test.ts">
66
- {mapJoin(models, (name, model) => (
67
- <InterfaceDeclaration export type={model} />
68
- ))}
69
- </SourceFile>
70
- </Output>,
67
+ <SourceFile path="test.ts">
68
+ <For each={Array.from(models.values())} hardline>
69
+ {(model) => <InterfaceDeclaration export type={model} />}
70
+ </For>
71
+ </SourceFile>
72
+ </Output>,
71
73
  );
72
74
 
73
75
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -96,12 +98,12 @@ describe("Typescript Interface", () => {
96
98
 
97
99
  const res = render(
98
100
  <Output>
99
- <SourceFile path="test.ts">
100
- {mapJoin(models, (name, model) => (
101
- <InterfaceDeclaration export type={model} />
102
- ))}
103
- </SourceFile>
104
- </Output>,
101
+ <SourceFile path="test.ts">
102
+ <For each={Array.from(models.values())} hardline>
103
+ {(model) => <InterfaceDeclaration export type={model} />}
104
+ </For>
105
+ </SourceFile>
106
+ </Output>,
105
107
  );
106
108
 
107
109
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -134,12 +136,12 @@ describe("Typescript Interface", () => {
134
136
 
135
137
  const res = render(
136
138
  <Output>
137
- <SourceFile path="test.ts">
138
- {mapJoin(models, (name, model) => (
139
- <InterfaceDeclaration export type={model} />
140
- ))}
141
- </SourceFile>
142
- </Output>,
139
+ <SourceFile path="test.ts">
140
+ <For each={Array.from(models.values())} hardline>
141
+ {(model) => <InterfaceDeclaration export type={model} />}
142
+ </For>
143
+ </SourceFile>
144
+ </Output>,
143
145
  );
144
146
 
145
147
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -182,12 +184,12 @@ describe("Typescript Interface", () => {
182
184
 
183
185
  const res = render(
184
186
  <Output>
185
- <SourceFile path="test.ts">
186
- {mapJoin(models, (name, model) => (
187
- <InterfaceDeclaration export type={model} />
188
- ))}
189
- </SourceFile>
190
- </Output>,
187
+ <SourceFile path="test.ts">
188
+ <For each={Array.from(models.values())} hardline>
189
+ {(model) => <InterfaceDeclaration export type={model} />}
190
+ </For>
191
+ </SourceFile>
192
+ </Output>,
191
193
  );
192
194
 
193
195
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -229,12 +231,12 @@ describe("Typescript Interface", () => {
229
231
 
230
232
  const res = render(
231
233
  <Output>
232
- <SourceFile path="test.ts">
233
- {models.map((model) => (
234
- <InterfaceDeclaration export type={model} />
235
- ))}
236
- </SourceFile>
237
- </Output>,
234
+ <SourceFile path="test.ts">
235
+ {models.map((model) => (
236
+ <InterfaceDeclaration export type={model} />
237
+ ))}
238
+ </SourceFile>
239
+ </Output>,
238
240
  );
239
241
 
240
242
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -276,10 +278,10 @@ describe("Typescript Interface", () => {
276
278
 
277
279
  const res = render(
278
280
  <Output>
279
- <SourceFile path="test.ts">
280
- <InterfaceDeclaration type={models[0]} />
281
- </SourceFile>
282
- </Output>,
281
+ <SourceFile path="test.ts">
282
+ <InterfaceDeclaration type={models[0]} />
283
+ </SourceFile>
284
+ </Output>,
283
285
  );
284
286
 
285
287
  const testFile = res.contents.find((file) => file.path === "test.ts");
@@ -391,8 +393,7 @@ describe("Typescript Interface", () => {
391
393
  <Output>
392
394
  <SourceFile path="test.ts">
393
395
  <InterfaceDeclaration export name="MyOperations" type={models[0]}>
394
- customProperty: string;
395
- customMethod(): void;
396
+ customProperty: string; customMethod(): void;
396
397
  </InterfaceDeclaration>
397
398
  </SourceFile>
398
399
  </Output>,
@@ -1,3 +1,4 @@
1
+ import * as ay from "@alloy-js/core";
1
2
  import { d } from "@alloy-js/core/testing";
2
3
  import { Enum, Model, Union } from "@typespec/compiler";
3
4
  import { describe, expect, it } from "vitest";
@@ -20,10 +21,12 @@ describe("Typescript Enum Member Expression", () => {
20
21
  `;
21
22
  const output = await getEmitOutput(code, (program) => {
22
23
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
23
- return <>
24
- <EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
25
- <InterfaceDeclaration type={Bar} />
26
- </>;
24
+ return (
25
+ <ay.List hardline>
26
+ <EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
27
+ <InterfaceDeclaration type={Bar} />
28
+ </ay.List>
29
+ );
27
30
  });
28
31
 
29
32
  expect(output).toBe(d`
@@ -52,10 +55,12 @@ describe("Typescript Enum Member Expression", () => {
52
55
  `;
53
56
  const output = await getEmitOutput(code, (program) => {
54
57
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
55
- return <>
56
- <EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
57
- <InterfaceDeclaration type={Bar} />
58
- </>;
58
+ return (
59
+ <ay.List hardline>
60
+ <EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
61
+ <InterfaceDeclaration type={Bar} />
62
+ </ay.List>
63
+ );
59
64
  });
60
65
 
61
66
  expect(output).toBe(d`
@@ -86,10 +91,12 @@ describe("Typescript Union Member Expression", () => {
86
91
  `;
87
92
  const output = await getEmitOutput(code, (program) => {
88
93
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
89
- return <>
90
- <UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
91
- <InterfaceDeclaration type={Bar} />
92
- </>;
94
+ return (
95
+ <ay.List hardline>
96
+ <UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
97
+ <InterfaceDeclaration type={Bar} />
98
+ </ay.List>
99
+ );
93
100
  });
94
101
 
95
102
  expect(output).toBe(d`
@@ -114,10 +121,12 @@ describe("Typescript Union Member Expression", () => {
114
121
  `;
115
122
  const output = await getEmitOutput(code, (program) => {
116
123
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
117
- return <>
118
- <UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
119
- <InterfaceDeclaration type={Bar} />
120
- </>;
124
+ return (
125
+ <ay.List hardline>
126
+ <UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
127
+ <InterfaceDeclaration type={Bar} />
128
+ </ay.List>
129
+ );
121
130
  });
122
131
 
123
132
  expect(output).toBe(d`
@@ -45,7 +45,12 @@ describe.skip("Typescript Type Transform", () => {
45
45
  {code`
46
46
  const wireWidget = {id: "1", birth_year: 1988, color: "blue"};
47
47
  `}
48
- const clientWidget = <ModelTransformExpression type={Widget} target="application" itemPath={["wireWidget"]} />
48
+ const clientWidget ={" "}
49
+ <ModelTransformExpression
50
+ type={Widget}
51
+ target="application"
52
+ itemPath={["wireWidget"]}
53
+ />
49
54
  </SourceFile>
50
55
  </Output>,
51
56
  );
@@ -81,7 +86,12 @@ describe.skip("Typescript Type Transform", () => {
81
86
  {code`
82
87
  const clientWidget = {id: "1", birthYear: 1988, color: "blue"};
83
88
  `}
84
- const wireWidget = <ModelTransformExpression type={Widget} target="transport" itemPath={["clientWidget"]} />
89
+ const wireWidget ={" "}
90
+ <ModelTransformExpression
91
+ type={Widget}
92
+ target="transport"
93
+ itemPath={["clientWidget"]}
94
+ />
85
95
  </SourceFile>
86
96
  </Output>,
87
97
  );
@@ -120,7 +130,12 @@ describe.skip("Typescript Type Transform", () => {
120
130
  {code`
121
131
  const wireWidget = {id: "1", birth_date: "1988-04-29T19:30:00Z", color: "blue"};
122
132
  `}
123
- const clientWidget = <ModelTransformExpression type={Widget} target="application" itemPath={["wireWidget"]} />
133
+ const clientWidget ={" "}
134
+ <ModelTransformExpression
135
+ type={Widget}
136
+ target="application"
137
+ itemPath={["wireWidget"]}
138
+ />
124
139
  </SourceFile>
125
140
  </Output>,
126
141
  );
@@ -329,7 +344,7 @@ describe.skip("Typescript Type Transform", () => {
329
344
  <SourceFile path="test.ts">
330
345
  {code`
331
346
  const clientWidget = {id: "1", my_color: "blue"};
332
- const wireWidget = ${<TypeTransformCall itemPath={["clientWidget"]} type={Widget} collapse={true} target="transport" />}
347
+ const wireWidget = ${(<TypeTransformCall itemPath={["clientWidget"]} type={Widget} collapse={true} target="transport" />)}
333
348
  `}
334
349
  </SourceFile>
335
350
  </Output>,
@@ -366,8 +381,8 @@ describe.skip("Typescript Type Transform", () => {
366
381
  <SourceFile path="test.ts">
367
382
  {code`
368
383
  const wireWidget = {id: "1", my_color: "blue"};
369
- const clientWidget = ${<ts.FunctionCallExpression refkey={getTypeTransformerRefkey(Widget, "application")} args={[<>wireWidget</>]}/>};
370
- const wireWidget2 = ${<ts.FunctionCallExpression refkey={getTypeTransformerRefkey(Widget, "transport")} args={["clientWidget"]}/>};
384
+ const clientWidget = ${(<ts.FunctionCallExpression target={getTypeTransformerRefkey(Widget, "application")} args={[<>wireWidget</>]} />)};
385
+ const wireWidget2 = ${(<ts.FunctionCallExpression target={getTypeTransformerRefkey(Widget, "transport")} args={["clientWidget"]} />)};
371
386
  `}
372
387
  </SourceFile>
373
388
  </Output>,
@@ -13,9 +13,7 @@ describe("Typescript Union Declaration", () => {
13
13
  const res = render(
14
14
  <Output>
15
15
  <SourceFile path="test.ts">
16
- <UnionDeclaration name="MyUnion">
17
- "red" | "blue"
18
- </UnionDeclaration>
16
+ <UnionDeclaration name="MyUnion">"red" | "blue"</UnionDeclaration>
19
17
  </SourceFile>
20
18
  </Output>,
21
19
  );
@@ -105,9 +103,7 @@ describe("Typescript Union Declaration", () => {
105
103
  const res = render(
106
104
  <Output>
107
105
  <SourceFile path="test.ts">
108
- <UnionDeclaration type={union}>
109
- "three"
110
- </UnionDeclaration>
106
+ <UnionDeclaration type={union}>"three"</UnionDeclaration>
111
107
  </SourceFile>
112
108
  </Output>,
113
109
  );
@@ -135,10 +131,10 @@ describe("Typescript Union Declaration", () => {
135
131
 
136
132
  const res = render(
137
133
  <Output>
138
- <SourceFile path="test.ts">
139
- let x: <UnionExpression type={union} /> = "one";
140
- </SourceFile>
141
- </Output>,
134
+ <SourceFile path="test.ts">
135
+ let x: <UnionExpression type={union} /> = "one";
136
+ </SourceFile>
137
+ </Output>,
142
138
  );
143
139
 
144
140
  const testFile = res.contents.find((file) => file.path === "test.ts");