@typespec/emitter-framework 0.6.0-dev.6 → 0.7.0-dev.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 +17 -0
- package/dist/src/core/components/index.d.ts +2 -0
- package/dist/src/core/components/index.d.ts.map +1 -0
- package/dist/src/core/components/index.js +1 -0
- package/dist/src/core/components/output.d.ts +10 -0
- package/dist/src/core/components/output.d.ts.map +1 -0
- package/dist/src/core/components/output.js +16 -0
- package/dist/src/core/context/index.d.ts +1 -0
- package/dist/src/core/context/index.d.ts.map +1 -1
- package/dist/src/core/context/index.js +2 -1
- package/dist/src/core/context/tsp-context.d.ts +13 -0
- package/dist/src/core/context/tsp-context.d.ts.map +1 -0
- package/dist/src/core/context/tsp-context.js +13 -0
- package/dist/src/core/index.d.ts +1 -0
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +1 -0
- package/dist/src/core/write-output.d.ts +2 -1
- package/dist/src/core/write-output.d.ts.map +1 -1
- package/dist/src/core/write-output.js +5 -6
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +4 -1
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +9 -3
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-member.js +4 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.js +4 -1
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.js +8 -5
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.js +26 -5
- package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/union-declaration.js +4 -1
- package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.js +4 -1
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.js +7 -1
- package/dist/test/typescript/components/arrow-function.test.js +11 -1
- package/dist/test/typescript/components/enum-declaration.test.js +47 -18
- package/dist/test/typescript/components/function-declaration.test.js +9 -1
- package/dist/test/typescript/components/function-expression.test.js +11 -1
- package/dist/test/typescript/components/function-type.test.js +11 -1
- package/dist/test/typescript/components/interface-declaration.test.js +20 -2
- package/dist/test/typescript/components/interface-method.test.js +26 -2
- package/dist/test/typescript/components/member-expression.test.js +61 -32
- package/dist/test/typescript/components/type-alias-declaration.test.js +9 -1
- package/dist/test/typescript/components/union-declaration.test.js +9 -1
- package/dist/test/typescript/components/value-expression.test.js +9 -7
- package/package.json +7 -7
- package/src/core/components/index.tsx +1 -0
- package/src/core/components/output.tsx +19 -0
- package/src/core/context/index.ts +1 -0
- package/src/core/context/tsp-context.ts +30 -0
- package/src/core/index.ts +1 -0
- package/src/core/write-output.ts +14 -7
- package/src/typescript/components/enum-declaration.tsx +2 -1
- package/src/typescript/components/interface-declaration.tsx +7 -3
- package/src/typescript/components/interface-member.tsx +2 -1
- package/src/typescript/components/type-alias-declaration.tsx +2 -1
- package/src/typescript/components/type-expression.tsx +7 -5
- package/src/typescript/components/type-transform.tsx +17 -5
- package/src/typescript/components/union-declaration.tsx +2 -1
- package/src/typescript/components/union-expression.tsx +2 -1
- package/src/typescript/utils/operation.ts +3 -1
- package/test/typescript/components/arrow-function.test.tsx +5 -4
- package/test/typescript/components/enum-declaration.test.tsx +29 -16
- package/test/typescript/components/function-declaration.test.tsx +9 -8
- package/test/typescript/components/function-expression.test.tsx +5 -4
- package/test/typescript/components/function-type.test.tsx +5 -4
- package/test/typescript/components/interface-declaration.test.tsx +20 -20
- package/test/typescript/components/interface-method.test.tsx +12 -10
- package/test/typescript/components/member-expression.test.tsx +25 -16
- package/test/typescript/components/type-alias-declaration.test.tsx +7 -6
- package/test/typescript/components/union-declaration.test.tsx +9 -7
- package/test/typescript/components/value-expression.test.tsx +22 -8
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from "@alloy-js/core";
|
|
2
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
3
|
import { Namespace } from "@typespec/compiler";
|
|
4
4
|
import { format } from "prettier";
|
|
5
5
|
import { assert, describe, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
7
|
import { UnionDeclaration } from "../../../src/typescript/components/union-declaration.js";
|
|
7
8
|
import { UnionExpression } from "../../../src/typescript/components/union-expression.js";
|
|
8
9
|
import { getProgram } from "../test-host.js";
|
|
@@ -10,8 +11,9 @@ import { getProgram } from "../test-host.js";
|
|
|
10
11
|
describe("Typescript Union Declaration", () => {
|
|
11
12
|
describe("Union not bound to Typespec Types", () => {
|
|
12
13
|
it("creates a union declaration", async () => {
|
|
14
|
+
const program = await getProgram("");
|
|
13
15
|
const res = render(
|
|
14
|
-
<Output>
|
|
16
|
+
<Output program={program}>
|
|
15
17
|
<SourceFile path="test.ts">
|
|
16
18
|
<UnionDeclaration name="MyUnion">"red" | "blue"</UnionDeclaration>
|
|
17
19
|
</SourceFile>
|
|
@@ -43,7 +45,7 @@ describe("Typescript Union Declaration", () => {
|
|
|
43
45
|
const union = Array.from((namespace as Namespace).unions.values())[0];
|
|
44
46
|
|
|
45
47
|
const res = render(
|
|
46
|
-
<Output>
|
|
48
|
+
<Output program={program}>
|
|
47
49
|
<SourceFile path="test.ts">
|
|
48
50
|
<UnionDeclaration type={union} />
|
|
49
51
|
</SourceFile>
|
|
@@ -72,7 +74,7 @@ describe("Typescript Union Declaration", () => {
|
|
|
72
74
|
const union = Array.from((namespace as Namespace).unions.values())[0];
|
|
73
75
|
|
|
74
76
|
const res = render(
|
|
75
|
-
<Output>
|
|
77
|
+
<Output program={program}>
|
|
76
78
|
<SourceFile path="test.ts">
|
|
77
79
|
<UnionDeclaration export type={union} name="MyUnion" />
|
|
78
80
|
</SourceFile>
|
|
@@ -101,7 +103,7 @@ describe("Typescript Union Declaration", () => {
|
|
|
101
103
|
const union = Array.from((namespace as Namespace).unions.values())[0];
|
|
102
104
|
|
|
103
105
|
const res = render(
|
|
104
|
-
<Output>
|
|
106
|
+
<Output program={program}>
|
|
105
107
|
<SourceFile path="test.ts">
|
|
106
108
|
<UnionDeclaration type={union}>"three"</UnionDeclaration>
|
|
107
109
|
</SourceFile>
|
|
@@ -130,7 +132,7 @@ describe("Typescript Union Declaration", () => {
|
|
|
130
132
|
const union = Array.from((namespace as Namespace).unions.values())[0];
|
|
131
133
|
|
|
132
134
|
const res = render(
|
|
133
|
-
<Output>
|
|
135
|
+
<Output program={program}>
|
|
134
136
|
<SourceFile path="test.ts">
|
|
135
137
|
let x: <UnionExpression type={union} /> = "one";
|
|
136
138
|
</SourceFile>
|
|
@@ -161,7 +163,7 @@ describe("Typescript Union Declaration", () => {
|
|
|
161
163
|
const union = Array.from((namespace as Namespace).enums.values())[0];
|
|
162
164
|
|
|
163
165
|
const res = render(
|
|
164
|
-
<Output>
|
|
166
|
+
<Output program={program}>
|
|
165
167
|
<SourceFile path="test.ts">
|
|
166
168
|
<UnionDeclaration type={union} />
|
|
167
169
|
</SourceFile>
|
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
import { Output, render } from "@alloy-js/core";
|
|
2
2
|
import { dedent } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
EnumValue,
|
|
6
|
+
Model,
|
|
7
|
+
Namespace,
|
|
8
|
+
Numeric,
|
|
9
|
+
NumericValue,
|
|
10
|
+
Program,
|
|
11
|
+
Value,
|
|
12
|
+
} from "@typespec/compiler";
|
|
5
13
|
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
6
14
|
import { assert, beforeAll, describe, expect, it } from "vitest";
|
|
7
15
|
import { ValueExpression } from "../../../src/typescript/components/value-expression.js";
|
|
8
|
-
import { getProgram
|
|
16
|
+
import { getProgram } from "../test-host.js";
|
|
9
17
|
|
|
18
|
+
let program: Program;
|
|
10
19
|
beforeAll(async () => {
|
|
11
|
-
await
|
|
20
|
+
program = await getProgram("");
|
|
12
21
|
});
|
|
13
22
|
|
|
14
23
|
it("renders strings", async () => {
|
|
15
|
-
const value =
|
|
24
|
+
const value = $(program).value.createString("test");
|
|
16
25
|
|
|
17
26
|
await testValueExpression(value, `"test"`);
|
|
18
27
|
});
|
|
19
28
|
|
|
20
29
|
describe("numeric values", () => {
|
|
21
30
|
it("renders integers", async () => {
|
|
22
|
-
const value =
|
|
31
|
+
const value = $(program).value.createNumeric(42);
|
|
23
32
|
|
|
24
33
|
await testValueExpression(value, `42`);
|
|
25
34
|
});
|
|
26
35
|
|
|
27
36
|
it("renders decimals", async () => {
|
|
28
|
-
const value =
|
|
37
|
+
const value = $(program).value.createNumeric(42.5);
|
|
29
38
|
|
|
30
39
|
await testValueExpression(value, `42.5`);
|
|
31
40
|
});
|
|
@@ -54,7 +63,7 @@ describe("numeric values", () => {
|
|
|
54
63
|
});
|
|
55
64
|
|
|
56
65
|
it("renders booleans", async () => {
|
|
57
|
-
const value =
|
|
66
|
+
const value = $(program).value.createBoolean(true);
|
|
58
67
|
await testValueExpression(value, `true`);
|
|
59
68
|
});
|
|
60
69
|
|
|
@@ -78,11 +87,16 @@ it("renders empty arrays", async () => {
|
|
|
78
87
|
});
|
|
79
88
|
|
|
80
89
|
it("renders arrays with mixed values", async () => {
|
|
90
|
+
const tk = $(program);
|
|
81
91
|
// Can be replaced with with TypeKit once #6976 is implemented
|
|
82
92
|
const value = {
|
|
83
93
|
entityKind: "Value",
|
|
84
94
|
valueKind: "ArrayValue",
|
|
85
|
-
values: [
|
|
95
|
+
values: [
|
|
96
|
+
tk.value.createString("foo"),
|
|
97
|
+
tk.value.createNumeric(42),
|
|
98
|
+
tk.value.createBoolean(true),
|
|
99
|
+
],
|
|
86
100
|
} as Value;
|
|
87
101
|
await testValueExpression(value, `["foo", 42, true]`);
|
|
88
102
|
});
|