@alloy-js/typescript 0.6.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 (230) hide show
  1. package/CHANGELOG.md +41 -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 -4
  18. package/dist/src/components/Declaration.d.ts.map +1 -1
  19. package/dist/src/components/Declaration.js +40 -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 +19 -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/ExportStatement.d.ts.map +1 -1
  29. package/dist/src/components/ExportStatement.js +3 -1
  30. package/dist/src/components/ExportStatement.js.map +1 -1
  31. package/dist/src/components/FunctionCallExpression.js +1 -1
  32. package/dist/src/components/FunctionCallExpression.js.map +1 -1
  33. package/dist/src/components/FunctionDeclaration.d.ts +21 -12
  34. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  35. package/dist/src/components/FunctionDeclaration.js +80 -45
  36. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  37. package/dist/src/components/IfStatement.d.ts +25 -0
  38. package/dist/src/components/IfStatement.d.ts.map +1 -0
  39. package/dist/src/components/IfStatement.js +34 -0
  40. package/dist/src/components/IfStatement.js.map +1 -0
  41. package/dist/src/components/Interface.d.ts +10 -2
  42. package/dist/src/components/Interface.d.ts.map +1 -1
  43. package/dist/src/components/Interface.js +66 -6
  44. package/dist/src/components/Interface.js.map +1 -1
  45. package/dist/src/components/JSDoc.d.ts.map +1 -1
  46. package/dist/src/components/JSDoc.js +1 -5
  47. package/dist/src/components/JSDoc.js.map +1 -1
  48. package/dist/src/components/JSDocParam.d.ts +22 -0
  49. package/dist/src/components/JSDocParam.d.ts.map +1 -0
  50. package/dist/src/components/JSDocParam.js +121 -0
  51. package/dist/src/components/JSDocParam.js.map +1 -0
  52. package/dist/src/components/MemberChainExpression.d.ts +2 -2
  53. package/dist/src/components/MemberChainExpression.d.ts.map +1 -1
  54. package/dist/src/components/MemberChainExpression.js +43 -7
  55. package/dist/src/components/MemberChainExpression.js.map +1 -1
  56. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  57. package/dist/src/components/ObjectExpression.js +9 -2
  58. package/dist/src/components/ObjectExpression.js.map +1 -1
  59. package/dist/src/components/PackageDirectory.d.ts +1 -3
  60. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  61. package/dist/src/components/PackageDirectory.js +9 -16
  62. package/dist/src/components/PackageDirectory.js.map +1 -1
  63. package/dist/src/components/PackageJson.d.ts +39 -0
  64. package/dist/src/components/PackageJson.d.ts.map +1 -1
  65. package/dist/src/components/PackageJson.js +30 -12
  66. package/dist/src/components/PackageJson.js.map +1 -1
  67. package/dist/src/components/PropertyName.d.ts +19 -0
  68. package/dist/src/components/PropertyName.d.ts.map +1 -0
  69. package/dist/src/components/PropertyName.js +36 -0
  70. package/dist/src/components/PropertyName.js.map +1 -0
  71. package/dist/src/components/SingleLineCommentBlock.d.ts +10 -0
  72. package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -0
  73. package/dist/src/components/SingleLineCommentBlock.js +20 -0
  74. package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
  75. package/dist/src/components/SourceFile.d.ts +6 -0
  76. package/dist/src/components/SourceFile.d.ts.map +1 -1
  77. package/dist/src/components/SourceFile.js +31 -0
  78. package/dist/src/components/SourceFile.js.map +1 -1
  79. package/dist/src/components/SwitchStatement.d.ts +31 -0
  80. package/dist/src/components/SwitchStatement.d.ts.map +1 -0
  81. package/dist/src/components/SwitchStatement.js +48 -0
  82. package/dist/src/components/SwitchStatement.js.map +1 -0
  83. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  84. package/dist/src/components/TypeDeclaration.js +16 -3
  85. package/dist/src/components/TypeDeclaration.js.map +1 -1
  86. package/dist/src/components/VarDeclaration.d.ts +1 -1
  87. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  88. package/dist/src/components/VarDeclaration.js +20 -6
  89. package/dist/src/components/VarDeclaration.js.map +1 -1
  90. package/dist/src/components/index.d.ts +7 -0
  91. package/dist/src/components/index.d.ts.map +1 -1
  92. package/dist/src/components/index.js +7 -0
  93. package/dist/src/components/index.js.map +1 -1
  94. package/dist/src/components/stc/index.d.ts +35 -112
  95. package/dist/src/components/stc/index.d.ts.map +1 -1
  96. package/dist/src/components/stc/index.js +8 -1
  97. package/dist/src/components/stc/index.js.map +1 -1
  98. package/dist/src/context/index.d.ts +2 -0
  99. package/dist/src/context/index.d.ts.map +1 -0
  100. package/dist/src/context/index.js +1 -0
  101. package/dist/src/context/index.js.map +1 -0
  102. package/dist/src/context/private-scope.d.ts +18 -0
  103. package/dist/src/context/private-scope.d.ts.map +1 -0
  104. package/dist/src/context/private-scope.js +9 -0
  105. package/dist/src/context/private-scope.js.map +1 -0
  106. package/dist/src/index.d.ts +1 -0
  107. package/dist/src/index.d.ts.map +1 -1
  108. package/dist/src/index.js +1 -0
  109. package/dist/src/index.js.map +1 -1
  110. package/dist/src/parameter-descriptor.d.ts +60 -0
  111. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  112. package/dist/src/parameter-descriptor.js +1 -0
  113. package/dist/src/parameter-descriptor.js.map +1 -0
  114. package/dist/src/symbols/reference.d.ts.map +1 -1
  115. package/dist/src/symbols/reference.js +55 -14
  116. package/dist/src/symbols/reference.js.map +1 -1
  117. package/dist/src/symbols/ts-member-scope.d.ts +1 -1
  118. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  119. package/dist/src/symbols/ts-member-scope.js +2 -0
  120. package/dist/src/symbols/ts-member-scope.js.map +1 -1
  121. package/dist/src/symbols/ts-output-symbol.d.ts +7 -3
  122. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  123. package/dist/src/symbols/ts-output-symbol.js +14 -2
  124. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  125. package/dist/src/symbols/ts-package-scope.d.ts +0 -15
  126. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  127. package/dist/src/symbols/ts-package-scope.js +0 -8
  128. package/dist/src/symbols/ts-package-scope.js.map +1 -1
  129. package/dist/src/utils.d.ts +7 -0
  130. package/dist/src/utils.d.ts.map +1 -1
  131. package/dist/src/utils.js +17 -0
  132. package/dist/src/utils.js.map +1 -1
  133. package/dist/test/block-scope.test.d.ts +2 -0
  134. package/dist/test/block-scope.test.d.ts.map +1 -0
  135. package/dist/test/enum-jsdoc.test.d.ts +2 -0
  136. package/dist/test/enum-jsdoc.test.d.ts.map +1 -0
  137. package/dist/test/function-declaration-jsdoc.test.d.ts +2 -0
  138. package/dist/test/function-declaration-jsdoc.test.d.ts.map +1 -0
  139. package/dist/test/if-statement.test.d.ts +2 -0
  140. package/dist/test/if-statement.test.d.ts.map +1 -0
  141. package/dist/test/interface-jsdoc.test.d.ts +2 -0
  142. package/dist/test/interface-jsdoc.test.d.ts.map +1 -0
  143. package/dist/test/jscomment.test.d.ts +2 -0
  144. package/dist/test/jscomment.test.d.ts.map +1 -0
  145. package/dist/test/jsdoc.test.d.ts.map +1 -1
  146. package/dist/test/jsdocparam.test.d.ts +2 -0
  147. package/dist/test/jsdocparam.test.d.ts.map +1 -0
  148. package/dist/test/name-conflict.test.d.ts +2 -0
  149. package/dist/test/name-conflict.test.d.ts.map +1 -0
  150. package/dist/test/package-json.test.d.ts +2 -0
  151. package/dist/test/package-json.test.d.ts.map +1 -0
  152. package/dist/test/source-file.test.d.ts +2 -0
  153. package/dist/test/source-file.test.d.ts.map +1 -0
  154. package/dist/test/switch-statement.test.d.ts +2 -0
  155. package/dist/test/switch-statement.test.d.ts.map +1 -0
  156. package/dist/test/var-declaration-jsdoc.test.d.ts +2 -0
  157. package/dist/test/var-declaration-jsdoc.test.d.ts.map +1 -0
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +3 -3
  160. package/src/components/ArrayExpression.tsx +13 -8
  161. package/src/components/BlockScope.tsx +31 -0
  162. package/src/components/CallSignature.tsx +67 -0
  163. package/src/components/ClassDeclaration.tsx +103 -50
  164. package/src/components/Declaration.tsx +72 -22
  165. package/src/components/EnumDeclaration.tsx +27 -19
  166. package/src/components/EnumMember.tsx +24 -4
  167. package/src/components/ExportStatement.tsx +3 -1
  168. package/src/components/FunctionCallExpression.tsx +1 -1
  169. package/src/components/FunctionDeclaration.tsx +107 -81
  170. package/src/components/IfStatement.tsx +51 -0
  171. package/src/components/Interface.tsx +61 -14
  172. package/src/components/JSDoc.tsx +1 -10
  173. package/src/components/JSDocParam.tsx +115 -0
  174. package/src/components/MemberChainExpression.tsx +37 -5
  175. package/src/components/ObjectExpression.tsx +7 -2
  176. package/src/components/PackageDirectory.tsx +12 -22
  177. package/src/components/PackageJson.tsx +86 -27
  178. package/src/components/PropertyName.tsx +50 -0
  179. package/src/components/SingleLineCommentBlock.tsx +21 -0
  180. package/src/components/SourceFile.tsx +29 -0
  181. package/src/components/SwitchStatement.tsx +78 -0
  182. package/src/components/TypeDeclaration.tsx +11 -4
  183. package/src/components/VarDeclaration.tsx +20 -12
  184. package/src/components/index.ts +7 -0
  185. package/src/components/stc/index.ts +8 -1
  186. package/src/context/index.ts +1 -0
  187. package/src/context/private-scope.ts +23 -0
  188. package/src/index.ts +1 -0
  189. package/src/parameter-descriptor.ts +71 -0
  190. package/src/symbols/reference.ts +77 -22
  191. package/src/symbols/ts-member-scope.ts +6 -2
  192. package/src/symbols/ts-output-symbol.ts +27 -10
  193. package/src/symbols/ts-package-scope.ts +0 -28
  194. package/src/utils.ts +33 -0
  195. package/temp/api.json +5372 -3410
  196. package/test/array.test.tsx +72 -0
  197. package/test/basic.test.tsx +2 -2
  198. package/test/block-scope.test.tsx +29 -0
  199. package/test/class.test.tsx +173 -5
  200. package/test/enum-jsdoc.test.tsx +74 -0
  201. package/test/enum.test.tsx +50 -3
  202. package/test/function-call-expression.test.tsx +5 -2
  203. package/test/function-declaration-jsdoc.test.tsx +89 -0
  204. package/test/function-declaration.test.tsx +13 -9
  205. package/test/if-statement.test.tsx +28 -0
  206. package/test/imports.test.tsx +25 -10
  207. package/test/interface-jsdoc.test.tsx +164 -0
  208. package/test/interface.test.tsx +17 -3
  209. package/test/jscomment.test.tsx +104 -0
  210. package/test/jsdoc.test.tsx +9 -15
  211. package/test/jsdocparam.test.tsx +188 -0
  212. package/test/member-chain.test.tsx +77 -0
  213. package/test/name-conflict.test.tsx +105 -0
  214. package/test/name-policy.test.tsx +1 -1
  215. package/test/package-external.test.tsx +98 -3
  216. package/test/package-json.test.tsx +93 -0
  217. package/test/package.test.tsx +56 -3
  218. package/test/reference.test.tsx +6 -2
  219. package/test/source-file.test.tsx +38 -0
  220. package/test/switch-statement.test.tsx +50 -0
  221. package/test/value-expression.test.tsx +9 -0
  222. package/test/var-declaration-jsdoc.test.tsx +70 -0
  223. package/test/var-declaration.test.tsx +1 -1
  224. package/tsconfig.json +1 -8
  225. package/vitest.config.ts +2 -10
  226. package/dist/src/components/JSDocParagraph.d.ts +0 -10
  227. package/dist/src/components/JSDocParagraph.d.ts.map +0 -1
  228. package/dist/src/components/JSDocParagraph.js +0 -23
  229. package/dist/src/components/JSDocParagraph.js.map +0 -1
  230. package/src/components/JSDocParagraph.tsx +0 -35
@@ -5,13 +5,19 @@ import {
5
5
  resolve,
6
6
  untrack,
7
7
  useContext,
8
+ useMemberScope,
8
9
  } from "@alloy-js/core";
9
10
  import { usePackage } from "../components/PackageDirectory.jsx";
10
11
  import { SourceFileContext } from "../components/SourceFile.jsx";
12
+ import {
13
+ PrivateScopeContext,
14
+ usePrivateScope,
15
+ } from "../context/private-scope.js";
16
+ import { isValidJSIdentifier } from "../utils.js";
11
17
  import { TSOutputScope } from "./scopes.js";
12
18
  import { TSMemberScope } from "./ts-member-scope.js";
13
19
  import { TSModuleScope } from "./ts-module-scope.js";
14
- import { TSOutputSymbol } from "./ts-output-symbol.js";
20
+ import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
15
21
  import { TSPackageScope } from "./ts-package-scope.js";
16
22
 
17
23
  export function ref(refkey: Refkey): () => string {
@@ -19,6 +25,8 @@ export function ref(refkey: Refkey): () => string {
19
25
  const resolveResult = resolve<TSOutputScope, TSOutputSymbol>(
20
26
  refkey as Refkey,
21
27
  );
28
+ const currentScope = useMemberScope();
29
+ const currentPrivateScope = usePrivateScope();
22
30
 
23
31
  return memo(() => {
24
32
  if (resolveResult.value === undefined) {
@@ -27,7 +35,25 @@ export function ref(refkey: Refkey): () => string {
27
35
 
28
36
  const { targetDeclaration, pathDown, memberPath } = resolveResult.value;
29
37
 
30
- validateSymbolReachable(pathDown);
38
+ // if we resolved a instance member, check if we should be able to access
39
+ // it.
40
+ if (targetDeclaration.flags & OutputSymbolFlags.InstanceMember) {
41
+ if (targetDeclaration.tsFlags & TSSymbolFlags.PrivateMember) {
42
+ if (currentPrivateScope?.instanceMembers !== targetDeclaration.scope) {
43
+ throw new Error(
44
+ "Cannot resolve private member symbols from a different scope",
45
+ );
46
+ }
47
+ } else {
48
+ if (currentScope?.instanceMembers !== targetDeclaration.scope) {
49
+ throw new Error(
50
+ "Cannot resolve member symbols from a different member scope",
51
+ );
52
+ }
53
+ }
54
+ }
55
+
56
+ validateSymbolReachable(pathDown, memberPath, currentPrivateScope);
31
57
 
32
58
  // Where the target declaration is relative to the referencing scope.
33
59
  // * package: target symbol is in a different package
@@ -53,10 +79,13 @@ export function ref(refkey: Refkey): () => string {
53
79
 
54
80
  // find public dependency
55
81
  for (const module of sourcePackage.exportedSymbols.values()) {
56
- if (module.exportedSymbols.has(importSymbol.refkey)) {
57
- localSymbol = untrack(() =>
58
- sourceFile!.scope.addImport(importSymbol, module),
59
- );
82
+ for (const refkey of importSymbol.refkeys) {
83
+ if (module.exportedSymbols.has(refkey)) {
84
+ localSymbol = untrack(() =>
85
+ sourceFile!.scope.addImport(importSymbol, module),
86
+ );
87
+ break;
88
+ }
60
89
  }
61
90
  }
62
91
 
@@ -84,32 +113,42 @@ export function ref(refkey: Refkey): () => string {
84
113
  memberPath[0] = localSymbol;
85
114
  }
86
115
 
87
- return addThisPrefix(
88
- targetDeclaration,
89
- buildMemberExpression(memberPath),
90
- );
116
+ return buildMemberExpression(memberPath);
91
117
  } else {
92
- return addThisPrefix(
93
- localSymbol ?? targetDeclaration,
94
- localSymbol ? localSymbol.name : targetDeclaration.name,
95
- );
118
+ return buildMemberExpression([localSymbol ?? targetDeclaration]);
96
119
  }
97
120
  });
98
121
  }
99
122
 
100
- function addThisPrefix(rootSymbol: TSOutputSymbol, name: string) {
101
- if (rootSymbol.flags & OutputSymbolFlags.InstanceMember) {
102
- return `this.${name}`;
123
+ function buildMemberExpression(path: TSOutputSymbol[]) {
124
+ let memberExpr = "";
125
+
126
+ const base = path[0];
127
+ if (base.flags & OutputSymbolFlags.InstanceMember) {
128
+ memberExpr += "this";
103
129
  } else {
104
- return name;
130
+ memberExpr += base.name;
131
+ path = path.slice(1);
132
+ }
133
+
134
+ for (const sym of path) {
135
+ if (sym.tsFlags & TSSymbolFlags.PrivateMember) {
136
+ memberExpr += `.#${sym.name}`;
137
+ } else if (isValidJSIdentifier(sym.name)) {
138
+ memberExpr += `.${sym.name}`;
139
+ } else {
140
+ memberExpr += `[${JSON.stringify(sym.name)}]`;
141
+ }
105
142
  }
106
- }
107
143
 
108
- function buildMemberExpression(symbolPath: TSOutputSymbol[]) {
109
- return symbolPath.map((sym) => sym.name).join(".");
144
+ return memberExpr;
110
145
  }
111
146
 
112
- function validateSymbolReachable(path: TSOutputScope[]) {
147
+ function validateSymbolReachable(
148
+ path: TSOutputScope[],
149
+ memberPath: TSOutputSymbol[] | undefined,
150
+ currentPrivateScope: PrivateScopeContext | undefined,
151
+ ) {
113
152
  for (const scope of path) {
114
153
  if (scope.kind === "function") {
115
154
  throw new Error(
@@ -117,4 +156,20 @@ function validateSymbolReachable(path: TSOutputScope[]) {
117
156
  );
118
157
  }
119
158
  }
159
+
160
+ if (memberPath) {
161
+ for (const sym of memberPath) {
162
+ // make sure we're not trying to access a static private from outside
163
+ // the static member scope.
164
+ if (
165
+ sym.flags & OutputSymbolFlags.StaticMember &&
166
+ sym.tsFlags & TSSymbolFlags.PrivateMember &&
167
+ currentPrivateScope?.staticMembers !== sym.scope
168
+ ) {
169
+ throw new Error(
170
+ "Cannot resolve private static member symbols from a different scope",
171
+ );
172
+ }
173
+ }
174
+ }
120
175
  }
@@ -1,4 +1,4 @@
1
- import { Binder, OutputScope } from "@alloy-js/core";
1
+ import { Binder, OutputScope, OutputScopeFlags } from "@alloy-js/core";
2
2
  import { TSOutputSymbol } from "./ts-output-symbol.js";
3
3
 
4
4
  export interface TSMemberScope extends OutputScope {
@@ -9,13 +9,17 @@ export interface TSMemberScope extends OutputScope {
9
9
 
10
10
  export function createTSMemberScope(
11
11
  binder: Binder,
12
- parent: OutputScope,
12
+ parent: OutputScope | undefined,
13
13
  owner: TSOutputSymbol,
14
14
  isStatic: boolean = false,
15
15
  ): TSMemberScope {
16
16
  return binder.createScope<TSMemberScope>({
17
17
  kind: "member",
18
18
  name: "members",
19
+ flags:
20
+ isStatic ?
21
+ OutputScopeFlags.StaticMemberScope
22
+ : OutputScopeFlags.MemberScope,
19
23
  owner,
20
24
  parent,
21
25
  isStatic,
@@ -6,14 +6,16 @@ import {
6
6
  useDefaultScope,
7
7
  } from "@alloy-js/core";
8
8
  import { TSOutputScope } from "./scopes.js";
9
- import { TSMemberScope } from "./ts-member-scope.js";
9
+ import { createTSMemberScope, TSMemberScope } from "./ts-member-scope.js";
10
10
 
11
11
  // prettier-ignore
12
12
  export enum TSSymbolFlags {
13
- None = 0,
14
- LocalImportSymbol = 1 << 0,
15
- TypeSymbol = 1 << 1,
16
- ParameterSymbol = 1 << 2,
13
+ None = 0,
14
+ LocalImportSymbol = 1 << 0,
15
+ TypeSymbol = 1 << 1,
16
+ ParameterSymbol = 1 << 2,
17
+ PrivateMember = 1 << 3,
18
+ PrivateMemberContainer = 1 << 4,
17
19
  }
18
20
 
19
21
  export interface TSOutputSymbol extends OutputSymbol {
@@ -21,18 +23,20 @@ export interface TSOutputSymbol extends OutputSymbol {
21
23
  export: boolean;
22
24
  default: boolean;
23
25
  tsFlags: TSSymbolFlags;
24
- memberScope?: TSMemberScope;
26
+ privateMemberScope?: TSMemberScope;
27
+ privateStaticMemberScope?: TSMemberScope;
25
28
  }
26
29
 
27
30
  export interface createTsSymbolOptions {
28
31
  name: string;
29
- refkey: Refkey;
32
+ refkey?: Refkey | Refkey[];
30
33
  binder?: Binder;
31
34
  scope?: TSOutputScope;
32
35
  export?: boolean;
33
36
  default?: boolean;
34
37
  flags?: OutputSymbolFlags;
35
38
  tsFlags?: TSSymbolFlags;
39
+ metadata?: Record<string, unknown>;
36
40
  }
37
41
 
38
42
  export function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol {
@@ -44,7 +48,7 @@ export function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol {
44
48
  }
45
49
 
46
50
  const binder = scope.binder;
47
-
51
+ const tsFlags = options.tsFlags ?? TSSymbolFlags.None;
48
52
  const sym = binder.createSymbol<TSOutputSymbol>({
49
53
  name: options.name,
50
54
  scope,
@@ -52,11 +56,24 @@ export function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol {
52
56
  export: !!options.export,
53
57
  default: !!options.default,
54
58
  flags: options.flags ?? OutputSymbolFlags.None,
55
- tsFlags: options.tsFlags ?? TSSymbolFlags.None,
59
+ tsFlags,
60
+ metadata: options.metadata,
56
61
  });
57
62
 
63
+ if (tsFlags & TSSymbolFlags.PrivateMemberContainer) {
64
+ sym.privateMemberScope = createTSMemberScope(binder, undefined, sym);
65
+ sym.privateStaticMemberScope = createTSMemberScope(
66
+ binder,
67
+ undefined,
68
+ sym,
69
+ true,
70
+ );
71
+ }
72
+
58
73
  if (options.export && scope.kind === "module") {
59
- scope.exportedSymbols.set(sym.refkey, sym);
74
+ for (const refkey of sym.refkeys) {
75
+ scope.exportedSymbols.set(refkey, sym);
76
+ }
60
77
  }
61
78
 
62
79
  return sym;
@@ -1,8 +1,4 @@
1
1
  import { Binder, OutputScope, Refkey } from "@alloy-js/core";
2
- import {
3
- ExportConditions,
4
- PackageExports,
5
- } from "../components/PackageJson.jsx";
6
2
  import { modulePath } from "../utils.js";
7
3
  import { TSModuleScope } from "./ts-module-scope.js";
8
4
 
@@ -31,20 +27,6 @@ export interface TSPackageScope extends OutputScope {
31
27
  */
32
28
  dependencies: Set<TSPackageScope>;
33
29
 
34
- /**
35
- * Fixed dependencies of this package. Only use this for packages in which you
36
- * do not intend to reference via the `Reference` component. Symbols from raw
37
- * dependencies cannot be auto imported.
38
- */
39
- rawDependencies: Map<string, string>;
40
-
41
- /**
42
- * Fixed exports of this package. Only use this for exports which you want to
43
- * add manually to the package. Otherwise use the `export` prop on
44
- * `SourceFile` to add an export.
45
- */
46
- rawExports: PackageExports;
47
-
48
30
  /**
49
31
  * All of the modules contained within the package. These modules may or may not
50
32
  * be exported.
@@ -57,9 +39,7 @@ export interface TSPackageScope extends OutputScope {
57
39
  builtin?: boolean;
58
40
 
59
41
  addExport(publicPath: string, localModule: TSModuleScope): void;
60
- addRawExport(publicPath: string, exportPath: string | ExportConditions): void;
61
42
  addDependency(pkg: TSPackageScope): void;
62
- addRawDependency(packageName: string, version: string): void;
63
43
  addModule(module: TSModuleScope): void;
64
44
  findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
65
45
  }
@@ -78,8 +58,6 @@ export function createTSPackageScope(
78
58
  parent,
79
59
  exportedSymbols: new Map(),
80
60
  dependencies: new Set(),
81
- rawDependencies: new Map(),
82
- rawExports: {},
83
61
  modules: new Set(),
84
62
  version,
85
63
  path: path,
@@ -90,12 +68,6 @@ export function createTSPackageScope(
90
68
  addExport(publicPath, module) {
91
69
  this.exportedSymbols.set(modulePath(publicPath), module);
92
70
  },
93
- addRawDependency(packageName, version) {
94
- this.rawDependencies.set(packageName, version);
95
- },
96
- addRawExport(localPath, exportPath) {
97
- this.rawExports[localPath] = exportPath;
98
- },
99
71
  addModule(module) {
100
72
  this.modules.add(module);
101
73
  },
package/src/utils.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { defaultProps, splitProps } from "@alloy-js/core/jsx-runtime";
2
+ import { CallSignatureProps } from "./components/CallSignature.jsx";
3
+
1
4
  export function modulePath(path: string) {
2
5
  if (path[0] !== ".") {
3
6
  path = "./" + path;
@@ -5,3 +8,33 @@ export function modulePath(path: string) {
5
8
 
6
9
  return path.replace(/\.ts$/, ".js");
7
10
  }
11
+
12
+ /**
13
+ * Extract only the call signature props from a props object which extends
14
+ * `CallSignatureProps`. You can provide default values for the props.
15
+ */
16
+ export function getCallSignatureProps(
17
+ props: CallSignatureProps,
18
+ defaults?: Partial<CallSignatureProps>,
19
+ ) {
20
+ const [callSignatureProps] = splitProps(props, [
21
+ "parameters",
22
+ "parametersChildren",
23
+ "typeParameters",
24
+ "typeParametersChildren",
25
+ "returnType",
26
+ ]);
27
+
28
+ if (!defaults) {
29
+ return callSignatureProps;
30
+ }
31
+
32
+ return defaultProps(callSignatureProps, defaults);
33
+ }
34
+
35
+ const identifierRegex =
36
+ /^(?:[\p{ID_Start}$_])(?:[\p{ID_Continue}$\u200C\u200D])*$/u;
37
+
38
+ export function isValidJSIdentifier(str: string) {
39
+ return identifierRegex.test(str);
40
+ }