@typespec/emitter-framework 0.8.0-dev.2 → 0.8.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.
- package/CHANGELOG.md +11 -0
- package/dist/src/typescript/components/enum-declaration.d.ts +1 -0
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +7 -0
- package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/function-declaration.js +8 -3
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +3 -0
- package/dist/src/typescript/components/interface-member.d.ts +3 -1
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-member.js +2 -0
- package/dist/src/typescript/components/interface-method.d.ts +3 -1
- package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-method.js +9 -2
- 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-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-declaration.js +10 -0
- package/dist/src/typescript/components/union-declaration.d.ts +3 -1
- 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 +103 -10
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.js +5 -0
- package/dist/test/typescript/components/enum-declaration.test.js +79 -0
- package/dist/test/typescript/components/function-declaration.test.js +81 -0
- package/dist/test/typescript/components/interface-declaration.test.js +232 -9
- package/dist/test/typescript/components/type-alias-declaration.test.js +75 -0
- package/dist/test/typescript/components/union-declaration.test.js +358 -106
- package/package.json +1 -1
- package/src/typescript/components/enum-declaration.tsx +12 -1
- package/src/typescript/components/function-declaration.tsx +6 -1
- package/src/typescript/components/interface-declaration.tsx +3 -1
- package/src/typescript/components/interface-member.tsx +4 -0
- package/src/typescript/components/interface-method.tsx +7 -1
- package/src/typescript/components/type-alias-declaration.tsx +2 -1
- package/src/typescript/components/type-declaration.tsx +8 -6
- package/src/typescript/components/union-declaration.tsx +4 -1
- package/src/typescript/components/union-expression.tsx +100 -7
- package/src/typescript/utils/operation.ts +3 -0
- package/test/typescript/components/enum-declaration.test.tsx +72 -0
- package/test/typescript/components/function-declaration.test.tsx +78 -0
- package/test/typescript/components/interface-declaration.test.tsx +223 -9
- package/test/typescript/components/type-alias-declaration.test.tsx +72 -0
- package/test/typescript/components/union-declaration.test.tsx +330 -102
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog - @typespec/emitter-framework
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Bump dependencies
|
|
6
|
+
|
|
7
|
+
- [#7363](https://github.com/microsoft/typespec/pull/7363) Upgrade alloy 16
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- [#7321](https://github.com/microsoft/typespec/pull/7321) Use wasm version of tree sitter for snippet extractor
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## 0.7.0
|
|
4
15
|
|
|
5
16
|
### Bump dependencies
|
|
@@ -8,6 +8,7 @@ export interface EnumDeclarationProps extends Omit<ts.TypeDeclarationProps, "nam
|
|
|
8
8
|
export declare function EnumDeclaration(props: EnumDeclarationProps): ay.Children;
|
|
9
9
|
export interface EnumMemberProps {
|
|
10
10
|
type: TspEnumMember;
|
|
11
|
+
doc?: ay.Children;
|
|
11
12
|
refkey?: ay.Refkey;
|
|
12
13
|
}
|
|
13
14
|
export declare function EnumMember(props: EnumMemberProps): ay.Children;
|
|
@@ -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;AAK9E,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;AAK9E,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,eA4C1D;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,GAAG,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC;IAClB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;CACpB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAShD"}
|
|
@@ -26,7 +26,9 @@ export function EnumDeclaration(props) {
|
|
|
26
26
|
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
27
27
|
const name = props.name ?? ts.useTSNamePolicy().getName(props.type.name, "enum");
|
|
28
28
|
const members = Array.from(type.members.entries());
|
|
29
|
+
const doc = props.doc ?? $.type.getDoc(type);
|
|
29
30
|
return _$createComponent(ts.EnumDeclaration, {
|
|
31
|
+
doc: doc,
|
|
30
32
|
name: name,
|
|
31
33
|
refkey: refkeys,
|
|
32
34
|
get ["default"]() {
|
|
@@ -40,7 +42,9 @@ export function EnumDeclaration(props) {
|
|
|
40
42
|
each: members,
|
|
41
43
|
joiner: ",\n",
|
|
42
44
|
children: ([key, value]) => {
|
|
45
|
+
const memberDoc = $.type.getDoc(value);
|
|
43
46
|
return _$createComponent(EnumMember, {
|
|
47
|
+
doc: memberDoc,
|
|
44
48
|
type: value,
|
|
45
49
|
get refkey() {
|
|
46
50
|
return _$memo(() => !!$.union.is(props.type))() ? efRefkey(props.type.variants.get(key)) : efRefkey(value);
|
|
@@ -53,6 +57,9 @@ export function EnumDeclaration(props) {
|
|
|
53
57
|
}
|
|
54
58
|
export function EnumMember(props) {
|
|
55
59
|
return _$createComponent(ts.EnumMember, {
|
|
60
|
+
get doc() {
|
|
61
|
+
return props.doc;
|
|
62
|
+
},
|
|
56
63
|
get name() {
|
|
57
64
|
return props.type.name;
|
|
58
65
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/function-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"function-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/function-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,WAAW,gCACf,SAAQ,IAAI,CAAC,EAAE,CAAC,wBAAwB,EAAE,MAAM,CAAC;IACjD,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,wBAAwB,GAChC,gCAAgC,GAChC,EAAE,CAAC,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qCAsClE;yBAtCe,mBAAmB;4BA+CyB,uBAAuB;;AAPnF,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,EAAE,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC7F,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,GAAG,EAAE,CAAC,uBAAuB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { useTsp } from "../../core/index.js";
|
|
3
4
|
import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
|
|
4
5
|
import { declarationRefkeys } from "../utils/refkey.js";
|
|
5
6
|
import { TypeExpression } from "./type-expression.js";
|
|
@@ -9,6 +10,9 @@ import { TypeExpression } from "./type-expression.js";
|
|
|
9
10
|
* provided will take precedence.
|
|
10
11
|
*/
|
|
11
12
|
export function FunctionDeclaration(props) {
|
|
13
|
+
const {
|
|
14
|
+
$
|
|
15
|
+
} = useTsp();
|
|
12
16
|
if (!isTypedFunctionDeclarationProps(props)) {
|
|
13
17
|
return _$createComponent(ts.FunctionDeclaration, props);
|
|
14
18
|
}
|
|
@@ -29,7 +33,9 @@ export function FunctionDeclaration(props) {
|
|
|
29
33
|
params: props.parameters,
|
|
30
34
|
mode: props.parametersMode
|
|
31
35
|
});
|
|
36
|
+
const doc = props.doc ?? $.type.getDoc(props.type);
|
|
32
37
|
return _$createComponent(ts.FunctionDeclaration, {
|
|
38
|
+
doc: doc,
|
|
33
39
|
refkey: refkeys,
|
|
34
40
|
name: name,
|
|
35
41
|
get async() {
|
|
@@ -45,10 +51,9 @@ export function FunctionDeclaration(props) {
|
|
|
45
51
|
return props.kind;
|
|
46
52
|
},
|
|
47
53
|
returnType: returnType,
|
|
54
|
+
parameters: allParameters,
|
|
48
55
|
get children() {
|
|
49
|
-
return
|
|
50
|
-
parameters: allParameters
|
|
51
|
-
}), _$memo(() => props.children)];
|
|
56
|
+
return props.children;
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
59
|
}
|
|
@@ -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;AAQ5B,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,
|
|
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;AAQ5B,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,eAmCpE;AAQD,MAAM,WAAW,wBAAyB,SAAQ,EAAE,CAAC,wBAAwB;IAC3E,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,eAMlE"}
|
|
@@ -27,7 +27,9 @@ export function InterfaceDeclaration(props) {
|
|
|
27
27
|
name = namePolicy.getName(name, "interface");
|
|
28
28
|
const refkeys = declarationRefkeys(props.refkey, props.type);
|
|
29
29
|
const extendsType = props.extends ?? getExtendsType($, props.type);
|
|
30
|
+
const doc = props.doc ?? $.type.getDoc(props.type);
|
|
30
31
|
return _$createComponent(ts.InterfaceDeclaration, {
|
|
32
|
+
doc: doc,
|
|
31
33
|
get ["default"]() {
|
|
32
34
|
return props.default;
|
|
33
35
|
},
|
|
@@ -130,6 +132,7 @@ function InterfaceBody(props) {
|
|
|
130
132
|
} : {};
|
|
131
133
|
return [_$createComponent(ay.For, _$mergeProps({
|
|
132
134
|
each: validTypeMembers,
|
|
135
|
+
semicolon: true,
|
|
133
136
|
line: true
|
|
134
137
|
}, enderProp, {
|
|
135
138
|
children: typeMember => {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
1
2
|
import { ModelProperty, Operation } from "@typespec/compiler";
|
|
2
3
|
export interface InterfaceMemberProps {
|
|
3
4
|
type: ModelProperty | Operation;
|
|
5
|
+
doc?: Children;
|
|
4
6
|
optional?: boolean;
|
|
5
7
|
}
|
|
6
|
-
export declare function InterfaceMember(props: InterfaceMemberProps):
|
|
8
|
+
export declare function InterfaceMember(props: InterfaceMemberProps): Children;
|
|
7
9
|
//# sourceMappingURL=interface-member.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-member.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-member.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interface-member.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-member.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAe,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAM3E,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YA8B1D"}
|
|
@@ -11,6 +11,7 @@ export function InterfaceMember(props) {
|
|
|
11
11
|
} = useTsp();
|
|
12
12
|
const namer = ts.useTSNamePolicy();
|
|
13
13
|
const name = namer.getName(props.type.name, "object-member-getter");
|
|
14
|
+
const doc = props.doc ?? $.type.getDoc(props.type);
|
|
14
15
|
if ($.modelProperty.is(props.type)) {
|
|
15
16
|
if (isNeverType(props.type.type)) {
|
|
16
17
|
return null;
|
|
@@ -21,6 +22,7 @@ export function InterfaceMember(props) {
|
|
|
21
22
|
unpackedType = part.type;
|
|
22
23
|
}
|
|
23
24
|
return _$createComponent(ts.InterfaceMember, {
|
|
25
|
+
doc: doc,
|
|
24
26
|
name: name,
|
|
25
27
|
get optional() {
|
|
26
28
|
return props.optional ?? props.type.optional;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
1
2
|
import * as ts from "@alloy-js/typescript";
|
|
2
3
|
import { Operation } from "@typespec/compiler";
|
|
3
4
|
export interface InterfaceMethodPropsWithType extends Omit<ts.InterfaceMethodProps, "name"> {
|
|
4
5
|
type: Operation;
|
|
5
6
|
name?: string;
|
|
7
|
+
doc?: Children;
|
|
6
8
|
parametersMode?: "prepend" | "append" | "replace";
|
|
7
9
|
}
|
|
8
10
|
export type InterfaceMethodProps = InterfaceMethodPropsWithType | ts.InterfaceMethodProps;
|
|
@@ -11,5 +13,5 @@ export type InterfaceMethodProps = InterfaceMethodPropsWithType | ts.InterfaceMe
|
|
|
11
13
|
* method by converting from a TypeSpec Operation. Any other props
|
|
12
14
|
* provided will take precedence.
|
|
13
15
|
*/
|
|
14
|
-
export declare function InterfaceMethod(props: Readonly<InterfaceMethodProps>):
|
|
16
|
+
export declare function InterfaceMethod(props: Readonly<InterfaceMethodProps>): Children;
|
|
15
17
|
//# sourceMappingURL=interface-method.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-method.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interface-method.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/interface-method.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAK/C,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACzF,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAE1F;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,YAgCpE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { splitProps } from "@alloy-js/core";
|
|
2
3
|
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
import { useTsp } from "../../core/index.js";
|
|
3
5
|
import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
|
|
4
6
|
import { TypeExpression } from "./type-expression.js";
|
|
5
7
|
/**
|
|
@@ -8,6 +10,9 @@ import { TypeExpression } from "./type-expression.js";
|
|
|
8
10
|
* provided will take precedence.
|
|
9
11
|
*/
|
|
10
12
|
export function InterfaceMethod(props) {
|
|
13
|
+
const {
|
|
14
|
+
$
|
|
15
|
+
} = useTsp();
|
|
11
16
|
const isTypeSpecTyped = "type" in props;
|
|
12
17
|
if (!isTypeSpecTyped) {
|
|
13
18
|
return _$createComponent(ts.InterfaceMethod, props);
|
|
@@ -23,9 +28,11 @@ export function InterfaceMethod(props) {
|
|
|
23
28
|
params: props.parameters,
|
|
24
29
|
mode: props.parametersMode
|
|
25
30
|
});
|
|
31
|
+
const doc = props.doc ?? $.type.getDoc(props.type);
|
|
26
32
|
return _$createComponent(ts.InterfaceMethod, _$mergeProps(forwardProps, updateProps, {
|
|
27
33
|
name: name,
|
|
28
34
|
returnType: returnType,
|
|
29
|
-
parameters: allParameters
|
|
35
|
+
parameters: allParameters,
|
|
36
|
+
doc: doc
|
|
30
37
|
}));
|
|
31
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-alias-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-alias-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAM1C,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":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAM1C,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,qCAwBpE"}
|
|
@@ -26,9 +26,12 @@ export function TypeAliasDeclaration(props) {
|
|
|
26
26
|
target: props.type
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
const doc = props.doc ?? $.type.getDoc(props.type);
|
|
29
30
|
const refkeys = declarationRefkeys(props.refkey, props.name);
|
|
30
31
|
const name = ts.useTSNamePolicy().getName(originalName, "type");
|
|
31
|
-
return _$createComponent(ts.TypeDeclaration, _$mergeProps(
|
|
32
|
+
return _$createComponent(ts.TypeDeclaration, _$mergeProps({
|
|
33
|
+
doc: doc
|
|
34
|
+
}, props, {
|
|
32
35
|
name: name,
|
|
33
36
|
refkey: refkeys,
|
|
34
37
|
get children() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"type-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAQ1C,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACjF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE1E,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qCA0B1D"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { useTsp } from "../../core/index.js";
|
|
3
4
|
import { declarationRefkeys } from "../utils/refkey.js";
|
|
4
5
|
import { EnumDeclaration } from "./enum-declaration.js";
|
|
5
6
|
import { InterfaceDeclaration } from "./interface-declaration.js";
|
|
6
7
|
import { TypeAliasDeclaration } from "./type-alias-declaration.js";
|
|
7
8
|
import { UnionDeclaration } from "./union-declaration.js";
|
|
8
9
|
export function TypeDeclaration(props) {
|
|
10
|
+
const {
|
|
11
|
+
$
|
|
12
|
+
} = useTsp();
|
|
9
13
|
if (!props.type) {
|
|
10
14
|
const refkeys = declarationRefkeys(props.refkey, props.name);
|
|
11
15
|
return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
|
|
@@ -16,25 +20,31 @@ export function TypeDeclaration(props) {
|
|
|
16
20
|
type,
|
|
17
21
|
...restProps
|
|
18
22
|
} = props;
|
|
23
|
+
const doc = props.doc ?? $.type.getDoc(type);
|
|
19
24
|
switch (type.kind) {
|
|
20
25
|
case "Model":
|
|
21
26
|
return _$createComponent(InterfaceDeclaration, _$mergeProps({
|
|
27
|
+
doc: doc,
|
|
22
28
|
type: type
|
|
23
29
|
}, restProps));
|
|
24
30
|
case "Union":
|
|
25
31
|
return _$createComponent(UnionDeclaration, _$mergeProps({
|
|
32
|
+
doc: doc,
|
|
26
33
|
type: type
|
|
27
34
|
}, restProps));
|
|
28
35
|
case "Enum":
|
|
29
36
|
return _$createComponent(EnumDeclaration, _$mergeProps({
|
|
37
|
+
doc: doc,
|
|
30
38
|
type: type
|
|
31
39
|
}, restProps));
|
|
32
40
|
case "Scalar":
|
|
33
41
|
return _$createComponent(TypeAliasDeclaration, _$mergeProps({
|
|
42
|
+
doc: doc,
|
|
34
43
|
type: type
|
|
35
44
|
}, restProps));
|
|
36
45
|
case "Operation":
|
|
37
46
|
return _$createComponent(TypeAliasDeclaration, _$mergeProps({
|
|
47
|
+
doc: doc,
|
|
38
48
|
type: type
|
|
39
49
|
}, restProps));
|
|
40
50
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
1
2
|
import * as ts from "@alloy-js/typescript";
|
|
2
3
|
import { Enum, Union } from "@typespec/compiler";
|
|
3
4
|
export interface TypedUnionDeclarationProps extends Omit<ts.TypeDeclarationProps, "name"> {
|
|
4
5
|
type: Union | Enum;
|
|
6
|
+
doc?: Children;
|
|
5
7
|
name?: string;
|
|
6
8
|
}
|
|
7
9
|
export type UnionDeclarationProps = TypedUnionDeclarationProps | ts.TypeDeclarationProps;
|
|
8
|
-
export declare function UnionDeclaration(props: UnionDeclarationProps):
|
|
10
|
+
export declare function UnionDeclaration(props: UnionDeclarationProps): Children;
|
|
9
11
|
//# sourceMappingURL=union-declaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union-declaration.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/union-declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAMjD,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":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAMjD,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,EAAE,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACvF,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,qBAAqB,GAAG,0BAA0B,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAEzF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,YAuB5D"}
|
|
@@ -28,7 +28,10 @@ export function UnionDeclaration(props) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
const name = ts.useTSNamePolicy().getName(originalName, "type");
|
|
31
|
-
|
|
31
|
+
const doc = props.doc ?? $.type.getDoc(type);
|
|
32
|
+
return _$createComponent(ts.TypeDeclaration, _$mergeProps({
|
|
33
|
+
doc: doc
|
|
34
|
+
}, props, {
|
|
32
35
|
name: name,
|
|
33
36
|
refkey: refkeys,
|
|
34
37
|
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,
|
|
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,EAAkB,IAAI,EAAc,KAAK,EAAgB,MAAM,oBAAoB,CAAC;AAK3F,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,eA+CvE"}
|
|
@@ -1,7 +1,9 @@
|
|
|
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 { compilerAssert } from "@typespec/compiler";
|
|
4
5
|
import { useTsp } from "../../core/context/tsp-context.js";
|
|
6
|
+
import { efRefkey } from "../utils/refkey.js";
|
|
5
7
|
import { TypeExpression } from "./type-expression.js";
|
|
6
8
|
export function UnionExpression({
|
|
7
9
|
type,
|
|
@@ -14,24 +16,115 @@ export function UnionExpression({
|
|
|
14
16
|
const variants = _$createComponent(ay.For, {
|
|
15
17
|
joiner: " | ",
|
|
16
18
|
each: items,
|
|
17
|
-
children: (_,
|
|
18
|
-
if ($.enumMember.is(
|
|
19
|
+
children: (_, type) => {
|
|
20
|
+
if ($.enumMember.is(type)) {
|
|
19
21
|
return _$createComponent(ts.ValueExpression, {
|
|
20
22
|
get jsValue() {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
return _$createComponent(TypeExpression, {
|
|
26
|
-
get type() {
|
|
27
|
-
return value.type;
|
|
23
|
+
return type.value ?? type.name;
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
26
|
}
|
|
27
|
+
const discriminatedUnion = $.union.getDiscriminatedUnion(type.union);
|
|
28
|
+
switch (discriminatedUnion?.options.envelope) {
|
|
29
|
+
case "object":
|
|
30
|
+
return _$createComponent(ObjectEnvelope, {
|
|
31
|
+
get discriminatorPropertyName() {
|
|
32
|
+
return discriminatedUnion.options.discriminatorPropertyName;
|
|
33
|
+
},
|
|
34
|
+
get envelopePropertyName() {
|
|
35
|
+
return discriminatedUnion.options.envelopePropertyName;
|
|
36
|
+
},
|
|
37
|
+
type: type
|
|
38
|
+
});
|
|
39
|
+
case "none":
|
|
40
|
+
return _$createComponent(NoneEnvelope, {
|
|
41
|
+
get discriminatorPropertyName() {
|
|
42
|
+
return discriminatedUnion.options.discriminatorPropertyName;
|
|
43
|
+
},
|
|
44
|
+
type: type
|
|
45
|
+
});
|
|
46
|
+
default:
|
|
47
|
+
return _$createComponent(TypeExpression, {
|
|
48
|
+
get type() {
|
|
49
|
+
return type.type;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
54
|
});
|
|
33
55
|
if (children || Array.isArray(children) && children.length) {
|
|
34
|
-
return [variants, " ",
|
|
56
|
+
return [variants, " ", `| ${children}`];
|
|
35
57
|
}
|
|
36
58
|
return variants;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Renders a discriminated union with "object" envelope style
|
|
62
|
+
* where model properties are nested inside an envelope
|
|
63
|
+
*/
|
|
64
|
+
function ObjectEnvelope(props) {
|
|
65
|
+
const {
|
|
66
|
+
$
|
|
67
|
+
} = useTsp();
|
|
68
|
+
const envelope = $.model.create({
|
|
69
|
+
properties: {
|
|
70
|
+
[props.discriminatorPropertyName]: $.modelProperty.create({
|
|
71
|
+
name: props.discriminatorPropertyName,
|
|
72
|
+
type: $.literal.createString(props.type.name)
|
|
73
|
+
}),
|
|
74
|
+
[props.envelopePropertyName]: $.modelProperty.create({
|
|
75
|
+
name: props.envelopePropertyName,
|
|
76
|
+
type: props.type.type
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return _$createComponent(TypeExpression, {
|
|
81
|
+
type: envelope
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Renders a discriminated union with "none" envelope style
|
|
86
|
+
* where discriminator property sits alongside model properties
|
|
87
|
+
*/
|
|
88
|
+
function NoneEnvelope(props) {
|
|
89
|
+
const {
|
|
90
|
+
$
|
|
91
|
+
} = useTsp();
|
|
92
|
+
compilerAssert($.model.is(props.type.type), "Expected all union variants to be models when using a discriminated union with no envelope");
|
|
93
|
+
|
|
94
|
+
// Render anonymous models as a set of properties + the discriminator
|
|
95
|
+
if ($.model.isExpresion(props.type.type)) {
|
|
96
|
+
const model = $.model.create({
|
|
97
|
+
properties: {
|
|
98
|
+
[props.discriminatorPropertyName]: $.modelProperty.create({
|
|
99
|
+
name: props.discriminatorPropertyName,
|
|
100
|
+
type: $.literal.createString(props.type.name)
|
|
101
|
+
}),
|
|
102
|
+
...Object.fromEntries(props.type.type.properties)
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return _$createComponent(TypeExpression, {
|
|
106
|
+
type: model
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return _$createComponent(ay.List, {
|
|
110
|
+
joiner: " & ",
|
|
111
|
+
get children() {
|
|
112
|
+
return [_$createComponent(ts.ObjectExpression, {
|
|
113
|
+
get children() {
|
|
114
|
+
return _$createComponent(ts.ObjectProperty, {
|
|
115
|
+
get name() {
|
|
116
|
+
return props.discriminatorPropertyName;
|
|
117
|
+
},
|
|
118
|
+
get value() {
|
|
119
|
+
return _$createComponent(ts.ValueExpression, {
|
|
120
|
+
get jsValue() {
|
|
121
|
+
return props.type.name;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}), [_$memo(() => efRefkey(props.type.type))]];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
37
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK3E,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,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK3E,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,CAa7F"}
|
|
@@ -30,10 +30,15 @@ export function buildParameterDescriptors(type, options = {}) {
|
|
|
30
30
|
return allParams;
|
|
31
31
|
}
|
|
32
32
|
export function buildParameterDescriptor(modelProperty) {
|
|
33
|
+
const {
|
|
34
|
+
$
|
|
35
|
+
} = useTsp();
|
|
33
36
|
const namePolicy = ts.useTSNamePolicy();
|
|
34
37
|
const paramName = namePolicy.getName(modelProperty.name, "parameter");
|
|
35
38
|
const isOptional = modelProperty.optional || modelProperty.defaultValue !== undefined;
|
|
39
|
+
const doc = $.type.getDoc(modelProperty);
|
|
36
40
|
return {
|
|
41
|
+
doc,
|
|
37
42
|
name: paramName,
|
|
38
43
|
refkey: efRefkey(modelProperty),
|
|
39
44
|
optional: isOptional,
|
|
@@ -36,6 +36,85 @@ describe("Typescript Enum Declaration", () => {
|
|
|
36
36
|
}
|
|
37
37
|
`);
|
|
38
38
|
});
|
|
39
|
+
it("adds JSDoc from TypeSpec", async () => {
|
|
40
|
+
const code = `
|
|
41
|
+
/**
|
|
42
|
+
* This is a test enum
|
|
43
|
+
*/
|
|
44
|
+
enum Foo {
|
|
45
|
+
@doc("This is one")
|
|
46
|
+
one: 1,
|
|
47
|
+
two: 2,
|
|
48
|
+
three: 3
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
const output = await getEmitOutput(code, program => {
|
|
52
|
+
const Foo = program.resolveTypeReference("Foo")[0];
|
|
53
|
+
return _$createComponent(TspContext.Provider, {
|
|
54
|
+
value: {
|
|
55
|
+
program
|
|
56
|
+
},
|
|
57
|
+
get children() {
|
|
58
|
+
return _$createComponent(EnumDeclaration, {
|
|
59
|
+
type: Foo
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
expect(output).toBe(d`
|
|
65
|
+
/**
|
|
66
|
+
* This is a test enum
|
|
67
|
+
*/
|
|
68
|
+
enum Foo {
|
|
69
|
+
/**
|
|
70
|
+
* This is one
|
|
71
|
+
*/
|
|
72
|
+
one = 1,
|
|
73
|
+
two = 2,
|
|
74
|
+
three = 3
|
|
75
|
+
}
|
|
76
|
+
`);
|
|
77
|
+
});
|
|
78
|
+
it("explicit doc take precedence", async () => {
|
|
79
|
+
const code = `
|
|
80
|
+
/**
|
|
81
|
+
* This is a test enum
|
|
82
|
+
*/
|
|
83
|
+
enum Foo {
|
|
84
|
+
@doc("This is one")
|
|
85
|
+
one: 1,
|
|
86
|
+
two: 2,
|
|
87
|
+
three: 3
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
const output = await getEmitOutput(code, program => {
|
|
91
|
+
const Foo = program.resolveTypeReference("Foo")[0];
|
|
92
|
+
return _$createComponent(TspContext.Provider, {
|
|
93
|
+
value: {
|
|
94
|
+
program
|
|
95
|
+
},
|
|
96
|
+
get children() {
|
|
97
|
+
return _$createComponent(EnumDeclaration, {
|
|
98
|
+
type: Foo,
|
|
99
|
+
doc: ["This is an explicit doc"]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
expect(output).toBe(d`
|
|
105
|
+
/**
|
|
106
|
+
* This is an explicit doc
|
|
107
|
+
*/
|
|
108
|
+
enum Foo {
|
|
109
|
+
/**
|
|
110
|
+
* This is one
|
|
111
|
+
*/
|
|
112
|
+
one = 1,
|
|
113
|
+
two = 2,
|
|
114
|
+
three = 3
|
|
115
|
+
}
|
|
116
|
+
`);
|
|
117
|
+
});
|
|
39
118
|
it("takes a union type parameter", async () => {
|
|
40
119
|
const code = `
|
|
41
120
|
union Foo {
|