@typespec/emitter-framework 0.6.0-dev.6 → 0.6.0-dev.7
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/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 +1 -1
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/components/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./output.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as ay from "@alloy-js/core";
|
|
2
|
+
import { Program } from "@typespec/compiler";
|
|
3
|
+
export interface OutputProps extends ay.OutputProps {
|
|
4
|
+
/**
|
|
5
|
+
* TypeSpec program.
|
|
6
|
+
*/
|
|
7
|
+
program: Program;
|
|
8
|
+
}
|
|
9
|
+
export declare function Output(props: OutputProps): ay.Children;
|
|
10
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/core/components/output.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,MAAM,WAAW,WAAY,SAAQ,EAAE,CAAC,WAAW;IACjD;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,eAOxC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import * as ay from "@alloy-js/core";
|
|
3
|
+
import { TspContext } from "../context/tsp-context.js";
|
|
4
|
+
export function Output(props) {
|
|
5
|
+
const [{
|
|
6
|
+
program
|
|
7
|
+
}, rest] = ay.splitProps(props, ["program"]);
|
|
8
|
+
return _$createComponent(TspContext.Provider, {
|
|
9
|
+
value: {
|
|
10
|
+
program
|
|
11
|
+
},
|
|
12
|
+
get children() {
|
|
13
|
+
return _$createComponent(ay.Output, rest);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./name-policy-context.js";
|
|
1
|
+
export * from "./name-policy-context.js";
|
|
2
|
+
export * from "./tsp-context.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentContext } from "@alloy-js/core";
|
|
2
|
+
import { Program } from "@typespec/compiler";
|
|
3
|
+
import { Typekit } from "@typespec/compiler/experimental/typekit";
|
|
4
|
+
export type TspContext = {
|
|
5
|
+
program: Program;
|
|
6
|
+
$: Typekit;
|
|
7
|
+
};
|
|
8
|
+
export declare const TspContext: ComponentContext<{
|
|
9
|
+
program: Program;
|
|
10
|
+
$?: Typekit;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function useTsp(): TspContext;
|
|
13
|
+
//# sourceMappingURL=tsp-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsp-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/tsp-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,EAAE,OAAO,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,gBAAgB,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,CAAC,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAC;AAEjB,wBAAgB,MAAM,IAaF,UAAU,CAC7B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createNamedContext, useContext } from "@alloy-js/core";
|
|
2
|
+
import { unsafe_$ } from "@typespec/compiler/experimental";
|
|
3
|
+
export const TspContext = createNamedContext("TspContext");
|
|
4
|
+
export function useTsp() {
|
|
5
|
+
const context = useContext(TspContext);
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error("TspContext is not set. Make sure the component is wrapped in TspContext.Provider or the emitter framework Output component.");
|
|
8
|
+
}
|
|
9
|
+
if (!context.$) {
|
|
10
|
+
context.$ = unsafe_$(context.program);
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Children } from "@alloy-js/core";
|
|
2
|
-
|
|
2
|
+
import { Program } from "@typespec/compiler";
|
|
3
|
+
export declare function writeOutput(program: Program, rootComponent: Children, emitterOutputDir: string): Promise<void>;
|
|
3
4
|
//# sourceMappingURL=write-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-output.d.ts","sourceRoot":"","sources":["../../../src/core/write-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA2B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"write-output.d.ts","sourceRoot":"","sources":["../../../src/core/write-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA2B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAuB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElE,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,QAAQ,EACvB,gBAAgB,EAAE,MAAM,iBAIzB"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { render } from "@alloy-js/core";
|
|
2
2
|
import { emitFile, joinPaths } from "@typespec/compiler";
|
|
3
|
-
|
|
4
|
-
export async function writeOutput(rootComponent, emitterOutputDir) {
|
|
3
|
+
export async function writeOutput(program, rootComponent, emitterOutputDir) {
|
|
5
4
|
const tree = render(rootComponent);
|
|
6
|
-
await writeOutputDirectory(tree, emitterOutputDir);
|
|
5
|
+
await writeOutputDirectory(program, tree, emitterOutputDir);
|
|
7
6
|
}
|
|
8
|
-
async function writeOutputDirectory(dir, emitterOutputDir) {
|
|
7
|
+
async function writeOutputDirectory(program, dir, emitterOutputDir) {
|
|
9
8
|
for (const sub of dir.contents) {
|
|
10
9
|
if (Array.isArray(sub.contents)) {
|
|
11
|
-
await writeOutputDirectory(sub, emitterOutputDir);
|
|
10
|
+
await writeOutputDirectory(program, sub, emitterOutputDir);
|
|
12
11
|
} else {
|
|
13
|
-
await emitFile(
|
|
12
|
+
await emitFile(program, {
|
|
14
13
|
content: sub.contents,
|
|
15
14
|
path: joinPaths(emitterOutputDir, sub.path)
|
|
16
15
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI9E,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"enum-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/enum-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI9E,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAwC1D;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;CACpB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAQhD"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ay from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
6
6
|
export function EnumDeclaration(props) {
|
|
7
|
+
const {
|
|
8
|
+
$
|
|
9
|
+
} = useTsp();
|
|
7
10
|
let type;
|
|
8
11
|
if ($.union.is(props.type)) {
|
|
9
12
|
if (!$.union.isValidEnum(props.type)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EACL,SAAS,EAET,KAAK,EAIN,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"interface-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EACL,SAAS,EAET,KAAK,EAIN,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,8BAA+B,SAAQ,IAAI,CAAC,EAAE,CAAC,yBAAyB,EAAE,MAAM,CAAC;IAChG,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,yBAAyB,GACjC,8BAA8B,GAC9B,EAAE,CAAC,yBAAyB,CAAC;AAEjC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAiCpE;AAQD,MAAM,WAAW,wBAAyB,SAAQ,EAAE,CAAC,wBAAwB;IAC3E,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,eAMlE"}
|
|
@@ -3,12 +3,15 @@ import * as ay from "@alloy-js/core";
|
|
|
3
3
|
import { refkey as getRefkey, mapJoin } from "@alloy-js/core";
|
|
4
4
|
import * as ts from "@alloy-js/typescript";
|
|
5
5
|
import { isNeverType } from "@typespec/compiler";
|
|
6
|
-
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
7
6
|
import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
7
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
8
8
|
import { reportDiagnostic } from "../../lib.js";
|
|
9
9
|
import { InterfaceMember } from "./interface-member.js";
|
|
10
10
|
import { TypeExpression } from "./type-expression.js";
|
|
11
11
|
export function InterfaceDeclaration(props) {
|
|
12
|
+
const {
|
|
13
|
+
$
|
|
14
|
+
} = useTsp();
|
|
12
15
|
if (!isTypedInterfaceDeclarationProps(props)) {
|
|
13
16
|
return _$createComponent(ts.InterfaceDeclaration, props);
|
|
14
17
|
}
|
|
@@ -22,7 +25,7 @@ export function InterfaceDeclaration(props) {
|
|
|
22
25
|
}
|
|
23
26
|
name = namePolicy.getName(name, "interface");
|
|
24
27
|
const refkey = props.refkey ?? getRefkey(props.type);
|
|
25
|
-
const extendsType = props.extends ?? getExtendsType(props.type);
|
|
28
|
+
const extendsType = props.extends ?? getExtendsType($, props.type);
|
|
26
29
|
return _$createComponent(ts.InterfaceDeclaration, {
|
|
27
30
|
get ["default"]() {
|
|
28
31
|
return props.default;
|
|
@@ -51,7 +54,7 @@ export function InterfaceExpression(props) {
|
|
|
51
54
|
}
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
|
-
function getExtendsType(type) {
|
|
57
|
+
function getExtendsType($, type) {
|
|
55
58
|
if (!$.model.is(type)) {
|
|
56
59
|
return undefined;
|
|
57
60
|
}
|
|
@@ -96,6 +99,9 @@ function getExtendsType(type) {
|
|
|
96
99
|
* Renders the members of an interface from its properties, including any additional children.
|
|
97
100
|
*/
|
|
98
101
|
function InterfaceBody(props) {
|
|
102
|
+
const {
|
|
103
|
+
$
|
|
104
|
+
} = useTsp();
|
|
99
105
|
let typeMembers;
|
|
100
106
|
if ($.model.is(props.type)) {
|
|
101
107
|
typeMembers = $.model.getProperties(props.type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-member.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-member.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM3E,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"interface-member.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-member.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM3E,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qCA4B1D"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { isNeverType } from "@typespec/compiler";
|
|
4
|
-
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
5
4
|
import { getHttpPart } from "@typespec/http";
|
|
5
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
6
|
import { InterfaceMethod } from "./interface-method.js";
|
|
7
7
|
import { TypeExpression } from "./type-expression.js";
|
|
8
8
|
export function InterfaceMember(props) {
|
|
9
|
+
const {
|
|
10
|
+
$
|
|
11
|
+
} = useTsp();
|
|
9
12
|
const namer = ts.useTSNamePolicy();
|
|
10
13
|
const name = namer.getName(props.type.name, "object-member-getter");
|
|
11
14
|
if ($.modelProperty.is(props.type)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-alias-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-alias-declaration.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK1C,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,yBAAyB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAE7F;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"type-alias-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-alias-declaration.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK1C,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,yBAAyB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAE7F;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,qCAqBpE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mergeProps as _$mergeProps, createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { refkey as getRefkey } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
6
6
|
import { TypeExpression } from "./type-expression.js";
|
|
7
7
|
/**
|
|
@@ -9,6 +9,9 @@ import { TypeExpression } from "./type-expression.js";
|
|
|
9
9
|
* type alias as the provided TypeSpec type.
|
|
10
10
|
*/
|
|
11
11
|
export function TypeAliasDeclaration(props) {
|
|
12
|
+
const {
|
|
13
|
+
$
|
|
14
|
+
} = useTsp();
|
|
12
15
|
if (!isTypedAliasDeclarationProps(props)) {
|
|
13
16
|
return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
|
|
14
17
|
get children() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-expression.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAgC,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"type-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-expression.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAgC,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,qCAAqC,CAAC;AAS7C,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAC;IAEX;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,qCA0DxD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { For, refkey } from "@alloy-js/core";
|
|
3
3
|
import { Reference, ValueExpression } from "@alloy-js/typescript";
|
|
4
|
-
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
5
4
|
import "@typespec/http/experimental/typekit";
|
|
5
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
6
|
import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
|
|
7
7
|
import { ArrayExpression } from "./array-expression.js";
|
|
8
8
|
import { FunctionType } from "./function-type.js";
|
|
@@ -10,8 +10,11 @@ import { InterfaceExpression } from "./interface-declaration.js";
|
|
|
10
10
|
import { RecordExpression } from "./record-expression.js";
|
|
11
11
|
import { UnionExpression } from "./union-expression.js";
|
|
12
12
|
export function TypeExpression(props) {
|
|
13
|
+
const {
|
|
14
|
+
$
|
|
15
|
+
} = useTsp();
|
|
13
16
|
const type = $.httpPart.unpack(props.type);
|
|
14
|
-
if (!props.noReference && isDeclaration(type)) {
|
|
17
|
+
if (!props.noReference && isDeclaration($, type)) {
|
|
15
18
|
// todo: probably need abstraction around deciding what's a declaration in the output
|
|
16
19
|
// (it may not correspond to things which are declarations in TypeSpec?)
|
|
17
20
|
return _$createComponent(Reference, {
|
|
@@ -26,7 +29,7 @@ export function TypeExpression(props) {
|
|
|
26
29
|
switch (type.kind) {
|
|
27
30
|
case "Scalar":
|
|
28
31
|
case "Intrinsic":
|
|
29
|
-
return [_$memo(() => getScalarIntrinsicExpression(type))];
|
|
32
|
+
return [_$memo(() => getScalarIntrinsicExpression($, type))];
|
|
30
33
|
case "Boolean":
|
|
31
34
|
case "Number":
|
|
32
35
|
case "String":
|
|
@@ -162,7 +165,7 @@ const intrinsicNameToTSType = new Map([
|
|
|
162
165
|
// String types
|
|
163
166
|
["url", "string"] // Matches TypeScript's `string`
|
|
164
167
|
]);
|
|
165
|
-
function getScalarIntrinsicExpression(type) {
|
|
168
|
+
function getScalarIntrinsicExpression($, type) {
|
|
166
169
|
let intrinsicName;
|
|
167
170
|
if ($.scalar.is(type)) {
|
|
168
171
|
if ($.scalar.isUtcDateTime(type) || $.scalar.extendsUtcDateTime(type)) {
|
|
@@ -192,7 +195,7 @@ function getScalarIntrinsicExpression(type) {
|
|
|
192
195
|
}
|
|
193
196
|
return tsType;
|
|
194
197
|
}
|
|
195
|
-
function isDeclaration(type) {
|
|
198
|
+
function isDeclaration($, type) {
|
|
196
199
|
switch (type.kind) {
|
|
197
200
|
case "Namespace":
|
|
198
201
|
case "Interface":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-transform.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,EAAU,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EAEL,KAAK,EAIL,IAAI,EACJ,KAAK,EACN,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"type-transform.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,EAAU,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EAEL,KAAK,EAIL,IAAI,EACJ,KAAK,EACN,MAAM,oBAAoB,CAAC;AAa5B,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;CACrC;AAwDD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,YAqEjE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,UAEvF;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,YAwE5E;AAyDD,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,QAAQ,CAuEzE"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { code, For, mapJoin, refkey } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
5
4
|
import { createRekeyableMap } from "@typespec/compiler/utils";
|
|
5
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
6
|
import { reportDiagnostic } from "../../lib.js";
|
|
7
7
|
import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
|
|
8
8
|
import { ArraySerializerRefkey, DateDeserializerRefkey, DateRfc3339SerializerRefkey, RecordSerializerRefkey } from "./static-serializers.js";
|
|
9
9
|
function UnionTransformExpression(props) {
|
|
10
|
+
const {
|
|
11
|
+
$
|
|
12
|
+
} = useTsp();
|
|
10
13
|
const discriminator = $.type.getDiscriminator(props.type);
|
|
11
14
|
if (!discriminator) {
|
|
12
15
|
// TODO: Handle non-discriminated unions
|
|
@@ -27,6 +30,9 @@ function UnionTransformExpression(props) {
|
|
|
27
30
|
});
|
|
28
31
|
}
|
|
29
32
|
function DiscriminateExpression(props) {
|
|
33
|
+
const {
|
|
34
|
+
$
|
|
35
|
+
} = useTsp();
|
|
30
36
|
const discriminatedUnion = $.model.is(props.type) ? $.model.getDiscriminatedUnion(props.type) : $.union.getDiscriminatedUnion(props.type);
|
|
31
37
|
if (!discriminatedUnion) {
|
|
32
38
|
return code`return item as any`;
|
|
@@ -60,6 +66,9 @@ function DiscriminateExpression(props) {
|
|
|
60
66
|
* Component that represents a function declaration that transforms a model to a transport or application model.
|
|
61
67
|
*/
|
|
62
68
|
export function TypeTransformDeclaration(props) {
|
|
69
|
+
const {
|
|
70
|
+
$
|
|
71
|
+
} = useTsp();
|
|
63
72
|
const namePolicy = ts.useTSNamePolicy();
|
|
64
73
|
|
|
65
74
|
// Record and array have their general serializers
|
|
@@ -149,6 +158,9 @@ export function getTypeTransformerRefkey(type, target) {
|
|
|
149
158
|
* Component that represents an object expression that transforms a model to a transport or application model.
|
|
150
159
|
*/
|
|
151
160
|
export function ModelTransformExpression(props) {
|
|
161
|
+
const {
|
|
162
|
+
$
|
|
163
|
+
} = useTsp();
|
|
152
164
|
if (props.type.baseModel) {
|
|
153
165
|
reportTypescriptDiagnostic($.program, {
|
|
154
166
|
code: "typescript-extended-model-transform-nyi",
|
|
@@ -208,7 +220,7 @@ export function ModelTransformExpression(props) {
|
|
|
208
220
|
type: unpackedType,
|
|
209
221
|
itemPath: itemPath
|
|
210
222
|
});
|
|
211
|
-
if (property.optional && needsTransform(unpackedType)) {
|
|
223
|
+
if (property.optional && needsTransform($, unpackedType)) {
|
|
212
224
|
value = [_$memo(() => itemPath.join(".")), " ?", " ", _$createComponent(TypeTransformCall, {
|
|
213
225
|
get target() {
|
|
214
226
|
return props.target;
|
|
@@ -233,6 +245,9 @@ export function ModelTransformExpression(props) {
|
|
|
233
245
|
* Given a type and target, gets the reference to the transform function
|
|
234
246
|
*/
|
|
235
247
|
function TransformReference(props) {
|
|
248
|
+
const {
|
|
249
|
+
$
|
|
250
|
+
} = useTsp();
|
|
236
251
|
if ($.scalar.is(props.type)) {
|
|
237
252
|
return _$createComponent(TransformScalarReference, {
|
|
238
253
|
get type() {
|
|
@@ -289,6 +304,9 @@ function TransformReference(props) {
|
|
|
289
304
|
* Handles scalar transformations
|
|
290
305
|
*/
|
|
291
306
|
function TransformScalarReference(props) {
|
|
307
|
+
const {
|
|
308
|
+
$
|
|
309
|
+
} = useTsp();
|
|
292
310
|
let reference;
|
|
293
311
|
if ($.scalar.isUtcDateTime(props.type)) {
|
|
294
312
|
// TODO: Handle encoding, likely to need access to parents to avoid passing the modelProperty
|
|
@@ -302,7 +320,7 @@ function TransformScalarReference(props) {
|
|
|
302
320
|
return null;
|
|
303
321
|
}
|
|
304
322
|
}
|
|
305
|
-
function needsTransform(type) {
|
|
323
|
+
function needsTransform($, type) {
|
|
306
324
|
return $.model.is(type) || $.scalar.isUtcDateTime(type);
|
|
307
325
|
}
|
|
308
326
|
|
|
@@ -310,7 +328,10 @@ function needsTransform(type) {
|
|
|
310
328
|
* This component represents a function call to transform a type
|
|
311
329
|
*/
|
|
312
330
|
export function TypeTransformCall(props) {
|
|
313
|
-
const
|
|
331
|
+
const {
|
|
332
|
+
$
|
|
333
|
+
} = useTsp();
|
|
334
|
+
const collapsedProperty = getCollapsedProperty($, props.type, props.collapse ?? false);
|
|
314
335
|
const itemPath = collapsedProperty ? [...(props.itemPath ?? []), collapsedProperty.name] : props.itemPath ?? [];
|
|
315
336
|
if (collapsedProperty?.optional) {
|
|
316
337
|
itemPath.unshift(`${props.optionsBagName}?`);
|
|
@@ -379,7 +400,7 @@ export function TypeTransformCall(props) {
|
|
|
379
400
|
}
|
|
380
401
|
return itemName;
|
|
381
402
|
}
|
|
382
|
-
function getCollapsedProperty(model, collapse) {
|
|
403
|
+
function getCollapsedProperty($, model, collapse) {
|
|
383
404
|
if (!$.model.is(model)) {
|
|
384
405
|
return undefined;
|
|
385
406
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-declaration.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKjD,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,qBAAqB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAEzF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"union-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-declaration.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKjD,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,qBAAqB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAEzF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,qCAsB5D"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { refkey as getRefkey } from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
5
|
import { reportDiagnostic } from "../../lib.js";
|
|
6
6
|
import { UnionExpression } from "./union-expression.js";
|
|
7
7
|
export function UnionDeclaration(props) {
|
|
8
|
+
const {
|
|
9
|
+
$
|
|
10
|
+
} = useTsp();
|
|
8
11
|
if (!isTypedUnionDeclarationProps(props)) {
|
|
9
12
|
return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
|
|
10
13
|
get children() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-expression.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAc,KAAK,EAAgB,MAAM,oBAAoB,CAAC;AAI3E,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"union-expression.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-expression.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAc,KAAK,EAAgB,MAAM,oBAAoB,CAAC;AAI3E,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,oBAAoB,eA4BvE"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ay from "@alloy-js/core";
|
|
3
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import {
|
|
4
|
+
import { useTsp } from "../../core/context/tsp-context.js";
|
|
5
5
|
import { TypeExpression } from "./type-expression.js";
|
|
6
6
|
export function UnionExpression({
|
|
7
7
|
type,
|
|
8
8
|
children
|
|
9
9
|
}) {
|
|
10
|
+
const {
|
|
11
|
+
$
|
|
12
|
+
} = useTsp();
|
|
10
13
|
const items = $.union.is(type) ? type.variants : type.members;
|
|
11
14
|
const variants = _$createComponent(ay.For, {
|
|
12
15
|
joiner: " | ",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAI3E,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,OAAO,GAAE;IAAE,kBAAkB,EAAE,OAAO,CAAA;CAAkC,GACvE,IAAI,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAI3E,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,OAAO,GAAE;IAAE,kBAAkB,EAAE,OAAO,CAAA;CAAkC,GACvE,IAAI,CASN;AAED,MAAM,WAAW,gCAAgC;IAC/C,MAAM,CAAC,EAAE,EAAE,CAAC,mBAAmB,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACzC;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,gCAAqC,GAC7C,EAAE,CAAC,mBAAmB,EAAE,GAAG,SAAS,CAkBtC;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,aAAa,GAAG,EAAE,CAAC,mBAAmB,CAU7F"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { refkey as getRefkey } from "@alloy-js/core";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import {
|
|
3
|
+
import { useTsp } from "../../core/index.js";
|
|
4
4
|
import { TypeExpression } from "../components/type-expression.js";
|
|
5
5
|
export function getReturnType(type, options = {
|
|
6
6
|
skipErrorFiltering: false
|
|
7
7
|
}) {
|
|
8
|
+
const {
|
|
9
|
+
$
|
|
10
|
+
} = useTsp();
|
|
8
11
|
let returnType = type.returnType;
|
|
9
12
|
if (!options.skipErrorFiltering && type.returnType.kind === "Union") {
|
|
10
13
|
returnType = $.union.filter(type.returnType, variant => !$.type.isError(variant.type));
|
|
@@ -12,6 +15,9 @@ export function getReturnType(type, options = {
|
|
|
12
15
|
return returnType;
|
|
13
16
|
}
|
|
14
17
|
export function buildParameterDescriptors(type, options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
$
|
|
20
|
+
} = useTsp();
|
|
15
21
|
const optionsParams = normalizeParameters(options.params);
|
|
16
22
|
if (options.mode === "replace") {
|
|
17
23
|
return optionsParams;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
5
|
import { beforeEach, describe, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../src/core/components/output.js";
|
|
6
7
|
import { ArrowFunction } from "../../../src/typescript/components/arrow-function.js";
|
|
7
8
|
import { assertFileContents } from "../../utils.js";
|
|
8
9
|
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
@@ -18,6 +19,9 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
18
19
|
@test op getName(id: string): string;
|
|
19
20
|
`);
|
|
20
21
|
const res = render(_$createComponent(Output, {
|
|
22
|
+
get program() {
|
|
23
|
+
return runner.program;
|
|
24
|
+
},
|
|
21
25
|
get children() {
|
|
22
26
|
return _$createComponent(SourceFile, {
|
|
23
27
|
path: "test.ts",
|
|
@@ -43,6 +47,9 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
43
47
|
@test op getName(id: string): string;
|
|
44
48
|
`);
|
|
45
49
|
const res = render(_$createComponent(Output, {
|
|
50
|
+
get program() {
|
|
51
|
+
return runner.program;
|
|
52
|
+
},
|
|
46
53
|
get children() {
|
|
47
54
|
return _$createComponent(SourceFile, {
|
|
48
55
|
path: "test.ts",
|
|
@@ -66,6 +73,9 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
66
73
|
@test op getName(id: string): string;
|
|
67
74
|
`);
|
|
68
75
|
const res = render(_$createComponent(Output, {
|
|
76
|
+
get program() {
|
|
77
|
+
return runner.program;
|
|
78
|
+
},
|
|
69
79
|
get children() {
|
|
70
80
|
return _$createComponent(SourceFile, {
|
|
71
81
|
path: "test.ts",
|