@alloy-js/typescript 0.23.0-dev.7 → 0.23.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 (196) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/dev/src/components/FunctionBase.js +1 -9
  3. package/dist/dev/src/components/FunctionBase.js.map +1 -1
  4. package/dist/dev/src/components/ImportStatement.js +42 -10
  5. package/dist/dev/src/components/ImportStatement.js.map +1 -1
  6. package/dist/dev/src/name-conflict-resolver.js +8 -2
  7. package/dist/dev/src/name-conflict-resolver.js.map +1 -1
  8. package/dist/dev/src/symbols/index.js +9 -3
  9. package/dist/dev/src/symbols/index.js.map +1 -1
  10. package/dist/dev/src/symbols/reference.js +19 -9
  11. package/dist/dev/src/symbols/reference.js.map +1 -1
  12. package/dist/dev/src/symbols/ts-module-scope.js +66 -2
  13. package/dist/dev/src/symbols/ts-module-scope.js.map +1 -1
  14. package/dist/dev/test/externals.test.js +17 -13
  15. package/dist/dev/test/externals.test.js.map +1 -1
  16. package/dist/dev/test/function-declaration.test.js +65 -7
  17. package/dist/dev/test/function-declaration.test.js.map +1 -1
  18. package/dist/dev/test/imports-reactive.test.js +223 -0
  19. package/dist/dev/test/imports-reactive.test.js.map +1 -0
  20. package/dist/dev/test/imports.test.js +262 -80
  21. package/dist/dev/test/imports.test.js.map +1 -1
  22. package/dist/dev/test/name-conflict.test.js.map +1 -1
  23. package/dist/src/components/FunctionBase.js +1 -5
  24. package/dist/src/components/FunctionBase.js.map +1 -1
  25. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  26. package/dist/src/components/ImportStatement.js +16 -8
  27. package/dist/src/components/ImportStatement.js.map +1 -1
  28. package/dist/src/name-conflict-resolver.d.ts +2 -2
  29. package/dist/src/name-conflict-resolver.d.ts.map +1 -1
  30. package/dist/src/name-conflict-resolver.js +8 -2
  31. package/dist/src/name-conflict-resolver.js.map +1 -1
  32. package/dist/src/symbols/index.d.ts.map +1 -1
  33. package/dist/src/symbols/index.js +9 -3
  34. package/dist/src/symbols/index.js.map +1 -1
  35. package/dist/src/symbols/reference.d.ts.map +1 -1
  36. package/dist/src/symbols/reference.js +13 -3
  37. package/dist/src/symbols/reference.js.map +1 -1
  38. package/dist/src/symbols/ts-module-scope.d.ts +7 -0
  39. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  40. package/dist/src/symbols/ts-module-scope.js +66 -2
  41. package/dist/src/symbols/ts-module-scope.js.map +1 -1
  42. package/dist/test/externals.test.js +5 -1
  43. package/dist/test/externals.test.js.map +1 -1
  44. package/dist/test/function-declaration.test.js +42 -0
  45. package/dist/test/function-declaration.test.js.map +1 -1
  46. package/dist/test/imports-reactive.test.d.ts +2 -0
  47. package/dist/test/imports-reactive.test.d.ts.map +1 -0
  48. package/dist/test/imports-reactive.test.js +167 -0
  49. package/dist/test/imports-reactive.test.js.map +1 -0
  50. package/dist/test/imports.test.js +121 -3
  51. package/dist/test/imports.test.js.map +1 -1
  52. package/dist/test/name-conflict.test.js.map +1 -1
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/docs/api/components/ArrowFunction.md +71 -0
  55. package/docs/api/components/BarrelFile.md +58 -0
  56. package/docs/api/components/BlockScope.md +97 -0
  57. package/docs/api/components/CallSignature.md +45 -0
  58. package/docs/api/components/CaseClause.md +102 -0
  59. package/docs/api/components/CatchClause.md +50 -0
  60. package/docs/api/components/ClassDeclaration.md +61 -0
  61. package/docs/api/components/ClassField.md +63 -0
  62. package/docs/api/components/ClassMember.md +56 -0
  63. package/docs/api/components/ClassMethod.md +75 -0
  64. package/docs/api/components/CommaList.md +31 -0
  65. package/docs/api/components/Declaration.md +87 -0
  66. package/docs/api/components/ElseClause.md +29 -0
  67. package/docs/api/components/ElseIfClause.md +30 -0
  68. package/docs/api/components/EnumDeclaration.md +29 -0
  69. package/docs/api/components/EnumMember.md +46 -0
  70. package/docs/api/components/ExportStatement.md +26 -0
  71. package/docs/api/components/FinallyClause.md +50 -0
  72. package/docs/api/components/FunctionCallExpression.md +29 -0
  73. package/docs/api/components/FunctionDeclaration.md +57 -0
  74. package/docs/api/components/FunctionExpression.md +71 -0
  75. package/docs/api/components/IfStatement.md +30 -0
  76. package/docs/api/components/ImportStatement.md +29 -0
  77. package/docs/api/components/ImportStatements.md +25 -0
  78. package/docs/api/components/InterfaceDeclaration.md +38 -0
  79. package/docs/api/components/InterfaceMember.md +99 -0
  80. package/docs/api/components/InterfaceMethod.md +74 -0
  81. package/docs/api/components/JSDoc.md +29 -0
  82. package/docs/api/components/JSDocComment.md +29 -0
  83. package/docs/api/components/JSDocExample.md +31 -0
  84. package/docs/api/components/MemberExpression.md +58 -0
  85. package/docs/api/components/NewExpression.md +26 -0
  86. package/docs/api/components/ObjectExpression.md +32 -0
  87. package/docs/api/components/ObjectProperty.md +44 -0
  88. package/docs/api/components/ObjectSpreadProperty.md +29 -0
  89. package/docs/api/components/PackageDirectory.md +102 -0
  90. package/docs/api/components/PackageJsonFile.md +82 -0
  91. package/docs/api/components/Reference.md +26 -0
  92. package/docs/api/components/SingleLineCommentBlock.md +29 -0
  93. package/docs/api/components/SourceFile.md +41 -0
  94. package/docs/api/components/SwitchStatement.md +30 -0
  95. package/docs/api/components/TSConfigJson.md +25 -0
  96. package/docs/api/components/TryStatement.md +50 -0
  97. package/docs/api/components/TypeRefContext.md +35 -0
  98. package/docs/api/components/ValueExpression.md +25 -0
  99. package/docs/api/components/VarDeclaration.md +44 -0
  100. package/docs/api/components/ensureTypeRefContext.md +28 -0
  101. package/docs/api/components/index.md +49 -0
  102. package/docs/api/contexts/Package-context.md +21 -0
  103. package/docs/api/contexts/PackageMetadata-context.md +18 -0
  104. package/docs/api/contexts/SourceFile-context.md +20 -0
  105. package/docs/api/contexts/index.md +5 -0
  106. package/docs/api/functions/createInstanceMemberSymbol.md +38 -0
  107. package/docs/api/functions/createLexicalScope.md +27 -0
  108. package/docs/api/functions/createMemberScope.md +28 -0
  109. package/docs/api/functions/createMemberSymbol.md +42 -0
  110. package/docs/api/functions/createPackage.md +18 -0
  111. package/docs/api/functions/createPrivateInstanceMemberSymbol.md +38 -0
  112. package/docs/api/functions/createPrivateStaticMemberSymbol.md +38 -0
  113. package/docs/api/functions/createStaticMemberSymbol.md +38 -0
  114. package/docs/api/functions/createTSNamePolicy.md +17 -0
  115. package/docs/api/functions/createTransientValueSymbol.md +17 -0
  116. package/docs/api/functions/createTypeAndValueSymbol.md +38 -0
  117. package/docs/api/functions/createTypeSymbol.md +38 -0
  118. package/docs/api/functions/createValueSymbol.md +38 -0
  119. package/docs/api/functions/decl.md +38 -0
  120. package/docs/api/functions/declMember.md +42 -0
  121. package/docs/api/functions/declType.md +38 -0
  122. package/docs/api/functions/getPackageScope.md +20 -0
  123. package/docs/api/functions/getSourceDirectoryData.md +18 -0
  124. package/docs/api/functions/index.md +27 -0
  125. package/docs/api/functions/ref.md +25 -0
  126. package/docs/api/functions/tsNameConflictResolver.md +19 -0
  127. package/docs/api/functions/useTSLexicalScope.md +17 -0
  128. package/docs/api/functions/useTSLexicalScopeIfPresent.md +17 -0
  129. package/docs/api/functions/useTSMemberScope.md +17 -0
  130. package/docs/api/functions/useTSNamePolicy.md +17 -0
  131. package/docs/api/functions/useTSScope.md +17 -0
  132. package/docs/api/index.md +7 -0
  133. package/docs/api/types/AddImportOptions.md +7 -0
  134. package/docs/api/types/BlockScopeProps.md +5 -0
  135. package/docs/api/types/CaseClauseProps.md +5 -0
  136. package/docs/api/types/CaseClausePropsBase.md +9 -0
  137. package/docs/api/types/CommonDeclarationProps.md +7 -0
  138. package/docs/api/types/CreatePackageProps.md +12 -0
  139. package/docs/api/types/CreateTsSymbolOptions.md +12 -0
  140. package/docs/api/types/DeclarationProps.md +5 -0
  141. package/docs/api/types/DeclarationPropsBase.md +8 -0
  142. package/docs/api/types/ExportConditions.md +7 -0
  143. package/docs/api/types/ExportPath.md +5 -0
  144. package/docs/api/types/ExternalPackage.md +7 -0
  145. package/docs/api/types/FunctionBodyProps.md +7 -0
  146. package/docs/api/types/FunctionParametersProps.md +10 -0
  147. package/docs/api/types/FunctionTypeParameterDescriptor.md +10 -0
  148. package/docs/api/types/FunctionTypeParametersProps.md +10 -0
  149. package/docs/api/types/FunctionTypeProps.md +13 -0
  150. package/docs/api/types/ImportRecords.md +5 -0
  151. package/docs/api/types/ImportedSymbol.md +8 -0
  152. package/docs/api/types/InterfaceExpressionProps.md +7 -0
  153. package/docs/api/types/InterfaceMemberProps.md +5 -0
  154. package/docs/api/types/InterfaceMemberPropsBase.md +11 -0
  155. package/docs/api/types/MemberExpressionPartProps.md +15 -0
  156. package/docs/api/types/ModuleExports.md +18 -0
  157. package/docs/api/types/ModuleSymbolsDescriptor.md +10 -0
  158. package/docs/api/types/NamedMap.md +18 -0
  159. package/docs/api/types/NamedModuleDescriptor.md +17 -0
  160. package/docs/api/types/PackageDescriptor.md +7 -0
  161. package/docs/api/types/PackageExports.md +7 -0
  162. package/docs/api/types/PackageRefkeys.md +10 -0
  163. package/docs/api/types/ParameterDescriptor.md +11 -0
  164. package/docs/api/types/ParameterDescriptorBase.md +16 -0
  165. package/docs/api/types/RefOptions.md +7 -0
  166. package/docs/api/types/SourceDirectoryData.md +7 -0
  167. package/docs/api/types/SourceFileHeaderProps.md +8 -0
  168. package/docs/api/types/TSLexicalScope.md +13 -0
  169. package/docs/api/types/TSMemberScope.md +14 -0
  170. package/docs/api/types/TSModuleScope.md +17 -0
  171. package/docs/api/types/TSOutputScope.md +5 -0
  172. package/docs/api/types/TSOutputSymbol.md +28 -0
  173. package/docs/api/types/TSPackageScope.md +21 -0
  174. package/docs/api/types/TSPackageScopeOptions.md +9 -0
  175. package/docs/api/types/TypeDeclarationProps.md +8 -0
  176. package/docs/api/types/TypeParameterDescriptor.md +13 -0
  177. package/docs/api/types/TypeScriptElements.md +5 -0
  178. package/docs/api/types/index.md +47 -0
  179. package/docs/api/variables/FunctionType.md +24 -0
  180. package/docs/api/variables/InterfaceExpression.md +5 -0
  181. package/docs/api/variables/TSSymbolFlags.md +5 -0
  182. package/docs/api/variables/TypeDeclaration.md +5 -0
  183. package/docs/api/variables/index.md +6 -0
  184. package/package.json +6 -6
  185. package/src/components/FunctionBase.tsx +1 -1
  186. package/src/components/ImportStatement.tsx +26 -12
  187. package/src/name-conflict-resolver.ts +12 -8
  188. package/src/symbols/index.ts +18 -3
  189. package/src/symbols/reference.tsx +17 -6
  190. package/src/symbols/ts-module-scope.ts +79 -2
  191. package/temp/api.json +68 -2
  192. package/test/externals.test.tsx +5 -1
  193. package/test/function-declaration.test.tsx +36 -0
  194. package/test/imports-reactive.test.tsx +128 -0
  195. package/test/imports.test.tsx +136 -2
  196. package/test/name-conflict.test.tsx +4 -4
@@ -0,0 +1,16 @@
1
+ # ParameterDescriptorBase
2
+
3
+ Common properties for ParameterDescriptor and FunctionTypeParameterDescriptor.
4
+
5
+ ## Members
6
+
7
+ | | | |
8
+ | -------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | doc | optional [Children](../../../core/types/children/) | Documentation for the parameter. |
10
+ | metadata | optional Record\<string, unknown> | Arbitrary metadata for the parameter symbol. |
11
+ | name | string \| [Namekey](../../../core/types/namekey/) | The name of the parameter. |
12
+ | nullish | optional boolean | Whether the parameter is can be null or undefined. when optional is true, this will be set to true by default, but explicitly setting this to false will override that. |
13
+ | optional | optional boolean | Whether the parameter is optional. |
14
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | The refkey for this parameter. |
15
+ | rest | optional boolean | Weather the parameter is rest parameter. |
16
+ | type | optional [Children](../../../core/types/children/) | The type of the parameter. |
@@ -0,0 +1,7 @@
1
+ # RefOptions
2
+
3
+ ## Members
4
+
5
+ | | | |
6
+ | ---- | ---------------- | - |
7
+ | type | optional boolean | |
@@ -0,0 +1,7 @@
1
+ # SourceDirectoryData
2
+
3
+ ## Members
4
+
5
+ | | | |
6
+ | ------- | --------------------------------------- | - |
7
+ | modules | Set<[TSModuleScope](../tsmodulescope/)> | |
@@ -0,0 +1,8 @@
1
+ # SourceFileHeaderProps
2
+
3
+ ## Members
4
+
5
+ | | | |
6
+ | ------------- | -------------------------------------------------- | - |
7
+ | header | optional [Children](../../../core/types/children/) | |
8
+ | headerComment | optional string | |
@@ -0,0 +1,13 @@
1
+ # TSLexicalScope
2
+
3
+ A lexical scope for TypeScript, which contains declaration spaces for types and values. This scope is used to hold symbols for things like variable or interface declarations.
4
+
5
+ ## Members
6
+
7
+ Extends [OutputScope](../../../core/types/outputscope/)
8
+
9
+ | | | |
10
+ | ----------------- | ------------------------------------------------------------------------ | - |
11
+ | declarationSpaces | string\[] | |
12
+ | types | import(“@alloy-js/core”).[OutputSpace](../../../core/types/outputspace/) | |
13
+ | values | import(“@alloy-js/core”).[OutputSpace](../../../core/types/outputspace/) | |
@@ -0,0 +1,14 @@
1
+ # TSMemberScope
2
+
3
+ A member scope for TypeScript. Member declarations create symbols in this scope, which will be added to the owner symbol’s members.
4
+
5
+ ## Members
6
+
7
+ Extends [TSLexicalScope](../tslexicalscope/)
8
+
9
+ | | | |
10
+ | ----------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
11
+ | constructor | (name: string, parentScope: TSOutputScope \| undefined, ownerSymbol: TSOutputSymbol, options: OutputScopeOptions) | Constructs a new instance of the [`TSMemberScope`](TSMemberScope.md) class |
12
+ | declarationSpaces | never\[] | |
13
+ | isMemberScope | boolean | |
14
+ | ownerSymbol | [TSOutputSymbol](../tsoutputsymbol/) | |
@@ -0,0 +1,17 @@
1
+ # TSModuleScope
2
+
3
+ A lexical scope for TypeScript which represents the top-level scope of a module. Manages the module’s imported and exported symbols.
4
+
5
+ ## Members
6
+
7
+ Extends [TSLexicalScope](../tslexicalscope/)
8
+
9
+ | | | |
10
+ | --------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | addImport | (targetSymbol: TSOutputSymbol, targetModule: TSModuleScope, options: AddImportOptions) => TSOutputSymbol | |
12
+ | debugInfo | Record\<string, unknown> | |
13
+ | exportedSymbols | Map<[Refkey](../../../core/types/refkey/), [TSOutputSymbol](../tsoutputsymbol/)> | |
14
+ | getAllSymbols | () => Set\<TSOutputSymbol> | |
15
+ | importedModules | [ImportRecords](../importrecords/) | |
16
+ | importedSymbols | Map<[TSOutputSymbol](../tsoutputsymbol/), [TSOutputSymbol](../tsoutputsymbol/)> | |
17
+ | removeImport | (targetSymbol: TSOutputSymbol, options: AddImportOptions) => void | Decrement the refcount for an import previously registered via addImport. When the last live consumer goes away, the local import symbol is deleted, which removes it from the module’s name spaces and triggers name-conflict-resolver reconciliation. |
@@ -0,0 +1,5 @@
1
+ # TSOutputScope
2
+
3
+ ```ts
4
+ type TSOutputScope = TSPackageScope | TSModuleScope | TSLexicalScope;
5
+ ```
@@ -0,0 +1,28 @@
1
+ # TSOutputSymbol
2
+
3
+ ## Members
4
+
5
+ Extends [OutputSymbol](../../../core/types/outputsymbol/)
6
+
7
+ | | | |
8
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
9
+ | constructor | (name: string \| Namekey, spaces: OutputSpace\[] \| OutputSpace \| undefined, options: CreateTsSymbolOptions) | Constructs a new instance of the [`TSOutputSymbol`](TSOutputSymbol.md) class |
10
+ | copy | () => TSOutputSymbol | |
11
+ | debugInfo | Record\<string, unknown> | |
12
+ | default | boolean | |
13
+ | export | boolean | |
14
+ | hasInstanceMembers | boolean | |
15
+ | instanceMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
16
+ | isInstanceMemberSymbol | boolean | |
17
+ | isPrivateMemberSymbol | boolean | |
18
+ | isPublicMemberSymbol | boolean | |
19
+ | isStaticMemberSymbol | boolean | |
20
+ | isTypeSymbol | boolean | |
21
+ | isValueSymbol | boolean | |
22
+ | memberSpaces | readonly \[“static”, “instance”, “private-static”, “private-instance”] | |
23
+ | ownerSymbol | [TSOutputSymbol](../tsoutputsymbol/) \| undefined | |
24
+ | privateInstanceMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
25
+ | privateStaticMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
26
+ | scope | [TSOutputScope](../tsoutputscope/) \| undefined | |
27
+ | staticMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
28
+ | tsFlags | [TSSymbolFlags](../../variables/tssymbolflags/) | |
@@ -0,0 +1,21 @@
1
+ # TSPackageScope
2
+
3
+ ## Members
4
+
5
+ Extends [OutputScope](../../../core/types/outputscope/)
6
+
7
+ | | | |
8
+ | ------------------ | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
9
+ | constructor | (name: string, version: string, path: string, options: TSPackageScopeOptions) | Constructs a new instance of the [`TSPackageScope`](TSPackageScope.md) class |
10
+ | addDependency | (pkg: TSPackageScope) => void | |
11
+ | addExport | (publicPath: string, module: TSModuleScope) => void | |
12
+ | addModule | (module: TSModuleScope) => void | |
13
+ | builtin | boolean | Whether this is a built-in package provided by the platform. |
14
+ | copyTo | () => TSPackageScope | |
15
+ | debugInfo | Record\<string, unknown> | |
16
+ | dependencies | Set<[TSPackageScope](../tspackagescope/)> | The scopes for the packages this package depends on. |
17
+ | exportedSymbols | Map\<string, [TSModuleScope](../tsmodulescope/)> | The symbols exported by this package. They are broken down by which paths they are exported from. It is possible a symbol may be present at multiple paths, in which case emitters can decide which symbol to use based on their own heuristics. |
18
+ | findExportedSymbol | (refkey: Refkey) => \[string, TSModuleScope] \| null | |
19
+ | modules | Set<[TSModuleScope](../tsmodulescope/)> | All of the modules contained within the package. These modules may or may not be exported. |
20
+ | path | string | The path of the root directory of the package. |
21
+ | version | string | The version of the this package. |
@@ -0,0 +1,9 @@
1
+ # TSPackageScopeOptions
2
+
3
+ ## Members
4
+
5
+ Extends [OutputScopeOptions](../../../core/types/outputscopeoptions/)
6
+
7
+ | | | |
8
+ | ------- | ---------------- | - |
9
+ | builtin | optional boolean | |
@@ -0,0 +1,8 @@
1
+ # TypeDeclarationProps
2
+
3
+ ## Members
4
+
5
+ Extends [CommonDeclarationProps](../commondeclarationprops/)
6
+
7
+ | |
8
+ | - |
@@ -0,0 +1,13 @@
1
+ # TypeParameterDescriptor
2
+
3
+ Information for a TypeScript generic type parameter.
4
+
5
+ ## Members
6
+
7
+ | | | |
8
+ | -------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------- |
9
+ | default | optional [Children](../../../core/types/children/) | The default type of the type parameter. |
10
+ | extends | optional [Children](../../../core/types/children/) | The extends constraint for the type parameter. |
11
+ | metadata | optional Record\<string, unknown> | Arbitrary metadata for the type parameter symbol. |
12
+ | name | string \| [Namekey](../../../core/types/namekey/) | The name of the type parameter. |
13
+ | refkey | optional [Refkey](../../../core/types/refkey/) \| [Refkey](../../../core/types/refkey/)\[] | A refkey or array of refkeys for this type parameter. |
@@ -0,0 +1,5 @@
1
+ # TypeScriptElements
2
+
3
+ ```ts
4
+ type TypeScriptElements = "function" | "parameter" | "class" | "variable" | "enum" | "object-member-data" | "object-member-getter" | "class-member-data" | "class-member-getter" | "enum-member" | "interface" | "interface-member" | "type";
5
+ ```
@@ -0,0 +1,47 @@
1
+ # typescript — types
2
+
3
+ - [AddImportOptions](AddImportOptions.md)
4
+ - [BlockScopeProps](BlockScopeProps.md) — type BlockScopeProps = BlockScopePropsWithScopeValue | BlockScopePropsWithScopeInfo;
5
+ - [CaseClauseProps](CaseClauseProps.md) — type CaseClauseProps = CaseClausePropsWithExpression | CaseClausePropsWithValue | CaseClausePropsWithDefault;
6
+ - [CaseClausePropsBase](CaseClausePropsBase.md)
7
+ - [CommonDeclarationProps](CommonDeclarationProps.md) — The base props for declaration components.
8
+ - [CreatePackageProps](CreatePackageProps.md) — Props for creating a package with a specific name, version, and descriptor.
9
+ - [CreateTsSymbolOptions](CreateTsSymbolOptions.md) — Extends [OutputSymbolOptions](../../../core/types/outputsymboloptions/)
10
+ - [DeclarationProps](DeclarationProps.md) — type DeclarationProps = DeclarationPropsWithSymbol | DeclarationPropsWithInfo;
11
+ - [DeclarationPropsBase](DeclarationPropsBase.md)
12
+ - [ExportConditions](ExportConditions.md)
13
+ - [ExportPath](ExportPath.md) — type ExportPath = string | ExportConditions;
14
+ - [ExternalPackage](ExternalPackage.md)
15
+ - [FunctionBodyProps](FunctionBodyProps.md)
16
+ - [FunctionParametersProps](FunctionParametersProps.md) — Props for function parameters
17
+ - [FunctionTypeParameterDescriptor](FunctionTypeParameterDescriptor.md) — Information for a TypeScript type function parameter.
18
+ - [FunctionTypeParametersProps](FunctionTypeParametersProps.md) — Props for a function type(FunctionType or InterfaceMethod)
19
+ - [FunctionTypeProps](FunctionTypeProps.md) — Options for [FunctionType](../../variables/functiontype/) component.
20
+ - [ImportedSymbol](ImportedSymbol.md)
21
+ - [ImportRecords](ImportRecords.md) — type ImportRecords = Map<TSModuleScope, Set<ImportedSymbol>>;
22
+ - [InterfaceExpressionProps](InterfaceExpressionProps.md)
23
+ - [InterfaceMemberProps](InterfaceMemberProps.md) — type InterfaceMemberProps = InterfacePropertyMemberProps | InterfaceIndexerMemberProps;
24
+ - [InterfaceMemberPropsBase](InterfaceMemberPropsBase.md)
25
+ - [MemberExpressionPartProps](MemberExpressionPartProps.md)
26
+ - [ModuleExports](ModuleExports.md) — Infers the exported members of a module based on its descriptor.
27
+ - [ModuleSymbolsDescriptor](ModuleSymbolsDescriptor.md) — Describes the symbols exported by a module.
28
+ - [NamedMap](NamedMap.md) — type NamedMap<TDescriptor extends readonly NamedModuleDescriptor[]> = {
29
+ - [NamedModuleDescriptor](NamedModuleDescriptor.md) — Describes the structure of a module descriptor.
30
+ - [PackageDescriptor](PackageDescriptor.md)
31
+ - [PackageExports](PackageExports.md)
32
+ - [PackageRefkeys](PackageRefkeys.md) — type PackageRefkeys<PD extends Record<string, {
33
+ - [ParameterDescriptor](ParameterDescriptor.md) — Information for a TypeScript function parameter.
34
+ - [ParameterDescriptorBase](ParameterDescriptorBase.md) — Common properties for ParameterDescriptor and FunctionTypeParameterDescriptor.
35
+ - [RefOptions](RefOptions.md)
36
+ - [SourceDirectoryData](SourceDirectoryData.md)
37
+ - [SourceFileHeaderProps](SourceFileHeaderProps.md)
38
+ - [TSLexicalScope](TSLexicalScope.md) — A lexical scope for TypeScript, which contains declaration spaces for types and values.
39
+ - [TSMemberScope](TSMemberScope.md) — A member scope for TypeScript.
40
+ - [TSModuleScope](TSModuleScope.md) — A lexical scope for TypeScript which represents the top-level scope of a module.
41
+ - [TSOutputScope](TSOutputScope.md) — type TSOutputScope = TSPackageScope | TSModuleScope | TSLexicalScope;
42
+ - [TSOutputSymbol](TSOutputSymbol.md) — Extends [OutputSymbol](../../../core/types/outputsymbol/)
43
+ - [TSPackageScope](TSPackageScope.md) — Extends [OutputScope](../../../core/types/outputscope/)
44
+ - [TSPackageScopeOptions](TSPackageScopeOptions.md) — Extends [OutputScopeOptions](../../../core/types/outputscopeoptions/)
45
+ - [TypeDeclarationProps](TypeDeclarationProps.md) — Extends [CommonDeclarationProps](../commondeclarationprops/)
46
+ - [TypeParameterDescriptor](TypeParameterDescriptor.md) — Information for a TypeScript generic type parameter.
47
+ - [TypeScriptElements](TypeScriptElements.md) — type TypeScriptElements = "function" | "parameter" | "class" | "variable" | "enum" | "object-member-data" | "object-memb
@@ -0,0 +1,24 @@
1
+ # FunctionType
2
+
3
+ A TypeScript function declaration.
4
+
5
+ ```ts
6
+ FunctionType: import("@alloy-js/core").Component<FunctionTypeProps> & {
7
+ TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
8
+ Parameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps>, "tag">>;
9
+ }
10
+ ```
11
+
12
+ ## Remarks
13
+
14
+ Providing parameters and type parameters can be accomplished in one of three ways:
15
+
16
+ 1. As an array of [TypeParameterDescriptor](../../types/typeparameterdescriptor/)s or [TypeParameterDescriptor](../../types/typeparameterdescriptor/)s.
17
+ 2. As raw content via the `parametersChildren` or `typeParametersChildren` props.
18
+ 3. As a child of this component via the \[unresolved link] or \[unresolved link] components.
19
+
20
+ ## Example
21
+
22
+ ```ts
23
+ (foo: string, bar: number) => void
24
+ ```
@@ -0,0 +1,5 @@
1
+ # InterfaceExpression
2
+
3
+ ```ts
4
+ InterfaceExpression: import("@alloy-js/core").Component<InterfaceExpressionProps>
5
+ ```
@@ -0,0 +1,5 @@
1
+ # TSSymbolFlags
2
+
3
+ ```ts
4
+ enum TSSymbolFlags
5
+ ```
@@ -0,0 +1,5 @@
1
+ # TypeDeclaration
2
+
3
+ ```ts
4
+ TypeDeclaration: import("@alloy-js/core").Component<TypeDeclarationProps>
5
+ ```
@@ -0,0 +1,6 @@
1
+ # typescript — variables
2
+
3
+ - [FunctionType](FunctionType.md) — A TypeScript function declaration.
4
+ - [InterfaceExpression](InterfaceExpression.md) — InterfaceExpression: import("@alloy-js/core").Component<InterfaceExpressionProps>
5
+ - [TSSymbolFlags](TSSymbolFlags.md) — enum TSSymbolFlags
6
+ - [TypeDeclaration](TypeDeclaration.md) — TypeDeclaration: import("@alloy-js/core").Component<TypeDeclarationProps>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/typescript",
3
- "version": "0.23.0-dev.7",
3
+ "version": "0.23.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,18 +30,18 @@
30
30
  "author": "brian.terlson@microsoft.com",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.12",
34
33
  "change-case": "^5.4.4",
35
- "pathe": "^2.0.3"
34
+ "pathe": "^2.0.3",
35
+ "@alloy-js/core": "~0.23.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.4",
39
- "@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.1",
40
38
  "@microsoft/api-extractor": "~7.52.8",
41
39
  "@rollup/plugin-typescript": "^12.1.2",
42
40
  "concurrently": "^9.2.0",
43
41
  "typescript": "^5.8.3",
44
- "vitest": "3.2.4"
42
+ "vitest": "3.2.4",
43
+ "@alloy-js/cli": "~0.23.0",
44
+ "@alloy-js/rollup-plugin": "~0.1.1"
45
45
  },
46
46
  "type": "module",
47
47
  "scripts": {
@@ -151,7 +151,7 @@ function parameter(
151
151
  </Show>
152
152
  <Show when={!!(param as any).default}>
153
153
  {" = "}
154
- <param.TypeSlot>{(param as any).default!}</param.TypeSlot>
154
+ {(param as any).default!}
155
155
  </Show>
156
156
  </group>
157
157
  );
@@ -102,20 +102,34 @@ export function ImportStatement(props: ImportStatementProps) {
102
102
  if (allNamedImportsAreTypes) {
103
103
  parts.push("type ");
104
104
  }
105
- parts.push("{ ");
106
105
  parts.push(
107
- mapJoin(
108
- () => namedImportSymbols,
109
- (nis) => (
110
- <ImportBinding
111
- importedSymbol={nis}
112
- inTypeImport={allNamedImportsAreTypes}
113
- />
114
- ),
115
- { joiner: ", " },
116
- ),
106
+ <group>
107
+ {"{"}
108
+ <indent>
109
+ <line />
110
+ {mapJoin(
111
+ () => namedImportSymbols,
112
+ (nis) => (
113
+ <ImportBinding
114
+ importedSymbol={nis}
115
+ inTypeImport={allNamedImportsAreTypes}
116
+ />
117
+ ),
118
+ {
119
+ joiner: (
120
+ <>
121
+ {","}
122
+ <line />
123
+ </>
124
+ ),
125
+ },
126
+ )}
127
+ <ifBreak>{","}</ifBreak>
128
+ </indent>
129
+ <line />
130
+ {"}"}
131
+ </group>,
117
132
  );
118
- parts.push(" }");
119
133
  }
120
134
  parts.push(` from "${props.path}";`);
121
135
 
@@ -1,22 +1,26 @@
1
+ import { OutputSymbol } from "@alloy-js/core";
1
2
  import { TSOutputSymbol, TSSymbolFlags } from "./symbols/index.js";
2
3
 
3
- export function tsNameConflictResolver(
4
- name: string,
5
- symbols: TSOutputSymbol[],
6
- ) {
7
- const goodNamedSymbols = symbols.filter(
4
+ export function tsNameConflictResolver(name: string, symbols: OutputSymbol[]) {
5
+ const goodNamedSymbols = (symbols as TSOutputSymbol[]).filter(
8
6
  (s) => ~s.tsFlags & TSSymbolFlags.LocalImportSymbol,
9
7
  );
10
- const badNamedSymbols = symbols.filter(
8
+ const badNamedSymbols = (symbols as TSOutputSymbol[]).filter(
11
9
  (s) => s.tsFlags & TSSymbolFlags.LocalImportSymbol,
12
10
  );
13
11
  let nameCount = 1;
12
+ if (goodNamedSymbols.length >= 1) {
13
+ // The first "good" symbol owns the plain name. Clear any prior
14
+ // deconflict rename so survivors reclaim the original name when a
15
+ // collision is resolved.
16
+ goodNamedSymbols[0].deconflictedName = undefined;
17
+ }
14
18
  if (goodNamedSymbols.length > 1) {
15
19
  for (const sym of goodNamedSymbols.slice(1)) {
16
- sym.name = name + "_" + nameCount++;
20
+ sym.deconflictedName = name + "_" + nameCount++;
17
21
  }
18
22
  }
19
23
  for (const sym of badNamedSymbols) {
20
- sym.name = name + "_" + nameCount++;
24
+ sym.deconflictedName = name + "_" + nameCount++;
21
25
  }
22
26
  }
@@ -28,7 +28,12 @@ export function createTypeAndValueSymbol(
28
28
  const scope = useLexicalScope();
29
29
  const spaces = scope ? [scope.types, scope.values] : [];
30
30
  const binder = options.binder ?? scope?.binder;
31
- return createSymbol(TSOutputSymbol, name, spaces, { ...options, binder });
31
+ const symbol = createSymbol(TSOutputSymbol, name, spaces, {
32
+ ...options,
33
+ binder,
34
+ });
35
+ onCleanup(() => symbol.delete());
36
+ return symbol;
32
37
  }
33
38
 
34
39
  export function createTypeSymbol(
@@ -43,7 +48,12 @@ export function createTypeSymbol(
43
48
  }
44
49
  const spaces = scope ? [scope.types] : [];
45
50
  const binder = options.binder ?? scope?.binder;
46
- return createSymbol(TSOutputSymbol, name, spaces, { ...options, binder });
51
+ const symbol = createSymbol(TSOutputSymbol, name, spaces, {
52
+ ...options,
53
+ binder,
54
+ });
55
+ onCleanup(() => symbol.delete());
56
+ return symbol;
47
57
  }
48
58
 
49
59
  export function createValueSymbol(
@@ -58,7 +68,12 @@ export function createValueSymbol(
58
68
  }
59
69
  const spaces = scope ? [scope.values] : [];
60
70
  const binder = options.binder ?? scope?.binder;
61
- return createSymbol(TSOutputSymbol, name, spaces, { ...options, binder });
71
+ const symbol = createSymbol(TSOutputSymbol, name, spaces, {
72
+ ...options,
73
+ binder,
74
+ });
75
+ onCleanup(() => symbol.delete());
76
+ return symbol;
62
77
  }
63
78
 
64
79
  export function createTransientValueSymbol() {
@@ -3,6 +3,7 @@ import {
3
3
  MemberResolutionContext,
4
4
  MemberResolver,
5
5
  memo,
6
+ onCleanup,
6
7
  Refkey,
7
8
  resolve,
8
9
  unresolvedRefkey,
@@ -65,8 +66,15 @@ export function ref(
65
66
  for (const module of sourcePackage.exportedSymbols.values()) {
66
67
  for (const refkey of lexicalDeclaration.refkeys) {
67
68
  if (module.exportedSymbols.has(refkey)) {
69
+ const scope = sourceFile!.scope;
70
+ const targetModule = module;
68
71
  localSymbol = untrack(() =>
69
- sourceFile!.scope.addImport(lexicalDeclaration, module, {
72
+ scope.addImport(lexicalDeclaration, targetModule, {
73
+ type: options?.type,
74
+ }),
75
+ );
76
+ onCleanup(() =>
77
+ scope.removeImport(lexicalDeclaration, {
70
78
  type: options?.type,
71
79
  }),
72
80
  );
@@ -81,12 +89,15 @@ export function ref(
81
89
  );
82
90
  }
83
91
  } else if (targetLocation === "module") {
92
+ const scope = sourceFile!.scope;
93
+ const targetModule = pathDown[0] as TSModuleScope;
84
94
  localSymbol = untrack(() =>
85
- sourceFile!.scope.addImport(
86
- lexicalDeclaration,
87
- pathDown[0] as TSModuleScope,
88
- { type: options?.type },
89
- ),
95
+ scope.addImport(lexicalDeclaration, targetModule, {
96
+ type: options?.type,
97
+ }),
98
+ );
99
+ onCleanup(() =>
100
+ scope.removeImport(lexicalDeclaration, { type: options?.type }),
90
101
  );
91
102
  }
92
103
 
@@ -17,6 +17,16 @@ export interface AddImportOptions {
17
17
  type?: boolean;
18
18
  }
19
19
 
20
+ interface ImportEntry {
21
+ local: TSOutputSymbol;
22
+ target: TSOutputSymbol;
23
+ module: TSModuleScope;
24
+ // Number of live `ref()` consumers that added this symbol as a value import.
25
+ valueRefCount: number;
26
+ // Number of live `ref()` consumers that added this symbol as a type-only import.
27
+ typeRefCount: number;
28
+ }
29
+
20
30
  /**
21
31
  * A lexical scope for TypeScript which represents the top-level scope of a
22
32
  * module. Manages the module's imported and exported symbols.
@@ -40,6 +50,11 @@ export class TSModuleScope extends TSLexicalScope {
40
50
  return this.#importedModules;
41
51
  }
42
52
 
53
+ // Internal refcount + kind bookkeeping keyed by the target (source-of-truth)
54
+ // symbol. Used by {@link removeImport} to know when to actually delete the
55
+ // local import symbol and associated records.
56
+ #importEntries: Map<TSOutputSymbol, ImportEntry> = new Map();
57
+
43
58
  addImport(
44
59
  targetSymbol: TSOutputSymbol,
45
60
  targetModule: TSModuleScope,
@@ -47,8 +62,14 @@ export class TSModuleScope extends TSLexicalScope {
47
62
  ) {
48
63
  const existing = this.importedSymbols.get(targetSymbol);
49
64
  if (existing) {
50
- if (!options?.type && existing.isTypeSymbol) {
51
- existing.spaces.push(this.values);
65
+ const entry = this.#importEntries.get(targetSymbol)!;
66
+ if (options?.type) {
67
+ entry.typeRefCount++;
68
+ } else {
69
+ entry.valueRefCount++;
70
+ if (existing.isTypeSymbol && !existing.isValueSymbol) {
71
+ existing.spaces.push(this.values);
72
+ }
52
73
  }
53
74
  return existing;
54
75
  }
@@ -89,10 +110,66 @@ export class TSModuleScope extends TSLexicalScope {
89
110
  local: localSymbol,
90
111
  target: targetSymbol,
91
112
  });
113
+ this.#importEntries.set(targetSymbol, {
114
+ local: localSymbol,
115
+ target: targetSymbol,
116
+ module: targetModule,
117
+ valueRefCount: options?.type ? 0 : 1,
118
+ typeRefCount: options?.type ? 1 : 0,
119
+ });
92
120
 
93
121
  return localSymbol;
94
122
  }
95
123
 
124
+ /**
125
+ * Decrement the refcount for an import previously registered via
126
+ * {@link TSModuleScope.addImport | addImport}. When the last live consumer goes away, the local import
127
+ * symbol is deleted, which removes it from the module's name spaces and
128
+ * triggers name-conflict-resolver reconciliation.
129
+ */
130
+ removeImport(targetSymbol: TSOutputSymbol, options?: AddImportOptions) {
131
+ const entry = this.#importEntries.get(targetSymbol);
132
+ if (!entry) {
133
+ return;
134
+ }
135
+
136
+ if (options?.type) {
137
+ if (entry.typeRefCount > 0) entry.typeRefCount--;
138
+ } else {
139
+ if (entry.valueRefCount > 0) entry.valueRefCount--;
140
+ // If there are no more value consumers but type consumers remain, demote
141
+ // the local symbol back to being type-only by removing it from the values
142
+ // space.
143
+ if (entry.valueRefCount === 0 && entry.typeRefCount > 0) {
144
+ if (entry.local.isValueSymbol && entry.local.isTypeSymbol) {
145
+ this.values.delete(entry.local);
146
+ }
147
+ }
148
+ }
149
+
150
+ if (entry.valueRefCount > 0 || entry.typeRefCount > 0) {
151
+ return;
152
+ }
153
+
154
+ // No more live references: tear it all down.
155
+ entry.local.delete();
156
+ this.#importedSymbols.delete(targetSymbol);
157
+ this.#importEntries.delete(targetSymbol);
158
+
159
+ const moduleSet = this.#importedModules.get(entry.module);
160
+ if (moduleSet) {
161
+ for (const imp of moduleSet) {
162
+ if (imp.target === targetSymbol) {
163
+ moduleSet.delete(imp);
164
+ break;
165
+ }
166
+ }
167
+ if (moduleSet.size === 0) {
168
+ this.#importedModules.delete(entry.module);
169
+ }
170
+ }
171
+ }
172
+
96
173
  getAllSymbols() {
97
174
  const allSymbols = new Set<TSOutputSymbol>();
98
175
  for (const symbol of this.values) {