@typespec/emitter-framework 0.8.0-dev.2 → 0.8.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/src/typescript/components/enum-declaration.d.ts +1 -0
  3. package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
  4. package/dist/src/typescript/components/enum-declaration.js +7 -0
  5. package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
  6. package/dist/src/typescript/components/function-declaration.js +8 -3
  7. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  8. package/dist/src/typescript/components/interface-declaration.js +3 -0
  9. package/dist/src/typescript/components/interface-member.d.ts +3 -1
  10. package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
  11. package/dist/src/typescript/components/interface-member.js +2 -0
  12. package/dist/src/typescript/components/interface-method.d.ts +3 -1
  13. package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
  14. package/dist/src/typescript/components/interface-method.js +9 -2
  15. package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
  16. package/dist/src/typescript/components/type-alias-declaration.js +5 -2
  17. package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
  18. package/dist/src/typescript/components/type-declaration.js +11 -1
  19. package/dist/src/typescript/components/union-declaration.d.ts +3 -1
  20. package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
  21. package/dist/src/typescript/components/union-declaration.js +4 -1
  22. package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
  23. package/dist/src/typescript/components/union-expression.js +103 -10
  24. package/dist/src/typescript/utils/operation.d.ts +3 -1
  25. package/dist/src/typescript/utils/operation.d.ts.map +1 -1
  26. package/dist/src/typescript/utils/operation.js +10 -3
  27. package/dist/test/typescript/components/enum-declaration.test.js +79 -0
  28. package/dist/test/typescript/components/function-declaration.test.js +81 -0
  29. package/dist/test/typescript/components/interface-declaration.test.js +232 -9
  30. package/dist/test/typescript/components/type-alias-declaration.test.js +75 -0
  31. package/dist/test/typescript/components/union-declaration.test.js +358 -106
  32. package/package.json +6 -6
  33. package/src/typescript/components/enum-declaration.tsx +12 -1
  34. package/src/typescript/components/function-declaration.tsx +6 -1
  35. package/src/typescript/components/interface-declaration.tsx +3 -1
  36. package/src/typescript/components/interface-member.tsx +4 -0
  37. package/src/typescript/components/interface-method.tsx +7 -1
  38. package/src/typescript/components/type-alias-declaration.tsx +3 -2
  39. package/src/typescript/components/type-declaration.tsx +9 -7
  40. package/src/typescript/components/union-declaration.tsx +4 -1
  41. package/src/typescript/components/union-expression.tsx +100 -7
  42. package/src/typescript/utils/operation.ts +14 -3
  43. package/test/typescript/components/enum-declaration.test.tsx +72 -0
  44. package/test/typescript/components/function-declaration.test.tsx +78 -0
  45. package/test/typescript/components/interface-declaration.test.tsx +223 -9
  46. package/test/typescript/components/type-alias-declaration.test.tsx +72 -0
  47. 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,eAmC1D;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
+ {"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;AAKtD,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,qCAkClE;yBAlCe,mBAAmB;4BA2CyB,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
+ {"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 [_$createComponent(ts.FunctionDeclaration.Parameters, {
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,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"}
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): import("@alloy-js/core").Children;
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":"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
+ {"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>): import("@alloy-js/core/jsx-runtime").Children;
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":"AACA,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/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,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,iDA4BpE"}
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 { splitProps, createComponent as _$createComponent, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
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,qCAuBpE"}
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 refkeys = declarationRefkeys(props.refkey, props.name);
29
+ const doc = props.doc ?? $.type.getDoc(props.type);
30
+ const refkeys = declarationRefkeys(props.refkey, props.type);
30
31
  const name = ts.useTSNamePolicy().getName(originalName, "type");
31
- return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
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;AAO1C,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,qCAyB1D"}
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,13 +1,17 @@
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
- const refkeys = declarationRefkeys(props.refkey, props.name);
14
+ const refkeys = declarationRefkeys(props.refkey, props.type);
11
15
  return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
12
16
  refkey: refkeys
13
17
  }));
@@ -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): import("@alloy-js/core").Children;
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,qCAsB5D"}
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
- return _$createComponent(ts.TypeDeclaration, _$mergeProps(props, {
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,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
+ {"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: (_, value) => {
18
- if ($.enumMember.is(value)) {
19
+ children: (_, type) => {
20
+ if ($.enumMember.is(type)) {
19
21
  return _$createComponent(ts.ValueExpression, {
20
22
  get jsValue() {
21
- return value.value ?? value.name;
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, " ", ` | ${children}`];
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,3 +1,4 @@
1
+ import { Refkey } from "@alloy-js/core";
1
2
  import * as ts from "@alloy-js/typescript";
2
3
  import { Model, ModelProperty, Operation, Type } from "@typespec/compiler";
3
4
  export declare function getReturnType(type: Operation, options?: {
@@ -6,7 +7,8 @@ export declare function getReturnType(type: Operation, options?: {
6
7
  export interface BuildParameterDescriptorsOptions {
7
8
  params?: ts.ParameterDescriptor[] | string[] | undefined;
8
9
  mode?: "prepend" | "append" | "replace";
10
+ suffixRefkey?: Refkey;
9
11
  }
10
12
  export declare function buildParameterDescriptors(type: Model, options?: BuildParameterDescriptorsOptions): ts.ParameterDescriptor[] | undefined;
11
- export declare function buildParameterDescriptor(modelProperty: ModelProperty): ts.ParameterDescriptor;
13
+ export declare function buildParameterDescriptor(modelProperty: ModelProperty, suffixRefkey: Refkey): ts.ParameterDescriptor;
12
14
  //# sourceMappingURL=operation.d.ts.map
@@ -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,CAU7F"}
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../../src/typescript/utils/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChD,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;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,gCAAqC,GAC7C,EAAE,CAAC,mBAAmB,EAAE,GAAG,SAAS,CAqBtC;AAED,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,MAAM,GACnB,EAAE,CAAC,mBAAmB,CAaxB"}
@@ -1,3 +1,4 @@
1
+ import { refkey } from "@alloy-js/core";
1
2
  import * as ts from "@alloy-js/typescript";
2
3
  import { useTsp } from "../../core/index.js";
3
4
  import { TypeExpression } from "../components/type-expression.js";
@@ -18,24 +19,30 @@ export function buildParameterDescriptors(type, options = {}) {
18
19
  const {
19
20
  $
20
21
  } = useTsp();
22
+ const suffixRefkey = options.suffixRefkey ?? refkey();
21
23
  const optionsParams = normalizeParameters(options.params);
22
24
  if (options.mode === "replace") {
23
25
  return optionsParams;
24
26
  }
25
27
  const modelProperties = $.model.getProperties(type);
26
- const operationParams = [...modelProperties.values()].map(buildParameterDescriptor);
28
+ const operationParams = [...modelProperties.values()].map(m => buildParameterDescriptor(m, suffixRefkey));
27
29
 
28
30
  // Merge parameters based on location
29
31
  const allParams = options.mode === "append" ? operationParams.concat(optionsParams) : optionsParams.concat(operationParams);
30
32
  return allParams;
31
33
  }
32
- export function buildParameterDescriptor(modelProperty) {
34
+ export function buildParameterDescriptor(modelProperty, suffixRefkey) {
35
+ const {
36
+ $
37
+ } = useTsp();
33
38
  const namePolicy = ts.useTSNamePolicy();
34
39
  const paramName = namePolicy.getName(modelProperty.name, "parameter");
35
40
  const isOptional = modelProperty.optional || modelProperty.defaultValue !== undefined;
41
+ const doc = $.type.getDoc(modelProperty);
36
42
  return {
43
+ doc,
37
44
  name: paramName,
38
- refkey: efRefkey(modelProperty),
45
+ refkey: efRefkey(modelProperty, suffixRefkey),
39
46
  optional: isOptional,
40
47
  type: TypeExpression({
41
48
  type: modelProperty.type
@@ -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 {