@typespec/emitter-framework 0.10.0-dev.2 → 0.10.0-dev.3

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 (28) hide show
  1. package/dist/src/core/write-output.js +10 -6
  2. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  3. package/dist/src/csharp/components/class/declaration.js +2 -1
  4. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  5. package/dist/src/typescript/components/interface-declaration.js +2 -2
  6. package/dist/src/typescript/components/union/expression.test.js +3 -3
  7. package/dist/test/typescript/components/function-declaration.test.js +31 -112
  8. package/dist/test/typescript/components/interface-declaration.test.js +146 -308
  9. package/dist/test/typescript/components/type-alias-declaration.test.js +17 -75
  10. package/dist/test/typescript/components/type-transform.test.js +32 -83
  11. package/dist/test/typescript/components/value-expression.test.js +3 -6
  12. package/dist/test/typescript/utils.d.ts +7 -0
  13. package/dist/test/typescript/utils.d.ts.map +1 -0
  14. package/dist/test/typescript/utils.js +18 -0
  15. package/dist/test/utils.d.ts.map +1 -1
  16. package/dist/test/utils.js +2 -0
  17. package/package.json +7 -7
  18. package/src/core/write-output.ts +10 -6
  19. package/src/csharp/components/class/declaration.tsx +2 -1
  20. package/src/typescript/components/interface-declaration.tsx +3 -3
  21. package/src/typescript/components/union/expression.test.tsx +5 -5
  22. package/test/typescript/components/function-declaration.test.tsx +31 -121
  23. package/test/typescript/components/interface-declaration.test.tsx +123 -342
  24. package/test/typescript/components/type-alias-declaration.test.tsx +17 -76
  25. package/test/typescript/components/type-transform.test.tsx +32 -93
  26. package/test/typescript/components/value-expression.test.tsx +4 -12
  27. package/test/typescript/utils.tsx +12 -0
  28. package/test/utils.ts +2 -1
@@ -1,11 +1,8 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { render } from "@alloy-js/core";
3
2
  import { SourceFile } from "@alloy-js/typescript";
4
- import { format } from "prettier";
5
- import { assert, describe, expect, it } from "vitest";
3
+ import { describe, expect, it } from "vitest";
6
4
  import { Output } from "../../../src/core/components/output.js";
7
5
  import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.js";
8
- import { assertFileContents } from "../../utils.js";
9
6
  import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
10
7
  describe("Typescript Type Alias Declaration", () => {
11
8
  describe("Type Alias bound to Typespec Scalar", () => {
@@ -17,7 +14,7 @@ describe("Typescript Type Alias Declaration", () => {
17
14
  `);
18
15
  const [namespace] = program.resolveTypeReference("DemoService");
19
16
  const scalar = Array.from(namespace.scalars.values())[0];
20
- const res = render(_$createComponent(Output, {
17
+ expect(_$createComponent(Output, {
21
18
  program: program,
22
19
  get children() {
23
20
  return _$createComponent(SourceFile, {
@@ -29,16 +26,7 @@ describe("Typescript Type Alias Declaration", () => {
29
26
  }
30
27
  });
31
28
  }
32
- }));
33
- const testFile = res.contents.find(file => file.path === "test.ts");
34
- assert(testFile, "test.ts file not rendered");
35
- const actualContent = await format(testFile.contents, {
36
- parser: "typescript"
37
- });
38
- const expectedContent = await format(`type MyDate = Date;`, {
39
- parser: "typescript"
40
- });
41
- expect(actualContent).toBe(expectedContent);
29
+ })).toRenderTo(`type MyDate = Date;`);
42
30
  });
43
31
  it("creates a type alias declaration with JSDoc", async () => {
44
32
  const program = await getProgram(`
@@ -50,7 +38,7 @@ describe("Typescript Type Alias Declaration", () => {
50
38
  `);
51
39
  const [namespace] = program.resolveTypeReference("DemoService");
52
40
  const scalar = Array.from(namespace.scalars.values())[0];
53
- const res = render(_$createComponent(Output, {
41
+ expect(_$createComponent(Output, {
54
42
  program: program,
55
43
  get children() {
56
44
  return _$createComponent(SourceFile, {
@@ -62,20 +50,11 @@ describe("Typescript Type Alias Declaration", () => {
62
50
  }
63
51
  });
64
52
  }
65
- }));
66
- const testFile = res.contents.find(file => file.path === "test.ts");
67
- assert(testFile, "test.ts file not rendered");
68
- const actualContent = await format(testFile.contents, {
69
- parser: "typescript"
70
- });
71
- const expectedContent = await format(`
53
+ })).toRenderTo(`
72
54
  /**
73
55
  * Type to represent a date
74
56
  */
75
- type MyDate = Date;`, {
76
- parser: "typescript"
77
- });
78
- expect(actualContent).toBe(expectedContent);
57
+ type MyDate = Date;`);
79
58
  });
80
59
  it("can override JSDoc", async () => {
81
60
  const program = await getProgram(`
@@ -87,7 +66,7 @@ describe("Typescript Type Alias Declaration", () => {
87
66
  `);
88
67
  const [namespace] = program.resolveTypeReference("DemoService");
89
68
  const scalar = Array.from(namespace.scalars.values())[0];
90
- const res = render(_$createComponent(Output, {
69
+ expect(_$createComponent(Output, {
91
70
  program: program,
92
71
  get children() {
93
72
  return _$createComponent(SourceFile, {
@@ -100,20 +79,11 @@ describe("Typescript Type Alias Declaration", () => {
100
79
  }
101
80
  });
102
81
  }
103
- }));
104
- const testFile = res.contents.find(file => file.path === "test.ts");
105
- assert(testFile, "test.ts file not rendered");
106
- const actualContent = await format(testFile.contents, {
107
- parser: "typescript"
108
- });
109
- const expectedContent = await format(`
82
+ })).toRenderTo(`
110
83
  /**
111
84
  * Overridden Doc
112
85
  */
113
- type MyDate = Date;`, {
114
- parser: "typescript"
115
- });
116
- expect(actualContent).toBe(expectedContent);
86
+ type MyDate = Date;`);
117
87
  });
118
88
  it("creates a type alias declaration for a utcDateTime with unixTimeStamp encoding", async () => {
119
89
  const program = await getProgram(`
@@ -123,7 +93,7 @@ describe("Typescript Type Alias Declaration", () => {
123
93
  `);
124
94
  const [namespace] = program.resolveTypeReference("DemoService");
125
95
  const scalar = Array.from(namespace.scalars.values())[0];
126
- const res = render(_$createComponent(Output, {
96
+ expect(_$createComponent(Output, {
127
97
  program: program,
128
98
  get children() {
129
99
  return _$createComponent(SourceFile, {
@@ -135,16 +105,7 @@ describe("Typescript Type Alias Declaration", () => {
135
105
  }
136
106
  });
137
107
  }
138
- }));
139
- const testFile = res.contents.find(file => file.path === "test.ts");
140
- assert(testFile, "test.ts file not rendered");
141
- const actualContent = await format(testFile.contents, {
142
- parser: "typescript"
143
- });
144
- const expectedContent = await format(`type MyDate = Date;`, {
145
- parser: "typescript"
146
- });
147
- expect(actualContent).toBe(expectedContent);
108
+ })).toRenderTo(`type MyDate = Date;`);
148
109
  });
149
110
  it("creates a type alias declaration for a utcDateTime with rfc7231 encoding", async () => {
150
111
  const program = await getProgram(`
@@ -154,7 +115,7 @@ describe("Typescript Type Alias Declaration", () => {
154
115
  `);
155
116
  const [namespace] = program.resolveTypeReference("DemoService");
156
117
  const scalar = Array.from(namespace.scalars.values())[0];
157
- const res = render(_$createComponent(Output, {
118
+ expect(_$createComponent(Output, {
158
119
  program: program,
159
120
  get children() {
160
121
  return _$createComponent(SourceFile, {
@@ -166,16 +127,7 @@ describe("Typescript Type Alias Declaration", () => {
166
127
  }
167
128
  });
168
129
  }
169
- }));
170
- const testFile = res.contents.find(file => file.path === "test.ts");
171
- assert(testFile, "test.ts file not rendered");
172
- const actualContent = await format(testFile.contents, {
173
- parser: "typescript"
174
- });
175
- const expectedContent = await format(`type MyDate = Date;`, {
176
- parser: "typescript"
177
- });
178
- expect(actualContent).toBe(expectedContent);
130
+ })).toRenderTo(`type MyDate = Date;`);
179
131
  });
180
132
  it("creates a type alias declaration for a utcDateTime with rfc3339 encoding", async () => {
181
133
  const program = await getProgram(`
@@ -185,7 +137,7 @@ describe("Typescript Type Alias Declaration", () => {
185
137
  `);
186
138
  const [namespace] = program.resolveTypeReference("DemoService");
187
139
  const scalar = Array.from(namespace.scalars.values())[0];
188
- const res = render(_$createComponent(Output, {
140
+ expect(_$createComponent(Output, {
189
141
  program: program,
190
142
  get children() {
191
143
  return _$createComponent(SourceFile, {
@@ -198,16 +150,7 @@ describe("Typescript Type Alias Declaration", () => {
198
150
  }
199
151
  });
200
152
  }
201
- }));
202
- const testFile = res.contents.find(file => file.path === "test.ts");
203
- assert(testFile, "test.ts file not rendered");
204
- const actualContent = await format(testFile.contents, {
205
- parser: "typescript"
206
- });
207
- const expectedContent = await format(`export type MyDate = Date;`, {
208
- parser: "typescript"
209
- });
210
- expect(actualContent).toBe(expectedContent);
153
+ })).toRenderTo(`export type MyDate = Date;`);
211
154
  });
212
155
  });
213
156
  });
@@ -218,7 +161,7 @@ describe("Typescript Type Alias Declaration", () => {
218
161
  } = await runner.compile(`
219
162
  @test op getName(id: string): string;
220
163
  `);
221
- const res = render(_$createComponent(Output, {
164
+ expect(_$createComponent(Output, {
222
165
  get program() {
223
166
  return runner.program;
224
167
  },
@@ -232,7 +175,6 @@ describe("Typescript Type Alias Declaration", () => {
232
175
  }
233
176
  });
234
177
  }
235
- }));
236
- assertFileContents(res, "type getName = (id: string) => string;");
178
+ })).toRenderTo("type getName = (id: string) => string;");
237
179
  });
238
180
  });
@@ -1,9 +1,8 @@
1
1
  import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
- import { code, Output, render } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
2
+ import { code, Output } from "@alloy-js/core";
4
3
  import * as ts from "@alloy-js/typescript";
5
4
  import { SourceFile } from "@alloy-js/typescript";
6
- import { assert, beforeEach, describe, expect, it } from "vitest";
5
+ import { beforeEach, describe, expect, it } from "vitest";
7
6
  import { ArraySerializer, DateDeserializer, RecordSerializer } from "../../../src/typescript/components/static-serializers.js";
8
7
  import { getTypeTransformerRefkey, ModelTransformExpression, TypeTransformCall, TypeTransformDeclaration } from "../../../src/typescript/components/type-transform.js";
9
8
  import { TypeDeclaration } from "../../../src/typescript/index.js";
@@ -28,7 +27,7 @@ describe.skip("Typescript Type Transform", () => {
28
27
  const {
29
28
  Widget
30
29
  } = await testRunner.compile(spec);
31
- const res = render(_$createComponent(Output, {
30
+ expect(_$createComponent(Output, {
32
31
  namePolicy: namePolicy,
33
32
  get children() {
34
33
  return _$createComponent(SourceFile, {
@@ -44,18 +43,13 @@ describe.skip("Typescript Type Transform", () => {
44
43
  }
45
44
  });
46
45
  }
47
- }));
48
- const testFile = res.contents.find(file => file.path === "test.ts");
49
- assert(testFile, "test.ts file not rendered");
50
- const actualContent = testFile.contents;
51
- const expectedContent = d`
46
+ })).toRenderTo(`
52
47
  const wireWidget = {id: "1", birth_year: 1988, color: "blue"};
53
48
  const clientWidget = {
54
49
  "id": wireWidget.id,
55
50
  "birthYear": wireWidget.birth_year,
56
51
  "color": wireWidget.color
57
- }`;
58
- expect(actualContent).toBe(expectedContent);
52
+ }`);
59
53
  });
60
54
  it("should render a transform expression to wire", async () => {
61
55
  const spec = `
@@ -69,7 +63,7 @@ describe.skip("Typescript Type Transform", () => {
69
63
  const {
70
64
  Widget
71
65
  } = await testRunner.compile(spec);
72
- const res = render(_$createComponent(Output, {
66
+ expect(_$createComponent(Output, {
73
67
  namePolicy: namePolicy,
74
68
  get children() {
75
69
  return _$createComponent(SourceFile, {
@@ -85,18 +79,13 @@ describe.skip("Typescript Type Transform", () => {
85
79
  }
86
80
  });
87
81
  }
88
- }));
89
- const testFile = res.contents.find(file => file.path === "test.ts");
90
- assert(testFile, "test.ts file not rendered");
91
- const actualContent = testFile.contents;
92
- const expectedContent = d`
82
+ })).toRenderTo(`
93
83
  const clientWidget = {id: "1", birthYear: 1988, color: "blue"};
94
84
  const wireWidget = {
95
85
  "id": clientWidget.id,
96
86
  "birth_year": clientWidget.birthYear,
97
87
  "color": clientWidget.color
98
- }`;
99
- expect(actualContent).toBe(expectedContent);
88
+ }`);
100
89
  });
101
90
  it("should render a transform expression that contains a utcDateTime to client", async () => {
102
91
  const spec = `
@@ -110,7 +99,7 @@ describe.skip("Typescript Type Transform", () => {
110
99
  const {
111
100
  Widget
112
101
  } = await testRunner.compile(spec);
113
- const res = render(_$createComponent(Output, {
102
+ expect(_$createComponent(Output, {
114
103
  namePolicy: namePolicy,
115
104
  get children() {
116
105
  return [_$createComponent(SourceFile, {
@@ -131,11 +120,7 @@ describe.skip("Typescript Type Transform", () => {
131
120
  }
132
121
  })];
133
122
  }
134
- }));
135
- const testFile = res.contents.find(file => file.path === "test.ts");
136
- assert(testFile, "test.ts file not rendered");
137
- const actualContent = testFile.contents;
138
- const expectedContent = d`
123
+ })).toRenderTo(`
139
124
  import { dateDeserializer } from "./static-serializers.js";
140
125
 
141
126
  const wireWidget = {id: "1", birth_date: "1988-04-29T19:30:00Z", color: "blue"};
@@ -143,8 +128,7 @@ describe.skip("Typescript Type Transform", () => {
143
128
  "id": wireWidget.id,
144
129
  "birthDate": dateDeserializer(wireWidget.birth_date),
145
130
  "color": wireWidget.color
146
- }`;
147
- expect(actualContent).toBe(expectedContent);
131
+ }`);
148
132
  });
149
133
  });
150
134
  describe("TypeTransformDeclaration", () => {
@@ -163,7 +147,7 @@ describe.skip("Typescript Type Transform", () => {
163
147
  const {
164
148
  Widget
165
149
  } = await testRunner.compile(spec);
166
- const res = render(_$createComponent(Output, {
150
+ expect(_$createComponent(Output, {
167
151
  namePolicy: namePolicy,
168
152
  get children() {
169
153
  return [_$createComponent(SourceFile, {
@@ -187,11 +171,7 @@ describe.skip("Typescript Type Transform", () => {
187
171
  }
188
172
  })];
189
173
  }
190
- }));
191
- const testFile = res.contents.find(file => file.path === "test.ts");
192
- assert(testFile, "test.ts file not rendered");
193
- const actualContent = testFile.contents;
194
- const expectedContent = d`
174
+ })).toRenderTo(`
195
175
  import { arraySerializer } from "./serializers.js";
196
176
 
197
177
  export interface Widget {
@@ -222,8 +202,7 @@ describe.skip("Typescript Type Transform", () => {
222
202
  "optionalString": item.optionalString
223
203
  };
224
204
  }
225
- `;
226
- expect(actualContent).toBe(expectedContent);
205
+ `);
227
206
  });
228
207
  it("should render a transform functions for a model containing record", async () => {
229
208
  const spec = `
@@ -239,7 +218,7 @@ describe.skip("Typescript Type Transform", () => {
239
218
  const {
240
219
  Widget
241
220
  } = await testRunner.compile(spec);
242
- const res = render(_$createComponent(Output, {
221
+ expect(_$createComponent(Output, {
243
222
  namePolicy: namePolicy,
244
223
  get children() {
245
224
  return [_$createComponent(SourceFile, {
@@ -263,11 +242,7 @@ describe.skip("Typescript Type Transform", () => {
263
242
  }
264
243
  })];
265
244
  }
266
- }));
267
- const testFile = res.contents.find(file => file.path === "test.ts");
268
- assert(testFile, "test.ts file not rendered");
269
- const actualContent = testFile.contents;
270
- const expectedContent = d`
245
+ })).toRenderTo(`
271
246
  import { recordSerializer } from "./serializers.js";
272
247
 
273
248
  export interface Widget {
@@ -295,8 +270,7 @@ describe.skip("Typescript Type Transform", () => {
295
270
  "nested": recordSerializer(item.nested, (i: any) => recordSerializer(i, widgetToTransport))
296
271
  };
297
272
  }
298
- `;
299
- expect(actualContent).toBe(expectedContent);
273
+ `);
300
274
  });
301
275
  it("should render a transform functions for a model", async () => {
302
276
  const spec = `
@@ -309,7 +283,7 @@ describe.skip("Typescript Type Transform", () => {
309
283
  const {
310
284
  Widget
311
285
  } = await testRunner.compile(spec);
312
- const res = render(_$createComponent(Output, {
286
+ expect(_$createComponent(Output, {
313
287
  namePolicy: namePolicy,
314
288
  get children() {
315
289
  return _$createComponent(SourceFile, {
@@ -328,11 +302,7 @@ describe.skip("Typescript Type Transform", () => {
328
302
  }
329
303
  });
330
304
  }
331
- }));
332
- const testFile = res.contents.find(file => file.path === "test.ts");
333
- assert(testFile, "test.ts file not rendered");
334
- const actualContent = testFile.contents;
335
- const expectedContent = d`
305
+ })).toRenderTo(`
336
306
  export interface Widget {
337
307
  "id": string;
338
308
  "myColor": "blue" | "red";
@@ -349,8 +319,7 @@ describe.skip("Typescript Type Transform", () => {
349
319
  "my_color": item.myColor
350
320
  };
351
321
  }
352
- `;
353
- expect(actualContent).toBe(expectedContent);
322
+ `);
354
323
  });
355
324
  });
356
325
  describe("Calling a model transform functions", () => {
@@ -364,7 +333,7 @@ describe.skip("Typescript Type Transform", () => {
364
333
  const {
365
334
  Widget
366
335
  } = await testRunner.compile(spec);
367
- const res = render(_$createComponent(Output, {
336
+ expect(_$createComponent(Output, {
368
337
  namePolicy: namePolicy,
369
338
  get children() {
370
339
  return _$createComponent(SourceFile, {
@@ -382,15 +351,10 @@ describe.skip("Typescript Type Transform", () => {
382
351
  }
383
352
  });
384
353
  }
385
- }));
386
- const testFile = res.contents.find(file => file.path === "test.ts");
387
- assert(testFile, "test.ts file not rendered");
388
- const actualContent = testFile.contents;
389
- const expectedContent = d`
354
+ })).toRenderTo(`
390
355
  const clientWidget = {id: "1", my_color: "blue"};
391
356
  const wireWidget = clientWidget.id
392
- `;
393
- expect(actualContent).toBe(expectedContent);
357
+ `);
394
358
  });
395
359
  it("should call transform functions for a model", async () => {
396
360
  const spec = `
@@ -403,7 +367,7 @@ describe.skip("Typescript Type Transform", () => {
403
367
  const {
404
368
  Widget
405
369
  } = await testRunner.compile(spec);
406
- const res = render(_$createComponent(Output, {
370
+ expect(_$createComponent(Output, {
407
371
  namePolicy: namePolicy,
408
372
  get children() {
409
373
  return [_$createComponent(SourceFile, {
@@ -443,18 +407,13 @@ describe.skip("Typescript Type Transform", () => {
443
407
  }
444
408
  })];
445
409
  }
446
- }));
447
- const testFile = res.contents.find(file => file.path === "test.ts");
448
- assert(testFile, "test.ts file not rendered");
449
- const actualContent = testFile.contents;
450
- const expectedContent = d`
410
+ })).toRenderTo(`
451
411
  import { widgetToApplication, widgetToTransport } from "./types.js";
452
412
 
453
413
  const wireWidget = {id: "1", my_color: "blue"};
454
414
  const clientWidget = widgetToApplication(wireWidget);
455
415
  const wireWidget2 = widgetToTransport(clientWidget);
456
- `;
457
- expect(actualContent).toBe(expectedContent);
416
+ `);
458
417
  });
459
418
  });
460
419
  });
@@ -478,7 +437,7 @@ describe.skip("Typescript Type Transform", () => {
478
437
  kind: "dog";
479
438
  }
480
439
  `);
481
- const res = render(_$createComponent(Output, {
440
+ expect(_$createComponent(Output, {
482
441
  namePolicy: namePolicy,
483
442
  get children() {
484
443
  return _$createComponent(SourceFile, {
@@ -515,11 +474,7 @@ describe.skip("Typescript Type Transform", () => {
515
474
  }
516
475
  });
517
476
  }
518
- }));
519
- const testFile = res.contents.find(file => file.path === "test.ts");
520
- assert(testFile, "test.ts file not rendered");
521
- const actualContent = testFile.contents;
522
- const expectedContent = d`
477
+ })).toRenderTo(`
523
478
  export interface Pet {
524
479
  "kind": string;
525
480
  }
@@ -565,8 +520,7 @@ describe.skip("Typescript Type Transform", () => {
565
520
  return dogToTransport(item)
566
521
  }
567
522
  }
568
- `;
569
- expect(actualContent).toBe(expectedContent);
523
+ `);
570
524
  });
571
525
  });
572
526
  describe("Discriminated Union Transforms", () => {
@@ -590,7 +544,7 @@ describe.skip("Typescript Type Transform", () => {
590
544
  kind: "dog";
591
545
  }
592
546
  `);
593
- const res = render(_$createComponent(Output, {
547
+ expect(_$createComponent(Output, {
594
548
  namePolicy: namePolicy,
595
549
  get children() {
596
550
  return _$createComponent(SourceFile, {
@@ -627,11 +581,7 @@ describe.skip("Typescript Type Transform", () => {
627
581
  }
628
582
  });
629
583
  }
630
- }));
631
- const testFile = res.contents.find(file => file.path === "test.ts");
632
- assert(testFile, "test.ts file not rendered");
633
- const actualContent = testFile.contents;
634
- const expectedContent = d`
584
+ })).toRenderTo(`
635
585
  export type Pet = Cat | Dog;
636
586
  export interface Dog {
637
587
  "kind": "dog";
@@ -675,8 +625,7 @@ describe.skip("Typescript Type Transform", () => {
675
625
  return dogToTransport(item)
676
626
  }
677
627
  }
678
- `;
679
- expect(actualContent).toBe(expectedContent);
628
+ `);
680
629
  });
681
630
  });
682
631
  });
@@ -1,5 +1,5 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { Output, render } from "@alloy-js/core";
2
+ import { Output } from "@alloy-js/core";
3
3
  import { dedent } from "@alloy-js/core/testing";
4
4
  import { SourceFile } from "@alloy-js/typescript";
5
5
  import { Numeric } from "@typespec/compiler";
@@ -174,7 +174,7 @@ it("renders enums", async () => {
174
174
  */
175
175
  async function testValueExpression(value, expected) {
176
176
  const prefix = "const val = ";
177
- const res = render(_$createComponent(Output, {
177
+ expect(_$createComponent(Output, {
178
178
  get children() {
179
179
  return _$createComponent(SourceFile, {
180
180
  path: "test.ts",
@@ -185,10 +185,7 @@ async function testValueExpression(value, expected) {
185
185
  }
186
186
  });
187
187
  }
188
- }));
189
- const testFile = res.contents.find(file => file.path === "test.ts");
190
- assert.exists(testFile, "test.ts file not rendered");
191
- assert.equal(testFile.contents, `${prefix}${expected}`, "test.ts file contents do not match expected");
188
+ })).toRenderTo(`${prefix}${expected}`);
192
189
  }
193
190
 
194
191
  /**
@@ -0,0 +1,7 @@
1
+ import type { Children } from "@alloy-js/core/jsx-runtime";
2
+ import type { Program } from "@typespec/compiler";
3
+ export declare function TestFile(props: {
4
+ program: Program;
5
+ children: Children;
6
+ }): Children;
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../test/typescript/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,YAMvE"}
@@ -0,0 +1,18 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { SourceFile } from "@alloy-js/typescript";
3
+ import { Output } from "../../src/core/components/output.js";
4
+ export function TestFile(props) {
5
+ return _$createComponent(Output, {
6
+ get program() {
7
+ return props.program;
8
+ },
9
+ get children() {
10
+ return _$createComponent(SourceFile, {
11
+ path: "test.ts",
12
+ get children() {
13
+ return props.children;
14
+ }
15
+ });
16
+ }
17
+ });
18
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAU,MAAM,gBAAgB,CAAC;AAG7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAIlD,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,+EAOtF;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,QAIxE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAU,MAAM,gBAAgB,CAAC;AAG7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAIlD,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,+EAOtF;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,QAKxE"}
@@ -9,10 +9,12 @@ export async function getEmitOutput(tspCode, cb) {
9
9
  path: "test.ts"
10
10
  }).children(cb(program))));
11
11
  const testFile = res.contents.find(file => file.path === "test.ts");
12
+ assert("contents" in testFile, "test.ts file does not have contents");
12
13
  return testFile.contents;
13
14
  }
14
15
  export function assertFileContents(res, contents) {
15
16
  const testFile = res.contents.find(file => file.path === "test.ts");
16
17
  assert(testFile, "test.ts file not rendered");
18
+ assert("contents" in testFile, "test.ts file does not have contents");
17
19
  assert.equal(testFile.contents, contents);
18
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/emitter-framework",
3
- "version": "0.10.0-dev.2",
3
+ "version": "0.10.0-dev.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -41,18 +41,18 @@
41
41
  "license": "MIT",
42
42
  "description": "",
43
43
  "peerDependencies": {
44
- "@alloy-js/core": "^0.18.2",
45
- "@alloy-js/csharp": "^0.18.0",
46
- "@alloy-js/typescript": "^0.18.0",
44
+ "@alloy-js/core": "^0.19.0",
45
+ "@alloy-js/csharp": "^0.19.0",
46
+ "@alloy-js/typescript": "^0.19.0",
47
47
  "@typespec/compiler": "^1.2.1",
48
48
  "@typespec/http": "^1.2.1",
49
49
  "@typespec/rest": "^0.72.1 || >=0.73.0-dev <0.73.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@alloy-js/cli": "^0.18.0",
53
- "@alloy-js/core": "^0.18.2",
52
+ "@alloy-js/cli": "^0.19.0",
53
+ "@alloy-js/core": "^0.19.0",
54
54
  "@alloy-js/rollup-plugin": "^0.1.0",
55
- "@alloy-js/typescript": "^0.18.0",
55
+ "@alloy-js/typescript": "^0.19.0",
56
56
  "@typespec/compiler": "^1.2.1",
57
57
  "@typespec/http": "^1.2.1",
58
58
  "@typespec/rest": "^0.72.1 || >=0.73.0-dev <0.73.0",
@@ -16,13 +16,17 @@ async function writeOutputDirectory(
16
16
  emitterOutputDir: string,
17
17
  ) {
18
18
  for (const sub of dir.contents) {
19
- if (Array.isArray(sub.contents)) {
20
- await writeOutputDirectory(program, sub as OutputDirectory, emitterOutputDir);
19
+ if ("contents" in sub) {
20
+ if (Array.isArray(sub.contents)) {
21
+ await writeOutputDirectory(program, sub as OutputDirectory, emitterOutputDir);
22
+ } else {
23
+ await emitFile(program, {
24
+ content: sub.contents as string,
25
+ path: joinPaths(emitterOutputDir, sub.path),
26
+ });
27
+ }
21
28
  } else {
22
- await emitFile(program, {
23
- content: sub.contents as string,
24
- path: joinPaths(emitterOutputDir, sub.path),
25
- });
29
+ // TODO: support copy file
26
30
  }
27
31
  }
28
32
  }
@@ -1,5 +1,6 @@
1
1
  import { type Children, For } from "@alloy-js/core";
2
2
  import * as cs from "@alloy-js/csharp";
3
+ import { Method } from "@alloy-js/csharp";
3
4
  import type { Interface, Model } from "@typespec/compiler";
4
5
  import { useTsp } from "../../../core/index.js";
5
6
  import { Property } from "../property/property.jsx";
@@ -66,7 +67,7 @@ function ClassMethods(props: ClassMethodsProps): Children {
66
67
  const abstractMethods: Children = [];
67
68
  for (const [name, method] of props.type.operations) {
68
69
  abstractMethods.push(
69
- <cs.ClassMethod
70
+ <Method
70
71
  name={namePolicy.getName(name, "class-method")}
71
72
  abstract
72
73
  parameters={[...method.parameters.properties.entries()].map(([name, prop]) => {