@typespec/emitter-framework 0.9.0-dev.0 → 0.9.0-dev.10

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 (192) hide show
  1. package/dist/src/core/components/output.d.ts +4 -4
  2. package/dist/src/core/components/output.d.ts.map +1 -1
  3. package/dist/src/core/components/output.js +3 -3
  4. package/dist/src/core/context/name-policy-context.d.ts +2 -2
  5. package/dist/src/core/context/name-policy-context.d.ts.map +1 -1
  6. package/dist/src/core/context/tsp-context.d.ts +2 -2
  7. package/dist/src/core/context/tsp-context.d.ts.map +1 -1
  8. package/dist/src/core/transport-name-policy.d.ts +1 -1
  9. package/dist/src/core/transport-name-policy.d.ts.map +1 -1
  10. package/dist/src/core/write-output.d.ts +2 -2
  11. package/dist/src/core/write-output.d.ts.map +1 -1
  12. package/dist/src/csharp/components/class/declaration.d.ts +13 -0
  13. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -0
  14. package/dist/src/csharp/components/class/declaration.js +91 -0
  15. package/dist/src/csharp/components/class/declaration.test.d.ts +2 -0
  16. package/dist/src/csharp/components/class/declaration.test.d.ts.map +1 -0
  17. package/dist/src/csharp/components/class/declaration.test.js +377 -0
  18. package/dist/src/csharp/components/enum/declaration.d.ts +9 -0
  19. package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
  20. package/dist/src/csharp/components/enum/declaration.js +55 -0
  21. package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
  22. package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
  23. package/dist/src/csharp/components/enum/declaration.test.js +309 -0
  24. package/dist/src/csharp/components/index.d.ts +5 -0
  25. package/dist/src/csharp/components/index.d.ts.map +1 -0
  26. package/dist/src/csharp/components/index.js +4 -0
  27. package/dist/src/csharp/components/property/property.d.ts +15 -0
  28. package/dist/src/csharp/components/property/property.d.ts.map +1 -0
  29. package/dist/src/csharp/components/property/property.js +85 -0
  30. package/dist/src/csharp/components/property/property.test.d.ts +2 -0
  31. package/dist/src/csharp/components/property/property.test.d.ts.map +1 -0
  32. package/dist/src/csharp/components/property/property.test.js +117 -0
  33. package/dist/src/csharp/components/type-expression.d.ts +11 -0
  34. package/dist/src/csharp/components/type-expression.d.ts.map +1 -0
  35. package/dist/src/csharp/components/type-expression.js +143 -0
  36. package/dist/src/csharp/components/type-expression.test.d.ts +2 -0
  37. package/dist/src/csharp/components/type-expression.test.d.ts.map +1 -0
  38. package/dist/src/csharp/components/type-expression.test.js +128 -0
  39. package/dist/src/csharp/components/utils/doc-comments.d.ts +14 -0
  40. package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -0
  41. package/dist/src/csharp/components/utils/doc-comments.js +67 -0
  42. package/dist/src/csharp/components/utils/refkey.d.ts +23 -0
  43. package/dist/src/csharp/components/utils/refkey.d.ts.map +1 -0
  44. package/dist/src/csharp/components/utils/refkey.js +35 -0
  45. package/dist/src/csharp/index.d.ts +2 -0
  46. package/dist/src/csharp/index.d.ts.map +1 -0
  47. package/dist/src/csharp/index.js +1 -0
  48. package/dist/src/testing/index.d.ts +1 -1
  49. package/dist/src/testing/index.d.ts.map +1 -1
  50. package/dist/src/testing/scenario-test/code-block-expectation.d.ts +33 -0
  51. package/dist/src/testing/scenario-test/code-block-expectation.d.ts.map +1 -0
  52. package/dist/src/testing/scenario-test/code-block-expectation.js +69 -0
  53. package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts +2 -0
  54. package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts.map +1 -0
  55. package/dist/src/testing/scenario-test/code-block-expectation.test.js +80 -0
  56. package/dist/src/testing/scenario-test/harness.d.ts +3 -3
  57. package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
  58. package/dist/src/testing/scenario-test/harness.js +69 -158
  59. package/dist/src/testing/scenario-test/index.d.ts +0 -1
  60. package/dist/src/testing/scenario-test/index.d.ts.map +1 -1
  61. package/dist/src/testing/scenario-test/index.js +1 -2
  62. package/dist/src/testing/scenario-test/snippet-extractor.d.ts +1 -1
  63. package/dist/src/testing/scenario-test/snippet-extractor.js +1 -1
  64. package/dist/src/typescript/components/array-expression.d.ts +2 -3
  65. package/dist/src/typescript/components/array-expression.d.ts.map +1 -1
  66. package/dist/src/typescript/components/array-expression.js +2 -2
  67. package/dist/src/typescript/components/arrow-function.d.ts +2 -2
  68. package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
  69. package/dist/src/typescript/components/arrow-function.js +2 -1
  70. package/dist/src/typescript/components/class-method.d.ts +1 -1
  71. package/dist/src/typescript/components/class-method.d.ts.map +1 -1
  72. package/dist/src/typescript/components/enum-declaration.d.ts +6 -6
  73. package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
  74. package/dist/src/typescript/components/enum-declaration.js +2 -2
  75. package/dist/src/typescript/components/function-declaration.d.ts +1 -1
  76. package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
  77. package/dist/src/typescript/components/function-expression.d.ts +2 -2
  78. package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
  79. package/dist/src/typescript/components/function-expression.js +2 -1
  80. package/dist/src/typescript/components/function-type.d.ts +2 -2
  81. package/dist/src/typescript/components/function-type.d.ts.map +1 -1
  82. package/dist/src/typescript/components/function-type.js +2 -1
  83. package/dist/src/typescript/components/interface-declaration.d.ts +4 -4
  84. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  85. package/dist/src/typescript/components/interface-declaration.js +3 -4
  86. package/dist/src/typescript/components/interface-member.d.ts +2 -2
  87. package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
  88. package/dist/src/typescript/components/interface-method.d.ts +2 -2
  89. package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
  90. package/dist/src/typescript/components/record-expression.d.ts +1 -1
  91. package/dist/src/typescript/components/record-expression.d.ts.map +1 -1
  92. package/dist/src/typescript/components/type-alias-declaration.d.ts +1 -1
  93. package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
  94. package/dist/src/typescript/components/type-declaration.d.ts +1 -1
  95. package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
  96. package/dist/src/typescript/components/type-expression.d.ts +1 -1
  97. package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
  98. package/dist/src/typescript/components/type-transform.d.ts +2 -2
  99. package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
  100. package/dist/src/typescript/components/union-declaration.d.ts +2 -2
  101. package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
  102. package/dist/src/typescript/components/union-expression.d.ts +3 -4
  103. package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
  104. package/dist/src/typescript/components/union-expression.js +3 -3
  105. package/dist/src/typescript/components/value-expression.d.ts +2 -2
  106. package/dist/src/typescript/components/value-expression.d.ts.map +1 -1
  107. package/dist/src/typescript/utils/operation.d.ts +2 -2
  108. package/dist/src/typescript/utils/operation.d.ts.map +1 -1
  109. package/dist/test/test-host.d.ts +2 -0
  110. package/dist/test/test-host.d.ts.map +1 -0
  111. package/dist/test/test-host.js +5 -0
  112. package/dist/test/testing/snippet-extractor-csharp.test.js +3 -3
  113. package/dist/test/testing/snippet-extractor-java.test.js +3 -3
  114. package/dist/test/testing/snippet-extractor-python.test.js +2 -2
  115. package/dist/test/testing/snippet-extractor-typescript.test.js +3 -3
  116. package/dist/test/typescript/components/member-expression.test.js +5 -5
  117. package/dist/test/typescript/test-host.d.ts +1 -1
  118. package/dist/test/typescript/test-host.d.ts.map +1 -1
  119. package/dist/test/utils.d.ts +2 -2
  120. package/dist/test/utils.d.ts.map +1 -1
  121. package/dist/test/vitest.setup.d.ts +2 -0
  122. package/dist/test/vitest.setup.d.ts.map +1 -0
  123. package/dist/test/vitest.setup.js +1 -0
  124. package/package.json +30 -8
  125. package/src/core/components/output.tsx +9 -5
  126. package/src/core/context/name-policy-context.ts +2 -2
  127. package/src/core/context/tsp-context.ts +2 -2
  128. package/src/core/transport-name-policy.ts +1 -1
  129. package/src/core/write-output.ts +2 -2
  130. package/src/csharp/components/class/declaration.test.tsx +339 -0
  131. package/src/csharp/components/class/declaration.tsx +86 -0
  132. package/src/csharp/components/enum/declaration.test.tsx +267 -0
  133. package/src/csharp/components/enum/declaration.tsx +56 -0
  134. package/src/csharp/components/index.ts +4 -0
  135. package/src/csharp/components/property/property.test.tsx +97 -0
  136. package/src/csharp/components/property/property.tsx +62 -0
  137. package/src/csharp/components/type-expression.test.tsx +133 -0
  138. package/src/csharp/components/type-expression.tsx +119 -0
  139. package/src/csharp/components/utils/doc-comments.tsx +58 -0
  140. package/src/csharp/components/utils/refkey.ts +36 -0
  141. package/src/csharp/index.ts +1 -0
  142. package/src/testing/index.ts +1 -1
  143. package/src/testing/scenario-test/code-block-expectation.test.ts +95 -0
  144. package/src/testing/scenario-test/code-block-expectation.ts +115 -0
  145. package/src/testing/scenario-test/harness.ts +92 -237
  146. package/src/testing/scenario-test/index.ts +0 -1
  147. package/src/testing/scenario-test/snippet-extractor.ts +1 -1
  148. package/src/typescript/components/array-expression.tsx +3 -3
  149. package/src/typescript/components/arrow-function.tsx +2 -2
  150. package/src/typescript/components/class-method.tsx +1 -1
  151. package/src/typescript/components/enum-declaration.tsx +6 -6
  152. package/src/typescript/components/function-declaration.tsx +1 -1
  153. package/src/typescript/components/function-expression.tsx +2 -2
  154. package/src/typescript/components/function-type.tsx +2 -2
  155. package/src/typescript/components/interface-declaration.tsx +11 -12
  156. package/src/typescript/components/interface-member.tsx +2 -2
  157. package/src/typescript/components/interface-method.tsx +2 -2
  158. package/src/typescript/components/record-expression.tsx +1 -1
  159. package/src/typescript/components/type-alias-declaration.tsx +1 -1
  160. package/src/typescript/components/type-declaration.tsx +1 -1
  161. package/src/typescript/components/type-expression.tsx +2 -2
  162. package/src/typescript/components/type-transform.tsx +3 -3
  163. package/src/typescript/components/union-declaration.tsx +2 -2
  164. package/src/typescript/components/union-expression.tsx +12 -7
  165. package/src/typescript/components/value-expression.tsx +2 -2
  166. package/src/typescript/utils/operation.ts +2 -2
  167. package/test/test-host.ts +4 -0
  168. package/test/testing/snippet-extractor-csharp.test.ts +4 -4
  169. package/test/testing/snippet-extractor-java.test.ts +4 -4
  170. package/test/testing/snippet-extractor-python.test.ts +3 -3
  171. package/test/testing/snippet-extractor-typescript.test.ts +4 -4
  172. package/test/typescript/components/arrow-function.test.tsx +2 -2
  173. package/test/typescript/components/enum-declaration.test.tsx +1 -1
  174. package/test/typescript/components/function-declaration.test.tsx +1 -1
  175. package/test/typescript/components/function-expression.test.tsx +2 -2
  176. package/test/typescript/components/function-type.test.tsx +2 -2
  177. package/test/typescript/components/interface-declaration.test.tsx +1 -1
  178. package/test/typescript/components/interface-method.test.tsx +2 -2
  179. package/test/typescript/components/member-expression.test.tsx +10 -10
  180. package/test/typescript/components/type-alias-declaration.test.tsx +1 -1
  181. package/test/typescript/components/type-transform.test.tsx +2 -2
  182. package/test/typescript/components/union-declaration.test.tsx +2 -2
  183. package/test/typescript/components/value-expression.test.tsx +6 -6
  184. package/test/typescript/test-host.ts +1 -1
  185. package/test/utils.ts +2 -2
  186. package/test/vitest.setup.ts +1 -0
  187. package/tsconfig.json +3 -1
  188. package/vitest.config.ts +2 -1
  189. package/dist/src/testing/scenario-test/test-host.d.ts +0 -8
  190. package/dist/src/testing/scenario-test/test-host.d.ts.map +0 -1
  191. package/dist/src/testing/scenario-test/test-host.js +0 -49
  192. package/src/testing/scenario-test/test-host.ts +0 -83
@@ -1,15 +1,14 @@
1
- import * as ay from "@alloy-js/core";
2
- import { Children, mapJoin } from "@alloy-js/core";
1
+ import { Block, type Children, For, mapJoin } from "@alloy-js/core";
3
2
  import * as ts from "@alloy-js/typescript";
4
3
  import {
5
- Interface,
4
+ type Interface,
6
5
  isNeverType,
7
- Model,
8
- ModelProperty,
9
- Operation,
10
- RekeyableMap,
6
+ type Model,
7
+ type ModelProperty,
8
+ type Operation,
9
+ type RekeyableMap,
11
10
  } from "@typespec/compiler";
12
- import { Typekit } from "@typespec/compiler/typekit";
11
+ import type { Typekit } from "@typespec/compiler/typekit";
13
12
  import { createRekeyableMap } from "@typespec/compiler/utils";
14
13
  import { useTsp } from "../../core/context/tsp-context.js";
15
14
  import { reportDiagnostic } from "../../lib.js";
@@ -74,9 +73,9 @@ export interface InterfaceExpressionProps extends ts.InterfaceExpressionProps {
74
73
 
75
74
  export function InterfaceExpression(props: InterfaceExpressionProps) {
76
75
  return (
77
- <ay.Block>
76
+ <Block>
78
77
  <InterfaceBody {...props} />
79
- </ay.Block>
78
+ </Block>
80
79
  );
81
80
  }
82
81
 
@@ -156,11 +155,11 @@ function InterfaceBody(props: TypedInterfaceDeclarationProps): Children {
156
155
 
157
156
  return (
158
157
  <>
159
- <ay.For each={validTypeMembers} semicolon line {...enderProp}>
158
+ <For each={validTypeMembers} semicolon line {...enderProp}>
160
159
  {(typeMember) => {
161
160
  return <InterfaceMember type={typeMember} />;
162
161
  }}
163
- </ay.For>
162
+ </For>
164
163
  {props.children}
165
164
  </>
166
165
  );
@@ -1,6 +1,6 @@
1
- import { Children } from "@alloy-js/core";
1
+ import { type Children } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { isNeverType, ModelProperty, Operation } from "@typespec/compiler";
3
+ import { isNeverType, type ModelProperty, type Operation } from "@typespec/compiler";
4
4
  import { getHttpPart } from "@typespec/http";
5
5
  import { useTsp } from "../../core/context/tsp-context.js";
6
6
  import { InterfaceMethod } from "./interface-method.jsx";
@@ -1,6 +1,6 @@
1
- import { Children, splitProps } from "@alloy-js/core";
1
+ import { type Children, splitProps } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Operation } from "@typespec/compiler";
3
+ import type { Operation } from "@typespec/compiler";
4
4
  import { useTsp } from "../../core/index.js";
5
5
  import { buildParameterDescriptors, getReturnType } from "../utils/operation.js";
6
6
  import { TypeExpression } from "./type-expression.jsx";
@@ -1,5 +1,5 @@
1
1
  import { code } from "@alloy-js/core";
2
- import { Type } from "@typespec/compiler";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { TypeExpression } from "./type-expression.js";
4
4
 
5
5
  export interface RecordExpressionProps {
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Type } from "@typespec/compiler";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { useTsp } from "../../core/context/tsp-context.js";
4
4
  import { reportDiagnostic } from "../../lib.js";
5
5
  import { declarationRefkeys } from "../utils/refkey.js";
@@ -1,5 +1,5 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
- import { Type } from "@typespec/compiler";
2
+ import type { Type } from "@typespec/compiler";
3
3
  import { useTsp } from "../../core/index.js";
4
4
  import { declarationRefkeys } from "../utils/refkey.js";
5
5
  import { EnumDeclaration } from "./enum-declaration.js";
@@ -1,7 +1,7 @@
1
1
  import { For } from "@alloy-js/core";
2
2
  import { Reference, ValueExpression } from "@alloy-js/typescript";
3
- import { IntrinsicType, Model, Scalar, Type } from "@typespec/compiler";
4
- import { Typekit } from "@typespec/compiler/typekit";
3
+ import type { IntrinsicType, Model, Scalar, Type } from "@typespec/compiler";
4
+ import type { Typekit } from "@typespec/compiler/typekit";
5
5
  import "@typespec/http/experimental/typekit";
6
6
  import { useTsp } from "../../core/context/tsp-context.js";
7
7
  import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
@@ -1,6 +1,6 @@
1
- import { Children, code, For, mapJoin, Refkey } from "@alloy-js/core";
1
+ import { type Children, code, For, mapJoin, type Refkey } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import {
3
+ import type {
4
4
  Discriminator,
5
5
  Model,
6
6
  ModelProperty,
@@ -9,7 +9,7 @@ import {
9
9
  Type,
10
10
  Union,
11
11
  } from "@typespec/compiler";
12
- import { Typekit } from "@typespec/compiler/typekit";
12
+ import type { Typekit } from "@typespec/compiler/typekit";
13
13
  import { createRekeyableMap } from "@typespec/compiler/utils";
14
14
  import { useTsp } from "../../core/context/tsp-context.js";
15
15
  import { reportDiagnostic } from "../../lib.js";
@@ -1,6 +1,6 @@
1
- import { Children } from "@alloy-js/core";
1
+ import { type Children } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Enum, Union } from "@typespec/compiler";
3
+ import type { Enum, Union } from "@typespec/compiler";
4
4
  import { useTsp } from "../../core/context/tsp-context.js";
5
5
  import { reportDiagnostic } from "../../lib.js";
6
6
  import { declarationRefkeys } from "../utils/refkey.js";
@@ -1,7 +1,12 @@
1
- import * as ay from "@alloy-js/core";
2
- import { Children } from "@alloy-js/core";
1
+ import { type Children, For, List } from "@alloy-js/core";
3
2
  import * as ts from "@alloy-js/typescript";
4
- import { compilerAssert, Enum, EnumMember, Union, UnionVariant } from "@typespec/compiler";
3
+ import {
4
+ compilerAssert,
5
+ type Enum,
6
+ type EnumMember,
7
+ type Union,
8
+ type UnionVariant,
9
+ } from "@typespec/compiler";
5
10
  import { useTsp } from "../../core/context/tsp-context.js";
6
11
  import { efRefkey } from "../utils/refkey.js";
7
12
  import { TypeExpression } from "./type-expression.jsx";
@@ -19,7 +24,7 @@ export function UnionExpression({ type, children }: UnionExpressionProps) {
19
24
  >;
20
25
 
21
26
  const variants = (
22
- <ay.For joiner={" | "} each={items}>
27
+ <For joiner={" | "} each={items}>
23
28
  {(_, type) => {
24
29
  if ($.enumMember.is(type)) {
25
30
  return <ts.ValueExpression jsValue={type.value ?? type.name} />;
@@ -46,7 +51,7 @@ export function UnionExpression({ type, children }: UnionExpressionProps) {
46
51
  return <TypeExpression type={type.type} />;
47
52
  }
48
53
  }}
49
- </ay.For>
54
+ </For>
50
55
  );
51
56
 
52
57
  if (children || (Array.isArray(children) && children.length)) {
@@ -121,7 +126,7 @@ function NoneEnvelope(props: NoneEnvelopeProps) {
121
126
  }
122
127
 
123
128
  return (
124
- <ay.List joiner={" & "}>
129
+ <List joiner={" & "}>
125
130
  <ts.ObjectExpression>
126
131
  <ts.ObjectProperty
127
132
  name={props.discriminatorPropertyName}
@@ -129,6 +134,6 @@ function NoneEnvelope(props: NoneEnvelopeProps) {
129
134
  />
130
135
  </ts.ObjectExpression>
131
136
  <>{efRefkey(props.type.type)}</>
132
- </ay.List>
137
+ </List>
133
138
  );
134
139
  }
@@ -1,6 +1,6 @@
1
- import { Children } from "@alloy-js/core";
1
+ import { type Children } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { compilerAssert, Value } from "@typespec/compiler";
3
+ import { compilerAssert, type Value } from "@typespec/compiler";
4
4
 
5
5
  /**
6
6
  * Properties for the {@link ValueExpression} component.
@@ -1,6 +1,6 @@
1
- import { refkey, Refkey } from "@alloy-js/core";
1
+ import { refkey, type Refkey } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { Model, ModelProperty, Operation, Type } from "@typespec/compiler";
3
+ import type { Model, ModelProperty, Operation, Type } from "@typespec/compiler";
4
4
  import { useTsp } from "../../core/index.js";
5
5
  import { TypeExpression } from "../components/type-expression.jsx";
6
6
  import { efRefkey } from "./refkey.js";
@@ -0,0 +1,4 @@
1
+ import { resolvePath } from "@typespec/compiler";
2
+ import { createTester } from "@typespec/compiler/testing";
3
+
4
+ export const Tester = createTester(resolvePath(import.meta.dirname, ".."), { libraries: [] });
@@ -2,14 +2,14 @@ import { d } from "@alloy-js/core/testing";
2
2
  import { beforeEach, describe, expect, it } from "vitest";
3
3
  import {
4
4
  createCSharpExtractorConfig,
5
- createSnipperExtractor,
6
- SnippetExtractor,
5
+ createSnippetExtractor,
6
+ type SnippetExtractor,
7
7
  } from "../../src/testing/index.js";
8
8
  describe("C# Snippet Extractor", () => {
9
9
  let extractor: SnippetExtractor;
10
10
 
11
11
  beforeEach(async () => {
12
- extractor = createSnipperExtractor(await createCSharpExtractorConfig());
12
+ extractor = createSnippetExtractor(await createCSharpExtractorConfig());
13
13
  });
14
14
 
15
15
  it("should extract a class", () => {
@@ -66,7 +66,7 @@ describe("C# Snippet Extractor - Enums", () => {
66
66
  let extractor: SnippetExtractor;
67
67
 
68
68
  beforeEach(async () => {
69
- extractor = createSnipperExtractor(await createCSharpExtractorConfig());
69
+ extractor = createSnippetExtractor(await createCSharpExtractorConfig());
70
70
  });
71
71
 
72
72
  it("should extract a basic enum", async () => {
@@ -2,15 +2,15 @@ import { d } from "@alloy-js/core/testing";
2
2
  import { beforeEach, describe, expect, it } from "vitest";
3
3
  import {
4
4
  createJavaExtractorConfig,
5
- createSnipperExtractor,
6
- SnippetExtractor,
5
+ createSnippetExtractor,
6
+ type SnippetExtractor,
7
7
  } from "../../src/testing/index.js";
8
8
 
9
9
  describe("Java Snippet Extractor", () => {
10
10
  let extractor: SnippetExtractor;
11
11
 
12
12
  beforeEach(async () => {
13
- extractor = createSnipperExtractor(await createJavaExtractorConfig());
13
+ extractor = createSnippetExtractor(await createJavaExtractorConfig());
14
14
  });
15
15
 
16
16
  it("should extract a class", () => {
@@ -67,7 +67,7 @@ describe("Java Snippet Extractor - Enums", () => {
67
67
  let extractor: SnippetExtractor;
68
68
 
69
69
  beforeEach(async () => {
70
- extractor = createSnipperExtractor(await createJavaExtractorConfig());
70
+ extractor = createSnippetExtractor(await createJavaExtractorConfig());
71
71
  });
72
72
 
73
73
  it("should extract a basic enum", async () => {
@@ -2,15 +2,15 @@ import { d } from "@alloy-js/core/testing";
2
2
  import { beforeEach, describe, expect, it } from "vitest";
3
3
  import {
4
4
  createPythonExtractorConfig,
5
- createSnipperExtractor,
6
- SnippetExtractor,
5
+ createSnippetExtractor,
6
+ type SnippetExtractor,
7
7
  } from "../../src/testing/index.js";
8
8
 
9
9
  describe("Python Snippet Extractor", () => {
10
10
  let extractor: SnippetExtractor;
11
11
 
12
12
  beforeEach(async () => {
13
- extractor = createSnipperExtractor(await createPythonExtractorConfig());
13
+ extractor = createSnippetExtractor(await createPythonExtractorConfig());
14
14
  });
15
15
 
16
16
  it("should extract a class", () => {
@@ -1,15 +1,15 @@
1
1
  import { d } from "@alloy-js/core/testing";
2
2
  import { beforeEach, describe, expect, it } from "vitest";
3
3
  import {
4
- createSnipperExtractor,
4
+ createSnippetExtractor,
5
5
  createTypeScriptExtractorConfig,
6
- SnippetExtractor,
6
+ type SnippetExtractor,
7
7
  } from "../../src/testing/index.js";
8
8
 
9
9
  describe("TypeScript Snippet Extractor", () => {
10
10
  let extractor: SnippetExtractor;
11
11
  beforeEach(async () => {
12
- extractor = createSnipperExtractor(await createTypeScriptExtractorConfig());
12
+ extractor = createSnippetExtractor(await createTypeScriptExtractorConfig());
13
13
  });
14
14
 
15
15
  it("should extract a class", async () => {
@@ -138,7 +138,7 @@ describe("TypeScript Snippet Extractor", () => {
138
138
  describe("TypeScript Snippet Extractor - Enums", () => {
139
139
  let extractor: SnippetExtractor;
140
140
  beforeEach(async () => {
141
- extractor = createSnipperExtractor(await createTypeScriptExtractorConfig());
141
+ extractor = createSnippetExtractor(await createTypeScriptExtractorConfig());
142
142
  });
143
143
 
144
144
  it("should extract a basic enum", async () => {
@@ -1,8 +1,8 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { SourceFile } from "@alloy-js/typescript";
4
- import { Operation } from "@typespec/compiler";
5
- import { BasicTestRunner } from "@typespec/compiler/testing";
4
+ import type { Operation } from "@typespec/compiler";
5
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
6
6
  import { beforeEach, describe, it } from "vitest";
7
7
  import { Output } from "../../../src/core/components/output.jsx";
8
8
  import { ArrowFunction } from "../../../src/typescript/components/arrow-function.jsx";
@@ -1,6 +1,6 @@
1
1
  import { List, StatementList } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
- import { Enum, Union } from "@typespec/compiler";
3
+ import type { Enum, Union } from "@typespec/compiler";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import { TspContext } from "../../../src/core/index.js";
6
6
  import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
@@ -1,7 +1,7 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { SourceFile } from "@alloy-js/typescript";
4
- import { Namespace } from "@typespec/compiler";
4
+ import type { Namespace } from "@typespec/compiler";
5
5
  import { format } from "prettier";
6
6
  import { assert, describe, expect, it } from "vitest";
7
7
  import { Output } from "../../../src/core/components/output.jsx";
@@ -1,8 +1,8 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { SourceFile } from "@alloy-js/typescript";
4
- import { Operation } from "@typespec/compiler";
5
- import { BasicTestRunner } from "@typespec/compiler/testing";
4
+ import type { Operation } from "@typespec/compiler";
5
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
6
6
  import { beforeEach, describe, it } from "vitest";
7
7
  import { Output } from "../../../src/core/components/output.jsx";
8
8
  import { FunctionExpression } from "../../../src/typescript/components/function-expression.jsx";
@@ -1,8 +1,8 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { SourceFile } from "@alloy-js/typescript";
4
- import { Operation } from "@typespec/compiler";
5
- import { BasicTestRunner } from "@typespec/compiler/testing";
4
+ import type { Operation } from "@typespec/compiler";
5
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
6
6
  import { beforeEach, describe, it } from "vitest";
7
7
  import { Output } from "../../../src/core/components/output.jsx";
8
8
  import { FunctionType } from "../../../src/typescript/index.js";
@@ -1,6 +1,6 @@
1
1
  import { For, List, render } from "@alloy-js/core";
2
2
  import { SourceFile } from "@alloy-js/typescript";
3
- import { Namespace } from "@typespec/compiler";
3
+ import type { Namespace } from "@typespec/compiler";
4
4
  import { format } from "prettier";
5
5
  import { assert, describe, expect, it } from "vitest";
6
6
  import { Output } from "../../../src/core/components/output.jsx";
@@ -1,8 +1,8 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
4
- import { Operation } from "@typespec/compiler";
5
- import { BasicTestRunner } from "@typespec/compiler/testing";
4
+ import type { Operation } from "@typespec/compiler";
5
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
6
6
  import { beforeEach, describe, it } from "vitest";
7
7
  import { Output } from "../../../src/core/components/output.jsx";
8
8
  import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
@@ -1,6 +1,6 @@
1
- import * as ay from "@alloy-js/core";
1
+ import { List } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
- import { Enum, Model, Union } from "@typespec/compiler";
3
+ import type { Enum, Model, Union } from "@typespec/compiler";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import { TspContext } from "../../../src/core/index.js";
6
6
  import { EnumDeclaration } from "../../../src/typescript/components/enum-declaration.js";
@@ -24,10 +24,10 @@ describe("Typescript Enum Member Expression", () => {
24
24
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
25
25
  return (
26
26
  <TspContext.Provider value={{ program }}>
27
- <ay.List hardline>
27
+ <List hardline>
28
28
  <EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
29
29
  <InterfaceDeclaration type={Bar} />
30
- </ay.List>
30
+ </List>
31
31
  </TspContext.Provider>
32
32
  );
33
33
  });
@@ -60,10 +60,10 @@ describe("Typescript Enum Member Expression", () => {
60
60
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
61
61
  return (
62
62
  <TspContext.Provider value={{ program }}>
63
- <ay.List hardline>
63
+ <List hardline>
64
64
  <EnumDeclaration type={program.resolveTypeReference("Foo")[0]! as Enum} />
65
65
  <InterfaceDeclaration type={Bar} />
66
- </ay.List>
66
+ </List>
67
67
  </TspContext.Provider>
68
68
  );
69
69
  });
@@ -98,10 +98,10 @@ describe("Typescript Union Member Expression", () => {
98
98
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
99
99
  return (
100
100
  <TspContext.Provider value={{ program }}>
101
- <ay.List hardline>
101
+ <List hardline>
102
102
  <UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
103
103
  <InterfaceDeclaration type={Bar} />
104
- </ay.List>
104
+ </List>
105
105
  </TspContext.Provider>
106
106
  );
107
107
  });
@@ -130,10 +130,10 @@ describe("Typescript Union Member Expression", () => {
130
130
  const Bar = program.resolveTypeReference("Bar")[0]! as Model;
131
131
  return (
132
132
  <TspContext.Provider value={{ program }}>
133
- <ay.List hardline>
133
+ <List hardline>
134
134
  <UnionDeclaration type={program.resolveTypeReference("Foo")[0]! as Union} />
135
135
  <InterfaceDeclaration type={Bar} />
136
- </ay.List>
136
+ </List>
137
137
  </TspContext.Provider>
138
138
  );
139
139
  });
@@ -1,6 +1,6 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { SourceFile } from "@alloy-js/typescript";
3
- import { Namespace, Operation } from "@typespec/compiler";
3
+ import type { Namespace, Operation } from "@typespec/compiler";
4
4
  import { format } from "prettier";
5
5
  import { assert, describe, expect, it } from "vitest";
6
6
  import { Output } from "../../../src/core/components/output.jsx";
@@ -2,8 +2,8 @@ import { code, Output, render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import * as ts from "@alloy-js/typescript";
4
4
  import { SourceFile } from "@alloy-js/typescript";
5
- import { Model } from "@typespec/compiler";
6
- import { BasicTestRunner } from "@typespec/compiler/testing";
5
+ import type { Model } from "@typespec/compiler";
6
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
7
7
  import { assert, beforeEach, describe, expect, it } from "vitest";
8
8
  import {
9
9
  ArraySerializer,
@@ -1,8 +1,8 @@
1
1
  import { render } from "@alloy-js/core";
2
2
  import { d } from "@alloy-js/core/testing";
3
3
  import { SourceFile } from "@alloy-js/typescript";
4
- import { Enum, Model, Union } from "@typespec/compiler";
5
- import { BasicTestRunner } from "@typespec/compiler/testing";
4
+ import type { Enum, Model, Union } from "@typespec/compiler";
5
+ import type { BasicTestRunner } from "@typespec/compiler/testing";
6
6
  import { beforeEach, describe, it } from "vitest";
7
7
  import { Output } from "../../../src/core/components/output.jsx";
8
8
  import { UnionDeclaration } from "../../../src/typescript/components/union-declaration.js";
@@ -2,13 +2,13 @@ import { Output, render } from "@alloy-js/core";
2
2
  import { dedent } from "@alloy-js/core/testing";
3
3
  import { SourceFile } from "@alloy-js/typescript";
4
4
  import {
5
- EnumValue,
6
- Model,
7
- Namespace,
5
+ type EnumValue,
6
+ type Model,
7
+ type Namespace,
8
8
  Numeric,
9
- NumericValue,
10
- Program,
11
- Value,
9
+ type NumericValue,
10
+ type Program,
11
+ type Value,
12
12
  } from "@typespec/compiler";
13
13
  import { $ } from "@typespec/compiler/typekit";
14
14
  import { assert, beforeAll, describe, expect, it } from "vitest";
@@ -1,4 +1,4 @@
1
- import { Program } from "@typespec/compiler";
1
+ import type { Program } from "@typespec/compiler";
2
2
  import {
3
3
  createTestHost,
4
4
  createTestWrapper,
package/test/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Children, OutputDirectory, render } from "@alloy-js/core";
1
+ import { type Children, type OutputDirectory, render } from "@alloy-js/core";
2
2
  import { Output } from "@alloy-js/core/stc";
3
3
  import { SourceFile } from "@alloy-js/typescript/stc";
4
- import { Program } from "@typespec/compiler";
4
+ import type { Program } from "@typespec/compiler";
5
5
  import { assert } from "vitest";
6
6
  import { getProgram } from "./typescript/test-host.js";
7
7
 
@@ -0,0 +1 @@
1
+ import "@alloy-js/core/testing";
package/tsconfig.json CHANGED
@@ -14,7 +14,9 @@
14
14
  "jsxImportSource": "@alloy-js/core",
15
15
  "emitDeclarationOnly": true,
16
16
  "outDir": "dist",
17
- "rootDir": "./"
17
+ "rootDir": "./",
18
+ "verbatimModuleSyntax": true,
19
+ "types": ["@alloy-js/core/testing/matchers"]
18
20
  },
19
21
  "include": ["src/**/*.ts", "src/**/*.tsx", "test/**/*.ts", "test/**/*.tsx"],
20
22
  "exclude": ["node_modules", "dist"]
package/vitest.config.ts CHANGED
@@ -6,8 +6,9 @@ export default mergeConfig(
6
6
  defaultTypeSpecVitestConfig,
7
7
  defineConfig({
8
8
  test: {
9
- include: ["test/**/*.test.ts", "test/**/*.test.tsx"],
9
+ include: ["src/**/*.test.ts", "src/**/*.test.tsx", "test/**/*.test.ts", "test/**/*.test.tsx"],
10
10
  passWithNoTests: true,
11
+ setupFiles: ["./test/vitest.setup.ts"],
11
12
  },
12
13
  esbuild: {
13
14
  jsx: "preserve",
@@ -1,8 +0,0 @@
1
- import { Diagnostic } from "@typespec/compiler";
2
- import { TypeSpecTestLibrary } from "@typespec/compiler/testing";
3
- export interface EmittedFile {
4
- path: string;
5
- content: string;
6
- }
7
- export declare function emitWithDiagnostics(testLibrary: TypeSpecTestLibrary, emitterOutputDir: string, code: string): Promise<[EmittedFile[], readonly Diagnostic[]]>;
8
- //# sourceMappingURL=test-host.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAKL,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AA4BD,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,mBAAmB,EAChC,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAOjD"}
@@ -1,49 +0,0 @@
1
- import { createTestHost, createTestWrapper } from "@typespec/compiler/testing";
2
- import { HttpTestLibrary } from "@typespec/http/testing";
3
- import { RestTestLibrary } from "@typespec/rest/testing";
4
- import { join, relative } from "path";
5
- async function createEmitterTestRunner(testLibrary, options = {}) {
6
- const libraries = options.testHostConfig?.libraries ?? [testLibrary, HttpTestLibrary, RestTestLibrary];
7
- const host = await createTestHost({
8
- libraries
9
- });
10
- return createTestWrapper(host, {
11
- autoImports: options.autoImports ?? ["@typespec/http", "@typespec/rest"],
12
- autoUsings: options.autoUsings ?? ["TypeSpec.Http", "TypeSpec.Rest"],
13
- compilerOptions: options.compilerOptions ?? {
14
- noEmit: false,
15
- emit: [testLibrary.name]
16
- }
17
- });
18
- }
19
- export async function emitWithDiagnostics(testLibrary, emitterOutputDir, code) {
20
- const runner = await createEmitterTestRunner(testLibrary);
21
- await runner.compileAndDiagnose(code, {
22
- outputDir: "tsp-output"
23
- });
24
- const result = await readFilesRecursively(emitterOutputDir, emitterOutputDir, runner);
25
- return [result, runner.program.diagnostics];
26
- }
27
- async function readFilesRecursively(currentDir, emitterOutputDir, runner) {
28
- const entries = await runner.program.host.readDir(currentDir);
29
- const result = [];
30
- for (const entry of entries) {
31
- const fullPath = join(currentDir, entry);
32
- const stat = await runner.program.host.stat(fullPath);
33
- if (stat.isDirectory()) {
34
- // Recursively read files in the directory
35
- const nestedFiles = await readFilesRecursively(fullPath, emitterOutputDir, runner);
36
- result.push(...nestedFiles);
37
- } else if (stat.isFile()) {
38
- // Read the file
39
- // Read the file and store it with a relative path
40
- const relativePath = relative(emitterOutputDir, fullPath);
41
- const fileContent = await runner.program.host.readFile(fullPath);
42
- result.push({
43
- path: relativePath,
44
- content: fileContent.text
45
- });
46
- }
47
- }
48
- return result;
49
- }