@alloy-js/typescript 0.1.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 (251) hide show
  1. package/LICENSE.txt +7 -0
  2. package/api-extractor.json +4 -0
  3. package/babel.config.cjs +4 -0
  4. package/dist/src/builtins/index.d.ts +2 -0
  5. package/dist/src/builtins/index.d.ts.map +1 -0
  6. package/dist/src/builtins/index.js +1 -0
  7. package/dist/src/builtins/index.js.map +1 -0
  8. package/dist/src/builtins/node.d.ts +183 -0
  9. package/dist/src/builtins/node.d.ts.map +1 -0
  10. package/dist/src/builtins/node.js +39 -0
  11. package/dist/src/builtins/node.js.map +1 -0
  12. package/dist/src/components/ArrayExpression.d.ts +7 -0
  13. package/dist/src/components/ArrayExpression.d.ts.map +1 -0
  14. package/dist/src/components/ArrayExpression.js +37 -0
  15. package/dist/src/components/ArrayExpression.js.map +1 -0
  16. package/dist/src/components/BarrelFile.d.ts +49 -0
  17. package/dist/src/components/BarrelFile.d.ts.map +1 -0
  18. package/dist/src/components/BarrelFile.js +73 -0
  19. package/dist/src/components/BarrelFile.js.map +1 -0
  20. package/dist/src/components/Block.d.ts +6 -0
  21. package/dist/src/components/Block.d.ts.map +1 -0
  22. package/dist/src/components/Block.js +11 -0
  23. package/dist/src/components/Block.js.map +1 -0
  24. package/dist/src/components/ClassDeclaration.d.ts +64 -0
  25. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  26. package/dist/src/components/ClassDeclaration.js +122 -0
  27. package/dist/src/components/ClassDeclaration.js.map +1 -0
  28. package/dist/src/components/Declaration.d.ts +53 -0
  29. package/dist/src/components/Declaration.d.ts.map +1 -0
  30. package/dist/src/components/Declaration.js +60 -0
  31. package/dist/src/components/Declaration.js.map +1 -0
  32. package/dist/src/components/EnumDeclaration.d.ts +12 -0
  33. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  34. package/dist/src/components/EnumDeclaration.js +48 -0
  35. package/dist/src/components/EnumDeclaration.js.map +1 -0
  36. package/dist/src/components/EnumMember.d.ts +28 -0
  37. package/dist/src/components/EnumMember.d.ts.map +1 -0
  38. package/dist/src/components/EnumMember.js +28 -0
  39. package/dist/src/components/EnumMember.js.map +1 -0
  40. package/dist/src/components/ExportStatement.d.ts +7 -0
  41. package/dist/src/components/ExportStatement.d.ts.map +1 -0
  42. package/dist/src/components/ExportStatement.js +15 -0
  43. package/dist/src/components/ExportStatement.js.map +1 -0
  44. package/dist/src/components/FunctionCallExpression.d.ts +7 -0
  45. package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
  46. package/dist/src/components/FunctionCallExpression.js +14 -0
  47. package/dist/src/components/FunctionCallExpression.js.map +1 -0
  48. package/dist/src/components/FunctionDeclaration.d.ts +29 -0
  49. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
  50. package/dist/src/components/FunctionDeclaration.js +91 -0
  51. package/dist/src/components/FunctionDeclaration.js.map +1 -0
  52. package/dist/src/components/ImportStatement.d.ts +11 -0
  53. package/dist/src/components/ImportStatement.d.ts.map +1 -0
  54. package/dist/src/components/ImportStatement.js +92 -0
  55. package/dist/src/components/ImportStatement.js.map +1 -0
  56. package/dist/src/components/Interface.d.ts +32 -0
  57. package/dist/src/components/Interface.d.ts.map +1 -0
  58. package/dist/src/components/Interface.js +50 -0
  59. package/dist/src/components/Interface.js.map +1 -0
  60. package/dist/src/components/ObjectExpression.d.ts +16 -0
  61. package/dist/src/components/ObjectExpression.d.ts.map +1 -0
  62. package/dist/src/components/ObjectExpression.js +101 -0
  63. package/dist/src/components/ObjectExpression.js.map +1 -0
  64. package/dist/src/components/PackageDirectory.d.ts +23 -0
  65. package/dist/src/components/PackageDirectory.d.ts.map +1 -0
  66. package/dist/src/components/PackageDirectory.js +62 -0
  67. package/dist/src/components/PackageDirectory.js.map +1 -0
  68. package/dist/src/components/PackageJson.d.ts +16 -0
  69. package/dist/src/components/PackageJson.d.ts.map +1 -0
  70. package/dist/src/components/PackageJson.js +36 -0
  71. package/dist/src/components/PackageJson.js.map +1 -0
  72. package/dist/src/components/Reference.d.ts +6 -0
  73. package/dist/src/components/Reference.d.ts.map +1 -0
  74. package/dist/src/components/Reference.js +8 -0
  75. package/dist/src/components/Reference.js.map +1 -0
  76. package/dist/src/components/SourceFile.d.ts +15 -0
  77. package/dist/src/components/SourceFile.d.ts.map +1 -0
  78. package/dist/src/components/SourceFile.js +62 -0
  79. package/dist/src/components/SourceFile.js.map +1 -0
  80. package/dist/src/components/TsConfigJson.d.ts +5 -0
  81. package/dist/src/components/TsConfigJson.d.ts.map +1 -0
  82. package/dist/src/components/TsConfigJson.js +53 -0
  83. package/dist/src/components/TsConfigJson.js.map +1 -0
  84. package/dist/src/components/TypeDeclaration.d.ts +5 -0
  85. package/dist/src/components/TypeDeclaration.d.ts.map +1 -0
  86. package/dist/src/components/TypeDeclaration.js +14 -0
  87. package/dist/src/components/TypeDeclaration.js.map +1 -0
  88. package/dist/src/components/ValueExpression.d.ts +5 -0
  89. package/dist/src/components/ValueExpression.d.ts.map +1 -0
  90. package/dist/src/components/ValueExpression.js +32 -0
  91. package/dist/src/components/ValueExpression.js.map +1 -0
  92. package/dist/src/components/VarDeclaration.d.ts +11 -0
  93. package/dist/src/components/VarDeclaration.d.ts.map +1 -0
  94. package/dist/src/components/VarDeclaration.js +29 -0
  95. package/dist/src/components/VarDeclaration.js.map +1 -0
  96. package/dist/src/components/index.d.ts +22 -0
  97. package/dist/src/components/index.d.ts.map +1 -0
  98. package/dist/src/components/index.js +22 -0
  99. package/dist/src/components/index.js.map +1 -0
  100. package/dist/src/components/stc/index.d.ts +102 -0
  101. package/dist/src/components/stc/index.d.ts.map +1 -0
  102. package/dist/src/components/stc/index.js +28 -0
  103. package/dist/src/components/stc/index.js.map +1 -0
  104. package/dist/src/create-package.d.ts +33 -0
  105. package/dist/src/create-package.d.ts.map +1 -0
  106. package/dist/src/create-package.js +50 -0
  107. package/dist/src/create-package.js.map +1 -0
  108. package/dist/src/index.d.ts +7 -0
  109. package/dist/src/index.d.ts.map +1 -0
  110. package/dist/src/index.js +7 -0
  111. package/dist/src/index.js.map +1 -0
  112. package/dist/src/name-conflict-resolver.d.ts +3 -0
  113. package/dist/src/name-conflict-resolver.d.ts.map +1 -0
  114. package/dist/src/name-conflict-resolver.js +15 -0
  115. package/dist/src/name-conflict-resolver.js.map +1 -0
  116. package/dist/src/name-policy.d.ts +5 -0
  117. package/dist/src/name-policy.d.ts.map +1 -0
  118. package/dist/src/name-policy.js +23 -0
  119. package/dist/src/name-policy.js.map +1 -0
  120. package/dist/src/source-directory-data.d.ts +7 -0
  121. package/dist/src/source-directory-data.d.ts.map +1 -0
  122. package/dist/src/source-directory-data.js +13 -0
  123. package/dist/src/source-directory-data.js.map +1 -0
  124. package/dist/src/symbols/index.d.ts +7 -0
  125. package/dist/src/symbols/index.d.ts.map +1 -0
  126. package/dist/src/symbols/index.js +7 -0
  127. package/dist/src/symbols/index.js.map +1 -0
  128. package/dist/src/symbols/reference.d.ts +3 -0
  129. package/dist/src/symbols/reference.d.ts.map +1 -0
  130. package/dist/src/symbols/reference.js +75 -0
  131. package/dist/src/symbols/reference.js.map +1 -0
  132. package/dist/src/symbols/scopes.d.ts +16 -0
  133. package/dist/src/symbols/scopes.d.ts.map +1 -0
  134. package/dist/src/symbols/scopes.js +5 -0
  135. package/dist/src/symbols/scopes.js.map +1 -0
  136. package/dist/src/symbols/ts-member-scope.d.ts +9 -0
  137. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -0
  138. package/dist/src/symbols/ts-member-scope.js +10 -0
  139. package/dist/src/symbols/ts-member-scope.js.map +1 -0
  140. package/dist/src/symbols/ts-module-scope.d.ts +19 -0
  141. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -0
  142. package/dist/src/symbols/ts-module-scope.js +36 -0
  143. package/dist/src/symbols/ts-module-scope.js.map +1 -0
  144. package/dist/src/symbols/ts-output-symbol.d.ts +28 -0
  145. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -0
  146. package/dist/src/symbols/ts-output-symbol.js +30 -0
  147. package/dist/src/symbols/ts-output-symbol.js.map +1 -0
  148. package/dist/src/symbols/ts-package-scope.d.ts +54 -0
  149. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -0
  150. package/dist/src/symbols/ts-package-scope.js +40 -0
  151. package/dist/src/symbols/ts-package-scope.js.map +1 -0
  152. package/dist/src/utils.d.ts +2 -0
  153. package/dist/src/utils.d.ts.map +1 -0
  154. package/dist/src/utils.js +7 -0
  155. package/dist/src/utils.js.map +1 -0
  156. package/dist/test/array.test.d.ts +2 -0
  157. package/dist/test/array.test.d.ts.map +1 -0
  158. package/dist/test/barrel.test.d.ts +2 -0
  159. package/dist/test/barrel.test.d.ts.map +1 -0
  160. package/dist/test/basic.test.d.ts +2 -0
  161. package/dist/test/basic.test.d.ts.map +1 -0
  162. package/dist/test/class.test.d.ts +2 -0
  163. package/dist/test/class.test.d.ts.map +1 -0
  164. package/dist/test/enum.test.d.ts +2 -0
  165. package/dist/test/enum.test.d.ts.map +1 -0
  166. package/dist/test/externals.test.d.ts +2 -0
  167. package/dist/test/externals.test.d.ts.map +1 -0
  168. package/dist/test/function-call-expression.test.d.ts +2 -0
  169. package/dist/test/function-call-expression.test.d.ts.map +1 -0
  170. package/dist/test/function-declaration.test.d.ts +2 -0
  171. package/dist/test/function-declaration.test.d.ts.map +1 -0
  172. package/dist/test/imports.test.d.ts +2 -0
  173. package/dist/test/imports.test.d.ts.map +1 -0
  174. package/dist/test/interface.test.d.ts +2 -0
  175. package/dist/test/interface.test.d.ts.map +1 -0
  176. package/dist/test/name-policy.test.d.ts +2 -0
  177. package/dist/test/name-policy.test.d.ts.map +1 -0
  178. package/dist/test/package-external.test.d.ts +2 -0
  179. package/dist/test/package-external.test.d.ts.map +1 -0
  180. package/dist/test/package.test.d.ts +2 -0
  181. package/dist/test/package.test.d.ts.map +1 -0
  182. package/dist/test/reference.test.d.ts +2 -0
  183. package/dist/test/reference.test.d.ts.map +1 -0
  184. package/dist/test/utils.d.ts +5 -0
  185. package/dist/test/utils.d.ts.map +1 -0
  186. package/dist/test/values.test.d.ts +2 -0
  187. package/dist/test/values.test.d.ts.map +1 -0
  188. package/dist/test/var-declaration.test.d.ts +2 -0
  189. package/dist/test/var-declaration.test.d.ts.map +1 -0
  190. package/dist/tsconfig.tsbuildinfo +1 -0
  191. package/package.json +49 -0
  192. package/src/builtins/index.ts +1 -0
  193. package/src/builtins/node.ts +219 -0
  194. package/src/components/ArrayExpression.tsx +41 -0
  195. package/src/components/BarrelFile.tsx +96 -0
  196. package/src/components/Block.tsx +12 -0
  197. package/src/components/ClassDeclaration.tsx +145 -0
  198. package/src/components/Declaration.tsx +105 -0
  199. package/src/components/EnumDeclaration.tsx +53 -0
  200. package/src/components/EnumMember.tsx +52 -0
  201. package/src/components/ExportStatement.tsx +21 -0
  202. package/src/components/FunctionCallExpression.tsx +15 -0
  203. package/src/components/FunctionDeclaration.tsx +132 -0
  204. package/src/components/ImportStatement.tsx +131 -0
  205. package/src/components/Interface.tsx +62 -0
  206. package/src/components/ObjectExpression.tsx +130 -0
  207. package/src/components/PackageDirectory.tsx +104 -0
  208. package/src/components/PackageJson.tsx +69 -0
  209. package/src/components/Reference.tsx +12 -0
  210. package/src/components/SourceFile.tsx +71 -0
  211. package/src/components/TsConfigJson.tsx +62 -0
  212. package/src/components/TypeDeclaration.tsx +10 -0
  213. package/src/components/ValueExpression.tsx +32 -0
  214. package/src/components/VarDeclaration.tsx +42 -0
  215. package/src/components/index.ts +21 -0
  216. package/src/components/stc/index.ts +28 -0
  217. package/src/create-package.ts +108 -0
  218. package/src/index.ts +6 -0
  219. package/src/name-conflict-resolver.ts +22 -0
  220. package/src/name-policy.ts +39 -0
  221. package/src/source-directory-data.ts +25 -0
  222. package/src/symbols/index.ts +6 -0
  223. package/src/symbols/reference.ts +120 -0
  224. package/src/symbols/scopes.ts +28 -0
  225. package/src/symbols/ts-member-scope.ts +23 -0
  226. package/src/symbols/ts-module-scope.ts +66 -0
  227. package/src/symbols/ts-output-symbol.ts +63 -0
  228. package/src/symbols/ts-package-scope.ts +112 -0
  229. package/src/utils.ts +7 -0
  230. package/temp/api.json +9866 -0
  231. package/test/array.test.tsx +14 -0
  232. package/test/barrel.test.tsx +46 -0
  233. package/test/basic.test.tsx +78 -0
  234. package/test/class.test.tsx +181 -0
  235. package/test/enum.test.tsx +132 -0
  236. package/test/externals.test.tsx +139 -0
  237. package/test/function-call-expression.test.tsx +49 -0
  238. package/test/function-declaration.test.tsx +201 -0
  239. package/test/imports.test.tsx +213 -0
  240. package/test/interface.test.tsx +124 -0
  241. package/test/name-policy.test.tsx +62 -0
  242. package/test/package-external.test.tsx +75 -0
  243. package/test/package.test.tsx +68 -0
  244. package/test/reference.test.tsx +59 -0
  245. package/test/utils.tsx +59 -0
  246. package/test/values.test.tsx +292 -0
  247. package/test/var-declaration.test.tsx +45 -0
  248. package/test/vitest.d.ts +10 -0
  249. package/tsconfig.json +11 -0
  250. package/tsdoc-metadata.json +11 -0
  251. package/vitest.config.ts +18 -0
@@ -0,0 +1,28 @@
1
+ import { OutputScope, useScope } from "@alloy-js/core";
2
+ import { TSMemberScope } from "./ts-member-scope.js";
3
+ import { TSModuleScope } from "./ts-module-scope.js";
4
+ import { TSPackageScope } from "./ts-package-scope.js";
5
+
6
+ export type TSOutputScope =
7
+ | TSGlobalScope
8
+ | TSPackageScope
9
+ | TSModuleScope
10
+ | TSFunctionScope
11
+ | TSMemberScope
12
+ | TSOtherScope;
13
+
14
+ export interface TSGlobalScope extends OutputScope {
15
+ kind: "global";
16
+ }
17
+
18
+ export interface TSFunctionScope extends OutputScope {
19
+ kind: "function";
20
+ }
21
+
22
+ export interface TSOtherScope extends OutputScope {
23
+ kind: never;
24
+ }
25
+
26
+ export function useTSScope() {
27
+ return useScope() as TSOutputScope;
28
+ }
@@ -0,0 +1,23 @@
1
+ import { Binder, OutputScope } from "@alloy-js/core";
2
+ import { TSOutputSymbol } from "./ts-output-symbol.js";
3
+
4
+ export interface TSMemberScope extends OutputScope {
5
+ kind: "member";
6
+ owner: TSOutputSymbol;
7
+ isStatic: boolean;
8
+ }
9
+
10
+ export function createTSMemberScope(
11
+ binder: Binder,
12
+ parent: OutputScope,
13
+ owner: TSOutputSymbol,
14
+ isStatic: boolean = false,
15
+ ): TSMemberScope {
16
+ return binder.createScope<TSMemberScope>({
17
+ kind: "member",
18
+ name: "members",
19
+ owner,
20
+ parent,
21
+ isStatic,
22
+ });
23
+ }
@@ -0,0 +1,66 @@
1
+ import { Binder, OutputScope, Refkey, refkey } from "@alloy-js/core";
2
+ import {
3
+ createTSSymbol,
4
+ TSOutputSymbol,
5
+ TSSymbolFlags,
6
+ } from "./ts-output-symbol.js";
7
+
8
+ export interface ImportedSymbol {
9
+ local: TSOutputSymbol;
10
+ target: TSOutputSymbol;
11
+ }
12
+ export type ImportRecords = Map<TSModuleScope, Set<ImportedSymbol>>;
13
+
14
+ export interface TSModuleScope extends OutputScope {
15
+ kind: "module";
16
+ exportedSymbols: Map<Refkey, TSOutputSymbol>;
17
+ /**
18
+ * A mapping of foreign symbols to module-local symbols
19
+ */
20
+ importedSymbols: Map<TSOutputSymbol, TSOutputSymbol>;
21
+ importedModules: ImportRecords;
22
+ addImport(symbol: TSOutputSymbol, module: TSModuleScope): TSOutputSymbol;
23
+ }
24
+
25
+ export function createTSModuleScope(
26
+ binder: Binder,
27
+ parent: OutputScope,
28
+ path: string,
29
+ ): TSModuleScope {
30
+ return binder.createScope<TSModuleScope>({
31
+ kind: "module",
32
+ name: path,
33
+ parent,
34
+ exportedSymbols: new Map(),
35
+ importedSymbols: new Map(),
36
+ importedModules: new Map(),
37
+ addImport(targetSymbol, targetModule) {
38
+ if (this.importedSymbols.has(targetSymbol)) {
39
+ return this.importedSymbols.get(targetSymbol)!;
40
+ }
41
+
42
+ if (targetModule.kind !== "module") {
43
+ throw new Error("Cannot import symbol that isn't in module scope");
44
+ }
45
+
46
+ if (!this.importedModules.has(targetModule)) {
47
+ this.importedModules.set(targetModule, new Set());
48
+ }
49
+
50
+ const localSymbol = createTSSymbol({
51
+ binder,
52
+ name: targetSymbol.name,
53
+ refkey: refkey({}),
54
+ tsFlags: TSSymbolFlags.LocalImportSymbol,
55
+ });
56
+
57
+ this.importedSymbols.set(targetSymbol, localSymbol);
58
+ this.importedModules.get(targetModule)!.add({
59
+ local: localSymbol,
60
+ target: targetSymbol,
61
+ });
62
+
63
+ return localSymbol;
64
+ },
65
+ });
66
+ }
@@ -0,0 +1,63 @@
1
+ import {
2
+ Binder,
3
+ OutputSymbol,
4
+ OutputSymbolFlags,
5
+ Refkey,
6
+ useDefaultScope,
7
+ } from "@alloy-js/core";
8
+ import { TSOutputScope } from "./scopes.js";
9
+ import { TSMemberScope } from "./ts-member-scope.js";
10
+
11
+ // prettier-ignore
12
+ export enum TSSymbolFlags {
13
+ None = 0,
14
+ LocalImportSymbol = 1 << 0,
15
+ TypeSymbol = 1 << 1,
16
+ ParameterSymbol = 1 << 2,
17
+ }
18
+
19
+ export interface TSOutputSymbol extends OutputSymbol {
20
+ scope: TSOutputScope;
21
+ export: boolean;
22
+ default: boolean;
23
+ tsFlags: TSSymbolFlags;
24
+ memberScope?: TSMemberScope;
25
+ }
26
+
27
+ export interface createTsSymbolOptions {
28
+ name: string;
29
+ refkey: Refkey;
30
+ binder?: Binder;
31
+ scope?: TSOutputScope;
32
+ export?: boolean;
33
+ default?: boolean;
34
+ flags?: OutputSymbolFlags;
35
+ tsFlags?: TSSymbolFlags;
36
+ }
37
+
38
+ export function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol {
39
+ const scope =
40
+ options.scope ?? (useDefaultScope(options.flags) as TSOutputScope);
41
+
42
+ if (scope.kind !== "module" && (options.export || options.default)) {
43
+ throw new Error("Can't export symbol from non-module scope");
44
+ }
45
+
46
+ const binder = scope.binder;
47
+
48
+ const sym = binder.createSymbol<TSOutputSymbol>({
49
+ name: options.name,
50
+ scope,
51
+ refkey: options.refkey,
52
+ export: !!options.export,
53
+ default: !!options.default,
54
+ flags: options.flags ?? OutputSymbolFlags.None,
55
+ tsFlags: options.tsFlags ?? TSSymbolFlags.None,
56
+ });
57
+
58
+ if (options.export && scope.kind === "module") {
59
+ scope.exportedSymbols.set(sym.refkey, sym);
60
+ }
61
+
62
+ return sym;
63
+ }
@@ -0,0 +1,112 @@
1
+ import { Binder, OutputScope, Refkey } from "@alloy-js/core";
2
+ import {
3
+ ExportConditions,
4
+ PackageExports,
5
+ } from "../components/PackageJson.jsx";
6
+ import { modulePath } from "../utils.js";
7
+ import { TSModuleScope } from "./ts-module-scope.js";
8
+
9
+ export interface TSPackageScope extends OutputScope {
10
+ kind: "package";
11
+ /**
12
+ * The version of the this package.
13
+ */
14
+ version: string;
15
+
16
+ /**
17
+ * The symbols exported by this package. They are broken down by which paths
18
+ * they are exported from. It is possible a symbol may be present at multiple
19
+ * paths, in which case emitters can decide which symbol to use based on their
20
+ * own heuristics.
21
+ */
22
+ exportedSymbols: Map<string, TSModuleScope>;
23
+
24
+ /**
25
+ * The path of the root directory of the package.
26
+ */
27
+ path: string;
28
+
29
+ /**
30
+ * The scopes for the packages this package depends on.
31
+ */
32
+ dependencies: Set<TSPackageScope>;
33
+
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
+ /**
49
+ * All of the modules contained within the package. These modules may or may not
50
+ * be exported.
51
+ */
52
+ modules: Set<TSModuleScope>;
53
+
54
+ /**
55
+ * Whether this is a built-in package provided by the platform.
56
+ */
57
+ builtin?: boolean;
58
+
59
+ addExport(publicPath: string, localModule: TSModuleScope): void;
60
+ addRawExport(publicPath: string, exportPath: string | ExportConditions): void;
61
+ addDependency(pkg: TSPackageScope): void;
62
+ addRawDependency(packageName: string, version: string): void;
63
+ addModule(module: TSModuleScope): void;
64
+ findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
65
+ }
66
+
67
+ export function createTSPackageScope(
68
+ binder: Binder,
69
+ parent: OutputScope | undefined,
70
+ name: string,
71
+ version: string,
72
+ path: string,
73
+ builtin: boolean = false,
74
+ ) {
75
+ return binder.createScope<TSPackageScope>({
76
+ kind: "package",
77
+ name,
78
+ parent,
79
+ exportedSymbols: new Map(),
80
+ dependencies: new Set(),
81
+ rawDependencies: new Map(),
82
+ rawExports: {},
83
+ modules: new Set(),
84
+ version,
85
+ path: path,
86
+ builtin,
87
+ addDependency(pkg) {
88
+ this.dependencies.add(pkg);
89
+ },
90
+ addExport(publicPath, module) {
91
+ this.exportedSymbols.set(modulePath(publicPath), module);
92
+ },
93
+ addRawDependency(packageName, version) {
94
+ this.rawDependencies.set(packageName, version);
95
+ },
96
+ addRawExport(localPath, exportPath) {
97
+ this.rawExports[localPath] = exportPath;
98
+ },
99
+ addModule(module) {
100
+ this.modules.add(module);
101
+ },
102
+ findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null {
103
+ for (const [publicPath, module] of this.exportedSymbols) {
104
+ if (module.exportedSymbols.has(refkey)) {
105
+ return [publicPath, module];
106
+ }
107
+ }
108
+
109
+ return null;
110
+ },
111
+ });
112
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,7 @@
1
+ export function modulePath(path: string) {
2
+ if (path[0] !== ".") {
3
+ path = "./" + path;
4
+ }
5
+
6
+ return path.replace(/\.ts$/, ".js");
7
+ }