@alloy-js/typescript 0.7.0 → 0.8.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 (202) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/src/components/ArrayExpression.d.ts.map +1 -1
  3. package/dist/src/components/ArrayExpression.js +9 -3
  4. package/dist/src/components/ArrayExpression.js.map +1 -1
  5. package/dist/src/components/BlockScope.d.ts +13 -0
  6. package/dist/src/components/BlockScope.d.ts.map +1 -0
  7. package/dist/src/components/BlockScope.js +20 -0
  8. package/dist/src/components/BlockScope.js.map +1 -0
  9. package/dist/src/components/CallSignature.d.ts +38 -0
  10. package/dist/src/components/CallSignature.d.ts.map +1 -0
  11. package/dist/src/components/CallSignature.js +26 -0
  12. package/dist/src/components/CallSignature.js.map +1 -0
  13. package/dist/src/components/ClassDeclaration.d.ts +3 -4
  14. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  15. package/dist/src/components/ClassDeclaration.js +99 -41
  16. package/dist/src/components/ClassDeclaration.js.map +1 -1
  17. package/dist/src/components/Declaration.d.ts +21 -8
  18. package/dist/src/components/Declaration.d.ts.map +1 -1
  19. package/dist/src/components/Declaration.js +39 -21
  20. package/dist/src/components/Declaration.js.map +1 -1
  21. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  22. package/dist/src/components/EnumDeclaration.js +18 -6
  23. package/dist/src/components/EnumDeclaration.js.map +1 -1
  24. package/dist/src/components/EnumMember.d.ts +8 -0
  25. package/dist/src/components/EnumMember.d.ts.map +1 -1
  26. package/dist/src/components/EnumMember.js +27 -5
  27. package/dist/src/components/EnumMember.js.map +1 -1
  28. package/dist/src/components/FunctionCallExpression.js +1 -1
  29. package/dist/src/components/FunctionCallExpression.js.map +1 -1
  30. package/dist/src/components/FunctionDeclaration.d.ts +21 -13
  31. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  32. package/dist/src/components/FunctionDeclaration.js +79 -45
  33. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  34. package/dist/src/components/IfStatement.d.ts +25 -0
  35. package/dist/src/components/IfStatement.d.ts.map +1 -0
  36. package/dist/src/components/IfStatement.js +34 -0
  37. package/dist/src/components/IfStatement.js.map +1 -0
  38. package/dist/src/components/Interface.d.ts +10 -2
  39. package/dist/src/components/Interface.d.ts.map +1 -1
  40. package/dist/src/components/Interface.js +66 -6
  41. package/dist/src/components/Interface.js.map +1 -1
  42. package/dist/src/components/JSDoc.d.ts.map +1 -1
  43. package/dist/src/components/JSDoc.js +1 -5
  44. package/dist/src/components/JSDoc.js.map +1 -1
  45. package/dist/src/components/JSDocParam.d.ts +22 -0
  46. package/dist/src/components/JSDocParam.d.ts.map +1 -0
  47. package/dist/src/components/JSDocParam.js +121 -0
  48. package/dist/src/components/JSDocParam.js.map +1 -0
  49. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  50. package/dist/src/components/ObjectExpression.js +9 -2
  51. package/dist/src/components/ObjectExpression.js.map +1 -1
  52. package/dist/src/components/PropertyName.d.ts +19 -0
  53. package/dist/src/components/PropertyName.d.ts.map +1 -0
  54. package/dist/src/components/PropertyName.js +36 -0
  55. package/dist/src/components/PropertyName.js.map +1 -0
  56. package/dist/src/components/SingleLineCommentBlock.d.ts +10 -0
  57. package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -0
  58. package/dist/src/components/SingleLineCommentBlock.js +20 -0
  59. package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
  60. package/dist/src/components/SourceFile.d.ts +6 -0
  61. package/dist/src/components/SourceFile.d.ts.map +1 -1
  62. package/dist/src/components/SourceFile.js +31 -0
  63. package/dist/src/components/SourceFile.js.map +1 -1
  64. package/dist/src/components/SwitchStatement.d.ts +31 -0
  65. package/dist/src/components/SwitchStatement.d.ts.map +1 -0
  66. package/dist/src/components/SwitchStatement.js +48 -0
  67. package/dist/src/components/SwitchStatement.js.map +1 -0
  68. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  69. package/dist/src/components/TypeDeclaration.js +16 -3
  70. package/dist/src/components/TypeDeclaration.js.map +1 -1
  71. package/dist/src/components/VarDeclaration.d.ts +1 -1
  72. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  73. package/dist/src/components/VarDeclaration.js +19 -6
  74. package/dist/src/components/VarDeclaration.js.map +1 -1
  75. package/dist/src/components/index.d.ts +7 -0
  76. package/dist/src/components/index.d.ts.map +1 -1
  77. package/dist/src/components/index.js +7 -0
  78. package/dist/src/components/index.js.map +1 -1
  79. package/dist/src/components/stc/index.d.ts +35 -112
  80. package/dist/src/components/stc/index.d.ts.map +1 -1
  81. package/dist/src/components/stc/index.js +8 -1
  82. package/dist/src/components/stc/index.js.map +1 -1
  83. package/dist/src/context/index.d.ts +2 -0
  84. package/dist/src/context/index.d.ts.map +1 -0
  85. package/dist/src/context/index.js +1 -0
  86. package/dist/src/context/index.js.map +1 -0
  87. package/dist/src/context/private-scope.d.ts +18 -0
  88. package/dist/src/context/private-scope.d.ts.map +1 -0
  89. package/dist/src/context/private-scope.js +9 -0
  90. package/dist/src/context/private-scope.js.map +1 -0
  91. package/dist/src/index.d.ts +1 -0
  92. package/dist/src/index.d.ts.map +1 -1
  93. package/dist/src/index.js +1 -0
  94. package/dist/src/index.js.map +1 -1
  95. package/dist/src/parameter-descriptor.d.ts +60 -0
  96. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  97. package/dist/src/parameter-descriptor.js +1 -0
  98. package/dist/src/parameter-descriptor.js.map +1 -0
  99. package/dist/src/symbols/reference.d.ts.map +1 -1
  100. package/dist/src/symbols/reference.js +50 -12
  101. package/dist/src/symbols/reference.js.map +1 -1
  102. package/dist/src/symbols/ts-member-scope.d.ts +1 -1
  103. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  104. package/dist/src/symbols/ts-member-scope.js +2 -0
  105. package/dist/src/symbols/ts-member-scope.js.map +1 -1
  106. package/dist/src/symbols/ts-output-symbol.d.ts +7 -4
  107. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  108. package/dist/src/symbols/ts-output-symbol.js +11 -2
  109. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  110. package/dist/src/utils.d.ts +7 -0
  111. package/dist/src/utils.d.ts.map +1 -1
  112. package/dist/src/utils.js +17 -0
  113. package/dist/src/utils.js.map +1 -1
  114. package/dist/test/block-scope.test.d.ts +2 -0
  115. package/dist/test/block-scope.test.d.ts.map +1 -0
  116. package/dist/test/enum-jsdoc.test.d.ts +2 -0
  117. package/dist/test/enum-jsdoc.test.d.ts.map +1 -0
  118. package/dist/test/function-declaration-jsdoc.test.d.ts +2 -0
  119. package/dist/test/function-declaration-jsdoc.test.d.ts.map +1 -0
  120. package/dist/test/if-statement.test.d.ts +2 -0
  121. package/dist/test/if-statement.test.d.ts.map +1 -0
  122. package/dist/test/interface-jsdoc.test.d.ts +2 -0
  123. package/dist/test/interface-jsdoc.test.d.ts.map +1 -0
  124. package/dist/test/jscomment.test.d.ts +2 -0
  125. package/dist/test/jscomment.test.d.ts.map +1 -0
  126. package/dist/test/jsdoc.test.d.ts.map +1 -1
  127. package/dist/test/jsdocparam.test.d.ts +2 -0
  128. package/dist/test/jsdocparam.test.d.ts.map +1 -0
  129. package/dist/test/name-conflict.test.d.ts +2 -0
  130. package/dist/test/name-conflict.test.d.ts.map +1 -0
  131. package/dist/test/package-json.test.d.ts +2 -0
  132. package/dist/test/package-json.test.d.ts.map +1 -0
  133. package/dist/test/source-file.test.d.ts +2 -0
  134. package/dist/test/source-file.test.d.ts.map +1 -0
  135. package/dist/test/switch-statement.test.d.ts +2 -0
  136. package/dist/test/switch-statement.test.d.ts.map +1 -0
  137. package/dist/test/var-declaration-jsdoc.test.d.ts +2 -0
  138. package/dist/test/var-declaration-jsdoc.test.d.ts.map +1 -0
  139. package/dist/tsconfig.tsbuildinfo +1 -1
  140. package/package.json +3 -3
  141. package/src/components/ArrayExpression.tsx +13 -12
  142. package/src/components/BlockScope.tsx +31 -0
  143. package/src/components/CallSignature.tsx +67 -0
  144. package/src/components/ClassDeclaration.tsx +103 -50
  145. package/src/components/Declaration.tsx +72 -27
  146. package/src/components/EnumDeclaration.tsx +26 -18
  147. package/src/components/EnumMember.tsx +24 -4
  148. package/src/components/FunctionCallExpression.tsx +1 -1
  149. package/src/components/FunctionDeclaration.tsx +106 -82
  150. package/src/components/IfStatement.tsx +51 -0
  151. package/src/components/Interface.tsx +61 -14
  152. package/src/components/JSDoc.tsx +1 -10
  153. package/src/components/JSDocParam.tsx +115 -0
  154. package/src/components/ObjectExpression.tsx +7 -2
  155. package/src/components/PropertyName.tsx +50 -0
  156. package/src/components/SingleLineCommentBlock.tsx +21 -0
  157. package/src/components/SourceFile.tsx +29 -0
  158. package/src/components/SwitchStatement.tsx +78 -0
  159. package/src/components/TypeDeclaration.tsx +11 -4
  160. package/src/components/VarDeclaration.tsx +19 -11
  161. package/src/components/index.ts +7 -0
  162. package/src/components/stc/index.ts +8 -1
  163. package/src/context/index.ts +1 -0
  164. package/src/context/private-scope.ts +23 -0
  165. package/src/index.ts +1 -0
  166. package/src/parameter-descriptor.ts +71 -0
  167. package/src/symbols/reference.ts +70 -18
  168. package/src/symbols/ts-member-scope.ts +6 -2
  169. package/src/symbols/ts-output-symbol.ts +24 -11
  170. package/src/utils.ts +33 -0
  171. package/temp/api.json +3816 -1925
  172. package/test/array.test.tsx +60 -0
  173. package/test/basic.test.tsx +2 -2
  174. package/test/block-scope.test.tsx +29 -0
  175. package/test/class.test.tsx +173 -5
  176. package/test/enum-jsdoc.test.tsx +74 -0
  177. package/test/enum.test.tsx +50 -3
  178. package/test/function-call-expression.test.tsx +5 -2
  179. package/test/function-declaration-jsdoc.test.tsx +89 -0
  180. package/test/function-declaration.test.tsx +13 -9
  181. package/test/if-statement.test.tsx +28 -0
  182. package/test/interface-jsdoc.test.tsx +164 -0
  183. package/test/interface.test.tsx +14 -0
  184. package/test/jscomment.test.tsx +104 -0
  185. package/test/jsdoc.test.tsx +9 -15
  186. package/test/jsdocparam.test.tsx +188 -0
  187. package/test/name-conflict.test.tsx +105 -0
  188. package/test/name-policy.test.tsx +1 -1
  189. package/test/package-json.test.tsx +93 -0
  190. package/test/reference.test.tsx +6 -2
  191. package/test/source-file.test.tsx +38 -0
  192. package/test/switch-statement.test.tsx +50 -0
  193. package/test/value-expression.test.tsx +9 -0
  194. package/test/var-declaration-jsdoc.test.tsx +70 -0
  195. package/test/var-declaration.test.tsx +1 -1
  196. package/tsconfig.json +1 -8
  197. package/vitest.config.ts +2 -10
  198. package/dist/src/components/JSDocParagraph.d.ts +0 -10
  199. package/dist/src/components/JSDocParagraph.d.ts.map +0 -1
  200. package/dist/src/components/JSDocParagraph.js +0 -23
  201. package/dist/src/components/JSDocParagraph.js.map +0 -1
  202. package/src/components/JSDocParagraph.tsx +0 -35
@@ -0,0 +1,31 @@
1
+ import {
2
+ Block,
3
+ BlockProps,
4
+ Scope,
5
+ ScopePropsWithInfo,
6
+ ScopePropsWithValue,
7
+ } from "@alloy-js/core";
8
+
9
+ export interface BlockScopePropsWithScopeValue
10
+ extends ScopePropsWithValue,
11
+ BlockProps {}
12
+ export interface BlockScopePropsWithScopeInfo
13
+ extends ScopePropsWithInfo,
14
+ BlockProps {}
15
+
16
+ export type BlockScopeProps =
17
+ | BlockScopePropsWithScopeValue
18
+ | BlockScopePropsWithScopeInfo;
19
+
20
+ /**
21
+ * Create a TypeScript block which includes a scope for any nested declarations.
22
+ * Can either provide the scope directly via the `value` prop, or else provide
23
+ * information about the scope.
24
+ */
25
+ export function BlockScope(props: BlockScopeProps) {
26
+ return (
27
+ <Scope {...props}>
28
+ <Block {...props}>{props.children}</Block>
29
+ </Scope>
30
+ );
31
+ }
@@ -0,0 +1,67 @@
1
+ import { Children } from "@alloy-js/core/jsx-runtime";
2
+ import {
3
+ ParameterDescriptor,
4
+ TypeParameterDescriptor,
5
+ } from "../parameter-descriptor.js";
6
+ import { FunctionDeclaration } from "./FunctionDeclaration.jsx";
7
+
8
+ export interface CallSignatureProps {
9
+ /**
10
+ * The parameters to the function. Can be an array of strings for parameters
11
+ * which don't have a type or a default value. Otherwise, it's an array of
12
+ * {@link ParameterDescriptor}s.
13
+ */
14
+ parameters?: ParameterDescriptor[] | string[];
15
+
16
+ /**
17
+ * Raw content to be used as the parameter list.
18
+ */
19
+ parametersChildren?: Children;
20
+
21
+ /**
22
+ * The type parameters for the function. Can be an array of strings for
23
+ * type parameters which don't have any constraints or a default type, otherwise
24
+ * it's an array of {@link TypeParameterDescriptor}s.
25
+ */
26
+ typeParameters?: TypeParameterDescriptor[] | string[];
27
+
28
+ /**
29
+ * Raw content to be used as the type parameter list.
30
+ */
31
+ typeParametersChildren?: Children;
32
+
33
+ /**
34
+ * The return type of the function.
35
+ */
36
+ returnType?: Children;
37
+ }
38
+ /**
39
+ * A TypeScript call signature, e.g. the part after the `function` keyword in an
40
+ * anonymous function expression, or a call signature in an interface.
41
+ *
42
+ * Any parameters or type parameters declared in this signature will be placed
43
+ * in the current scope. This component does not make a scope to hold its
44
+ * parameters.
45
+ */
46
+ export function CallSignature(props: CallSignatureProps) {
47
+ const sTypeParameters =
48
+ props.typeParametersChildren ?
49
+ <>
50
+ {"<"}
51
+ {props.typeParametersChildren}
52
+ {">"}
53
+ </>
54
+ : <FunctionDeclaration.TypeParameters parameters={props.typeParameters} />;
55
+
56
+ const sParams = props.parametersChildren ?? (
57
+ <FunctionDeclaration.Parameters parameters={props.parameters} />
58
+ );
59
+
60
+ const sReturnType = props.returnType ? <>: {props.returnType}</> : undefined;
61
+
62
+ return (
63
+ <>
64
+ {sTypeParameters}({sParams}){sReturnType}
65
+ </>
66
+ );
67
+ }
@@ -2,19 +2,26 @@ import {
2
2
  Block,
3
3
  Children,
4
4
  MemberDeclaration,
5
- MemberName,
6
5
  Name,
7
6
  OutputSymbolFlags,
7
+ Prose,
8
8
  Refkey,
9
9
  Scope,
10
+ Show,
11
+ splitProps,
12
+ useMemberScope,
10
13
  } from "@alloy-js/core";
14
+
15
+ import { usePrivateScope } from "../context/private-scope.js";
11
16
  import { useTSNamePolicy } from "../name-policy.js";
12
- import { createTSSymbol, TSOutputSymbol } from "../symbols/ts-output-symbol.js";
17
+ import { TSOutputScope } from "../symbols/scopes.js";
18
+ import { createTSSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
19
+ import { getCallSignatureProps } from "../utils.js";
20
+ import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
13
21
  import { BaseDeclarationProps, Declaration } from "./Declaration.jsx";
14
- import {
15
- FunctionDeclaration,
16
- ParameterDescriptor,
17
- } from "./FunctionDeclaration.jsx";
22
+ import { JSDoc } from "./JSDoc.jsx";
23
+ import { JSDocParams } from "./JSDocParam.jsx";
24
+ import { PropertyName } from "./PropertyName.jsx";
18
25
 
19
26
  export interface ClassDeclarationProps extends BaseDeclarationProps {
20
27
  extends?: Children;
@@ -54,14 +61,33 @@ export interface ClassDeclarationProps extends BaseDeclarationProps {
54
61
  * ```
55
62
  */
56
63
  export function ClassDeclaration(props: ClassDeclarationProps) {
64
+ const namePolicy = useTSNamePolicy();
57
65
  const extendsPart = props.extends && <> extends {props.extends}</>;
58
- const flags = OutputSymbolFlags.MemberContainer;
66
+
67
+ const sym = createTSSymbol({
68
+ name: namePolicy.getName(props.name!, "class"),
69
+ refkey: props.refkey,
70
+ export: props.export,
71
+ default: props.default,
72
+ flags:
73
+ (props.flags ?? OutputSymbolFlags.None) |
74
+ (OutputSymbolFlags.MemberContainer |
75
+ OutputSymbolFlags.StaticMemberContainer),
76
+ tsFlags: TSSymbolFlags.PrivateMemberContainer,
77
+ metadata: props.metadata,
78
+ });
59
79
 
60
80
  return (
61
- <Declaration {...props} flags={flags} nameKind="class">
62
- class <Name />
63
- {extendsPart} <Block>{props.children}</Block>
64
- </Declaration>
81
+ <>
82
+ <Show when={Boolean(props.doc)}>
83
+ <JSDoc children={props.doc} />
84
+ <hbr />
85
+ </Show>
86
+ <Declaration symbol={sym} export={props.export} default={props.default}>
87
+ class <Name />
88
+ {extendsPart} <Block>{props.children}</Block>
89
+ </Declaration>
90
+ </>
65
91
  );
66
92
  }
67
93
 
@@ -74,39 +100,56 @@ export interface ClassMemberProps {
74
100
  jsPrivate?: boolean;
75
101
  static?: boolean;
76
102
  children?: Children;
103
+ doc?: Children;
77
104
  }
78
105
 
79
106
  export function ClassMember(props: ClassMemberProps) {
80
- let sym: TSOutputSymbol | undefined;
81
107
  const namer = useTSNamePolicy();
82
- let name = namer.getName(props.name, "class-member-data");
83
-
84
- if (props.refkey) {
85
- let flags = OutputSymbolFlags.None;
86
- if (props.static) {
87
- flags |= OutputSymbolFlags.StaticMember;
88
- } else {
89
- flags |= OutputSymbolFlags.InstanceMember;
90
- }
91
-
92
- sym = createTSSymbol({
93
- name: props.jsPrivate ? `#${name}` : name,
94
- refkey: props.refkey,
95
- flags,
96
- });
97
- } else if (props.jsPrivate) {
98
- // we won't be using the symbol name, so munge the name
99
- name = `#${name}`;
108
+ const name = namer.getName(props.name, "class-member-data");
109
+
110
+ let flags = OutputSymbolFlags.None;
111
+
112
+ if (props.static) {
113
+ flags |= OutputSymbolFlags.StaticMember;
114
+ } else {
115
+ flags |= OutputSymbolFlags.InstanceMember;
100
116
  }
101
117
 
118
+ let scope: TSOutputScope;
119
+ if (props.jsPrivate) {
120
+ const memberScope = usePrivateScope()!;
121
+ scope =
122
+ props.static ? memberScope.staticMembers : memberScope.instanceMembers;
123
+ } else {
124
+ const memberScope = useMemberScope();
125
+ scope = (
126
+ props.static ?
127
+ memberScope.staticMembers!
128
+ : memberScope.instanceMembers!) as TSOutputScope;
129
+ }
130
+
131
+ const sym = createTSSymbol({
132
+ name,
133
+ scope,
134
+ refkey: props.refkey,
135
+ flags,
136
+ tsFlags: props.jsPrivate ? TSSymbolFlags.PrivateMember : TSSymbolFlags.None,
137
+ });
138
+
102
139
  return (
103
- <MemberDeclaration symbol={sym} name={name} refkey={props.refkey}>
104
- {props.public && "public "}
105
- {props.private && "private "}
106
- {props.protected && "protected "}
107
- {props.static && "static "}
108
- {props.children}
109
- </MemberDeclaration>
140
+ <>
141
+ <Show when={Boolean(props.doc)}>
142
+ <JSDoc children={props.doc} />
143
+ <hbr />
144
+ </Show>
145
+ <MemberDeclaration symbol={sym}>
146
+ {props.public && "public "}
147
+ {props.private && "private "}
148
+ {props.protected && "protected "}
149
+ {props.static && "static "}
150
+ {props.children}
151
+ </MemberDeclaration>
152
+ </>
110
153
  );
111
154
  }
112
155
 
@@ -121,30 +164,40 @@ export function ClassField(props: ClassFieldProps) {
121
164
 
122
165
  return (
123
166
  <ClassMember {...props}>
124
- <MemberName />
167
+ <PropertyName />
125
168
  {typeSection}
126
169
  {initializerSection}
127
170
  </ClassMember>
128
171
  );
129
172
  }
130
173
 
131
- export interface ClassMethodProps extends ClassMemberProps {
174
+ export interface ClassMethodProps extends ClassMemberProps, CallSignatureProps {
132
175
  async?: boolean;
133
- parameters?: Record<string, Children | ParameterDescriptor>;
134
- returnType?: Children;
135
176
  children?: Children;
136
177
  }
137
178
 
138
179
  export function ClassMethod(props: ClassMethodProps) {
139
- const returnType = props.returnType && <>: {props.returnType}</>;
180
+ const callProps = getCallSignatureProps(props);
181
+ const [_, rest] = splitProps(props, ["doc"]);
182
+
140
183
  return (
141
- <ClassMember {...props}>
142
- {props.async && "async "}
143
- <MemberName />
144
- <Scope name={props.name} kind="function">
145
- (<FunctionDeclaration.Parameters parameters={props.parameters} />)
146
- {returnType} <Block>{props.children}</Block>
147
- </Scope>
148
- </ClassMember>
184
+ <>
185
+ <Show when={Boolean(props.doc)}>
186
+ <JSDoc>
187
+ {props.doc && <Prose children={props.doc} />}
188
+ {Array.isArray(rest.parameters) && (
189
+ <JSDocParams parameters={rest.parameters} />
190
+ )}
191
+ </JSDoc>
192
+ <hbr />
193
+ </Show>
194
+ <ClassMember {...rest}>
195
+ {props.async && "async "}
196
+ <PropertyName />
197
+ <Scope name={props.name} kind="function">
198
+ <CallSignature {...callProps} /> <Block>{props.children}</Block>
199
+ </Scope>
200
+ </ClassMember>
201
+ </>
149
202
  );
150
203
  }
@@ -6,11 +6,17 @@ import {
6
6
  Refkey,
7
7
  } from "@alloy-js/core";
8
8
  import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
9
- import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
9
+ import {
10
+ createTSSymbol,
11
+ TSOutputSymbol,
12
+ TSSymbolFlags,
13
+ } from "../symbols/index.js";
10
14
 
11
15
  // imports for documentation
12
16
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
17
  import { TypeDeclaration } from "./TypeDeclaration.jsx";
18
+
19
+ import { PrivateScopeContext } from "../context/private-scope.js";
14
20
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
21
  import { EnumDeclaration } from "./EnumDeclaration.jsx";
16
22
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -24,14 +30,9 @@ export interface BaseDeclarationProps {
24
30
  name: string;
25
31
 
26
32
  /**
27
- * The unique key for this declaration.
28
- */
29
- refkey?: Refkey;
30
-
31
- /**
32
- * Multiple unique keys for this declaration.
33
+ * The refkey or array of refkeys for this declaration.
33
34
  */
34
- refkeys?: Refkey[];
35
+ refkey?: Refkey | Refkey[];
35
36
 
36
37
  /**
37
38
  * Whether to export this declaration from the module.
@@ -55,13 +56,33 @@ export interface BaseDeclarationProps {
55
56
  * value (e.g. var, const, let).
56
57
  */
57
58
  kind?: "type" | "value";
59
+
60
+ /**
61
+ * Arbitrary metadata about this declaration.
62
+ */
63
+ metadata?: Record<string, unknown>;
64
+
65
+ /**
66
+ * Documentation for this declaration
67
+ */
68
+ doc?: Children;
58
69
  }
59
70
 
60
- export interface DeclarationProps extends BaseDeclarationProps {
71
+ export interface DeclarationProps extends Omit<BaseDeclarationProps, "name"> {
72
+ /**
73
+ * The name of this declaration.
74
+ */
75
+ name?: string;
76
+
61
77
  /**
62
78
  * The name policy kind to apply to the declaration.
63
79
  */
64
- nameKind: TypeScriptElements;
80
+ nameKind?: TypeScriptElements;
81
+
82
+ /**
83
+ * The symbol to use for this declaration.
84
+ */
85
+ symbol?: TSOutputSymbol;
65
86
  }
66
87
 
67
88
  /**
@@ -79,29 +100,53 @@ export interface DeclarationProps extends BaseDeclarationProps {
79
100
  *
80
101
  */
81
102
  export function Declaration(props: DeclarationProps) {
82
- const namePolicy = useTSNamePolicy();
103
+ let sym: TSOutputSymbol;
104
+
105
+ if (props.symbol) {
106
+ sym = props.symbol;
107
+ } else {
108
+ const namePolicy = useTSNamePolicy();
109
+
110
+ let tsFlags: TSSymbolFlags = TSSymbolFlags.None;
111
+ if (props.kind && props.kind === "type") {
112
+ tsFlags &= TSSymbolFlags.TypeSymbol;
113
+ }
114
+
115
+ sym = createTSSymbol({
116
+ name: namePolicy.getName(props.name!, props.nameKind!),
117
+ refkey: props.refkey,
118
+ export: props.export,
119
+ default: props.default,
120
+ flags: props.flags,
121
+ tsFlags,
122
+ metadata: props.metadata,
123
+ });
124
+ }
83
125
 
84
- let tsFlags: TSSymbolFlags = TSSymbolFlags.None;
85
- if (props.kind && props.kind === "type") {
86
- tsFlags &= TSSymbolFlags.TypeSymbol;
126
+ function withMemberScope(children: Children) {
127
+ return <MemberScope owner={sym}>{children}</MemberScope>;
87
128
  }
88
129
 
89
- const sym = createTSSymbol({
90
- name: namePolicy.getName(props.name, props.nameKind),
91
- refkey: props.refkey,
92
- refkeys: props.refkeys,
93
- export: props.export,
94
- default: props.default,
95
- flags: props.flags,
96
- tsFlags,
97
- });
130
+ function withPrivateMemberScope(children: Children) {
131
+ const context: PrivateScopeContext = {
132
+ instanceMembers: sym.privateMemberScope!,
133
+ staticMembers: sym.privateStaticMemberScope!,
134
+ };
135
+ return (
136
+ <PrivateScopeContext.Provider value={context}>
137
+ {children}
138
+ </PrivateScopeContext.Provider>
139
+ );
140
+ }
98
141
 
99
- let children: Children;
142
+ let children: Children = () => props.children;
100
143
 
101
144
  if (sym.flags & OutputSymbolFlags.MemberContainer) {
102
- children = <MemberScope owner={sym}>{props.children}</MemberScope>;
103
- } else {
104
- children = () => props.children;
145
+ children = withMemberScope(children);
146
+ }
147
+
148
+ if (sym.tsFlags & TSSymbolFlags.PrivateMemberContainer) {
149
+ children = withPrivateMemberScope(children);
105
150
  }
106
151
 
107
152
  return (
@@ -6,12 +6,14 @@ import {
6
6
  MemberScope,
7
7
  Name,
8
8
  OutputSymbolFlags,
9
+ Show,
9
10
  useBinder,
10
11
  } from "@alloy-js/core";
11
12
  import { useTSNamePolicy } from "../name-policy.js";
12
13
  import { createTSSymbol, useTSScope } from "../symbols/index.js";
13
14
  import { BaseDeclarationProps } from "./Declaration.js";
14
15
  import { EnumMember } from "./EnumMember.jsx";
16
+ import { JSDoc } from "./JSDoc.jsx";
15
17
  export interface EnumDeclarationProps extends BaseDeclarationProps {
16
18
  /**
17
19
  * A JS object representing the enum member names and values.
@@ -31,30 +33,36 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
31
33
  scope,
32
34
  name: name,
33
35
  refkey: props.refkey,
34
- refkeys: props.refkeys,
35
36
  default: props.default,
36
37
  export: props.export,
37
38
  flags: OutputSymbolFlags.StaticMemberContainer,
39
+ metadata: props.metadata,
38
40
  });
39
41
 
40
42
  const valueEntries = computed(() => Object.entries(props.jsValue ?? {}));
41
43
  return (
42
- <CoreDeclaration symbol={sym}>
43
- {props.export ? "export " : ""}
44
- {props.default ? "default " : ""}enum <Name />{" "}
45
- <MemberScope owner={sym}>
46
- <Block>
47
- <For each={valueEntries} comma hardline enderPunctuation>
48
- {([name, value]) => <EnumMember name={name} jsValue={value} />}
49
- </For>
50
- {props.children && (
51
- <>
52
- {valueEntries.value.length > 0 && <hbr />}
53
- {props.children}
54
- </>
55
- )}
56
- </Block>
57
- </MemberScope>
58
- </CoreDeclaration>
44
+ <>
45
+ <Show when={Boolean(props.doc)}>
46
+ <JSDoc children={props.doc} />
47
+ <hbr />
48
+ </Show>
49
+ <CoreDeclaration symbol={sym}>
50
+ {props.export ? "export " : ""}
51
+ {props.default ? "default " : ""}enum <Name />{" "}
52
+ <MemberScope owner={sym}>
53
+ <Block>
54
+ <For each={valueEntries} comma hardline enderPunctuation>
55
+ {([name, value]) => <EnumMember name={name} jsValue={value} />}
56
+ </For>
57
+ {props.children && (
58
+ <>
59
+ {valueEntries.value.length > 0 && <hbr />}
60
+ {props.children}
61
+ </>
62
+ )}
63
+ </Block>
64
+ </MemberScope>
65
+ </CoreDeclaration>
66
+ </>
59
67
  );
60
68
  }
@@ -1,6 +1,8 @@
1
- import { Children, OutputSymbolFlags, Refkey } from "@alloy-js/core";
1
+ import { Children, OutputSymbolFlags, Refkey, Show } from "@alloy-js/core";
2
2
  import { useTSNamePolicy } from "../name-policy.js";
3
3
  import { createTSSymbol, TSOutputSymbol } from "../symbols/ts-output-symbol.js";
4
+ import { JSDoc } from "./JSDoc.jsx";
5
+ import { PropertyName } from "./PropertyName.jsx";
4
6
  import { ValueExpression } from "./ValueExpression.jsx";
5
7
 
6
8
  export interface EnumMemberProps {
@@ -27,6 +29,16 @@ export interface EnumMemberProps {
27
29
  * The JS value of the enum member.
28
30
  */
29
31
  jsValue?: string | number;
32
+
33
+ /**
34
+ * Arbitrary symbol metadata for the enum member.
35
+ */
36
+ metadata?: Record<string, unknown>;
37
+
38
+ /**
39
+ * Documentation for the enum member.
40
+ */
41
+ doc?: Children;
30
42
  }
31
43
 
32
44
  /**
@@ -41,15 +53,23 @@ export function EnumMember(props: EnumMemberProps) {
41
53
  name,
42
54
  refkey: props.refkey,
43
55
  flags: OutputSymbolFlags.StaticMember,
56
+ metadata: props.metadata,
44
57
  });
45
58
  }
46
- const nameCode = sym ? sym.name : name;
59
+ const actualName = sym ? sym.name : name;
47
60
  const valueCode =
48
- props.jsValue ? <ValueExpression jsValue={props.jsValue} /> : props.value;
61
+ props.jsValue !== undefined ?
62
+ <ValueExpression jsValue={props.jsValue} />
63
+ : props.value;
49
64
 
50
65
  return (
51
66
  <>
52
- {nameCode} = {valueCode}
67
+ <Show when={Boolean(props.doc)}>
68
+ <JSDoc children={props.doc} />
69
+ <hbr />
70
+ </Show>
71
+ <PropertyName name={actualName} />
72
+ <Show when={valueCode !== undefined}> = {valueCode}</Show>
53
73
  </>
54
74
  );
55
75
  }
@@ -12,7 +12,7 @@ export function FunctionCallExpression(props: FunctionCallExpressionProps) {
12
12
  <Wrap
13
13
  when={!!props.args && props.args.length > 1}
14
14
  with={Indent}
15
- props={{ break: "soft", trailingBreak: true }}
15
+ props={{ softline: true, trailingBreak: true }}
16
16
  >
17
17
  <For each={props.args ?? []} comma line>
18
18
  {(arg) => arg}