@alloy-js/typescript 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/src/builtins/node.js +1 -2
  3. package/dist/src/components/ArrayExpression.js +2 -5
  4. package/dist/src/components/ArrowFunction.d.ts +40 -0
  5. package/dist/src/components/ArrowFunction.d.ts.map +1 -0
  6. package/dist/src/components/ArrowFunction.js +67 -0
  7. package/dist/src/components/BarrelFile.js +1 -2
  8. package/dist/src/components/BlockScope.js +2 -4
  9. package/dist/src/components/CallSignature.js +2 -4
  10. package/dist/src/components/ClassDeclaration.d.ts +2 -0
  11. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  12. package/dist/src/components/ClassDeclaration.js +16 -8
  13. package/dist/src/components/CommaList.js +2 -5
  14. package/dist/src/components/Declaration.js +3 -5
  15. package/dist/src/components/EnumDeclaration.js +2 -5
  16. package/dist/src/components/EnumMember.js +2 -4
  17. package/dist/src/components/ExportStatement.js +1 -2
  18. package/dist/src/components/FunctionBase.d.ts +60 -0
  19. package/dist/src/components/FunctionBase.d.ts.map +1 -0
  20. package/dist/src/components/FunctionBase.js +217 -0
  21. package/dist/src/components/FunctionCallExpression.js +2 -5
  22. package/dist/src/components/FunctionDeclaration.d.ts +3 -18
  23. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  24. package/dist/src/components/FunctionDeclaration.js +9 -157
  25. package/dist/src/components/FunctionExpression.d.ts +39 -0
  26. package/dist/src/components/FunctionExpression.d.ts.map +1 -0
  27. package/dist/src/components/FunctionExpression.js +66 -0
  28. package/dist/src/components/FunctionType.d.ts +38 -0
  29. package/dist/src/components/FunctionType.d.ts.map +1 -0
  30. package/dist/src/components/FunctionType.js +77 -0
  31. package/dist/src/components/IfStatement.js +2 -4
  32. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  33. package/dist/src/components/ImportStatement.js +10 -4
  34. package/dist/src/components/Interface.d.ts +3 -2
  35. package/dist/src/components/Interface.d.ts.map +1 -1
  36. package/dist/src/components/Interface.js +40 -15
  37. package/dist/src/components/InterfaceMethod.d.ts +43 -0
  38. package/dist/src/components/InterfaceMethod.d.ts.map +1 -0
  39. package/dist/src/components/InterfaceMethod.js +87 -0
  40. package/dist/src/components/JSDoc.js +1 -2
  41. package/dist/src/components/JSDocComment.js +3 -5
  42. package/dist/src/components/JSDocExample.js +2 -5
  43. package/dist/src/components/JSDocParam.js +2 -5
  44. package/dist/src/components/MemberChainExpression.js +2 -4
  45. package/dist/src/components/MemberDeclaration.d.ts +34 -0
  46. package/dist/src/components/MemberDeclaration.d.ts.map +1 -0
  47. package/dist/src/components/MemberDeclaration.js +29 -0
  48. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  49. package/dist/src/components/MemberExpression.js +5 -7
  50. package/dist/src/components/ObjectExpression.js +2 -5
  51. package/dist/src/components/PackageDirectory.js +2 -5
  52. package/dist/src/components/PackageJson.js +1 -2
  53. package/dist/src/components/PropertyName.js +1 -2
  54. package/dist/src/components/Reference.d.ts +8 -1
  55. package/dist/src/components/Reference.d.ts.map +1 -1
  56. package/dist/src/components/Reference.js +8 -4
  57. package/dist/src/components/SingleLineCommentBlock.js +2 -4
  58. package/dist/src/components/SourceFile.js +2 -4
  59. package/dist/src/components/SwitchStatement.js +2 -5
  60. package/dist/src/components/TsConfigJson.js +1 -2
  61. package/dist/src/components/TypeDeclaration.d.ts +1 -1
  62. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  63. package/dist/src/components/TypeDeclaration.js +4 -7
  64. package/dist/src/components/TypeRefContext.d.ts +22 -0
  65. package/dist/src/components/TypeRefContext.d.ts.map +1 -0
  66. package/dist/src/components/TypeRefContext.js +41 -0
  67. package/dist/src/components/ValueExpression.js +1 -2
  68. package/dist/src/components/VarDeclaration.d.ts +1 -0
  69. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  70. package/dist/src/components/VarDeclaration.js +11 -8
  71. package/dist/src/components/index.d.ts +7 -0
  72. package/dist/src/components/index.d.ts.map +1 -1
  73. package/dist/src/components/index.js +7 -1
  74. package/dist/src/components/stc/index.d.ts +8 -0
  75. package/dist/src/components/stc/index.d.ts.map +1 -1
  76. package/dist/src/components/stc/index.js +9 -2
  77. package/dist/src/context/private-scope.js +1 -2
  78. package/dist/src/context/type-ref-context.d.ts +15 -0
  79. package/dist/src/context/type-ref-context.d.ts.map +1 -0
  80. package/dist/src/context/type-ref-context.js +12 -0
  81. package/dist/src/create-package.js +1 -2
  82. package/dist/src/index.js +1 -2
  83. package/dist/src/name-conflict-resolver.js +1 -2
  84. package/dist/src/name-policy.js +1 -2
  85. package/dist/src/parameter-descriptor.d.ts +33 -17
  86. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  87. package/dist/src/source-directory-data.js +1 -2
  88. package/dist/src/symbols/index.js +1 -2
  89. package/dist/src/symbols/reference.d.ts +4 -1
  90. package/dist/src/symbols/reference.d.ts.map +1 -1
  91. package/dist/src/symbols/reference.js +13 -8
  92. package/dist/src/symbols/scopes.js +1 -2
  93. package/dist/src/symbols/ts-member-scope.js +1 -2
  94. package/dist/src/symbols/ts-module-scope.d.ts +4 -1
  95. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  96. package/dist/src/symbols/ts-module-scope.js +11 -5
  97. package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
  98. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  99. package/dist/src/symbols/ts-output-symbol.js +2 -2
  100. package/dist/src/symbols/ts-package-scope.js +1 -2
  101. package/dist/src/utils.js +1 -2
  102. package/dist/test/array.test.js +105 -0
  103. package/dist/test/arrow-function.test.d.ts +2 -0
  104. package/dist/test/arrow-function.test.d.ts.map +1 -0
  105. package/dist/test/arrow-function.test.js +194 -0
  106. package/dist/test/barrel.test.js +53 -0
  107. package/dist/test/basic.test.js +91 -0
  108. package/dist/test/block-scope.test.js +30 -0
  109. package/dist/test/class.test.js +438 -0
  110. package/dist/test/enum-jsdoc.test.js +88 -0
  111. package/dist/test/enum.test.js +247 -0
  112. package/dist/test/externals.test.js +145 -0
  113. package/dist/test/function-call-expression.test.js +87 -0
  114. package/dist/test/function-declaration-jsdoc.test.js +91 -0
  115. package/dist/test/function-declaration.test.js +228 -0
  116. package/dist/test/function-expression.test.d.ts +2 -0
  117. package/dist/test/function-expression.test.d.ts.map +1 -0
  118. package/dist/test/function-expression.test.js +194 -0
  119. package/dist/test/function-type.test.d.ts +2 -0
  120. package/dist/test/function-type.test.d.ts.map +1 -0
  121. package/dist/test/function-type.test.js +122 -0
  122. package/dist/test/if-statement.test.js +25 -0
  123. package/dist/test/imports.test.d.ts.map +1 -1
  124. package/dist/test/imports.test.js +640 -0
  125. package/dist/test/interface-jsdoc.test.js +178 -0
  126. package/dist/test/interface.test.d.ts.map +1 -1
  127. package/dist/test/interface.test.js +490 -0
  128. package/dist/test/jscomment.test.js +70 -0
  129. package/dist/test/jsdoc.test.js +134 -0
  130. package/dist/test/jsdocparam.test.js +164 -0
  131. package/dist/test/member-chain.test.js +141 -0
  132. package/dist/test/member-expression.test.js +575 -0
  133. package/dist/test/name-conflict.test.js +108 -0
  134. package/dist/test/name-policy.test.js +122 -0
  135. package/dist/test/package-external.test.js +196 -0
  136. package/dist/test/package-json.test.js +93 -0
  137. package/dist/test/package.test.js +136 -0
  138. package/dist/test/reference.test.js +81 -0
  139. package/dist/test/source-file.test.js +36 -0
  140. package/dist/test/switch-statement.test.js +61 -0
  141. package/dist/test/utils.js +45 -0
  142. package/dist/test/value-expression.test.js +30 -0
  143. package/dist/test/values.test.js +351 -0
  144. package/dist/test/var-declaration-jsdoc.test.js +50 -0
  145. package/dist/test/var-declaration.test.js +63 -0
  146. package/dist/test/vitest.d.js +1 -0
  147. package/dist/tsconfig.tsbuildinfo +1 -1
  148. package/package.json +13 -18
  149. package/src/components/ArrowFunction.tsx +87 -0
  150. package/src/components/ClassDeclaration.tsx +19 -3
  151. package/src/components/Declaration.tsx +1 -1
  152. package/src/components/FunctionBase.tsx +282 -0
  153. package/src/components/FunctionDeclaration.tsx +13 -195
  154. package/src/components/FunctionExpression.tsx +86 -0
  155. package/src/components/FunctionType.tsx +93 -0
  156. package/src/components/ImportStatement.tsx +30 -3
  157. package/src/components/Interface.tsx +58 -23
  158. package/src/components/InterfaceMethod.tsx +96 -0
  159. package/src/components/JSDocComment.tsx +1 -1
  160. package/src/components/MemberDeclaration.tsx +76 -0
  161. package/src/components/MemberExpression.tsx +7 -2
  162. package/src/components/Reference.tsx +12 -2
  163. package/src/components/TypeDeclaration.tsx +16 -13
  164. package/src/components/TypeRefContext.tsx +49 -0
  165. package/src/components/VarDeclaration.tsx +6 -2
  166. package/src/components/index.ts +11 -0
  167. package/src/components/stc/index.ts +8 -0
  168. package/src/context/type-ref-context.tsx +19 -0
  169. package/src/parameter-descriptor.ts +35 -17
  170. package/src/symbols/reference.ts +21 -6
  171. package/src/symbols/ts-module-scope.ts +19 -4
  172. package/src/symbols/ts-output-symbol.ts +1 -0
  173. package/temp/api.json +4999 -2681
  174. package/test/arrow-function.test.tsx +188 -0
  175. package/test/class.test.tsx +5 -6
  176. package/test/enum-jsdoc.test.tsx +6 -6
  177. package/test/function-call-expression.test.tsx +1 -2
  178. package/test/function-declaration-jsdoc.test.tsx +3 -3
  179. package/test/function-declaration.test.tsx +1 -2
  180. package/test/function-expression.test.tsx +195 -0
  181. package/test/function-type.test.tsx +118 -0
  182. package/test/imports.test.tsx +165 -1
  183. package/test/interface-jsdoc.test.tsx +9 -9
  184. package/test/interface.test.tsx +256 -6
  185. package/test/jsdoc.test.tsx +5 -5
  186. package/test/jsdocparam.test.tsx +8 -8
  187. package/test/member-expression.test.tsx +171 -2
  188. package/test/var-declaration-jsdoc.test.tsx +3 -3
  189. package/test/var-declaration.test.tsx +1 -1
  190. package/tsdoc-metadata.json +1 -1
  191. package/babel.config.cjs +0 -4
  192. package/dist/src/builtins/index.js.map +0 -1
  193. package/dist/src/builtins/node.js.map +0 -1
  194. package/dist/src/components/ArrayExpression.js.map +0 -1
  195. package/dist/src/components/BarrelFile.js.map +0 -1
  196. package/dist/src/components/BlockScope.js.map +0 -1
  197. package/dist/src/components/CallSignature.js.map +0 -1
  198. package/dist/src/components/ClassDeclaration.js.map +0 -1
  199. package/dist/src/components/CommaList.js.map +0 -1
  200. package/dist/src/components/Declaration.js.map +0 -1
  201. package/dist/src/components/EnumDeclaration.js.map +0 -1
  202. package/dist/src/components/EnumMember.js.map +0 -1
  203. package/dist/src/components/ExportStatement.js.map +0 -1
  204. package/dist/src/components/FunctionCallExpression.js.map +0 -1
  205. package/dist/src/components/FunctionDeclaration.js.map +0 -1
  206. package/dist/src/components/IfStatement.js.map +0 -1
  207. package/dist/src/components/ImportStatement.js.map +0 -1
  208. package/dist/src/components/Interface.js.map +0 -1
  209. package/dist/src/components/JSDoc.js.map +0 -1
  210. package/dist/src/components/JSDocComment.js.map +0 -1
  211. package/dist/src/components/JSDocExample.js.map +0 -1
  212. package/dist/src/components/JSDocParam.js.map +0 -1
  213. package/dist/src/components/MemberChainExpression.js.map +0 -1
  214. package/dist/src/components/MemberExpression.js.map +0 -1
  215. package/dist/src/components/ObjectExpression.js.map +0 -1
  216. package/dist/src/components/PackageDirectory.js.map +0 -1
  217. package/dist/src/components/PackageJson.js.map +0 -1
  218. package/dist/src/components/PropertyName.js.map +0 -1
  219. package/dist/src/components/Reference.js.map +0 -1
  220. package/dist/src/components/SingleLineCommentBlock.js.map +0 -1
  221. package/dist/src/components/SourceFile.js.map +0 -1
  222. package/dist/src/components/SwitchStatement.js.map +0 -1
  223. package/dist/src/components/TsConfigJson.js.map +0 -1
  224. package/dist/src/components/TypeDeclaration.js.map +0 -1
  225. package/dist/src/components/ValueExpression.js.map +0 -1
  226. package/dist/src/components/VarDeclaration.js.map +0 -1
  227. package/dist/src/components/index.js.map +0 -1
  228. package/dist/src/components/stc/index.js.map +0 -1
  229. package/dist/src/context/index.js.map +0 -1
  230. package/dist/src/context/private-scope.js.map +0 -1
  231. package/dist/src/create-package.js.map +0 -1
  232. package/dist/src/index.js.map +0 -1
  233. package/dist/src/name-conflict-resolver.js.map +0 -1
  234. package/dist/src/name-policy.js.map +0 -1
  235. package/dist/src/parameter-descriptor.js.map +0 -1
  236. package/dist/src/source-directory-data.js.map +0 -1
  237. package/dist/src/symbols/index.js.map +0 -1
  238. package/dist/src/symbols/reference.js.map +0 -1
  239. package/dist/src/symbols/scopes.js.map +0 -1
  240. package/dist/src/symbols/ts-member-scope.js.map +0 -1
  241. package/dist/src/symbols/ts-module-scope.js.map +0 -1
  242. package/dist/src/symbols/ts-output-symbol.js.map +0 -1
  243. package/dist/src/symbols/ts-package-scope.js.map +0 -1
  244. package/dist/src/utils.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { Refkey } from "@alloy-js/core";
2
+ import { Children } from "@alloy-js/core/jsx-runtime";
3
+ import { CallSignatureProps } from "./CallSignature.jsx";
4
+ /** Props for {@link (InterfaceMethod:namespace)} component */
5
+ export interface InterfaceMethodProps extends CallSignatureProps {
6
+ /** Interface member name */
7
+ readonly name: string;
8
+ /** If the method is async. It will change the returnType from `T` to `Promise<T>` */
9
+ readonly async?: boolean;
10
+ /** Documentation for this method. */
11
+ readonly doc?: Children;
12
+ /** Jsx content */
13
+ readonly children?: Children;
14
+ /** Ref key for the member declaration */
15
+ readonly refkey?: Refkey | Refkey[];
16
+ }
17
+ /**
18
+ * An interface method declaration.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * (foo: string, bar: number) => void
23
+ * ```
24
+ *
25
+ * @remarks
26
+ *
27
+ * Providing parameters and type parameters can be accomplished in one of three
28
+ * ways:
29
+ *
30
+ * 1. As an array of {@link TypeParameterDescriptor}s or
31
+ * {@link TypeParameterDescriptor}s.
32
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
33
+ * props.
34
+ * 3. As a child of this component via the
35
+ * {@link (InterfaceMethod:namespace).Parameters} or
36
+ * {@link (InterfaceMethod:namespace).TypeParameters} components.
37
+ */
38
+ export declare function InterfaceMethod(props: InterfaceMethodProps): Children;
39
+ export declare namespace InterfaceMethod {
40
+ var TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
41
+ var Parameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps>, "tag">>;
42
+ }
43
+ //# sourceMappingURL=InterfaceMethod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InterfaceMethod.d.ts","sourceRoot":"","sources":["../../../src/components/InterfaceMethod.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAUxE,8DAA8D;AAC9D,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;IACxB,kBAAkB;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAmC1D;yBAnCe,eAAe"}
@@ -0,0 +1,87 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, findKeyedChild, MemberDeclaration, Prose, Scope, Show } from "@alloy-js/core";
3
+ import { useTSNamePolicy } from "../name-policy.js";
4
+ import { getCallSignatureProps } from "../utils.js";
5
+ import { CallSignature } from "./CallSignature.js";
6
+ import { FunctionParameters, FunctionTypeParameters, getReturnType, TypeParameters } from "./FunctionBase.js";
7
+ import { JSDoc } from "./JSDoc.js";
8
+ import { JSDocParams } from "./JSDocParam.js";
9
+
10
+ /** Props for {@link (InterfaceMethod:namespace)} component */
11
+
12
+ /**
13
+ * An interface method declaration.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * (foo: string, bar: number) => void
18
+ * ```
19
+ *
20
+ * @remarks
21
+ *
22
+ * Providing parameters and type parameters can be accomplished in one of three
23
+ * ways:
24
+ *
25
+ * 1. As an array of {@link TypeParameterDescriptor}s or
26
+ * {@link TypeParameterDescriptor}s.
27
+ * 2. As raw content via the `parametersChildren` or `typeParametersChildren`
28
+ * props.
29
+ * 3. As a child of this component via the
30
+ * {@link (InterfaceMethod:namespace).Parameters} or
31
+ * {@link (InterfaceMethod:namespace).TypeParameters} components.
32
+ */
33
+ export function InterfaceMethod(props) {
34
+ const children = childrenArray(() => props.children);
35
+ const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
36
+ const parametersChildren = findKeyedChild(children, FunctionParameters.tag) ?? undefined;
37
+ const returnType = getReturnType(props.returnType ?? "void", {
38
+ async: props.async
39
+ });
40
+ const callSignatureProps = getCallSignatureProps(props, {
41
+ parametersChildren,
42
+ typeParametersChildren
43
+ });
44
+ const namer = useTSNamePolicy();
45
+ const name = namer.getName(props.name, "interface-member");
46
+ return [_$createComponent(Show, {
47
+ get when() {
48
+ return Boolean(props.doc);
49
+ },
50
+ get children() {
51
+ return [_$createComponent(JSDoc, {
52
+ get children() {
53
+ return [_$memo(() => _$memo(() => !!props.doc)() && _$createComponent(Prose, {
54
+ get children() {
55
+ return props.doc;
56
+ }
57
+ })), _$memo(() => _$memo(() => !!Array.isArray(props.parameters))() && _$createComponent(JSDocParams, {
58
+ get parameters() {
59
+ return props.parameters;
60
+ }
61
+ }))];
62
+ }
63
+ }), _$createIntrinsic("hbr", {})];
64
+ }
65
+ }), _$createComponent(MemberDeclaration, _$mergeProps({
66
+ "static": true
67
+ }, props, {
68
+ get refkey() {
69
+ return props.refkey;
70
+ },
71
+ get children() {
72
+ return [name, _$createComponent(Scope, {
73
+ get name() {
74
+ return props.name;
75
+ },
76
+ kind: "function",
77
+ get children() {
78
+ return _$createComponent(CallSignature, _$mergeProps(callSignatureProps, {
79
+ returnType: returnType
80
+ }));
81
+ }
82
+ })];
83
+ }
84
+ }))];
85
+ }
86
+ InterfaceMethod.TypeParameters = TypeParameters;
87
+ InterfaceMethod.Parameters = FunctionTypeParameters;
@@ -16,5 +16,4 @@ export function JSDoc(props) {
16
16
  });
17
17
  }
18
18
  });
19
- }
20
- //# sourceMappingURL=JSDoc.js.map
19
+ }
@@ -1,5 +1,4 @@
1
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
1
+ import { createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
3
2
  /**
4
3
  * A JSDoc comment block. This is a low-level component that merely creates the
5
4
  * block. Consider using {@link JSDoc} if you want to create more complex
@@ -11,6 +10,5 @@ export function JSDocComment(props) {
11
10
  get children() {
12
11
  return [_$createIntrinsic("hbr", {}), _$memo(() => props.children)];
13
12
  }
14
- }), _$createIntrinsic("hbr", {}), " **/"];
15
- }
16
- //# sourceMappingURL=JSDocComment.js.map
13
+ }), _$createIntrinsic("hbr", {}), " */"];
14
+ }
@@ -1,6 +1,4 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
3
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
1
+ import { createIntrinsic as _$createIntrinsic, memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
4
2
  import { Show } from "@alloy-js/core";
5
3
  /**
6
4
  * Create a JSDoc example set off with `@example`. When the `fenced` prop is true, a `language` prop can
@@ -22,5 +20,4 @@ export function JSDocExample(props) {
22
20
  return [_$createIntrinsic("hbr", {}), "```"];
23
21
  }
24
22
  })];
25
- }
26
- //# sourceMappingURL=JSDocExample.js.map
23
+ }
@@ -1,6 +1,4 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
3
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
4
2
  import { For, Prose, Show } from "@alloy-js/core";
5
3
  /**
6
4
  * A component that creates a JSDoc block with `@param` tags for each parameter.
@@ -117,5 +115,4 @@ function JSDocParamDescription(props) {
117
115
  })];
118
116
  }
119
117
  });
120
- }
121
- //# sourceMappingURL=JSDocParam.js.map
118
+ }
@@ -1,5 +1,4 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
3
2
  import { childrenArray, computed, For, List, Show } from "@alloy-js/core";
4
3
  import { isComponentCreator } from "@alloy-js/core/jsx-runtime";
5
4
  import { FunctionCallExpression } from "./FunctionCallExpression.js";
@@ -96,5 +95,4 @@ function flattenCallChains(children) {
96
95
  }
97
96
  }
98
97
  return flatChildren;
99
- }
100
- //# sourceMappingURL=MemberChainExpression.js.map
98
+ }
@@ -0,0 +1,34 @@
1
+ import { MemberDeclarationPropsWithInfo, OutputSymbolFlags } from "@alloy-js/core";
2
+ import { TypeScriptElements } from "../name-policy.js";
3
+ import { TSOutputSymbol } from "../symbols/index.js";
4
+ export interface MemberDeclarationProps extends Omit<MemberDeclarationPropsWithInfo, "name"> {
5
+ /**
6
+ * The name of this member declaration.
7
+ */
8
+ name?: string;
9
+ /** Name that shouldn't go through the name policy resolver again. */
10
+ exactName?: string;
11
+ /**
12
+ * Whether this is a memberdeclaration of a type (e.g. interface, type alias) or a
13
+ * value (e.g. var, const, let).
14
+ */
15
+ kind?: "type" | "value";
16
+ /**
17
+ * The name policy kind to apply to the memberdeclaration.
18
+ */
19
+ nameKind?: TypeScriptElements;
20
+ /**
21
+ * Flags for the symbol created by this component.
22
+ */
23
+ flags?: OutputSymbolFlags;
24
+ /**
25
+ * The symbol to use for this memberdeclaration.
26
+ */
27
+ symbol?: TSOutputSymbol;
28
+ /**
29
+ * Whether this member can be null or undefined.
30
+ */
31
+ nullish?: boolean;
32
+ }
33
+ export declare function MemberDeclaration(props: Readonly<MemberDeclarationProps>): import("@alloy-js/core").Children;
34
+ //# sourceMappingURL=MemberDeclaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemberDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/MemberDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAEL,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,8BAA8B,EAAE,MAAM,CAAC;IACpD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,qCA2BxE"}
@@ -0,0 +1,29 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { MemberDeclaration as CoreMemberDeclaration } from "@alloy-js/core";
3
+ import { useTSNamePolicy } from "../name-policy.js";
4
+ import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
5
+ export function MemberDeclaration(props) {
6
+ let sym;
7
+ if (props.symbol) {
8
+ sym = props.symbol;
9
+ } else {
10
+ const namePolicy = useTSNamePolicy();
11
+ let tsFlags = props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None;
12
+ if (props.kind === "type") {
13
+ tsFlags |= TSSymbolFlags.TypeSymbol;
14
+ }
15
+ sym = createTSSymbol({
16
+ name: props.exactName ?? namePolicy.getName(props.name, props.nameKind),
17
+ refkey: props.refkey,
18
+ flags: props.flags,
19
+ tsFlags,
20
+ metadata: props.metadata
21
+ });
22
+ }
23
+ return _$createComponent(CoreMemberDeclaration, {
24
+ symbol: sym,
25
+ get children() {
26
+ return props.children;
27
+ }
28
+ });
29
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"MemberExpression.d.ts","sourceRoot":"","sources":["../../../src/components/MemberExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAGZ,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAGxB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,QAAQ,CAwHvE;yBAxHe,gBAAgB;sBA+KS,yBAAyB;;AAhClE,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
1
+ {"version":3,"file":"MemberExpression.d.ts","sourceRoot":"","sources":["../../../src/components/MemberExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAGZ,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,QAAQ,CA4HvE;yBA5He,gBAAgB;sBAmLS,yBAAyB;;AAhClE,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
@@ -1,7 +1,6 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
3
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
1
+ import { createIntrinsic as _$createIntrinsic, memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
4
2
  import { childrenArray, computed, For, isComponentCreator, ref, toRef, useBinder } from "@alloy-js/core";
3
+ import { TSSymbolFlags } from "../symbols/ts-output-symbol.js";
5
4
  import { isValidJSIdentifier } from "../utils.js";
6
5
  /**
7
6
  * Create a member expression from parts. Each part can provide one of
@@ -55,7 +54,7 @@ export function MemberExpression(props) {
55
54
  const symbolRef = binder.getSymbolForRefkey(partProps.refkey);
56
55
  part.base = computed(() => {
57
56
  if (symbolRef.value) {
58
- part.nullish.value = !!symbolRef.value.metadata.nullish;
57
+ part.nullish.value = !!(symbolRef.value.tsFlags & TSSymbolFlags.Nullish);
59
58
  part.accessStyle.value = accessStyleForMemberName(symbolRef.value.name);
60
59
  return symbolRef.value.name;
61
60
  } else {
@@ -63,7 +62,7 @@ export function MemberExpression(props) {
63
62
  }
64
63
  });
65
64
  } else if (partProps.symbol) {
66
- part.nullish.value = !!partProps.symbol.metadata.nullish;
65
+ part.nullish.value = !!(partProps.symbol.tsFlags & TSSymbolFlags.Nullish);
67
66
  part.accessStyle = computed(() => {
68
67
  return accessStyleForMemberName(partProps.symbol.name);
69
68
  });
@@ -175,5 +174,4 @@ MemberExpression.Part = function (props) {
175
174
  * This component does nothing except hold props which are retrieved by
176
175
  * the `MemberExpression` component.
177
176
  */
178
- };
179
- //# sourceMappingURL=MemberExpression.js.map
177
+ };
@@ -1,6 +1,4 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
3
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
4
2
  import { AssignmentContext, Block, computed, createAssignmentContext, For, getAssignmentSymbol, Match, MemberScope, OutputSymbolFlags, Switch, Wrap } from "@alloy-js/core";
5
3
  import { useTSNamePolicy } from "../name-policy.js";
6
4
  import { createTSSymbol } from "../symbols/index.js";
@@ -107,5 +105,4 @@ export function ObjectProperty(props) {
107
105
  value: assignmentContext,
108
106
  children: value
109
107
  })];
110
- }
111
- //# sourceMappingURL=ObjectExpression.js.map
108
+ }
@@ -1,6 +1,4 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
3
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, mergeProps as _$mergeProps, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
4
2
  import { createNamedContext, Scope, shallowRef, SourceDirectory, SourceDirectoryContext, splitProps, useBinder, useContext, useScope } from "@alloy-js/core";
5
3
  import { join } from "pathe";
6
4
  import { createTSPackageScope } from "../symbols/index.js";
@@ -51,5 +49,4 @@ function createPackageContext(name, version, path) {
51
49
  scope,
52
50
  outFileMapper: shallowRef(path => modulePath(path))
53
51
  };
54
- }
55
- //# sourceMappingURL=PackageDirectory.js.map
52
+ }
@@ -50,5 +50,4 @@ export function PackageJsonFile(props) {
50
50
  filetype: "json",
51
51
  children: jsonContent
52
52
  });
53
- }
54
- //# sourceMappingURL=PackageJson.js.map
53
+ }
@@ -32,5 +32,4 @@ function quoteIfNeeded(name) {
32
32
  } else {
33
33
  return `"${name.replace(/"/g, '\\"')}"`;
34
34
  }
35
- }
36
- //# sourceMappingURL=PropertyName.js.map
35
+ }
@@ -1,6 +1,13 @@
1
1
  import { Refkey } from "@alloy-js/core";
2
2
  export interface ReferenceProps {
3
3
  refkey: Refkey;
4
+ /**
5
+ * Whether this is a reference to a type.
6
+ *
7
+ * @remarks
8
+ * This affect things like import where `type` keyword might be used.
9
+ */
10
+ type?: boolean;
4
11
  }
5
- export declare function Reference({ refkey }: ReferenceProps): import("@alloy-js/core").Children;
12
+ export declare function Reference({ refkey, type }: ReferenceProps): import("@alloy-js/core").Children;
6
13
  //# sourceMappingURL=Reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["../../../src/components/Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,cAAc,qCAInD"}
1
+ {"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["../../../src/components/Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,cAAc,qCAKzD"}
@@ -1,8 +1,12 @@
1
+ import { isTypeRefContext } from "../context/type-ref-context.js";
1
2
  import { ref } from "../symbols/index.js";
2
3
  export function Reference({
3
- refkey
4
+ refkey,
5
+ type
4
6
  }) {
5
- const reference = ref(refkey);
7
+ const inTypeRef = isTypeRefContext();
8
+ const reference = ref(refkey, {
9
+ type: type ?? inTypeRef
10
+ });
6
11
  return [reference];
7
- }
8
- //# sourceMappingURL=Reference.js.map
12
+ }
@@ -1,5 +1,4 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
3
2
  import { Prose } from "@alloy-js/core";
4
3
  /**
5
4
  * A single line comment block. The children are rendered as a prose element, which means that they
@@ -16,5 +15,4 @@ export function SingleLineCommentBlock(props) {
16
15
  });
17
16
  }
18
17
  })];
19
- }
20
- //# sourceMappingURL=SingleLineCommentBlock.js.map
18
+ }
@@ -1,5 +1,4 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
3
2
  import { SourceFile as CoreSourceFile, createNamedContext, Scope, Show, SourceDirectoryContext, useBinder, useContext, useScope } from "@alloy-js/core";
4
3
  import { join } from "pathe";
5
4
  import { getSourceDirectoryData } from "../source-directory-data.js";
@@ -96,5 +95,4 @@ function SourceFileHeader(props) {
96
95
  return props.header;
97
96
  }
98
97
  }), _$createIntrinsic("hbr", {})];
99
- }
100
- //# sourceMappingURL=SourceFile.js.map
98
+ }
@@ -1,6 +1,4 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
3
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
4
2
  import { Block, Indent, Match, Switch } from "@alloy-js/core";
5
3
  import { BlockScope } from "./BlockScope.js";
6
4
  import { ValueExpression } from "./ValueExpression.js";
@@ -44,5 +42,4 @@ export function CaseClause(props) {
44
42
  return [_$memo(() => props.children), _$memo(() => _$memo(() => !!props.break)() && [_$createIntrinsic("hbr", {}), "break;"])];
45
43
  }
46
44
  })];
47
- }
48
- //# sourceMappingURL=SwitchStatement.js.map
45
+ }
@@ -49,5 +49,4 @@ export function TSConfigJson(props) {
49
49
  filetype: "json",
50
50
  children: jsonContent
51
51
  });
52
- }
53
- //# sourceMappingURL=TsConfigJson.js.map
52
+ }
@@ -1,5 +1,5 @@
1
1
  import { BaseDeclarationProps } from "./Declaration.js";
2
2
  export interface TypeDeclarationProps extends BaseDeclarationProps {
3
3
  }
4
- export declare function TypeDeclaration(props: TypeDeclarationProps): import("@alloy-js/core").Children;
4
+ export declare const TypeDeclaration: (props: TypeDeclarationProps) => import("@alloy-js/core").Children;
5
5
  //# sourceMappingURL=TypeDeclaration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TypeDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/TypeDeclaration.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAGrE,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;CAAG;AAErE,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qCAY1D"}
1
+ {"version":3,"file":"TypeDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/TypeDeclaration.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAIrE,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;CAAG;AAErE,eAAO,MAAM,eAAe,oEAc3B,CAAC"}
@@ -1,11 +1,9 @@
1
- import { mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
3
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
4
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
5
2
  import { Name, Show } from "@alloy-js/core";
6
3
  import { Declaration } from "./Declaration.js";
7
4
  import { JSDoc } from "./JSDoc.js";
8
- export function TypeDeclaration(props) {
5
+ import { ensureTypeRefContext } from "./TypeRefContext.js";
6
+ export const TypeDeclaration = ensureTypeRefContext(props => {
9
7
  return [_$createComponent(Show, {
10
8
  get when() {
11
9
  return Boolean(props.doc);
@@ -23,5 +21,4 @@ export function TypeDeclaration(props) {
23
21
  return ["type ", _$createComponent(Name, {}), " = ", _$memo(() => props.children), ";"];
24
22
  }
25
23
  }))];
26
- }
27
- //# sourceMappingURL=TypeDeclaration.js.map
24
+ });
@@ -0,0 +1,22 @@
1
+ import type { Children } from "@alloy-js/core/jsx-runtime";
2
+ export interface TypeRefContextProps {
3
+ /**
4
+ * Children
5
+ */
6
+ children: Children;
7
+ }
8
+ /**
9
+ * Set the current context of reference to be type reference.
10
+ *
11
+ * @remarks
12
+ * References used inside the children of this component will be treated as type reference {@link Reference}.
13
+ *
14
+ * Prefer using {@link ensureTypeRefContext} when wrapping the whole component to reduce tree nodes.
15
+ */
16
+ export declare const TypeRefContext: ({ children }: TypeRefContextProps) => Children;
17
+ /** Ensure the current component is inside a type ref context.
18
+ * If not it will wrap in a {@link TypeRefContext} component.
19
+ * If yes it will not add an extra node and return the original component.
20
+ */
21
+ export declare function ensureTypeRefContext<A extends unknown[]>(fn: (...args: A) => Children): (...args: A) => Children;
22
+ //# sourceMappingURL=TypeRefContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeRefContext.d.ts","sourceRoot":"","sources":["../../../src/components/TypeRefContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAM3D,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,cAAc,mBAAmB,aAM/D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,OAAO,EAAE,EACtD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,QAAQ,GAC3B,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,QAAQ,CAa1B"}
@@ -0,0 +1,41 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { isTypeRefContext, TypeRefContext as TypeRefContextDef } from "../context/type-ref-context.js";
3
+ /**
4
+ * Set the current context of reference to be type reference.
5
+ *
6
+ * @remarks
7
+ * References used inside the children of this component will be treated as type reference {@link Reference}.
8
+ *
9
+ * Prefer using {@link ensureTypeRefContext} when wrapping the whole component to reduce tree nodes.
10
+ */
11
+ export const TypeRefContext = ({
12
+ children
13
+ }) => {
14
+ return _$createComponent(TypeRefContextDef.Provider, {
15
+ value: {
16
+ type: true
17
+ },
18
+ children: children
19
+ });
20
+ };
21
+
22
+ /** Ensure the current component is inside a type ref context.
23
+ * If not it will wrap in a {@link TypeRefContext} component.
24
+ * If yes it will not add an extra node and return the original component.
25
+ */
26
+ export function ensureTypeRefContext(fn) {
27
+ return (...args) => {
28
+ const ref = isTypeRefContext();
29
+ if (!ref) {
30
+ return _$createComponent(TypeRefContextDef.Provider, {
31
+ value: {
32
+ type: true
33
+ },
34
+ get children() {
35
+ return fn(...args);
36
+ }
37
+ });
38
+ }
39
+ return fn(...args);
40
+ };
41
+ }
@@ -30,5 +30,4 @@ export function ValueExpression(props) {
30
30
  return jsValue;
31
31
  }
32
32
  });
33
- }
34
- //# sourceMappingURL=ValueExpression.js.map
33
+ }
@@ -6,6 +6,7 @@ export interface VarDeclarationProps extends BaseDeclarationProps {
6
6
  var?: boolean;
7
7
  initializer?: Children;
8
8
  type?: Children;
9
+ nullish?: boolean;
9
10
  }
10
11
  export declare function VarDeclaration(props: VarDeclarationProps): Children;
11
12
  //# sourceMappingURL=VarDeclaration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VarDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VarDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YAkCxD"}
1
+ {"version":3,"file":"VarDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VarDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YAoCxD"}
@@ -1,20 +1,24 @@
1
- import { createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
3
- import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
4
2
  import { AssignmentContext, Declaration as CoreDeclaration, createAssignmentContext, Name, Show } from "@alloy-js/core";
5
3
  import { useTSNamePolicy } from "../name-policy.js";
6
- import { createTSSymbol } from "../symbols/index.js";
4
+ import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
7
5
  import { JSDoc } from "./JSDoc.js";
6
+ import { TypeRefContext } from "./TypeRefContext.js";
8
7
  export function VarDeclaration(props) {
9
8
  const keyword = props.var ? "var" : props.let ? "let" : "const";
10
- const type = props.type ? [": ", _$memo(() => props.type)] : undefined;
9
+ const type = props.type ? _$createComponent(TypeRefContext, {
10
+ get children() {
11
+ return [": ", _$memo(() => props.type)];
12
+ }
13
+ }) : undefined;
11
14
  const name = useTSNamePolicy().getName(props.name, "variable");
12
15
  const sym = createTSSymbol({
13
16
  name: name,
14
17
  refkey: props.refkey,
15
18
  default: props.default,
16
19
  export: props.export,
17
- metadata: props.metadata
20
+ metadata: props.metadata,
21
+ tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None
18
22
  });
19
23
  const assignmentContext = createAssignmentContext(sym);
20
24
  return [_$createComponent(Show, {
@@ -39,5 +43,4 @@ export function VarDeclaration(props) {
39
43
  })];
40
44
  }
41
45
  })];
42
- }
43
- //# sourceMappingURL=VarDeclaration.js.map
46
+ }