@alloy-js/typescript 0.19.0 → 0.20.0-dev.1
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/dist/src/builtins/node.d.ts +1 -1
- package/dist/src/components/ArrowFunction.d.ts.map +1 -1
- package/dist/src/components/ArrowFunction.js +7 -13
- package/dist/src/components/BlockScope.d.ts.map +1 -1
- package/dist/src/components/BlockScope.js +3 -2
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +20 -30
- package/dist/src/components/Declaration.d.ts +2 -9
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +20 -43
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +5 -9
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +3 -4
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +2 -1
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +15 -12
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +3 -3
- package/dist/src/components/FunctionExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionExpression.js +7 -13
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +3 -3
- package/dist/src/components/IfStatement.d.ts.map +1 -1
- package/dist/src/components/IfStatement.js +2 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +3 -4
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +14 -13
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
- package/dist/src/components/InterfaceMethod.js +4 -3
- package/dist/src/components/LexicalScope.d.ts +12 -0
- package/dist/src/components/LexicalScope.d.ts.map +1 -0
- package/dist/src/components/LexicalScope.js +24 -0
- package/dist/src/components/MemberDeclaration.d.ts +1 -10
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +3 -7
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +13 -5
- package/dist/src/components/MemberScope.d.ts +15 -0
- package/dist/src/components/MemberScope.d.ts.map +1 -0
- package/dist/src/components/MemberScope.js +17 -0
- package/dist/src/components/NewExpression.d.ts.map +1 -1
- package/dist/src/components/NewExpression.js +5 -5
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +10 -14
- package/dist/src/components/PropertyName.js +1 -2
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +3 -2
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +14 -26
- package/dist/src/context/index.d.ts +1 -1
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +1 -1
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +11 -33
- package/dist/src/symbols/index.d.ts +19 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +72 -1
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +68 -70
- package/dist/src/symbols/scopes.d.ts +5 -8
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/scopes.js +26 -0
- package/dist/src/symbols/ts-lexical-scope.d.ts +12 -0
- package/dist/src/symbols/ts-lexical-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-lexical-scope.js +16 -0
- package/dist/src/symbols/ts-member-scope.d.ts +12 -4
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +15 -6
- package/dist/src/symbols/ts-module-scope.d.ts +8 -3
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +29 -18
- package/dist/src/symbols/ts-output-symbol.d.ts +19 -18
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +60 -37
- package/dist/src/symbols/ts-package-scope.d.ts +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +4 -5
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +23 -1
- package/dist/test/class.test.js +4 -4
- package/dist/test/externals.test.js +2 -38
- package/dist/test/reference.test.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/components/ArrowFunction.tsx +7 -10
- package/src/components/BlockScope.tsx +3 -3
- package/src/components/ClassDeclaration.tsx +19 -44
- package/src/components/Declaration.tsx +22 -53
- package/src/components/EnumDeclaration.tsx +4 -11
- package/src/components/EnumMember.tsx +3 -3
- package/src/components/ExportStatement.tsx +2 -1
- package/src/components/FunctionBase.tsx +33 -28
- package/src/components/FunctionDeclaration.tsx +3 -3
- package/src/components/FunctionExpression.tsx +7 -10
- package/src/components/FunctionType.tsx +3 -3
- package/src/components/IfStatement.tsx +2 -1
- package/src/components/ImportStatement.tsx +4 -8
- package/src/components/Interface.tsx +15 -22
- package/src/components/InterfaceMethod.tsx +4 -4
- package/src/components/LexicalScope.tsx +27 -0
- package/src/components/MemberDeclaration.tsx +8 -20
- package/src/components/MemberExpression.tsx +25 -5
- package/src/components/MemberScope.tsx +29 -0
- package/src/components/NewExpression.tsx +4 -5
- package/src/components/ObjectExpression.tsx +11 -18
- package/src/components/PropertyName.tsx +2 -2
- package/src/components/SourceFile.tsx +3 -1
- package/src/components/VarDeclaration.tsx +14 -28
- package/src/context/index.ts +1 -1
- package/src/create-package.ts +10 -39
- package/src/symbols/index.ts +118 -0
- package/src/symbols/reference.tsx +163 -0
- package/src/symbols/scopes.ts +38 -13
- package/src/symbols/ts-lexical-scope.ts +18 -0
- package/src/symbols/ts-member-scope.ts +23 -6
- package/src/symbols/ts-module-scope.ts +31 -21
- package/src/symbols/ts-output-symbol.ts +111 -49
- package/src/symbols/ts-package-scope.ts +5 -5
- package/src/utils.ts +38 -1
- package/temp/api.json +1641 -713
- package/test/class.test.tsx +10 -4
- package/test/externals.test.tsx +1 -40
- package/test/reference.test.tsx +5 -5
- package/tsdoc-metadata.json +1 -1
- package/dist/src/context/private-scope.d.ts +0 -18
- package/dist/src/context/private-scope.d.ts.map +0 -1
- package/dist/src/context/private-scope.js +0 -8
- package/src/context/private-scope.ts +0 -23
- package/src/symbols/reference.ts +0 -197
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { reactive, shallowReactive } from "@alloy-js/core";
|
|
2
|
+
import { TSLexicalScope } from "./ts-lexical-scope.js";
|
|
2
3
|
import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A lexical scope for TypeScript which represents the top-level scope of a
|
|
6
|
+
* module. Manages the module's imported and exported symbols.
|
|
7
|
+
*/
|
|
8
|
+
export class TSModuleScope extends TSLexicalScope {
|
|
7
9
|
#exportedSymbols = shallowReactive(new Map());
|
|
8
10
|
get exportedSymbols() {
|
|
9
11
|
return this.#exportedSymbols;
|
|
@@ -19,26 +21,25 @@ export class TSModuleScope extends OutputScope {
|
|
|
19
21
|
addImport(targetSymbol, targetModule, options) {
|
|
20
22
|
const existing = this.importedSymbols.get(targetSymbol);
|
|
21
23
|
if (existing) {
|
|
22
|
-
if (!options?.type && existing.
|
|
23
|
-
existing.
|
|
24
|
+
if (!options?.type && existing.isTypeSymbol) {
|
|
25
|
+
existing.spaces.push(this.values);
|
|
24
26
|
}
|
|
25
27
|
return existing;
|
|
26
28
|
}
|
|
27
|
-
if (targetModule.kind !== "module") {
|
|
28
|
-
throw new Error("Cannot import symbol that isn't in module scope");
|
|
29
|
-
}
|
|
30
29
|
if (!this.importedModules.has(targetModule)) {
|
|
31
30
|
this.importedModules.set(targetModule, new Set());
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
binder: this.binder,
|
|
35
|
-
scope: this,
|
|
36
|
-
aliasTarget: targetSymbol,
|
|
37
|
-
tsFlags: TSSymbolFlags.LocalImportSymbol
|
|
38
|
-
});
|
|
39
|
-
targetSymbol.copyTo(localSymbol);
|
|
32
|
+
let localSymbol;
|
|
40
33
|
if (options?.type) {
|
|
41
|
-
localSymbol.
|
|
34
|
+
localSymbol = new TSOutputSymbol(targetSymbol.name, this.types, {
|
|
35
|
+
aliasTarget: targetSymbol,
|
|
36
|
+
tsFlags: TSSymbolFlags.LocalImportSymbol
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
localSymbol = new TSOutputSymbol(targetSymbol.name, this.values, {
|
|
40
|
+
aliasTarget: targetSymbol,
|
|
41
|
+
tsFlags: TSSymbolFlags.LocalImportSymbol
|
|
42
|
+
});
|
|
42
43
|
}
|
|
43
44
|
this.importedSymbols.set(targetSymbol, localSymbol);
|
|
44
45
|
this.importedModules.get(targetModule).add({
|
|
@@ -47,4 +48,14 @@ export class TSModuleScope extends OutputScope {
|
|
|
47
48
|
});
|
|
48
49
|
return localSymbol;
|
|
49
50
|
}
|
|
51
|
+
getAllSymbols() {
|
|
52
|
+
const allSymbols = new Set();
|
|
53
|
+
for (const symbol of this.values) {
|
|
54
|
+
allSymbols.add(symbol);
|
|
55
|
+
}
|
|
56
|
+
for (const symbol of this.types) {
|
|
57
|
+
allSymbols.add(symbol);
|
|
58
|
+
}
|
|
59
|
+
return allSymbols;
|
|
60
|
+
}
|
|
50
61
|
}
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputSpace, OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
|
|
2
2
|
import { TSOutputScope } from "./scopes.js";
|
|
3
|
-
import { TSMemberScope } from "./ts-member-scope.js";
|
|
4
3
|
export declare enum TSSymbolFlags {
|
|
5
4
|
None = 0,
|
|
6
5
|
LocalImportSymbol = 1,
|
|
7
6
|
TypeSymbol = 2,
|
|
8
7
|
ParameterSymbol = 4,
|
|
9
|
-
|
|
10
|
-
PrivateMemberContainer = 16,
|
|
11
|
-
Nullish = 32
|
|
8
|
+
Nullish = 8
|
|
12
9
|
}
|
|
13
10
|
export interface CreateTsSymbolOptions extends OutputSymbolOptions {
|
|
14
|
-
scope?: TSOutputScope;
|
|
15
|
-
owner?: TSOutputSymbol;
|
|
16
11
|
export?: boolean;
|
|
17
12
|
default?: boolean;
|
|
18
13
|
tsFlags?: TSSymbolFlags;
|
|
14
|
+
hasInstanceMembers?: boolean;
|
|
19
15
|
}
|
|
20
16
|
export declare class TSOutputSymbol extends OutputSymbol {
|
|
21
17
|
#private;
|
|
22
|
-
|
|
18
|
+
static readonly memberSpaces: readonly ["static", "instance", "private-static", "private-instance"];
|
|
19
|
+
constructor(name: string, spaces: OutputSpace[] | OutputSpace | undefined, options?: CreateTsSymbolOptions);
|
|
20
|
+
get ownerSymbol(): TSOutputSymbol | undefined;
|
|
21
|
+
copy(): TSOutputSymbol;
|
|
23
22
|
get export(): boolean;
|
|
24
23
|
set export(value: boolean);
|
|
25
24
|
get default(): boolean;
|
|
26
25
|
set default(value: boolean);
|
|
27
26
|
get tsFlags(): TSSymbolFlags;
|
|
27
|
+
get hasInstanceMembers(): boolean;
|
|
28
28
|
set tsFlags(value: TSSymbolFlags);
|
|
29
|
-
get scope(): TSOutputScope;
|
|
30
|
-
|
|
31
|
-
get
|
|
32
|
-
get
|
|
33
|
-
get
|
|
34
|
-
get
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
get scope(): TSOutputScope | undefined;
|
|
30
|
+
get staticMembers(): import("@alloy-js/core").OutputMemberSpace;
|
|
31
|
+
get instanceMembers(): import("@alloy-js/core").OutputMemberSpace;
|
|
32
|
+
get privateInstanceMembers(): import("@alloy-js/core").OutputMemberSpace;
|
|
33
|
+
get privateStaticMembers(): import("@alloy-js/core").OutputMemberSpace;
|
|
34
|
+
get isPrivateMemberSymbol(): boolean;
|
|
35
|
+
get isPublicMemberSymbol(): boolean;
|
|
36
|
+
get isStaticMemberSymbol(): boolean;
|
|
37
|
+
get isInstanceMemberSymbol(): boolean;
|
|
38
|
+
get isTypeSymbol(): boolean;
|
|
39
|
+
get isValueSymbol(): boolean;
|
|
39
40
|
}
|
|
40
41
|
//# 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,WAAW,EACX,YAAY,EACZ,mBAAmB,EAMpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,oBAAY,aAAa;IACvB,IAAI,IAAsB;IAC1B,iBAAiB,IAAc;IAC/B,UAAU,IAAqB;IAC/B,eAAe,IAAgB;IAC/B,OAAO,IAAS;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,qBAAa,cAAe,SAAQ,YAAY;;IAC9C,MAAM,CAAC,QAAQ,CAAC,YAAY,wEAKjB;gBAGT,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,GAAG,SAAS,EAC/C,OAAO,GAAE,qBAA0B;IAwBrC,IAAI,WAAW,IACe,cAAc,GAAG,SAAS,CACvD;IAED,IAAI;IA+BJ,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,IAWQ,aAAa,CAR/B;IAGD,IAAI,kBAAkB,YAGrB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,aAAa,EAO/B;IAED,IAAI,KAAK,IAAI,aAAa,GAAG,SAAS,CAErC;IAED,IAAI,aAAa,+CAEhB;IAED,IAAI,eAAe,+CAElB;IAED,IAAI,sBAAsB,+CAEzB;IAED,IAAI,oBAAoB,+CAEvB;IAED,IAAI,qBAAqB,YAOxB;IAED,IAAI,oBAAoB,YAEvB;IAED,IAAI,oBAAoB,YAEvB;IAED,IAAI,sBAAsB,YAOzB;IAED,IAAI,YAAY,YAEf;IAED,IAAI,aAAa,YAEhB;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { OutputSymbol, track, TrackOpTypes, trigger, TriggerOpTypes, watch } from "@alloy-js/core";
|
|
2
|
+
import { TSModuleScope } from "./ts-module-scope.js";
|
|
3
3
|
|
|
4
4
|
// prettier-ignore
|
|
5
5
|
export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
|
|
@@ -7,37 +7,47 @@ export let TSSymbolFlags = /*#__PURE__*/function (TSSymbolFlags) {
|
|
|
7
7
|
TSSymbolFlags[TSSymbolFlags["LocalImportSymbol"] = 1] = "LocalImportSymbol";
|
|
8
8
|
TSSymbolFlags[TSSymbolFlags["TypeSymbol"] = 2] = "TypeSymbol";
|
|
9
9
|
TSSymbolFlags[TSSymbolFlags["ParameterSymbol"] = 4] = "ParameterSymbol";
|
|
10
|
-
TSSymbolFlags[TSSymbolFlags["
|
|
11
|
-
TSSymbolFlags[TSSymbolFlags["PrivateMemberContainer"] = 16] = "PrivateMemberContainer";
|
|
12
|
-
TSSymbolFlags[TSSymbolFlags["Nullish"] = 32] = "Nullish";
|
|
10
|
+
TSSymbolFlags[TSSymbolFlags["Nullish"] = 8] = "Nullish";
|
|
13
11
|
return TSSymbolFlags;
|
|
14
12
|
}({});
|
|
15
13
|
export class TSOutputSymbol extends OutputSymbol {
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
static memberSpaces = ["static", "instance", "private-static", "private-instance"];
|
|
15
|
+
constructor(name, spaces, options = {}) {
|
|
16
|
+
super(name, spaces, options);
|
|
18
17
|
this.#export = !!options.export;
|
|
19
18
|
this.#default = !!options.default;
|
|
20
19
|
this.#tsFlags = options.tsFlags ?? TSSymbolFlags.None;
|
|
21
|
-
this.#
|
|
22
|
-
this
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
});
|
|
20
|
+
this.#hasInstanceMembers = !!options.hasInstanceMembers;
|
|
21
|
+
if (this.ownerSymbol?.isTypeSymbol || this.spaces.some(s => s.key === "types") && !this.spaces.some(s => s.key === "values")) {
|
|
22
|
+
// Classes and enums are both types and values. The check above will treat them as values
|
|
23
|
+
// exclusively so that referencing occurs properly. This should instead use type or value
|
|
24
|
+
// referencing based on type context.
|
|
25
|
+
this.#tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
34
26
|
}
|
|
35
|
-
if (options.export && this.scope.
|
|
27
|
+
if (options.export && this.scope && this.scope instanceof TSModuleScope) {
|
|
36
28
|
for (const refkey of this.refkeys) {
|
|
37
29
|
this.scope.exportedSymbols.set(refkey, this);
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
32
|
}
|
|
33
|
+
get ownerSymbol() {
|
|
34
|
+
return super.ownerSymbol;
|
|
35
|
+
}
|
|
36
|
+
copy() {
|
|
37
|
+
const copy = new TSOutputSymbol(this.name, undefined, {
|
|
38
|
+
binder: this.binder,
|
|
39
|
+
aliasTarget: this.aliasTarget,
|
|
40
|
+
default: this.default,
|
|
41
|
+
export: this.export,
|
|
42
|
+
tsFlags: this.tsFlags,
|
|
43
|
+
metadata: this.metadata
|
|
44
|
+
});
|
|
45
|
+
this.initializeCopy(copy);
|
|
46
|
+
watch(() => this.default, def => copy.default = def);
|
|
47
|
+
watch(() => this.export, exp => copy.export = exp);
|
|
48
|
+
watch(() => this.tsFlags, flags => copy.tsFlags = flags);
|
|
49
|
+
return copy;
|
|
50
|
+
}
|
|
41
51
|
#export;
|
|
42
52
|
get export() {
|
|
43
53
|
track(this, TrackOpTypes.GET, "export");
|
|
@@ -67,6 +77,11 @@ export class TSOutputSymbol extends OutputSymbol {
|
|
|
67
77
|
track(this, TrackOpTypes.GET, "tsFlags");
|
|
68
78
|
return this.#tsFlags;
|
|
69
79
|
}
|
|
80
|
+
#hasInstanceMembers = false;
|
|
81
|
+
get hasInstanceMembers() {
|
|
82
|
+
track(this, TrackOpTypes.GET, "hasInstanceMembers");
|
|
83
|
+
return this.#hasInstanceMembers;
|
|
84
|
+
}
|
|
70
85
|
set tsFlags(value) {
|
|
71
86
|
const oldValue = this.#tsFlags;
|
|
72
87
|
if (oldValue === value) {
|
|
@@ -78,26 +93,34 @@ export class TSOutputSymbol extends OutputSymbol {
|
|
|
78
93
|
get scope() {
|
|
79
94
|
return super.scope;
|
|
80
95
|
}
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
get staticMembers() {
|
|
97
|
+
return this.memberSpaceFor("static");
|
|
83
98
|
}
|
|
84
|
-
get
|
|
85
|
-
return
|
|
99
|
+
get instanceMembers() {
|
|
100
|
+
return this.memberSpaceFor("instance");
|
|
86
101
|
}
|
|
87
|
-
get
|
|
88
|
-
return
|
|
102
|
+
get privateInstanceMembers() {
|
|
103
|
+
return this.memberSpaceFor("private-instance");
|
|
89
104
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.#privateMemberScope;
|
|
105
|
+
get privateStaticMembers() {
|
|
106
|
+
return this.memberSpaceFor("private-static");
|
|
93
107
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return this.#privateStaticMemberScope;
|
|
108
|
+
get isPrivateMemberSymbol() {
|
|
109
|
+
return this.spaces.length > 0 && this.spaces.filter(s => s.key === "private-static" || s.key === "private-instance").length > 0;
|
|
97
110
|
}
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
get isPublicMemberSymbol() {
|
|
112
|
+
return !this.isPrivateMemberSymbol;
|
|
113
|
+
}
|
|
114
|
+
get isStaticMemberSymbol() {
|
|
115
|
+
return !this.isInstanceMemberSymbol;
|
|
116
|
+
}
|
|
117
|
+
get isInstanceMemberSymbol() {
|
|
118
|
+
return this.spaces.length > 0 && this.spaces.filter(s => s.key === "instance" || s.key === "private-instance").length > 0;
|
|
119
|
+
}
|
|
120
|
+
get isTypeSymbol() {
|
|
121
|
+
return !!(this.tsFlags & TSSymbolFlags.TypeSymbol);
|
|
122
|
+
}
|
|
123
|
+
get isValueSymbol() {
|
|
124
|
+
return this.spaces.some(s => s.key === "values");
|
|
102
125
|
}
|
|
103
126
|
}
|
|
@@ -5,7 +5,6 @@ export interface TSPackageScopeOptions extends OutputScopeOptions {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class TSPackageScope extends OutputScope {
|
|
7
7
|
#private;
|
|
8
|
-
get kind(): "package";
|
|
9
8
|
/**
|
|
10
9
|
* The version of the this package.
|
|
11
10
|
*/
|
|
@@ -39,5 +38,6 @@ export declare class TSPackageScope extends OutputScope {
|
|
|
39
38
|
addExport(publicPath: string, module: TSModuleScope): void;
|
|
40
39
|
addModule(module: TSModuleScope): void;
|
|
41
40
|
findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
|
|
41
|
+
copyTo(): TSPackageScope;
|
|
42
42
|
}
|
|
43
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,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
|
|
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;;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;IAUlE,MAAM,IAAI,cAAc;CAGzB"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { OutputScope, shallowReactive } from "@alloy-js/core";
|
|
2
2
|
import { modulePath } from "../utils.js";
|
|
3
3
|
export class TSPackageScope extends OutputScope {
|
|
4
|
-
get kind() {
|
|
5
|
-
return "package";
|
|
6
|
-
}
|
|
7
|
-
|
|
8
4
|
/**
|
|
9
5
|
* The version of the this package.
|
|
10
6
|
*/
|
|
@@ -57,7 +53,7 @@ export class TSPackageScope extends OutputScope {
|
|
|
57
53
|
}
|
|
58
54
|
#builtin;
|
|
59
55
|
constructor(name, version, path, options = {}) {
|
|
60
|
-
super(name, options);
|
|
56
|
+
super(name, undefined, options);
|
|
61
57
|
this.#version = version;
|
|
62
58
|
this.#path = path;
|
|
63
59
|
this.#builtin = !!options.builtin;
|
|
@@ -79,4 +75,7 @@ export class TSPackageScope extends OutputScope {
|
|
|
79
75
|
}
|
|
80
76
|
return null;
|
|
81
77
|
}
|
|
78
|
+
copyTo() {
|
|
79
|
+
throw new Error("Not supported");
|
|
80
|
+
}
|
|
82
81
|
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CallSignatureProps } from "./components/CallSignature.jsx";
|
|
2
|
+
import { TSLexicalScope } from "./symbols/ts-lexical-scope.js";
|
|
3
|
+
import { TSOutputSymbol } from "./symbols/ts-output-symbol.js";
|
|
2
4
|
export declare function modulePath(path: string): string;
|
|
3
5
|
/**
|
|
4
6
|
* Extract only the call signature props from a props object which extends
|
|
@@ -6,4 +8,6 @@ export declare function modulePath(path: string): string;
|
|
|
6
8
|
*/
|
|
7
9
|
export declare function getCallSignatureProps(props: CallSignatureProps, defaults?: Partial<CallSignatureProps>): CallSignatureProps;
|
|
8
10
|
export declare function isValidJSIdentifier(str: string): boolean;
|
|
11
|
+
export declare function useLexicalScope(): TSLexicalScope | undefined;
|
|
12
|
+
export declare function useMemberOwner(): TSOutputSymbol;
|
|
9
13
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAMtC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,sBAevC;AAKD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,WAE9C;AAED,wBAAgB,eAAe,IAAI,cAAc,GAAG,SAAS,CAa5D;AAED,wBAAgB,cAAc,IAAI,cAAc,CAa/C"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { defaultProps, splitProps } from "@alloy-js/core";
|
|
1
|
+
import { defaultProps, splitProps, useMemberContext, useScope } from "@alloy-js/core";
|
|
2
|
+
import { TSLexicalScope } from "./symbols/ts-lexical-scope.js";
|
|
3
|
+
import { TSOutputSymbol } from "./symbols/ts-output-symbol.js";
|
|
2
4
|
export function modulePath(path) {
|
|
3
5
|
if (path[0] !== ".") {
|
|
4
6
|
path = "./" + path;
|
|
@@ -20,4 +22,24 @@ export function getCallSignatureProps(props, defaults) {
|
|
|
20
22
|
const identifierRegex = /^(?:[\p{ID_Start}$_])(?:[\p{ID_Continue}$\u200C\u200D])*$/u;
|
|
21
23
|
export function isValidJSIdentifier(str) {
|
|
22
24
|
return identifierRegex.test(str);
|
|
25
|
+
}
|
|
26
|
+
export function useLexicalScope() {
|
|
27
|
+
const scope = useScope();
|
|
28
|
+
if (!scope) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (!(scope instanceof TSLexicalScope)) {
|
|
32
|
+
throw new Error("A lexical scope is required but the current scope is not a lexical scope");
|
|
33
|
+
}
|
|
34
|
+
return scope;
|
|
35
|
+
}
|
|
36
|
+
export function useMemberOwner() {
|
|
37
|
+
const memberScope = useMemberContext();
|
|
38
|
+
if (!memberScope) {
|
|
39
|
+
throw new Error("A member owner is required but no member scope was found");
|
|
40
|
+
}
|
|
41
|
+
if (!(memberScope.ownerSymbol instanceof TSOutputSymbol)) {
|
|
42
|
+
throw new Error("A member owner is required but the current owner is not a TSOutputSymbol");
|
|
43
|
+
}
|
|
44
|
+
return memberScope.ownerSymbol;
|
|
23
45
|
}
|
package/dist/test/class.test.js
CHANGED
|
@@ -135,7 +135,7 @@ describe("instance members", () => {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
}), one]);
|
|
138
|
-
}).toThrow(/Cannot
|
|
138
|
+
}).toThrow(/Cannot reference instance member 'one' without an instance of 'Foo'/);
|
|
139
139
|
});
|
|
140
140
|
it("cannot be referenced outside the class when protected", () => {
|
|
141
141
|
const one = refkey();
|
|
@@ -155,7 +155,7 @@ describe("instance members", () => {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
}), one]);
|
|
158
|
-
}).toThrow(/Cannot
|
|
158
|
+
}).toThrow(/Cannot reference instance member 'one' without an instance of 'Foo'/);
|
|
159
159
|
});
|
|
160
160
|
it("cannot be referenced outside the class when private", () => {
|
|
161
161
|
const one = refkey();
|
|
@@ -175,7 +175,7 @@ describe("instance members", () => {
|
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
}), one]);
|
|
178
|
-
}).toThrow(/Cannot
|
|
178
|
+
}).toThrow(/Cannot reference instance member 'one' without an instance of 'Foo'/);
|
|
179
179
|
});
|
|
180
180
|
it("works with invalid identifier names", () => {
|
|
181
181
|
const one = refkey();
|
|
@@ -397,7 +397,7 @@ describe("static members", () => {
|
|
|
397
397
|
}
|
|
398
398
|
});
|
|
399
399
|
}
|
|
400
|
-
}), _$createIntrinsic("hbr", {}), two, ";"])).toThrow(/Cannot
|
|
400
|
+
}), _$createIntrinsic("hbr", {}), two, ";"])).toThrow(/Cannot reference/);
|
|
401
401
|
});
|
|
402
402
|
});
|
|
403
403
|
describe("instance methods", () => {
|
|
@@ -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 {
|
|
3
|
+
import { it } from "vitest";
|
|
4
4
|
import { fs } from "../src/builtins/node.js";
|
|
5
|
-
import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile
|
|
5
|
+
import { createPackage, FunctionDeclaration, PackageDirectory, SourceFile } from "../src/index.js";
|
|
6
6
|
import { assertFileContents } from "./utils.js";
|
|
7
7
|
it("can import builtins", () => {
|
|
8
8
|
const testLib = createPackage({
|
|
@@ -191,40 +191,4 @@ it("can import static members", () => {
|
|
|
191
191
|
}
|
|
192
192
|
`
|
|
193
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
|
-
}));
|
|
230
194
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Output, refkey, render } from "@alloy-js/core";
|
|
3
3
|
import "@alloy-js/core/testing";
|
|
4
4
|
import { it } from "vitest";
|
|
5
5
|
import * as ts from "../src/components/index.js";
|
|
@@ -11,7 +11,7 @@ it("works with back references", () => {
|
|
|
11
11
|
return [_$createComponent(ts.SourceFile, {
|
|
12
12
|
path: "test1.ts",
|
|
13
13
|
get children() {
|
|
14
|
-
return _$createComponent(Declaration, {
|
|
14
|
+
return _$createComponent(ts.Declaration, {
|
|
15
15
|
name: "foo",
|
|
16
16
|
get refkey() {
|
|
17
17
|
return refkey("foo");
|
|
@@ -57,7 +57,7 @@ it("works with forward references", () => {
|
|
|
57
57
|
}), _$createComponent(ts.SourceFile, {
|
|
58
58
|
path: "test1.ts",
|
|
59
59
|
get children() {
|
|
60
|
-
return _$createComponent(Declaration, {
|
|
60
|
+
return _$createComponent(ts.Declaration, {
|
|
61
61
|
name: "foo",
|
|
62
62
|
get refkey() {
|
|
63
63
|
return refkey("foo");
|