@typespec/emitter-framework 0.6.0-dev.2 → 0.6.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.
- package/dist/src/typescript/components/arrow-function.d.ts +17 -0
- package/dist/src/typescript/components/arrow-function.d.ts.map +1 -0
- package/dist/src/typescript/components/arrow-function.js +31 -0
- package/dist/src/typescript/components/arrow-function.js.map +1 -0
- package/dist/src/typescript/components/function-declaration.d.ts +5 -0
- package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/function-declaration.js +5 -1
- package/dist/src/typescript/components/function-declaration.js.map +1 -1
- package/dist/src/typescript/components/function-expression.d.ts +17 -0
- package/dist/src/typescript/components/function-expression.d.ts.map +1 -0
- package/dist/src/typescript/components/function-expression.js +31 -0
- package/dist/src/typescript/components/function-expression.js.map +1 -0
- package/dist/src/typescript/components/function-type.d.ts +17 -0
- package/dist/src/typescript/components/function-type.d.ts.map +1 -0
- package/dist/src/typescript/components/function-type.js +31 -0
- package/dist/src/typescript/components/function-type.js.map +1 -0
- package/dist/src/typescript/components/index.d.ts +6 -0
- package/dist/src/typescript/components/index.d.ts.map +1 -1
- package/dist/src/typescript/components/index.js +6 -0
- package/dist/src/typescript/components/index.js.map +1 -1
- package/dist/src/typescript/components/interface-member.d.ts +1 -2
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-member.js +3 -19
- package/dist/src/typescript/components/interface-member.js.map +1 -1
- package/dist/src/typescript/components/interface-method.d.ts +15 -0
- package/dist/src/typescript/components/interface-method.d.ts.map +1 -0
- package/dist/src/typescript/components/interface-method.js +34 -0
- package/dist/src/typescript/components/interface-method.js.map +1 -0
- package/dist/src/typescript/components/type-alias-declaration.d.ts +6 -2
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.js +7 -2
- package/dist/src/typescript/components/type-alias-declaration.js.map +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-declaration.js +4 -0
- package/dist/src/typescript/components/type-declaration.js.map +1 -1
- package/dist/src/typescript/components/type-expression.d.ts +6 -0
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.js +6 -1
- package/dist/src/typescript/components/type-expression.js.map +1 -1
- package/dist/test/typescript/components/arrow-function.test.d.ts +2 -0
- package/dist/test/typescript/components/arrow-function.test.d.ts.map +1 -0
- package/dist/test/typescript/components/function-expression.test.d.ts +2 -0
- package/dist/test/typescript/components/function-expression.test.d.ts.map +1 -0
- package/dist/test/typescript/components/function-type.test.d.ts +2 -0
- package/dist/test/typescript/components/function-type.test.d.ts.map +1 -0
- package/dist/test/typescript/components/interface-method.test.d.ts +2 -0
- package/dist/test/typescript/components/interface-method.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +3 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/typescript/components/arrow-function.tsx +39 -0
- package/src/typescript/components/function-declaration.tsx +5 -2
- package/src/typescript/components/function-expression.tsx +41 -0
- package/src/typescript/components/function-type.tsx +38 -0
- package/src/typescript/components/index.ts +6 -0
- package/src/typescript/components/interface-member.tsx +2 -19
- package/src/typescript/components/interface-method.tsx +50 -0
- package/src/typescript/components/type-alias-declaration.tsx +10 -4
- package/src/typescript/components/type-declaration.tsx +2 -0
- package/src/typescript/components/type-expression.tsx +11 -2
- package/test/typescript/components/arrow-function.test.tsx +85 -0
- package/test/typescript/components/function-expression.test.tsx +85 -0
- package/test/typescript/components/function-type.test.tsx +80 -0
- package/test/typescript/components/interface-declaration.test.tsx +6 -6
- package/test/typescript/components/interface-method.test.tsx +69 -0
- package/test/typescript/components/type-alias-declaration.test.tsx +20 -2
- package/test/utils.ts +8 -1
|
@@ -564,7 +564,7 @@ describe("Typescript Interface", () => {
|
|
|
564
564
|
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
565
565
|
const expectedContent = await format(
|
|
566
566
|
`export interface WidgetOperations {
|
|
567
|
-
getName
|
|
567
|
+
getName(id: string): string;
|
|
568
568
|
}`,
|
|
569
569
|
{
|
|
570
570
|
parser: "typescript",
|
|
@@ -605,8 +605,8 @@ describe("Typescript Interface", () => {
|
|
|
605
605
|
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
606
606
|
const expectedContent = await format(
|
|
607
607
|
`export interface WidgetOperations {
|
|
608
|
-
getName
|
|
609
|
-
getOtherName
|
|
608
|
+
getName(foo: Foo): string;
|
|
609
|
+
getOtherName(name: string): string
|
|
610
610
|
}
|
|
611
611
|
export interface Foo {
|
|
612
612
|
name: string;
|
|
@@ -654,7 +654,7 @@ describe("Typescript Interface", () => {
|
|
|
654
654
|
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
655
655
|
const expectedContent = await format(
|
|
656
656
|
`export interface WidgetOperations {
|
|
657
|
-
getName
|
|
657
|
+
getName(id: string): Widget;
|
|
658
658
|
}
|
|
659
659
|
export interface Widget {
|
|
660
660
|
id: string;
|
|
@@ -707,8 +707,8 @@ describe("Typescript Interface", () => {
|
|
|
707
707
|
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
708
708
|
const expectedContent = await format(
|
|
709
709
|
`export interface WidgetOperationsExtended {
|
|
710
|
-
getName
|
|
711
|
-
delete
|
|
710
|
+
getName(id: string): Widget;
|
|
711
|
+
delete(id: string): void;
|
|
712
712
|
}
|
|
713
713
|
export interface Widget {
|
|
714
714
|
id: string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Output, render } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
|
|
4
|
+
import { Operation } from "@typespec/compiler";
|
|
5
|
+
import { BasicTestRunner } from "@typespec/compiler/testing";
|
|
6
|
+
import { beforeEach, describe, it } from "vitest";
|
|
7
|
+
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
8
|
+
import { assertFileContents } from "../../utils.js";
|
|
9
|
+
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
10
|
+
|
|
11
|
+
describe("interface methods with a `type` prop", () => {
|
|
12
|
+
let runner: BasicTestRunner;
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
runner = await createEmitterFrameworkTestRunner();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("creates a interface member", async () => {
|
|
19
|
+
const { getName } = (await runner.compile(`
|
|
20
|
+
@test op getName(id: string): string;
|
|
21
|
+
`)) as { getName: Operation };
|
|
22
|
+
|
|
23
|
+
const res = render(
|
|
24
|
+
<Output>
|
|
25
|
+
<SourceFile path="test.ts">
|
|
26
|
+
<InterfaceDeclaration name="basicInterface">
|
|
27
|
+
<InterfaceMethod type={getName} name={getName.name} />
|
|
28
|
+
</InterfaceDeclaration>
|
|
29
|
+
</SourceFile>
|
|
30
|
+
</Output>,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
assertFileContents(
|
|
34
|
+
res,
|
|
35
|
+
d`
|
|
36
|
+
interface basicInterface {
|
|
37
|
+
getName(id: string): string
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("creates an async interface function", async () => {
|
|
44
|
+
const { getName } = (await runner.compile(`
|
|
45
|
+
@test op getName(id: string): string;
|
|
46
|
+
`)) as { getName: Operation };
|
|
47
|
+
|
|
48
|
+
const res = render(
|
|
49
|
+
<Output>
|
|
50
|
+
<SourceFile path="test.ts">
|
|
51
|
+
<InterfaceDeclaration name="basicInterface">
|
|
52
|
+
<InterfaceMethod async type={getName} />
|
|
53
|
+
</InterfaceDeclaration>
|
|
54
|
+
</SourceFile>
|
|
55
|
+
</Output>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
assertFileContents(
|
|
59
|
+
res,
|
|
60
|
+
d`
|
|
61
|
+
interface basicInterface {
|
|
62
|
+
getName(id: string): Promise<string>
|
|
63
|
+
}
|
|
64
|
+
`,
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it.todo("can append extra parameters with raw params provided", async () => {});
|
|
69
|
+
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Output, render } from "@alloy-js/core";
|
|
2
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
|
-
import { Namespace } from "@typespec/compiler";
|
|
3
|
+
import { Namespace, Operation } from "@typespec/compiler";
|
|
4
4
|
import { format } from "prettier";
|
|
5
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
6
|
import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.jsx";
|
|
7
|
-
import {
|
|
7
|
+
import { assertFileContents } from "../../utils.js";
|
|
8
|
+
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
8
9
|
|
|
9
10
|
describe("Typescript Type Alias Declaration", () => {
|
|
10
11
|
describe("Type Alias bound to Typespec Scalar", () => {
|
|
@@ -117,4 +118,21 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
120
|
});
|
|
121
|
+
|
|
122
|
+
it("creates a type alias of a function", async () => {
|
|
123
|
+
const runner = await createEmitterFrameworkTestRunner();
|
|
124
|
+
const { getName } = (await runner.compile(`
|
|
125
|
+
@test op getName(id: string): string;
|
|
126
|
+
`)) as { getName: Operation };
|
|
127
|
+
|
|
128
|
+
const res = render(
|
|
129
|
+
<Output>
|
|
130
|
+
<SourceFile path="test.ts">
|
|
131
|
+
<TypeAliasDeclaration type={getName} />
|
|
132
|
+
</SourceFile>
|
|
133
|
+
</Output>,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
assertFileContents(res, "type getName = (id: string) => string;");
|
|
137
|
+
});
|
|
120
138
|
});
|
package/test/utils.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Children, render } from "@alloy-js/core";
|
|
1
|
+
import { Children, OutputDirectory, render } from "@alloy-js/core";
|
|
2
2
|
import { Output } from "@alloy-js/core/stc";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript/stc";
|
|
4
4
|
import { Program } from "@typespec/compiler";
|
|
5
|
+
import { assert } from "vitest";
|
|
5
6
|
import { getProgram } from "./typescript/test-host.js";
|
|
6
7
|
|
|
7
8
|
export async function getEmitOutput(tspCode: string, cb: (program: Program) => Children) {
|
|
@@ -12,3 +13,9 @@ export async function getEmitOutput(tspCode: string, cb: (program: Program) => C
|
|
|
12
13
|
|
|
13
14
|
return testFile.contents;
|
|
14
15
|
}
|
|
16
|
+
|
|
17
|
+
export function assertFileContents(res: OutputDirectory, contents: string) {
|
|
18
|
+
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
19
|
+
assert(testFile, "test.ts file not rendered");
|
|
20
|
+
assert.equal(testFile.contents, contents);
|
|
21
|
+
}
|