@alloy-js/typescript 0.16.0 → 0.17.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/CHANGELOG.md +13 -0
- package/dist/src/builtins/node.d.ts +9 -41
- package/dist/src/builtins/node.d.ts.map +1 -1
- package/dist/src/components/ArrowFunction.d.ts +3 -3
- package/dist/src/components/BarrelFile.d.ts +1 -1
- package/dist/src/components/BarrelFile.d.ts.map +1 -1
- package/dist/src/components/BlockScope.d.ts +1 -1
- package/dist/src/components/BlockScope.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +5 -7
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -4
- package/dist/src/components/EnumDeclaration.d.ts +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +3 -4
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +3 -4
- package/dist/src/components/FunctionBase.d.ts +4 -4
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +15 -10
- package/dist/src/components/FunctionDeclaration.d.ts +3 -3
- package/dist/src/components/FunctionExpression.d.ts +3 -3
- package/dist/src/components/FunctionType.d.ts +2 -2
- package/dist/src/components/ImportStatement.d.ts +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/Interface.js +1 -1
- package/dist/src/components/InterfaceMethod.d.ts +2 -2
- package/dist/src/components/MemberDeclaration.d.ts +1 -1
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +4 -4
- package/dist/src/components/MemberExpression.d.ts +6 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +38 -14
- package/dist/src/components/NewExpression.d.ts +5 -0
- package/dist/src/components/NewExpression.d.ts.map +1 -0
- package/dist/src/components/NewExpression.js +12 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +14 -15
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +3 -3
- package/dist/src/components/PackageJson.d.ts +1 -1
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PropertyName.d.ts +1 -1
- package/dist/src/components/PropertyName.d.ts.map +1 -1
- package/dist/src/components/Reference.d.ts +1 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +5 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +3 -3
- package/dist/src/components/TsConfigJson.d.ts +1 -1
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +30 -10
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/stc/index.d.ts +45 -43
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +46 -44
- package/dist/src/create-package.d.ts +62 -18
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +153 -15
- package/dist/src/source-directory-data.d.ts.map +1 -1
- package/dist/src/source-directory-data.js +2 -2
- package/dist/src/symbols/reference.d.ts +2 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +3 -4
- package/dist/src/symbols/scopes.d.ts +1 -4
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.d.ts +4 -6
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +8 -10
- package/dist/src/symbols/ts-module-scope.d.ts +8 -11
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +47 -40
- package/dist/src/symbols/ts-output-symbol.d.ts +23 -16
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +88 -27
- package/dist/src/symbols/ts-package-scope.d.ts +18 -14
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +78 -27
- package/dist/test/class.test.js +2 -1
- package/dist/test/externals.test.js +87 -2
- package/dist/test/function-declaration.test.js +74 -3
- package/dist/test/member-expression.test.js +108 -2
- package/dist/test/new-expression.test.d.ts +2 -0
- package/dist/test/new-expression.test.d.ts.map +1 -0
- package/dist/test/new-expression.test.js +62 -0
- package/dist/test/var-declaration.test.d.ts.map +1 -1
- package/dist/test/var-declaration.test.js +145 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/ClassDeclaration.tsx +5 -7
- package/src/components/Declaration.tsx +3 -8
- package/src/components/EnumDeclaration.tsx +3 -4
- package/src/components/EnumMember.tsx +3 -4
- package/src/components/FunctionBase.tsx +25 -18
- package/src/components/ImportStatement.tsx +0 -1
- package/src/components/Interface.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +5 -8
- package/src/components/MemberExpression.tsx +67 -15
- package/src/components/NewExpression.tsx +25 -0
- package/src/components/ObjectExpression.tsx +18 -16
- package/src/components/PackageDirectory.tsx +2 -10
- package/src/components/Reference.tsx +4 -2
- package/src/components/SourceFile.tsx +2 -5
- package/src/components/VarDeclaration.tsx +34 -11
- package/src/components/index.ts +1 -0
- package/src/components/stc/index.ts +46 -44
- package/src/create-package.ts +274 -35
- package/src/source-directory-data.ts +2 -2
- package/src/symbols/reference.ts +10 -5
- package/src/symbols/scopes.ts +1 -6
- package/src/symbols/ts-member-scope.ts +8 -23
- package/src/symbols/ts-module-scope.ts +58 -62
- package/src/symbols/ts-output-symbol.ts +108 -50
- package/src/symbols/ts-package-scope.ts +71 -53
- package/temp/api.json +1589 -1619
- package/test/class.test.tsx +2 -1
- package/test/externals.test.tsx +99 -1
- package/test/function-declaration.test.tsx +75 -2
- package/test/member-expression.test.tsx +93 -2
- package/test/new-expression.test.tsx +42 -0
- package/test/values.test.tsx +1 -0
- package/test/var-declaration.test.tsx +101 -1
- package/tsdoc-metadata.json +1 -1
|
@@ -1,43 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { OutputScope, reactive, shallowReactive } from "@alloy-js/core";
|
|
2
|
+
import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
|
|
3
|
+
export class TSModuleScope extends OutputScope {
|
|
4
|
+
get kind() {
|
|
5
|
+
return "module";
|
|
6
|
+
}
|
|
7
|
+
#exportedSymbols = shallowReactive(new Map());
|
|
8
|
+
get exportedSymbols() {
|
|
9
|
+
return this.#exportedSymbols;
|
|
10
|
+
}
|
|
11
|
+
#importedSymbols = shallowReactive(new Map());
|
|
12
|
+
get importedSymbols() {
|
|
13
|
+
return this.#importedSymbols;
|
|
14
|
+
}
|
|
15
|
+
#importedModules = reactive(new Map());
|
|
16
|
+
get importedModules() {
|
|
17
|
+
return this.#importedModules;
|
|
18
|
+
}
|
|
19
|
+
addImport(targetSymbol, targetModule, options) {
|
|
20
|
+
const existing = this.importedSymbols.get(targetSymbol);
|
|
21
|
+
if (existing) {
|
|
22
|
+
if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
|
|
23
|
+
existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.importedModules.get(targetModule).add({
|
|
37
|
-
local: localSymbol,
|
|
38
|
-
target: targetSymbol
|
|
39
|
-
});
|
|
40
|
-
return localSymbol;
|
|
25
|
+
return existing;
|
|
26
|
+
}
|
|
27
|
+
if (targetModule.kind !== "module") {
|
|
28
|
+
throw new Error("Cannot import symbol that isn't in module scope");
|
|
29
|
+
}
|
|
30
|
+
if (!this.importedModules.has(targetModule)) {
|
|
31
|
+
this.importedModules.set(targetModule, new Set());
|
|
32
|
+
}
|
|
33
|
+
const localSymbol = new TSOutputSymbol(targetSymbol.name, {
|
|
34
|
+
binder: this.binder,
|
|
35
|
+
scope: this,
|
|
36
|
+
aliasTarget: targetSymbol,
|
|
37
|
+
tsFlags: TSSymbolFlags.LocalImportSymbol
|
|
38
|
+
});
|
|
39
|
+
targetSymbol.copyTo(localSymbol);
|
|
40
|
+
if (options?.type) {
|
|
41
|
+
localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
this.importedSymbols.set(targetSymbol, localSymbol);
|
|
44
|
+
this.importedModules.get(targetModule).add({
|
|
45
|
+
local: localSymbol,
|
|
46
|
+
target: targetSymbol
|
|
47
|
+
});
|
|
48
|
+
return localSymbol;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputScopeFlags, OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
|
|
2
2
|
import { TSOutputScope } from "./scopes.js";
|
|
3
3
|
import { TSMemberScope } from "./ts-member-scope.js";
|
|
4
4
|
export declare enum TSSymbolFlags {
|
|
@@ -10,24 +10,31 @@ export declare enum TSSymbolFlags {
|
|
|
10
10
|
PrivateMemberContainer = 16,
|
|
11
11
|
Nullish = 32
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
14
|
-
scope: TSOutputScope;
|
|
15
|
-
export: boolean;
|
|
16
|
-
default: boolean;
|
|
17
|
-
tsFlags: TSSymbolFlags;
|
|
18
|
-
privateMemberScope?: TSMemberScope;
|
|
19
|
-
privateStaticMemberScope?: TSMemberScope;
|
|
20
|
-
}
|
|
21
|
-
export interface createTsSymbolOptions {
|
|
22
|
-
name: string;
|
|
23
|
-
refkey?: Refkey | Refkey[];
|
|
24
|
-
binder?: Binder;
|
|
13
|
+
export interface CreateTsSymbolOptions extends OutputSymbolOptions {
|
|
25
14
|
scope?: TSOutputScope;
|
|
15
|
+
owner?: TSOutputSymbol;
|
|
26
16
|
export?: boolean;
|
|
27
17
|
default?: boolean;
|
|
28
|
-
flags?: OutputSymbolFlags;
|
|
29
18
|
tsFlags?: TSSymbolFlags;
|
|
30
|
-
metadata?: Record<string, unknown>;
|
|
31
19
|
}
|
|
32
|
-
export declare
|
|
20
|
+
export declare class TSOutputSymbol extends OutputSymbol {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(name: string, options?: CreateTsSymbolOptions);
|
|
23
|
+
get export(): boolean;
|
|
24
|
+
set export(value: boolean);
|
|
25
|
+
get default(): boolean;
|
|
26
|
+
set default(value: boolean);
|
|
27
|
+
get tsFlags(): TSSymbolFlags;
|
|
28
|
+
set tsFlags(value: TSSymbolFlags);
|
|
29
|
+
get scope(): TSOutputScope;
|
|
30
|
+
set scope(value: TSOutputScope);
|
|
31
|
+
get staticMemberScope(): TSMemberScope | undefined;
|
|
32
|
+
get instanceMemberScope(): TSMemberScope | undefined;
|
|
33
|
+
get privateMemberScope(): TSMemberScope | undefined;
|
|
34
|
+
get privateStaticMemberScope(): TSMemberScope | undefined;
|
|
35
|
+
protected createMemberScope(name: string, options: {
|
|
36
|
+
owner?: OutputSymbol;
|
|
37
|
+
flags?: OutputScopeFlags;
|
|
38
|
+
}): TSMemberScope;
|
|
39
|
+
}
|
|
33
40
|
//# sourceMappingURL=ts-output-symbol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"ts-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EAKpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,oBAAY,aAAa;IACvB,IAAI,IAAsB;IAC1B,iBAAiB,IAAc;IAC/B,UAAU,IAAqB;IAC/B,eAAe,IAAgB;IAC/B,aAAa,IAAkB;IAC/B,sBAAsB,KAAS;IAC/B,OAAO,KAAS;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,qBAAa,cAAe,SAAQ,YAAY;;gBAClC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;IAgC7D,IAAI,MAAM,IAKQ,OAAO,CAFxB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAMxB;IAGD,IAAI,OAAO,IAKQ,OAAO,CAFzB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAMzB;IAGD,IAAI,OAAO,IAIQ,aAAa,CAD/B;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,aAAa,EAO/B;IAED,IAAI,KAAK,IAGQ,aAAa,CAD7B;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,aAAa,EAE7B;IAED,IAAI,iBAAiB,IACe,aAAa,GAAG,SAAS,CAC5D;IAED,IAAI,mBAAmB,IACe,aAAa,GAAG,SAAS,CAC9D;IAGD,IAAI,kBAAkB,8BAErB;IAGD,IAAI,wBAAwB,8BAE3B;IAED,SAAS,CAAC,iBAAiB,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,YAAY,CAAC;QAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAC1D,aAAa;CAKjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { OutputScopeFlags, OutputSymbol, track, TrackOpTypes, trigger, TriggerOpTypes } from "@alloy-js/core";
|
|
2
|
+
import { TSMemberScope } from "./ts-member-scope.js";
|
|
3
3
|
|
|
4
4
|
// prettier-ignore
|
|
5
5
|
export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
|
|
@@ -12,31 +12,92 @@ export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
|
|
|
12
12
|
TSSymbolFlags[TSSymbolFlags["Nullish"] = 32] = "Nullish";
|
|
13
13
|
return TSSymbolFlags;
|
|
14
14
|
}({});
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
sym.privateStaticMemberScope = createTSMemberScope(binder, undefined, sym, true);
|
|
35
|
-
}
|
|
36
|
-
if (options.export && scope.kind === "module") {
|
|
37
|
-
for (const refkey of sym.refkeys) {
|
|
38
|
-
scope.exportedSymbols.set(refkey, sym);
|
|
15
|
+
export class TSOutputSymbol extends OutputSymbol {
|
|
16
|
+
constructor(name, options = {}) {
|
|
17
|
+
super(name, options);
|
|
18
|
+
this.#export = !!options.export;
|
|
19
|
+
this.#default = !!options.default;
|
|
20
|
+
this.#tsFlags = options.tsFlags ?? TSSymbolFlags.None;
|
|
21
|
+
this.#privateMemberScope = undefined;
|
|
22
|
+
this.#privateStaticMemberScope = undefined;
|
|
23
|
+
if (this.#tsFlags & TSSymbolFlags.PrivateMemberContainer) {
|
|
24
|
+
this.#privateMemberScope = new TSMemberScope("private members", {
|
|
25
|
+
binder: this.binder,
|
|
26
|
+
owner: this,
|
|
27
|
+
flags: OutputScopeFlags.InstanceMemberScope
|
|
28
|
+
});
|
|
29
|
+
this.#privateStaticMemberScope = new TSMemberScope("private static members", {
|
|
30
|
+
flags: OutputScopeFlags.StaticMemberScope,
|
|
31
|
+
binder: this.binder,
|
|
32
|
+
owner: this
|
|
33
|
+
});
|
|
39
34
|
}
|
|
35
|
+
if (options.export && this.scope.kind === "module") {
|
|
36
|
+
for (const refkey of this.refkeys) {
|
|
37
|
+
this.scope.exportedSymbols.set(refkey, this);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
#export;
|
|
42
|
+
get export() {
|
|
43
|
+
track(this, TrackOpTypes.GET, "export");
|
|
44
|
+
return this.#export;
|
|
45
|
+
}
|
|
46
|
+
set export(value) {
|
|
47
|
+
if (this.#export === value) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.#export = value;
|
|
51
|
+
trigger(this, TriggerOpTypes.SET, "export", value, !value);
|
|
52
|
+
}
|
|
53
|
+
#default;
|
|
54
|
+
get default() {
|
|
55
|
+
track(this, TrackOpTypes.GET, "default");
|
|
56
|
+
return this.#default;
|
|
57
|
+
}
|
|
58
|
+
set default(value) {
|
|
59
|
+
if (this.#default === value) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.#default = value;
|
|
63
|
+
trigger(this, TriggerOpTypes.SET, "default", value, !value);
|
|
64
|
+
}
|
|
65
|
+
#tsFlags;
|
|
66
|
+
get tsFlags() {
|
|
67
|
+
track(this, TrackOpTypes.GET, "tsFlags");
|
|
68
|
+
return this.#tsFlags;
|
|
69
|
+
}
|
|
70
|
+
set tsFlags(value) {
|
|
71
|
+
const oldValue = this.#tsFlags;
|
|
72
|
+
if (oldValue === value) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.#tsFlags = value;
|
|
76
|
+
trigger(this, TriggerOpTypes.SET, "tsFlags", value, oldValue);
|
|
77
|
+
}
|
|
78
|
+
get scope() {
|
|
79
|
+
return super.scope;
|
|
80
|
+
}
|
|
81
|
+
set scope(value) {
|
|
82
|
+
super.scope = value;
|
|
83
|
+
}
|
|
84
|
+
get staticMemberScope() {
|
|
85
|
+
return super.staticMemberScope;
|
|
86
|
+
}
|
|
87
|
+
get instanceMemberScope() {
|
|
88
|
+
return super.instanceMemberScope;
|
|
89
|
+
}
|
|
90
|
+
#privateMemberScope;
|
|
91
|
+
get privateMemberScope() {
|
|
92
|
+
return this.#privateMemberScope;
|
|
93
|
+
}
|
|
94
|
+
#privateStaticMemberScope;
|
|
95
|
+
get privateStaticMemberScope() {
|
|
96
|
+
return this.#privateStaticMemberScope;
|
|
97
|
+
}
|
|
98
|
+
createMemberScope(name, options) {
|
|
99
|
+
return new TSMemberScope(name, {
|
|
100
|
+
...options
|
|
101
|
+
});
|
|
40
102
|
}
|
|
41
|
-
return sym;
|
|
42
103
|
}
|
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputScope, OutputScopeOptions, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { TSModuleScope } from "./ts-module-scope.js";
|
|
3
|
-
export interface
|
|
4
|
-
|
|
3
|
+
export interface TSPackageScopeOptions extends OutputScopeOptions {
|
|
4
|
+
builtin?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class TSPackageScope extends OutputScope {
|
|
7
|
+
#private;
|
|
8
|
+
get kind(): "package";
|
|
5
9
|
/**
|
|
6
10
|
* The version of the this package.
|
|
7
11
|
*/
|
|
8
|
-
version: string;
|
|
12
|
+
get version(): string;
|
|
9
13
|
/**
|
|
10
14
|
* The symbols exported by this package. They are broken down by which paths
|
|
11
15
|
* they are exported from. It is possible a symbol may be present at multiple
|
|
12
16
|
* paths, in which case emitters can decide which symbol to use based on their
|
|
13
17
|
* own heuristics.
|
|
14
18
|
*/
|
|
15
|
-
exportedSymbols: Map<string, TSModuleScope>;
|
|
16
|
-
/**
|
|
17
|
-
* The path of the root directory of the package.
|
|
18
|
-
*/
|
|
19
|
-
path: string;
|
|
19
|
+
get exportedSymbols(): Map<string, TSModuleScope>;
|
|
20
20
|
/**
|
|
21
21
|
* The scopes for the packages this package depends on.
|
|
22
22
|
*/
|
|
23
|
-
dependencies: Set<TSPackageScope>;
|
|
23
|
+
get dependencies(): Set<TSPackageScope>;
|
|
24
24
|
/**
|
|
25
25
|
* All of the modules contained within the package. These modules may or may not
|
|
26
26
|
* be exported.
|
|
27
27
|
*/
|
|
28
|
-
modules: Set<TSModuleScope>;
|
|
28
|
+
get modules(): Set<TSModuleScope>;
|
|
29
|
+
/**
|
|
30
|
+
* The path of the root directory of the package.
|
|
31
|
+
*/
|
|
32
|
+
get path(): string;
|
|
29
33
|
/**
|
|
30
34
|
* Whether this is a built-in package provided by the platform.
|
|
31
35
|
*/
|
|
32
|
-
builtin
|
|
33
|
-
|
|
36
|
+
get builtin(): boolean;
|
|
37
|
+
constructor(name: string, version: string, path: string, options?: TSPackageScopeOptions);
|
|
34
38
|
addDependency(pkg: TSPackageScope): void;
|
|
39
|
+
addExport(publicPath: string, module: TSModuleScope): void;
|
|
35
40
|
addModule(module: TSModuleScope): void;
|
|
36
41
|
findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
|
|
37
42
|
}
|
|
38
|
-
export declare function createTSPackageScope(binder: Binder, parent: OutputScope | undefined, name: string, version: string, path: string, builtin?: boolean): TSPackageScope;
|
|
39
43
|
//# sourceMappingURL=ts-package-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-package-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-package-scope.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ts-package-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/ts-package-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,MAAM,EAEP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,IAAI,IAAI,IACC,SAAS,CACjB;IAED;;OAEG;IACH,IAAI,OAAO,WAEV;IAGD;;;;;OAKG;IACH,IAAI,eAAe,+BAElB;IAGD;;OAEG;IACH,IAAI,YAAY,wBAEf;IAGD;;;OAGG;IACH,IAAI,OAAO,uBAEV;IAGD;;OAEG;IACH,IAAI,IAAI,WAEP;IAGD;;OAEG;IACH,IAAI,OAAO,YAEV;gBAIC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAA0B;IAQrC,aAAa,CAAC,GAAG,EAAE,cAAc;IAGjC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa;IAGnD,SAAS,CAAC,MAAM,EAAE,aAAa;IAI/B,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI;CASnE"}
|
|
@@ -1,31 +1,82 @@
|
|
|
1
|
+
import { OutputScope, shallowReactive } from "@alloy-js/core";
|
|
1
2
|
import { modulePath } from "../utils.js";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
export class TSPackageScope extends OutputScope {
|
|
4
|
+
get kind() {
|
|
5
|
+
return "package";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The version of the this package.
|
|
10
|
+
*/
|
|
11
|
+
get version() {
|
|
12
|
+
return this.#version;
|
|
13
|
+
}
|
|
14
|
+
#version;
|
|
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
|
+
get exportedSymbols() {
|
|
23
|
+
return this.#exportedSymbols;
|
|
24
|
+
}
|
|
25
|
+
#exportedSymbols = shallowReactive(new Map());
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The scopes for the packages this package depends on.
|
|
29
|
+
*/
|
|
30
|
+
get dependencies() {
|
|
31
|
+
return this.#dependencies;
|
|
32
|
+
}
|
|
33
|
+
#dependencies = shallowReactive(new Set());
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* All of the modules contained within the package. These modules may or may not
|
|
37
|
+
* be exported.
|
|
38
|
+
*/
|
|
39
|
+
get modules() {
|
|
40
|
+
return this.#modules;
|
|
41
|
+
}
|
|
42
|
+
#modules = shallowReactive(new Set());
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The path of the root directory of the package.
|
|
46
|
+
*/
|
|
47
|
+
get path() {
|
|
48
|
+
return this.#path;
|
|
49
|
+
}
|
|
50
|
+
#path;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether this is a built-in package provided by the platform.
|
|
54
|
+
*/
|
|
55
|
+
get builtin() {
|
|
56
|
+
return this.#builtin;
|
|
57
|
+
}
|
|
58
|
+
#builtin;
|
|
59
|
+
constructor(name, version, path, options = {}) {
|
|
60
|
+
super(name, options);
|
|
61
|
+
this.#version = version;
|
|
62
|
+
this.#path = path;
|
|
63
|
+
this.#builtin = !!options.builtin;
|
|
64
|
+
}
|
|
65
|
+
addDependency(pkg) {
|
|
66
|
+
this.dependencies.add(pkg);
|
|
67
|
+
}
|
|
68
|
+
addExport(publicPath, module) {
|
|
69
|
+
this.exportedSymbols.set(modulePath(publicPath), module);
|
|
70
|
+
}
|
|
71
|
+
addModule(module) {
|
|
72
|
+
this.modules.add(module);
|
|
73
|
+
}
|
|
74
|
+
findExportedSymbol(refkey) {
|
|
75
|
+
for (const [publicPath, module] of this.exportedSymbols) {
|
|
76
|
+
if (module.exportedSymbols.has(refkey)) {
|
|
77
|
+
return [publicPath, module];
|
|
27
78
|
}
|
|
28
|
-
return null;
|
|
29
79
|
}
|
|
30
|
-
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
31
82
|
}
|
package/dist/test/class.test.js
CHANGED
|
@@ -252,7 +252,8 @@ describe("instance members", () => {
|
|
|
252
252
|
const rk2 = refkey();
|
|
253
253
|
const tree = render(_$createComponent(Output, {
|
|
254
254
|
nameConflictResolver: () => {
|
|
255
|
-
|
|
255
|
+
// do nothing
|
|
256
|
+
return undefined;
|
|
256
257
|
},
|
|
257
258
|
get children() {
|
|
258
259
|
return [_$createComponent(ts.SourceFile, {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { memo as _$memo, createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { Output, render } from "@alloy-js/core";
|
|
3
|
-
import { it } from "vitest";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
4
|
import { fs } from "../src/builtins/node.js";
|
|
5
|
-
import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile } from "../src/index.js";
|
|
5
|
+
import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile, TSOutputSymbol } from "../src/index.js";
|
|
6
6
|
import { assertFileContents } from "./utils.js";
|
|
7
7
|
it("can import builtins", () => {
|
|
8
8
|
const testLib = createPackage({
|
|
@@ -142,4 +142,89 @@ it("can import builtins without a package", () => {
|
|
|
142
142
|
}
|
|
143
143
|
`
|
|
144
144
|
});
|
|
145
|
+
});
|
|
146
|
+
it("can import static members", () => {
|
|
147
|
+
const mcpSdk = createPackage({
|
|
148
|
+
name: "@modelcontextprotocol/sdk",
|
|
149
|
+
version: "^3.23.0",
|
|
150
|
+
descriptor: {
|
|
151
|
+
"./server/index.js": {
|
|
152
|
+
named: [{
|
|
153
|
+
name: "server",
|
|
154
|
+
staticMembers: ["setRequestHandler", {
|
|
155
|
+
name: "nested",
|
|
156
|
+
staticMembers: ["nestedHandler"]
|
|
157
|
+
}],
|
|
158
|
+
instanceMembers: ["instanceHandler"]
|
|
159
|
+
}, {
|
|
160
|
+
name: "noMembers"
|
|
161
|
+
}, "simpleName"]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const res = render(_$createComponent(Output, {
|
|
166
|
+
externals: [mcpSdk],
|
|
167
|
+
get children() {
|
|
168
|
+
return _$createComponent(SourceFile, {
|
|
169
|
+
path: "index.ts",
|
|
170
|
+
get children() {
|
|
171
|
+
return _$createComponent(FunctionDeclaration, {
|
|
172
|
+
name: "foo",
|
|
173
|
+
get children() {
|
|
174
|
+
return [_$memo(() => mcpSdk["./server/index.js"].server), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].server.static.setRequestHandler), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].server.static.nested.static.nestedHandler), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].noMembers), "();", _$createIntrinsic("hbr", {}), _$memo(() => mcpSdk["./server/index.js"].simpleName), "();"];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}));
|
|
181
|
+
assertFileContents(res, {
|
|
182
|
+
"index.ts": `
|
|
183
|
+
import { noMembers, server, simpleName } from "@modelcontextprotocol/sdk/server/index.js";
|
|
184
|
+
|
|
185
|
+
function foo() {
|
|
186
|
+
server();
|
|
187
|
+
server.setRequestHandler();
|
|
188
|
+
server.nested.nestedHandler();
|
|
189
|
+
noMembers();
|
|
190
|
+
simpleName();
|
|
191
|
+
}
|
|
192
|
+
`
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
it("can import instance members", () => {
|
|
196
|
+
const mcpSdk = createPackage({
|
|
197
|
+
name: "@modelcontextprotocol/sdk",
|
|
198
|
+
version: "^3.23.0",
|
|
199
|
+
descriptor: {
|
|
200
|
+
"./server/index.js": {
|
|
201
|
+
named: [{
|
|
202
|
+
name: "Server",
|
|
203
|
+
instanceMembers: ["instanceHandler"]
|
|
204
|
+
}]
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
function RunTest() {
|
|
209
|
+
const sym = new TSOutputSymbol("foo");
|
|
210
|
+
const binder = sym.binder;
|
|
211
|
+
expect(binder).toBeDefined();
|
|
212
|
+
const source = binder.getSymbolForRefkey(mcpSdk["./server/index.js"].Server).value;
|
|
213
|
+
expect(source).toBeDefined();
|
|
214
|
+
expect(source.instanceMemberScope?.symbols.size).toBe(1);
|
|
215
|
+
source.instantiateTo(sym);
|
|
216
|
+
expect(sym.staticMemberScope?.symbols.size).toBe(1);
|
|
217
|
+
expect([...sym.staticMemberScope.symbols][0].name).toBe("instanceHandler");
|
|
218
|
+
}
|
|
219
|
+
render(_$createComponent(Output, {
|
|
220
|
+
externals: [mcpSdk],
|
|
221
|
+
get children() {
|
|
222
|
+
return _$createComponent(SourceFile, {
|
|
223
|
+
path: "index.ts",
|
|
224
|
+
get children() {
|
|
225
|
+
return _$createComponent(RunTest, {});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}));
|
|
145
230
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { refkey, StatementList } from "@alloy-js/core";
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List, memberRefkey, refkey, StatementList } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
|
-
import {
|
|
5
|
+
import { ClassField } from "../src/components/stc/index.js";
|
|
6
|
+
import { ClassDeclaration, FunctionDeclaration, InterfaceDeclaration, InterfaceMember, VarDeclaration } from "../src/index.js";
|
|
6
7
|
import { toSourceText } from "./utils.js";
|
|
7
8
|
it("works", () => {
|
|
8
9
|
expect(toSourceText(_$createComponent(FunctionDeclaration, {
|
|
@@ -243,4 +244,74 @@ describe("symbols", () => {
|
|
|
243
244
|
}
|
|
244
245
|
`);
|
|
245
246
|
});
|
|
247
|
+
it("adds symbols for members of parameters when a type is provided", () => {
|
|
248
|
+
const ifaceRk = refkey();
|
|
249
|
+
const ifaceMemberRk = refkey();
|
|
250
|
+
const clsRk = refkey();
|
|
251
|
+
const clsMemberRk = refkey();
|
|
252
|
+
const ifaceParamRk = refkey();
|
|
253
|
+
const clsParamRk = refkey();
|
|
254
|
+
const ifaceParam = {
|
|
255
|
+
name: "ifaceParam",
|
|
256
|
+
refkey: ifaceParamRk,
|
|
257
|
+
type: ifaceRk,
|
|
258
|
+
optional: true
|
|
259
|
+
};
|
|
260
|
+
const clsParam = {
|
|
261
|
+
name: "classParam",
|
|
262
|
+
refkey: clsParamRk,
|
|
263
|
+
type: clsRk,
|
|
264
|
+
optional: true
|
|
265
|
+
};
|
|
266
|
+
const decl = _$createComponent(List, {
|
|
267
|
+
doubleHardline: true,
|
|
268
|
+
get children() {
|
|
269
|
+
return [_$createComponent(InterfaceDeclaration, {
|
|
270
|
+
name: "IFace",
|
|
271
|
+
refkey: ifaceRk,
|
|
272
|
+
get children() {
|
|
273
|
+
return _$createComponent(InterfaceMember, {
|
|
274
|
+
name: "ifaceProp",
|
|
275
|
+
refkey: ifaceMemberRk,
|
|
276
|
+
children: "string"
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}), _$createComponent(ClassDeclaration, {
|
|
280
|
+
name: "Class",
|
|
281
|
+
refkey: clsRk,
|
|
282
|
+
get children() {
|
|
283
|
+
return _$createComponent(ClassField, {
|
|
284
|
+
name: "classProp",
|
|
285
|
+
refkey: clsMemberRk,
|
|
286
|
+
children: "42"
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}), _$createComponent(FunctionDeclaration, {
|
|
290
|
+
name: "fn",
|
|
291
|
+
parameters: [ifaceParam, clsParam],
|
|
292
|
+
get children() {
|
|
293
|
+
return _$createComponent(StatementList, {
|
|
294
|
+
get children() {
|
|
295
|
+
return [["console.log(", _$memo(() => memberRefkey(ifaceParamRk, ifaceMemberRk)), ")"], ["console.log(", _$memo(() => memberRefkey(clsParamRk, clsMemberRk)), ");"]];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
})];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
expect(toSourceText(decl)).toBe(d`
|
|
303
|
+
interface IFace {
|
|
304
|
+
ifaceProp: string
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
class Class {
|
|
308
|
+
classProp = 42
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function fn(ifaceParam?: IFace, classParam?: Class) {
|
|
312
|
+
console.log(ifaceParam?.ifaceProp);
|
|
313
|
+
console.log(classParam?.classProp);;
|
|
314
|
+
}
|
|
315
|
+
`);
|
|
316
|
+
});
|
|
246
317
|
});
|