@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.
- package/LICENSE.txt +7 -0
- package/api-extractor.json +4 -0
- package/babel.config.cjs +4 -0
- package/dist/src/builtins/index.d.ts +2 -0
- package/dist/src/builtins/index.d.ts.map +1 -0
- package/dist/src/builtins/index.js +1 -0
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/node.d.ts +183 -0
- package/dist/src/builtins/node.d.ts.map +1 -0
- package/dist/src/builtins/node.js +39 -0
- package/dist/src/builtins/node.js.map +1 -0
- package/dist/src/components/ArrayExpression.d.ts +7 -0
- package/dist/src/components/ArrayExpression.d.ts.map +1 -0
- package/dist/src/components/ArrayExpression.js +37 -0
- package/dist/src/components/ArrayExpression.js.map +1 -0
- package/dist/src/components/BarrelFile.d.ts +49 -0
- package/dist/src/components/BarrelFile.d.ts.map +1 -0
- package/dist/src/components/BarrelFile.js +73 -0
- package/dist/src/components/BarrelFile.js.map +1 -0
- package/dist/src/components/Block.d.ts +6 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +11 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts +64 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/ClassDeclaration.js +122 -0
- package/dist/src/components/ClassDeclaration.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +53 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +60 -0
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts +12 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/EnumDeclaration.js +48 -0
- package/dist/src/components/EnumDeclaration.js.map +1 -0
- package/dist/src/components/EnumMember.d.ts +28 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -0
- package/dist/src/components/EnumMember.js +28 -0
- package/dist/src/components/EnumMember.js.map +1 -0
- package/dist/src/components/ExportStatement.d.ts +7 -0
- package/dist/src/components/ExportStatement.d.ts.map +1 -0
- package/dist/src/components/ExportStatement.js +15 -0
- package/dist/src/components/ExportStatement.js.map +1 -0
- package/dist/src/components/FunctionCallExpression.d.ts +7 -0
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +14 -0
- package/dist/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts +29 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
- package/dist/src/components/FunctionDeclaration.js +91 -0
- package/dist/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts +11 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +92 -0
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +32 -0
- package/dist/src/components/Interface.d.ts.map +1 -0
- package/dist/src/components/Interface.js +50 -0
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +16 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -0
- package/dist/src/components/ObjectExpression.js +101 -0
- package/dist/src/components/ObjectExpression.js.map +1 -0
- package/dist/src/components/PackageDirectory.d.ts +23 -0
- package/dist/src/components/PackageDirectory.d.ts.map +1 -0
- package/dist/src/components/PackageDirectory.js +62 -0
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/PackageJson.d.ts +16 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -0
- package/dist/src/components/PackageJson.js +36 -0
- package/dist/src/components/PackageJson.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +8 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +15 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +62 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/TsConfigJson.d.ts +5 -0
- package/dist/src/components/TsConfigJson.d.ts.map +1 -0
- package/dist/src/components/TsConfigJson.js +53 -0
- package/dist/src/components/TsConfigJson.js.map +1 -0
- package/dist/src/components/TypeDeclaration.d.ts +5 -0
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -0
- package/dist/src/components/TypeDeclaration.js +14 -0
- package/dist/src/components/TypeDeclaration.js.map +1 -0
- package/dist/src/components/ValueExpression.d.ts +5 -0
- package/dist/src/components/ValueExpression.d.ts.map +1 -0
- package/dist/src/components/ValueExpression.js +32 -0
- package/dist/src/components/ValueExpression.js.map +1 -0
- package/dist/src/components/VarDeclaration.d.ts +11 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -0
- package/dist/src/components/VarDeclaration.js +29 -0
- package/dist/src/components/VarDeclaration.js.map +1 -0
- package/dist/src/components/index.d.ts +22 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +22 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +102 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +28 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/create-package.d.ts +33 -0
- package/dist/src/create-package.d.ts.map +1 -0
- package/dist/src/create-package.js +50 -0
- package/dist/src/create-package.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-conflict-resolver.d.ts +3 -0
- package/dist/src/name-conflict-resolver.d.ts.map +1 -0
- package/dist/src/name-conflict-resolver.js +15 -0
- package/dist/src/name-conflict-resolver.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +23 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/source-directory-data.d.ts +7 -0
- package/dist/src/source-directory-data.d.ts.map +1 -0
- package/dist/src/source-directory-data.js +13 -0
- package/dist/src/source-directory-data.js.map +1 -0
- package/dist/src/symbols/index.d.ts +7 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +7 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +3 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +75 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +16 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +5 -0
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/src/symbols/ts-member-scope.d.ts +9 -0
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-member-scope.js +10 -0
- package/dist/src/symbols/ts-member-scope.js.map +1 -0
- package/dist/src/symbols/ts-module-scope.d.ts +19 -0
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-module-scope.js +36 -0
- package/dist/src/symbols/ts-module-scope.js.map +1 -0
- package/dist/src/symbols/ts-output-symbol.d.ts +28 -0
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/ts-output-symbol.js +30 -0
- package/dist/src/symbols/ts-output-symbol.js.map +1 -0
- package/dist/src/symbols/ts-package-scope.d.ts +54 -0
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-package-scope.js +40 -0
- package/dist/src/symbols/ts-package-scope.js.map +1 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +7 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/array.test.d.ts +2 -0
- package/dist/test/array.test.d.ts.map +1 -0
- package/dist/test/barrel.test.d.ts +2 -0
- package/dist/test/barrel.test.d.ts.map +1 -0
- package/dist/test/basic.test.d.ts +2 -0
- package/dist/test/basic.test.d.ts.map +1 -0
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/enum.test.d.ts +2 -0
- package/dist/test/enum.test.d.ts.map +1 -0
- package/dist/test/externals.test.d.ts +2 -0
- package/dist/test/externals.test.d.ts.map +1 -0
- package/dist/test/function-call-expression.test.d.ts +2 -0
- package/dist/test/function-call-expression.test.d.ts.map +1 -0
- package/dist/test/function-declaration.test.d.ts +2 -0
- package/dist/test/function-declaration.test.d.ts.map +1 -0
- package/dist/test/imports.test.d.ts +2 -0
- package/dist/test/imports.test.d.ts.map +1 -0
- package/dist/test/interface.test.d.ts +2 -0
- package/dist/test/interface.test.d.ts.map +1 -0
- package/dist/test/name-policy.test.d.ts +2 -0
- package/dist/test/name-policy.test.d.ts.map +1 -0
- package/dist/test/package-external.test.d.ts +2 -0
- package/dist/test/package-external.test.d.ts.map +1 -0
- package/dist/test/package.test.d.ts +2 -0
- package/dist/test/package.test.d.ts.map +1 -0
- package/dist/test/reference.test.d.ts +2 -0
- package/dist/test/reference.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +5 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/values.test.d.ts +2 -0
- package/dist/test/values.test.d.ts.map +1 -0
- package/dist/test/var-declaration.test.d.ts +2 -0
- package/dist/test/var-declaration.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +49 -0
- package/src/builtins/index.ts +1 -0
- package/src/builtins/node.ts +219 -0
- package/src/components/ArrayExpression.tsx +41 -0
- package/src/components/BarrelFile.tsx +96 -0
- package/src/components/Block.tsx +12 -0
- package/src/components/ClassDeclaration.tsx +145 -0
- package/src/components/Declaration.tsx +105 -0
- package/src/components/EnumDeclaration.tsx +53 -0
- package/src/components/EnumMember.tsx +52 -0
- package/src/components/ExportStatement.tsx +21 -0
- package/src/components/FunctionCallExpression.tsx +15 -0
- package/src/components/FunctionDeclaration.tsx +132 -0
- package/src/components/ImportStatement.tsx +131 -0
- package/src/components/Interface.tsx +62 -0
- package/src/components/ObjectExpression.tsx +130 -0
- package/src/components/PackageDirectory.tsx +104 -0
- package/src/components/PackageJson.tsx +69 -0
- package/src/components/Reference.tsx +12 -0
- package/src/components/SourceFile.tsx +71 -0
- package/src/components/TsConfigJson.tsx +62 -0
- package/src/components/TypeDeclaration.tsx +10 -0
- package/src/components/ValueExpression.tsx +32 -0
- package/src/components/VarDeclaration.tsx +42 -0
- package/src/components/index.ts +21 -0
- package/src/components/stc/index.ts +28 -0
- package/src/create-package.ts +108 -0
- package/src/index.ts +6 -0
- package/src/name-conflict-resolver.ts +22 -0
- package/src/name-policy.ts +39 -0
- package/src/source-directory-data.ts +25 -0
- package/src/symbols/index.ts +6 -0
- package/src/symbols/reference.ts +120 -0
- package/src/symbols/scopes.ts +28 -0
- package/src/symbols/ts-member-scope.ts +23 -0
- package/src/symbols/ts-module-scope.ts +66 -0
- package/src/symbols/ts-output-symbol.ts +63 -0
- package/src/symbols/ts-package-scope.ts +112 -0
- package/src/utils.ts +7 -0
- package/temp/api.json +9866 -0
- package/test/array.test.tsx +14 -0
- package/test/barrel.test.tsx +46 -0
- package/test/basic.test.tsx +78 -0
- package/test/class.test.tsx +181 -0
- package/test/enum.test.tsx +132 -0
- package/test/externals.test.tsx +139 -0
- package/test/function-call-expression.test.tsx +49 -0
- package/test/function-declaration.test.tsx +201 -0
- package/test/imports.test.tsx +213 -0
- package/test/interface.test.tsx +124 -0
- package/test/name-policy.test.tsx +62 -0
- package/test/package-external.test.tsx +75 -0
- package/test/package.test.tsx +68 -0
- package/test/reference.test.tsx +59 -0
- package/test/utils.tsx +59 -0
- package/test/values.test.tsx +292 -0
- package/test/var-declaration.test.tsx +45 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +11 -0
- package/tsdoc-metadata.json +11 -0
- 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
|
+
}
|