@alloy-js/typescript 0.20.0-dev.0 → 0.20.0-dev.2

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 (318) hide show
  1. package/dist/src/builtins/index.js +2 -1
  2. package/dist/src/builtins/index.js.map +1 -0
  3. package/dist/src/builtins/node.d.ts +1 -1
  4. package/dist/src/builtins/node.js +2 -1
  5. package/dist/src/builtins/node.js.map +1 -0
  6. package/dist/src/components/ArrayExpression.js +2 -1
  7. package/dist/src/components/ArrayExpression.js.map +1 -0
  8. package/dist/src/components/ArrowFunction.d.ts.map +1 -1
  9. package/dist/src/components/ArrowFunction.js +9 -14
  10. package/dist/src/components/ArrowFunction.js.map +1 -0
  11. package/dist/src/components/BarrelFile.js +2 -1
  12. package/dist/src/components/BarrelFile.js.map +1 -0
  13. package/dist/src/components/BlockScope.d.ts.map +1 -1
  14. package/dist/src/components/BlockScope.js +5 -3
  15. package/dist/src/components/BlockScope.js.map +1 -0
  16. package/dist/src/components/CallSignature.js +2 -1
  17. package/dist/src/components/CallSignature.js.map +1 -0
  18. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  19. package/dist/src/components/ClassDeclaration.js +22 -31
  20. package/dist/src/components/ClassDeclaration.js.map +1 -0
  21. package/dist/src/components/CommaList.js +2 -1
  22. package/dist/src/components/CommaList.js.map +1 -0
  23. package/dist/src/components/Declaration.d.ts +2 -9
  24. package/dist/src/components/Declaration.d.ts.map +1 -1
  25. package/dist/src/components/Declaration.js +22 -44
  26. package/dist/src/components/Declaration.js.map +1 -0
  27. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  28. package/dist/src/components/EnumDeclaration.js +7 -10
  29. package/dist/src/components/EnumDeclaration.js.map +1 -0
  30. package/dist/src/components/EnumMember.d.ts.map +1 -1
  31. package/dist/src/components/EnumMember.js +5 -5
  32. package/dist/src/components/EnumMember.js.map +1 -0
  33. package/dist/src/components/ExportStatement.d.ts.map +1 -1
  34. package/dist/src/components/ExportStatement.js +4 -2
  35. package/dist/src/components/ExportStatement.js.map +1 -0
  36. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  37. package/dist/src/components/FunctionBase.js +17 -13
  38. package/dist/src/components/FunctionBase.js.map +1 -0
  39. package/dist/src/components/FunctionCallExpression.js +2 -1
  40. package/dist/src/components/FunctionCallExpression.js.map +1 -0
  41. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  42. package/dist/src/components/FunctionDeclaration.js +5 -4
  43. package/dist/src/components/FunctionDeclaration.js.map +1 -0
  44. package/dist/src/components/FunctionExpression.d.ts.map +1 -1
  45. package/dist/src/components/FunctionExpression.js +9 -14
  46. package/dist/src/components/FunctionExpression.js.map +1 -0
  47. package/dist/src/components/FunctionType.d.ts.map +1 -1
  48. package/dist/src/components/FunctionType.js +5 -4
  49. package/dist/src/components/FunctionType.js.map +1 -0
  50. package/dist/src/components/IfStatement.d.ts.map +1 -1
  51. package/dist/src/components/IfStatement.js +4 -2
  52. package/dist/src/components/IfStatement.js.map +1 -0
  53. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  54. package/dist/src/components/ImportStatement.js +5 -5
  55. package/dist/src/components/ImportStatement.js.map +1 -0
  56. package/dist/src/components/Interface.d.ts.map +1 -1
  57. package/dist/src/components/Interface.js +16 -14
  58. package/dist/src/components/Interface.js.map +1 -0
  59. package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
  60. package/dist/src/components/InterfaceMethod.js +6 -4
  61. package/dist/src/components/InterfaceMethod.js.map +1 -0
  62. package/dist/src/components/JSDoc.js +2 -1
  63. package/dist/src/components/JSDoc.js.map +1 -0
  64. package/dist/src/components/JSDocComment.js +2 -1
  65. package/dist/src/components/JSDocComment.js.map +1 -0
  66. package/dist/src/components/JSDocExample.js +2 -1
  67. package/dist/src/components/JSDocExample.js.map +1 -0
  68. package/dist/src/components/JSDocParam.js +2 -1
  69. package/dist/src/components/JSDocParam.js.map +1 -0
  70. package/dist/src/components/LexicalScope.d.ts +12 -0
  71. package/dist/src/components/LexicalScope.d.ts.map +1 -0
  72. package/dist/src/components/LexicalScope.js +25 -0
  73. package/dist/src/components/LexicalScope.js.map +1 -0
  74. package/dist/src/components/MemberDeclaration.d.ts +1 -10
  75. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  76. package/dist/src/components/MemberDeclaration.js +5 -8
  77. package/dist/src/components/MemberDeclaration.js.map +1 -0
  78. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  79. package/dist/src/components/MemberExpression.js +15 -6
  80. package/dist/src/components/MemberExpression.js.map +1 -0
  81. package/dist/src/components/MemberScope.d.ts +15 -0
  82. package/dist/src/components/MemberScope.d.ts.map +1 -0
  83. package/dist/src/components/MemberScope.js +18 -0
  84. package/dist/src/components/MemberScope.js.map +1 -0
  85. package/dist/src/components/NewExpression.d.ts.map +1 -1
  86. package/dist/src/components/NewExpression.js +7 -6
  87. package/dist/src/components/NewExpression.js.map +1 -0
  88. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  89. package/dist/src/components/ObjectExpression.js +12 -15
  90. package/dist/src/components/ObjectExpression.js.map +1 -0
  91. package/dist/src/components/PackageDirectory.js +2 -1
  92. package/dist/src/components/PackageDirectory.js.map +1 -0
  93. package/dist/src/components/PackageJson.js +2 -1
  94. package/dist/src/components/PackageJson.js.map +1 -0
  95. package/dist/src/components/PropertyName.js +3 -3
  96. package/dist/src/components/PropertyName.js.map +1 -0
  97. package/dist/src/components/Reference.js +2 -1
  98. package/dist/src/components/Reference.js.map +1 -0
  99. package/dist/src/components/SingleLineCommentBlock.js +2 -1
  100. package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
  101. package/dist/src/components/SourceFile.d.ts.map +1 -1
  102. package/dist/src/components/SourceFile.js +5 -3
  103. package/dist/src/components/SourceFile.js.map +1 -0
  104. package/dist/src/components/SwitchStatement.js +2 -1
  105. package/dist/src/components/SwitchStatement.js.map +1 -0
  106. package/dist/src/components/TsConfigJson.js +2 -1
  107. package/dist/src/components/TsConfigJson.js.map +1 -0
  108. package/dist/src/components/TypeDeclaration.js +2 -1
  109. package/dist/src/components/TypeDeclaration.js.map +1 -0
  110. package/dist/src/components/TypeRefContext.js +2 -1
  111. package/dist/src/components/TypeRefContext.js.map +1 -0
  112. package/dist/src/components/ValueExpression.js +2 -1
  113. package/dist/src/components/ValueExpression.js.map +1 -0
  114. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  115. package/dist/src/components/VarDeclaration.js +16 -27
  116. package/dist/src/components/VarDeclaration.js.map +1 -0
  117. package/dist/src/components/index.js +2 -1
  118. package/dist/src/components/index.js.map +1 -0
  119. package/dist/src/components/interface/expression.test.js +2 -1
  120. package/dist/src/components/interface/expression.test.js.map +1 -0
  121. package/dist/src/components/stc/index.js +2 -1
  122. package/dist/src/components/stc/index.js.map +1 -0
  123. package/dist/src/context/index.d.ts +1 -1
  124. package/dist/src/context/index.d.ts.map +1 -1
  125. package/dist/src/context/index.js +2 -1
  126. package/dist/src/context/index.js.map +1 -0
  127. package/dist/src/context/type-ref-context.js +2 -1
  128. package/dist/src/context/type-ref-context.js.map +1 -0
  129. package/dist/src/create-package.d.ts.map +1 -1
  130. package/dist/src/create-package.js +13 -34
  131. package/dist/src/create-package.js.map +1 -0
  132. package/dist/src/index.js +2 -1
  133. package/dist/src/index.js.map +1 -0
  134. package/dist/src/name-conflict-resolver.js +2 -1
  135. package/dist/src/name-conflict-resolver.js.map +1 -0
  136. package/dist/src/name-policy.js +2 -1
  137. package/dist/src/name-policy.js.map +1 -0
  138. package/dist/src/parameter-descriptor.js +2 -1
  139. package/dist/src/parameter-descriptor.js.map +1 -0
  140. package/dist/src/source-directory-data.js +2 -1
  141. package/dist/src/source-directory-data.js.map +1 -0
  142. package/dist/src/symbols/index.d.ts +19 -0
  143. package/dist/src/symbols/index.d.ts.map +1 -1
  144. package/dist/src/symbols/index.js +73 -1
  145. package/dist/src/symbols/index.js.map +1 -0
  146. package/dist/src/symbols/reference.d.ts +2 -2
  147. package/dist/src/symbols/reference.d.ts.map +1 -1
  148. package/dist/src/symbols/reference.js +69 -70
  149. package/dist/src/symbols/reference.js.map +1 -0
  150. package/dist/src/symbols/scopes.d.ts +5 -8
  151. package/dist/src/symbols/scopes.d.ts.map +1 -1
  152. package/dist/src/symbols/scopes.js +28 -1
  153. package/dist/src/symbols/scopes.js.map +1 -0
  154. package/dist/src/symbols/ts-lexical-scope.d.ts +12 -0
  155. package/dist/src/symbols/ts-lexical-scope.d.ts.map +1 -0
  156. package/dist/src/symbols/ts-lexical-scope.js +17 -0
  157. package/dist/src/symbols/ts-lexical-scope.js.map +1 -0
  158. package/dist/src/symbols/ts-member-scope.d.ts +12 -4
  159. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  160. package/dist/src/symbols/ts-member-scope.js +17 -7
  161. package/dist/src/symbols/ts-member-scope.js.map +1 -0
  162. package/dist/src/symbols/ts-module-scope.d.ts +8 -3
  163. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  164. package/dist/src/symbols/ts-module-scope.js +31 -19
  165. package/dist/src/symbols/ts-module-scope.js.map +1 -0
  166. package/dist/src/symbols/ts-output-symbol.d.ts +19 -18
  167. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  168. package/dist/src/symbols/ts-output-symbol.js +62 -38
  169. package/dist/src/symbols/ts-output-symbol.js.map +1 -0
  170. package/dist/src/symbols/ts-package-scope.d.ts +1 -1
  171. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  172. package/dist/src/symbols/ts-package-scope.js +6 -6
  173. package/dist/src/symbols/ts-package-scope.js.map +1 -0
  174. package/dist/src/utils.d.ts +4 -0
  175. package/dist/src/utils.d.ts.map +1 -1
  176. package/dist/src/utils.js +25 -2
  177. package/dist/src/utils.js.map +1 -0
  178. package/dist/test/array.test.js +2 -1
  179. package/dist/test/array.test.js.map +1 -0
  180. package/dist/test/arrow-function.test.js +2 -1
  181. package/dist/test/arrow-function.test.js.map +1 -0
  182. package/dist/test/barrel.test.js +26 -17
  183. package/dist/test/barrel.test.js.map +1 -0
  184. package/dist/test/basic.test.js +22 -26
  185. package/dist/test/basic.test.js.map +1 -0
  186. package/dist/test/block-scope.test.js +2 -1
  187. package/dist/test/block-scope.test.js.map +1 -0
  188. package/dist/test/class.test.js +24 -18
  189. package/dist/test/class.test.js.map +1 -0
  190. package/dist/test/enum-jsdoc.test.js +2 -1
  191. package/dist/test/enum-jsdoc.test.js.map +1 -0
  192. package/dist/test/enum.test.js +2 -1
  193. package/dist/test/enum.test.js.map +1 -0
  194. package/dist/test/externals.test.js +12 -51
  195. package/dist/test/externals.test.js.map +1 -0
  196. package/dist/test/function-call-expression.test.js +9 -8
  197. package/dist/test/function-call-expression.test.js.map +1 -0
  198. package/dist/test/function-declaration-jsdoc.test.js +2 -1
  199. package/dist/test/function-declaration-jsdoc.test.js.map +1 -0
  200. package/dist/test/function-declaration.test.js +2 -1
  201. package/dist/test/function-declaration.test.js.map +1 -0
  202. package/dist/test/function-expression.test.js +2 -1
  203. package/dist/test/function-expression.test.js.map +1 -0
  204. package/dist/test/function-type.test.js +2 -1
  205. package/dist/test/function-type.test.js.map +1 -0
  206. package/dist/test/if-statement.test.js +2 -1
  207. package/dist/test/if-statement.test.js.map +1 -0
  208. package/dist/test/imports.test.d.ts.map +1 -1
  209. package/dist/test/imports.test.js +62 -60
  210. package/dist/test/imports.test.js.map +1 -0
  211. package/dist/test/interface-jsdoc.test.js +2 -1
  212. package/dist/test/interface-jsdoc.test.js.map +1 -0
  213. package/dist/test/interface.test.js +2 -1
  214. package/dist/test/interface.test.js.map +1 -0
  215. package/dist/test/jscomment.test.js +2 -1
  216. package/dist/test/jscomment.test.js.map +1 -0
  217. package/dist/test/jsdoc.test.js +2 -1
  218. package/dist/test/jsdoc.test.js.map +1 -0
  219. package/dist/test/jsdocparam.test.js +2 -1
  220. package/dist/test/jsdocparam.test.js.map +1 -0
  221. package/dist/test/member-expression.test.js +8 -7
  222. package/dist/test/member-expression.test.js.map +1 -0
  223. package/dist/test/name-conflict.test.js +5 -7
  224. package/dist/test/name-conflict.test.js.map +1 -0
  225. package/dist/test/name-policy.test.js +9 -13
  226. package/dist/test/name-policy.test.js.map +1 -0
  227. package/dist/test/new-expression.test.js +6 -7
  228. package/dist/test/new-expression.test.js.map +1 -0
  229. package/dist/test/object.test.js +2 -1
  230. package/dist/test/object.test.js.map +1 -0
  231. package/dist/test/package-external.test.js +71 -66
  232. package/dist/test/package-external.test.js.map +1 -0
  233. package/dist/test/package-json.test.js +8 -10
  234. package/dist/test/package-json.test.js.map +1 -0
  235. package/dist/test/package.test.js +12 -12
  236. package/dist/test/package.test.js.map +1 -0
  237. package/dist/test/reference.test.js +10 -12
  238. package/dist/test/reference.test.js.map +1 -0
  239. package/dist/test/source-file.test.js +7 -10
  240. package/dist/test/source-file.test.js.map +1 -0
  241. package/dist/test/switch-statement.test.js +2 -1
  242. package/dist/test/switch-statement.test.js.map +1 -0
  243. package/dist/test/utils.js +6 -2
  244. package/dist/test/utils.js.map +1 -0
  245. package/dist/test/value-expression.test.js +2 -1
  246. package/dist/test/value-expression.test.js.map +1 -0
  247. package/dist/test/values.test.d.ts.map +1 -1
  248. package/dist/test/values.test.js +11 -8
  249. package/dist/test/values.test.js.map +1 -0
  250. package/dist/test/var-declaration-jsdoc.test.js +2 -1
  251. package/dist/test/var-declaration-jsdoc.test.js.map +1 -0
  252. package/dist/test/var-declaration.test.d.ts.map +1 -1
  253. package/dist/test/var-declaration.test.js +21 -12
  254. package/dist/test/var-declaration.test.js.map +1 -0
  255. package/dist/test/vitest.setup.js +2 -1
  256. package/dist/test/vitest.setup.js.map +1 -0
  257. package/dist/tsconfig.tsbuildinfo +1 -1
  258. package/package.json +4 -4
  259. package/src/components/ArrowFunction.tsx +7 -10
  260. package/src/components/BlockScope.tsx +3 -3
  261. package/src/components/ClassDeclaration.tsx +19 -44
  262. package/src/components/Declaration.tsx +22 -53
  263. package/src/components/EnumDeclaration.tsx +4 -11
  264. package/src/components/EnumMember.tsx +3 -3
  265. package/src/components/ExportStatement.tsx +2 -1
  266. package/src/components/FunctionBase.tsx +33 -28
  267. package/src/components/FunctionDeclaration.tsx +3 -3
  268. package/src/components/FunctionExpression.tsx +7 -10
  269. package/src/components/FunctionType.tsx +3 -3
  270. package/src/components/IfStatement.tsx +2 -1
  271. package/src/components/ImportStatement.tsx +4 -8
  272. package/src/components/Interface.tsx +15 -22
  273. package/src/components/InterfaceMethod.tsx +4 -4
  274. package/src/components/LexicalScope.tsx +27 -0
  275. package/src/components/MemberDeclaration.tsx +8 -20
  276. package/src/components/MemberExpression.tsx +25 -5
  277. package/src/components/MemberScope.tsx +29 -0
  278. package/src/components/NewExpression.tsx +4 -5
  279. package/src/components/ObjectExpression.tsx +11 -18
  280. package/src/components/PropertyName.tsx +2 -2
  281. package/src/components/SourceFile.tsx +3 -1
  282. package/src/components/VarDeclaration.tsx +14 -28
  283. package/src/context/index.ts +1 -1
  284. package/src/create-package.ts +10 -39
  285. package/src/symbols/index.ts +118 -0
  286. package/src/symbols/reference.tsx +163 -0
  287. package/src/symbols/scopes.ts +38 -13
  288. package/src/symbols/ts-lexical-scope.ts +18 -0
  289. package/src/symbols/ts-member-scope.ts +23 -6
  290. package/src/symbols/ts-module-scope.ts +31 -21
  291. package/src/symbols/ts-output-symbol.ts +111 -49
  292. package/src/symbols/ts-package-scope.ts +5 -5
  293. package/src/utils.ts +38 -1
  294. package/temp/api.json +1641 -713
  295. package/test/barrel.test.tsx +24 -18
  296. package/test/basic.test.tsx +20 -29
  297. package/test/class.test.tsx +28 -18
  298. package/test/externals.test.tsx +10 -57
  299. package/test/function-call-expression.test.tsx +6 -7
  300. package/test/imports.test.tsx +57 -74
  301. package/test/member-expression.test.tsx +5 -13
  302. package/test/name-conflict.test.tsx +4 -7
  303. package/test/name-policy.test.tsx +7 -15
  304. package/test/new-expression.test.tsx +4 -7
  305. package/test/package-external.test.tsx +69 -73
  306. package/test/package-json.test.tsx +6 -11
  307. package/test/package.test.tsx +8 -11
  308. package/test/reference.test.tsx +10 -15
  309. package/test/source-file.test.tsx +5 -11
  310. package/test/utils.tsx +1 -1
  311. package/test/values.test.tsx +8 -8
  312. package/test/var-declaration.test.tsx +19 -20
  313. package/tsdoc-metadata.json +1 -1
  314. package/dist/src/context/private-scope.d.ts +0 -18
  315. package/dist/src/context/private-scope.d.ts.map +0 -1
  316. package/dist/src/context/private-scope.js +0 -8
  317. package/src/context/private-scope.ts +0 -23
  318. package/src/symbols/reference.ts +0 -197
@@ -10,7 +10,6 @@ import {
10
10
  ImportedSymbol,
11
11
  ImportRecords,
12
12
  TSPackageScope,
13
- TSSymbolFlags,
14
13
  } from "../symbols/index.js";
15
14
  import { modulePath } from "../utils.js";
16
15
  import { usePackage } from "./PackageDirectory.js";
@@ -31,11 +30,7 @@ export function ImportStatements(props: ImportStatementsProps) {
31
30
  () => imports.value,
32
31
  ([module, importedSymbols]) => {
33
32
  let targetPath: string;
34
-
35
- if (
36
- (pkg && pkg.scope !== module.parent) ||
37
- (!pkg && module.parent!.kind !== "global")
38
- ) {
33
+ if (pkg?.scope !== module.parent) {
39
34
  // importing from another package, so let's calculate the import.
40
35
  const targetPackage = module.parent as TSPackageScope;
41
36
  let foundPath: string | false = false;
@@ -101,7 +96,7 @@ export function ImportStatement(props: ImportStatementProps) {
101
96
  return a.local.name.localeCompare(b.local.name);
102
97
  });
103
98
  const allNamedImportsAreTypes = namedImportSymbols.every(
104
- (nis) => nis.local.tsFlags & TSSymbolFlags.TypeSymbol,
99
+ (nis) => nis.local.isTypeSymbol && !nis.local.isValueSymbol,
105
100
  );
106
101
 
107
102
  if (allNamedImportsAreTypes) {
@@ -150,7 +145,8 @@ function ImportBinding(props: Readonly<ImportBindingProps>) {
150
145
  const prefix = memo(() =>
151
146
  (
152
147
  !props.inTypeImport &&
153
- props.importedSymbol.local.tsFlags & TSSymbolFlags.TypeSymbol
148
+ props.importedSymbol.local.isTypeSymbol &&
149
+ !props.importedSymbol.local.isValueSymbol
154
150
  ) ?
155
151
  "type "
156
152
  : "",
@@ -7,9 +7,7 @@ import {
7
7
  emitSymbol,
8
8
  findKeyedChild,
9
9
  findUnkeyedChildren,
10
- MemberScope,
11
10
  Name,
12
- OutputSymbolFlags,
13
11
  Refkey,
14
12
  Show,
15
13
  takeSymbols,
@@ -19,9 +17,11 @@ import { BaseDeclarationProps, Declaration } from "./Declaration.js";
19
17
  import { JSDoc } from "./JSDoc.jsx";
20
18
 
21
19
  import { TypeParameterDescriptor } from "../parameter-descriptor.js";
20
+ import { useTSLexicalScope, useTSMemberScope } from "../symbols/scopes.js";
22
21
  import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
23
22
  import { TypeParameters } from "./FunctionBase.jsx";
24
23
  import { MemberDeclaration } from "./MemberDeclaration.jsx";
24
+ import { MemberScope } from "./MemberScope.jsx";
25
25
  import { PropertyName } from "./PropertyName.jsx";
26
26
  import { ensureTypeRefContext } from "./TypeRefContext.jsx";
27
27
 
@@ -43,8 +43,8 @@ const _InterfaceDeclaration = ensureTypeRefContext(
43
43
  const takenSymbols = ExprSlot.ref.value;
44
44
  for (const symbol of takenSymbols) {
45
45
  // ignore non-transient symbols (likely not the result of an expression).
46
- if (symbol.flags & OutputSymbolFlags.Transient) {
47
- symbol.moveTo(sym);
46
+ if (symbol.isTransient) {
47
+ symbol.moveMembersTo(sym);
48
48
  }
49
49
  }
50
50
  }
@@ -65,11 +65,11 @@ const _InterfaceDeclaration = ensureTypeRefContext(
65
65
  : <TypeParameters parameters={props.typeParameters} />;
66
66
 
67
67
  const extendsPart = props.extends ? <> extends {props.extends}</> : "";
68
- const flags = OutputSymbolFlags.StaticMemberContainer;
69
-
70
68
  const name = useTSNamePolicy().getName(props.name, "interface");
71
69
  const filteredChildren = findUnkeyedChildren(children);
72
- const sym = new TSOutputSymbol(name, {
70
+ const currentScope = useTSLexicalScope();
71
+
72
+ const sym = new TSOutputSymbol(name, currentScope.types, {
73
73
  refkeys: props.refkey,
74
74
  default: props.default,
75
75
  export: props.export,
@@ -82,13 +82,7 @@ const _InterfaceDeclaration = ensureTypeRefContext(
82
82
  <JSDoc children={props.doc} />
83
83
  <hbr />
84
84
  </Show>
85
- <Declaration
86
- {...props}
87
- nameKind="interface"
88
- flags={flags}
89
- kind="type"
90
- symbol={sym}
91
- >
85
+ <Declaration {...props} nameKind="interface" kind="type" symbol={sym}>
92
86
  interface <Name />
93
87
  {sTypeParameters}
94
88
  {extendsPart}{" "}
@@ -122,16 +116,15 @@ export interface InterfaceExpressionProps {
122
116
 
123
117
  export const InterfaceExpression = ensureTypeRefContext(
124
118
  (props: InterfaceExpressionProps) => {
125
- const symbol = new TSOutputSymbol("", {
126
- flags:
127
- OutputSymbolFlags.StaticMemberContainer | OutputSymbolFlags.Transient,
119
+ const symbol = new TSOutputSymbol("", undefined, {
120
+ transient: true,
128
121
  });
129
122
 
130
123
  emitSymbol(symbol);
131
124
 
132
125
  return (
133
126
  <group>
134
- <MemberScope owner={symbol}>
127
+ <MemberScope ownerSymbol={symbol}>
135
128
  <Block>{props.children}</Block>
136
129
  </MemberScope>
137
130
  </group>
@@ -176,9 +169,9 @@ export function InterfaceMember(props: InterfaceMemberProps) {
176
169
  const name = namer.getName(props.name!, "interface-member");
177
170
  let sym = undefined;
178
171
  if (props.name) {
179
- sym = new TSOutputSymbol(name, {
172
+ const scope = useTSMemberScope();
173
+ sym = new TSOutputSymbol(name, scope.ownerSymbol.staticMembers, {
180
174
  refkeys: props.refkey,
181
- flags: OutputSymbolFlags.StaticMember,
182
175
  tsFlags:
183
176
  TSSymbolFlags.TypeSymbol |
184
177
  ((props.nullish ?? props.optional) ?
@@ -191,8 +184,8 @@ export function InterfaceMember(props: InterfaceMemberProps) {
191
184
  effect(() => {
192
185
  if (taken.size > 1) return;
193
186
  const symbol = Array.from(taken)[0];
194
- if (symbol?.flags & OutputSymbolFlags.Transient) {
195
- symbol.moveTo(sym!);
187
+ if (symbol?.isTransient) {
188
+ symbol.moveMembersTo(sym!);
196
189
  }
197
190
  });
198
191
  } else {
@@ -1,10 +1,8 @@
1
1
  import {
2
2
  childrenArray,
3
3
  findKeyedChild,
4
- MemberDeclaration,
5
4
  Prose,
6
5
  Refkey,
7
- Scope,
8
6
  Show,
9
7
  type Children,
10
8
  } from "@alloy-js/core";
@@ -19,6 +17,8 @@ import {
19
17
  } from "./FunctionBase.jsx";
20
18
  import { JSDoc } from "./JSDoc.jsx";
21
19
  import { JSDocParams } from "./JSDocParam.jsx";
20
+ import { LexicalScope } from "./LexicalScope.jsx";
21
+ import { MemberDeclaration } from "./MemberDeclaration.jsx";
22
22
 
23
23
  /** Props for {@link (InterfaceMethod:namespace)} component */
24
24
  export interface InterfaceMethodProps extends CallSignatureProps {
@@ -84,9 +84,9 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
84
84
  </Show>
85
85
  <MemberDeclaration static {...props} refkey={props.refkey}>
86
86
  {name}
87
- <Scope name={props.name} kind="function">
87
+ <LexicalScope name={props.name}>
88
88
  <CallSignature {...callSignatureProps} returnType={returnType} />
89
- </Scope>
89
+ </LexicalScope>
90
90
  </MemberDeclaration>
91
91
  </>
92
92
  );
@@ -0,0 +1,27 @@
1
+ import { Scope, ScopePropsWithInfo, ScopePropsWithValue } from "@alloy-js/core";
2
+ import { createLexicalScope, TSLexicalScope } from "../symbols/index.js";
3
+
4
+ export interface LexicalScopePropsWithScopeValue extends ScopePropsWithValue {}
5
+ export interface LeixcalScopePropsWithScopeInfo extends ScopePropsWithInfo {}
6
+
7
+ export type LexicalScopeProps =
8
+ | LexicalScopePropsWithScopeValue
9
+ | LeixcalScopePropsWithScopeInfo;
10
+
11
+ /**
12
+ * A lexical scope for TypeScript, which contains declaration spaces for types
13
+ * and values. Declaration components will create symbols in this scope.
14
+ */
15
+ export function LexicalScope(props: LexicalScopeProps) {
16
+ let scope;
17
+ if ("value" in props) {
18
+ if (!(props.value instanceof TSLexicalScope)) {
19
+ throw new Error("LexicalScope value must be a TSLexicalScope instance");
20
+ }
21
+ scope = props.value;
22
+ } else {
23
+ scope = createLexicalScope(props.name ?? "Lexical scope", props);
24
+ }
25
+
26
+ return <Scope value={scope}>{props.children}</Scope>;
27
+ }
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  MemberDeclaration as CoreMemberDeclaration,
3
3
  MemberDeclarationPropsWithInfo,
4
- OutputSymbolFlags,
5
4
  } from "@alloy-js/core";
6
5
  import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
7
- import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
6
+ import {
7
+ createStaticMemberSymbol,
8
+ TSOutputSymbol,
9
+ TSSymbolFlags,
10
+ } from "../symbols/index.js";
8
11
 
9
12
  export interface MemberDeclarationProps
10
13
  extends Omit<MemberDeclarationPropsWithInfo, "name"> {
@@ -16,22 +19,11 @@ export interface MemberDeclarationProps
16
19
  /** Name that shouldn't go through the name policy resolver again. */
17
20
  exactName?: string;
18
21
 
19
- /**
20
- * Whether this is a memberdeclaration of a type (e.g. interface, type alias) or a
21
- * value (e.g. var, const, let).
22
- */
23
- kind?: "type" | "value";
24
-
25
22
  /**
26
23
  * The name policy kind to apply to the memberdeclaration.
27
24
  */
28
25
  nameKind?: TypeScriptElements;
29
26
 
30
- /**
31
- * Flags for the symbol created by this component.
32
- */
33
- flags?: OutputSymbolFlags;
34
-
35
27
  /**
36
28
  * The symbol to use for this memberdeclaration.
37
29
  */
@@ -50,18 +42,14 @@ export function MemberDeclaration(props: Readonly<MemberDeclarationProps>) {
50
42
  } else {
51
43
  const namePolicy = useTSNamePolicy();
52
44
 
53
- let tsFlags: TSSymbolFlags =
45
+ const tsFlags: TSSymbolFlags =
54
46
  props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None;
55
47
 
56
- if (props.kind === "type") {
57
- tsFlags |= TSSymbolFlags.TypeSymbol;
58
- }
59
-
60
48
  const name =
61
49
  props.exactName ?? namePolicy.getName(props.name!, props.nameKind!);
62
- sym = new TSOutputSymbol(name, {
50
+
51
+ sym = createStaticMemberSymbol(name, {
63
52
  refkeys: props.refkey,
64
- flags: props.flags,
65
53
  tsFlags,
66
54
  metadata: props.metadata,
67
55
  });
@@ -30,8 +30,10 @@ interface PartDescriptorWithIndex extends PartDescriptorBase {
30
30
  }
31
31
  interface PartDescriptorBase {
32
32
  accessStyle: "dot" | "bracket";
33
+ jsPrivate: boolean;
33
34
  quoteId: boolean;
34
35
  nullish: boolean;
36
+ type: boolean;
35
37
  args?: Children[];
36
38
  }
37
39
 
@@ -233,6 +235,18 @@ function createPartDescriptorFromProps(
233
235
  return false;
234
236
  }),
235
237
  args: ref<any>(partProps.args === true ? [] : partProps.args),
238
+ jsPrivate: computed(() => {
239
+ return (
240
+ !!symbolSource.value &&
241
+ (symbolSource.value as TSOutputSymbol).isPrivateMemberSymbol
242
+ );
243
+ }),
244
+ type: computed(() => {
245
+ return (
246
+ !!symbolSource.value &&
247
+ (symbolSource.value as TSOutputSymbol).isTypeSymbol
248
+ );
249
+ }),
236
250
  };
237
251
 
238
252
  return reactive(part);
@@ -386,7 +400,9 @@ function formatNonCallChain(parts: PartDescriptor[]): Children {
386
400
  // Determine if we should use nullish operator from previous part
387
401
  const prevPart = parts[i - 1];
388
402
 
389
- if (part.args !== undefined) {
403
+ if (prevPart.type) {
404
+ expression.push(formatArrayAccess(prevPart, part));
405
+ } else if (part.args !== undefined) {
390
406
  // For parts with only args (no name), append function call directly with appropriate nullish operator
391
407
  expression.push(formatCallExpr(prevPart, part));
392
408
  } else if (part.accessStyle === "dot") {
@@ -405,12 +421,12 @@ function formatNonCallChain(parts: PartDescriptor[]): Children {
405
421
  function formatArrayAccess(prevPart: PartDescriptor, part: PartDescriptor) {
406
422
  return (
407
423
  <group>
408
- {prevPart.nullish ? "?." : ""}[
424
+ {!prevPart.type && prevPart.nullish ? "?." : ""}[
409
425
  <indent>
410
426
  <sbr />
411
- {part.quoteId && '"'}
427
+ {(prevPart.type || part.quoteId) && '"'}
412
428
  {isIdPartDescriptor(part) ? part.id : part.index}
413
- {part.quoteId && '"'}
429
+ {(prevPart.type || part.quoteId) && '"'}
414
430
  </indent>
415
431
  <sbr />]
416
432
  </group>
@@ -423,7 +439,11 @@ function formatDotAccess(prevPart: PartDescriptor, part: PartDescriptor) {
423
439
  <indent>
424
440
  <sbr />
425
441
  {prevPart.nullish ? "?." : "."}
426
- {isIdPartDescriptor(part) ? part.id : part.index}
442
+ {isIdPartDescriptor(part) ?
443
+ part.jsPrivate ?
444
+ `#${part.id}`
445
+ : part.id
446
+ : part.index}
427
447
  </indent>
428
448
  </group>
429
449
  );
@@ -0,0 +1,29 @@
1
+ import { Children, MemberScope as CoreMemberScope } from "@alloy-js/core";
2
+ import { useTSLexicalScopeIfPresent } from "../symbols/scopes.js";
3
+ import { TSMemberScope } from "../symbols/ts-member-scope.js";
4
+ import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
5
+
6
+ export interface MemberScopeProps {
7
+ children: Children;
8
+
9
+ /**
10
+ * The symbol that this member scope will create member symbols on.
11
+ */
12
+ ownerSymbol: TSOutputSymbol;
13
+ }
14
+
15
+ /**
16
+ * A member scope for TypeScript. Member declarations will create symbols
17
+ * in this scope, which will be added to the owner symbol's members.
18
+ */
19
+ export function MemberScope(props: MemberScopeProps) {
20
+ const memberScope = new TSMemberScope(
21
+ "member-scope",
22
+ useTSLexicalScopeIfPresent(),
23
+ props.ownerSymbol,
24
+ );
25
+
26
+ return (
27
+ <CoreMemberScope value={memberScope}>{props.children}</CoreMemberScope>
28
+ );
29
+ }
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  emitSymbol,
3
3
  instantiateTakenMembersTo as instantiateTakenSymbolsTo,
4
- OutputSymbolFlags,
5
4
  } from "@alloy-js/core";
6
- import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
5
+ import { createValueSymbol } from "../symbols/index.js";
7
6
  import {
8
7
  FunctionCallExpression,
9
8
  FunctionCallExpressionProps,
@@ -12,10 +11,10 @@ import {
12
11
  export interface NewExpressionProps extends FunctionCallExpressionProps {}
13
12
 
14
13
  export function NewExpression(props: NewExpressionProps) {
15
- const sym = new TSOutputSymbol("", {
16
- flags: OutputSymbolFlags.Transient,
14
+ const sym = createValueSymbol("", {
15
+ transient: true,
17
16
  });
18
- instantiateTakenSymbolsTo(sym);
17
+ instantiateTakenSymbolsTo(sym, "static", "instance");
19
18
  emitSymbol(sym);
20
19
  return (
21
20
  <>
@@ -1,21 +1,21 @@
1
1
  import {
2
- AssignmentContext,
3
2
  Block,
4
3
  Children,
5
4
  computed,
6
- createAssignmentContext,
7
5
  emitSymbol,
8
6
  For,
9
7
  Match,
10
- MemberScope,
11
8
  moveTakenMembersTo,
12
- OutputSymbolFlags,
13
9
  Refkey,
14
10
  Switch,
15
11
  takeSymbols,
16
12
  } from "@alloy-js/core";
17
13
  import { useTSNamePolicy } from "../name-policy.js";
18
- import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
14
+ import {
15
+ createStaticMemberSymbol,
16
+ createTransientValueSymbol,
17
+ } from "../symbols/index.js";
18
+ import { MemberScope } from "./MemberScope.jsx";
19
19
  import { PropertyName } from "./PropertyName.jsx";
20
20
  import { ValueExpression } from "./ValueExpression.js";
21
21
 
@@ -28,12 +28,10 @@ export interface ObjectExpressionProps {
28
28
  }
29
29
 
30
30
  export function ObjectExpression(props: ObjectExpressionProps) {
31
- const symbol = new TSOutputSymbol("", {
32
- flags:
33
- OutputSymbolFlags.StaticMemberContainer | OutputSymbolFlags.Transient,
34
- });
31
+ const symbol = createTransientValueSymbol();
35
32
 
36
33
  emitSymbol(symbol);
34
+ moveTakenMembersTo(symbol);
37
35
 
38
36
  const jsValueProperties = computed(() => {
39
37
  const jsValue = props.jsValue;
@@ -59,7 +57,7 @@ export function ObjectExpression(props: ObjectExpressionProps) {
59
57
  </Match>
60
58
  <Match else>
61
59
  <group>
62
- <MemberScope owner={symbol}>
60
+ <MemberScope ownerSymbol={symbol}>
63
61
  <Block>
64
62
  <For each={jsValueProperties} comma softline enderPunctuation>
65
63
  {([name, value]) => (
@@ -108,12 +106,12 @@ export function ObjectProperty(props: ObjectPropertyProps) {
108
106
 
109
107
  let sym = undefined;
110
108
  if (props.refkey && props.name) {
111
- sym = new TSOutputSymbol(symbolName!, {
109
+ sym = createStaticMemberSymbol(symbolName!, {
112
110
  refkeys: props.refkey,
113
- flags: OutputSymbolFlags.StaticMember,
114
111
  });
115
112
 
116
113
  moveTakenMembersTo(sym);
114
+ emitSymbol(sym);
117
115
  } else {
118
116
  // noop
119
117
  takeSymbols();
@@ -129,14 +127,9 @@ export function ObjectProperty(props: ObjectPropertyProps) {
129
127
  value = props.children;
130
128
  }
131
129
 
132
- const assignmentContext: AssignmentContext | undefined =
133
- sym ? createAssignmentContext(sym) : undefined;
134
130
  return (
135
131
  <>
136
- {name}:{" "}
137
- <AssignmentContext.Provider value={assignmentContext}>
138
- {value}
139
- </AssignmentContext.Provider>
132
+ {name}: {value}
140
133
  </>
141
134
  );
142
135
  }
@@ -1,5 +1,5 @@
1
1
  import { MemberDeclarationContext, useContext } from "@alloy-js/core";
2
- import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
2
+ import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
3
3
  import { isValidJSIdentifier } from "../utils.js";
4
4
 
5
5
  export interface PropertyNameProps {
@@ -33,7 +33,7 @@ export function PropertyName(props: PropertyNameProps) {
33
33
  return "(no member declaration context)";
34
34
  }
35
35
 
36
- if (declSymbol.tsFlags & TSSymbolFlags.PrivateMember) {
36
+ if (declSymbol.isPrivateMemberSymbol) {
37
37
  return <>#{declSymbol.name}</>;
38
38
  } else {
39
39
  return <>{quoteIfNeeded(declSymbol.name)}</>;
@@ -6,6 +6,7 @@ import {
6
6
  Show,
7
7
  SourceDirectoryContext,
8
8
  useContext,
9
+ useScope,
9
10
  type Children,
10
11
  } from "@alloy-js/core";
11
12
 
@@ -39,7 +40,8 @@ export function SourceFile(props: SourceFileProps) {
39
40
  const sdData = getSourceDirectoryData(directoryContext);
40
41
  const currentDir = directoryContext.path;
41
42
  const path: string = join(currentDir, props.path);
42
- const scope = new TSModuleScope(path);
43
+ const parent = useScope();
44
+ const scope = new TSModuleScope(path, parent);
43
45
  sdData.modules.add(scope);
44
46
  const pkg = useContext(PackageContext);
45
47
  if (pkg) {
@@ -2,13 +2,12 @@ import {
2
2
  Children,
3
3
  Declaration as CoreDeclaration,
4
4
  createSymbolSlot,
5
- effect,
6
5
  Name,
7
- OutputSymbolFlags,
8
6
  Show,
9
7
  } from "@alloy-js/core";
10
8
  import { useTSNamePolicy } from "../name-policy.js";
11
- import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
9
+ import { createValueSymbol } from "../symbols/index.js";
10
+ import { TSSymbolFlags } from "../symbols/ts-output-symbol.js";
12
11
  import { BaseDeclarationProps } from "./Declaration.js";
13
12
  import { JSDoc } from "./JSDoc.jsx";
14
13
  import { TypeRefContext } from "./TypeRefContext.jsx";
@@ -25,25 +24,20 @@ export interface VarDeclarationProps extends BaseDeclarationProps {
25
24
  export function VarDeclaration(props: VarDeclarationProps) {
26
25
  const TypeSymbolSlot = createSymbolSlot();
27
26
  const ValueTypeSymbolSlot = createSymbolSlot();
28
-
29
- effect(() => {
30
- if (TypeSymbolSlot.ref.value) {
31
- const takenSymbols = TypeSymbolSlot.ref.value;
32
- for (const symbol of takenSymbols) {
33
- symbol.instantiateTo(sym);
34
- }
35
- } else if (ValueTypeSymbolSlot.ref.value) {
36
- const takenSymbols = ValueTypeSymbolSlot.ref.value;
37
- for (const symbol of takenSymbols) {
38
- // ignore non-transient symbols (likely not the result of an
39
- // expression).
40
- if (symbol.flags & OutputSymbolFlags.Transient) {
41
- symbol.moveTo(sym);
42
- }
43
- }
44
- }
27
+ const name = useTSNamePolicy().getName(props.name, "variable");
28
+ const sym = createValueSymbol(name, {
29
+ refkeys: props.refkey,
30
+ default: props.default,
31
+ export: props.export,
32
+ metadata: props.metadata,
33
+ tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,
34
+ type: props.type ? TypeSymbolSlot.firstSymbol : undefined,
45
35
  });
46
36
 
37
+ if (!props.type) {
38
+ ValueTypeSymbolSlot.moveMembersTo(sym);
39
+ }
40
+
47
41
  const keyword =
48
42
  props.var ? "var"
49
43
  : props.let ? "let"
@@ -54,14 +48,6 @@ export function VarDeclaration(props: VarDeclarationProps) {
54
48
  : <TypeSymbolSlot>{props.type}</TypeSymbolSlot>
55
49
  </TypeRefContext>
56
50
  : undefined;
57
- const name = useTSNamePolicy().getName(props.name, "variable");
58
- const sym = new TSOutputSymbol(name, {
59
- refkeys: props.refkey,
60
- default: props.default,
61
- export: props.export,
62
- metadata: props.metadata,
63
- tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,
64
- });
65
51
 
66
52
  return (
67
53
  <>
@@ -1 +1 @@
1
- export * from "./private-scope.js";
1
+ // type ref context isn't exported because it conflicts with the component of the same name.