@alloy-js/typescript 0.20.0-dev.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 +3 -3
- 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
package/test/class.test.tsx
CHANGED
|
@@ -102,7 +102,9 @@ describe("instance members", () => {
|
|
|
102
102
|
{one}
|
|
103
103
|
</>,
|
|
104
104
|
);
|
|
105
|
-
}).toThrow(
|
|
105
|
+
}).toThrow(
|
|
106
|
+
/Cannot reference instance member 'one' without an instance of 'Foo'/,
|
|
107
|
+
);
|
|
106
108
|
});
|
|
107
109
|
|
|
108
110
|
it("cannot be referenced outside the class when protected", () => {
|
|
@@ -120,7 +122,9 @@ describe("instance members", () => {
|
|
|
120
122
|
{one}
|
|
121
123
|
</>,
|
|
122
124
|
);
|
|
123
|
-
}).toThrow(
|
|
125
|
+
}).toThrow(
|
|
126
|
+
/Cannot reference instance member 'one' without an instance of 'Foo'/,
|
|
127
|
+
);
|
|
124
128
|
});
|
|
125
129
|
|
|
126
130
|
it("cannot be referenced outside the class when private", () => {
|
|
@@ -138,7 +142,9 @@ describe("instance members", () => {
|
|
|
138
142
|
{one}
|
|
139
143
|
</>,
|
|
140
144
|
);
|
|
141
|
-
}).toThrow(
|
|
145
|
+
}).toThrow(
|
|
146
|
+
/Cannot reference instance member 'one' without an instance of 'Foo'/,
|
|
147
|
+
);
|
|
142
148
|
});
|
|
143
149
|
|
|
144
150
|
it("works with invalid identifier names", () => {
|
|
@@ -310,7 +316,7 @@ describe("static members", () => {
|
|
|
310
316
|
{two};
|
|
311
317
|
</>,
|
|
312
318
|
),
|
|
313
|
-
).toThrow(/Cannot
|
|
319
|
+
).toThrow(/Cannot reference/);
|
|
314
320
|
});
|
|
315
321
|
});
|
|
316
322
|
|
package/test/externals.test.tsx
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Output, render } from "@alloy-js/core";
|
|
2
|
-
import {
|
|
2
|
+
import { it } from "vitest";
|
|
3
3
|
import { fs } from "../src/builtins/node.js";
|
|
4
4
|
import {
|
|
5
5
|
createPackage,
|
|
6
6
|
FunctionDeclaration,
|
|
7
7
|
PackageDirectory,
|
|
8
8
|
SourceFile,
|
|
9
|
-
TSOutputSymbol,
|
|
10
9
|
} from "../src/index.js";
|
|
11
10
|
import { assertFileContents } from "./utils.js";
|
|
12
11
|
|
|
@@ -196,41 +195,3 @@ it("can import static members", () => {
|
|
|
196
195
|
`,
|
|
197
196
|
});
|
|
198
197
|
});
|
|
199
|
-
|
|
200
|
-
it("can import instance members", () => {
|
|
201
|
-
const mcpSdk = createPackage({
|
|
202
|
-
name: "@modelcontextprotocol/sdk",
|
|
203
|
-
version: "^3.23.0",
|
|
204
|
-
descriptor: {
|
|
205
|
-
"./server/index.js": {
|
|
206
|
-
named: [{ name: "Server", instanceMembers: ["instanceHandler"] }],
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
function RunTest() {
|
|
212
|
-
const sym = new TSOutputSymbol("foo");
|
|
213
|
-
const binder = sym.binder!;
|
|
214
|
-
|
|
215
|
-
expect(binder).toBeDefined();
|
|
216
|
-
|
|
217
|
-
const source = binder.getSymbolForRefkey(
|
|
218
|
-
mcpSdk["./server/index.js"].Server,
|
|
219
|
-
).value!;
|
|
220
|
-
expect(source).toBeDefined();
|
|
221
|
-
expect(source.instanceMemberScope?.symbols.size).toBe(1);
|
|
222
|
-
|
|
223
|
-
source.instantiateTo(sym);
|
|
224
|
-
|
|
225
|
-
expect(sym.staticMemberScope?.symbols.size).toBe(1);
|
|
226
|
-
expect([...sym.staticMemberScope!.symbols][0].name).toBe("instanceHandler");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
render(
|
|
230
|
-
<Output externals={[mcpSdk]}>
|
|
231
|
-
<SourceFile path="index.ts">
|
|
232
|
-
<RunTest />
|
|
233
|
-
</SourceFile>
|
|
234
|
-
</Output>,
|
|
235
|
-
);
|
|
236
|
-
});
|
package/test/reference.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Output, refkey, render } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { it } from "vitest";
|
|
4
4
|
import * as ts from "../src/components/index.js";
|
|
@@ -9,9 +9,9 @@ it("works with back references", () => {
|
|
|
9
9
|
const res = render(
|
|
10
10
|
<Output>
|
|
11
11
|
<ts.SourceFile path="test1.ts">
|
|
12
|
-
<Declaration name="foo" refkey={refkey("foo")}>
|
|
12
|
+
<ts.Declaration name="foo" refkey={refkey("foo")}>
|
|
13
13
|
const foo = 1;
|
|
14
|
-
</Declaration>
|
|
14
|
+
</ts.Declaration>
|
|
15
15
|
</ts.SourceFile>
|
|
16
16
|
|
|
17
17
|
<ts.SourceFile path="test2.ts">
|
|
@@ -39,9 +39,9 @@ it("works with forward references", () => {
|
|
|
39
39
|
const v = <Reference refkey={refkey("foo")} />;
|
|
40
40
|
</ts.SourceFile>
|
|
41
41
|
<ts.SourceFile path="test1.ts">
|
|
42
|
-
<Declaration name="foo" refkey={refkey("foo")}>
|
|
42
|
+
<ts.Declaration name="foo" refkey={refkey("foo")}>
|
|
43
43
|
const foo = 1;
|
|
44
|
-
</Declaration>
|
|
44
|
+
</ts.Declaration>
|
|
45
45
|
</ts.SourceFile>
|
|
46
46
|
</Output>,
|
|
47
47
|
);
|
package/tsdoc-metadata.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from "@alloy-js/core";
|
|
2
|
-
import { TSMemberScope } from "../symbols/ts-member-scope.js";
|
|
3
|
-
export interface PrivateScopeContext {
|
|
4
|
-
/**
|
|
5
|
-
* Scope for private static members.
|
|
6
|
-
*/
|
|
7
|
-
staticMembers: TSMemberScope;
|
|
8
|
-
/**
|
|
9
|
-
* Scope for private instance members.
|
|
10
|
-
*/
|
|
11
|
-
instanceMembers: TSMemberScope;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Provides scopes for instance and static private members.
|
|
15
|
-
*/
|
|
16
|
-
export declare const PrivateScopeContext: ComponentContext<PrivateScopeContext>;
|
|
17
|
-
export declare function usePrivateScope(): PrivateScopeContext | undefined;
|
|
18
|
-
//# sourceMappingURL=private-scope.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-scope.d.ts","sourceRoot":"","sources":["../../../src/context/private-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6B,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,aAAa,EAAE,aAAa,CAAC;IAC7B;;OAEG;IACH,eAAe,EAAE,aAAa,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,CAAC,mBAAmB,CAChC,CAAC;AAEvC,wBAAgB,eAAe,oCAE9B"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from "@alloy-js/core";
|
|
2
|
-
/**
|
|
3
|
-
* Provides scopes for instance and static private members.
|
|
4
|
-
*/
|
|
5
|
-
export const PrivateScopeContext = createContext();
|
|
6
|
-
export function usePrivateScope() {
|
|
7
|
-
return useContext(PrivateScopeContext);
|
|
8
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ComponentContext, createContext, useContext } from "@alloy-js/core";
|
|
2
|
-
import { TSMemberScope } from "../symbols/ts-member-scope.js";
|
|
3
|
-
|
|
4
|
-
export interface PrivateScopeContext {
|
|
5
|
-
/**
|
|
6
|
-
* Scope for private static members.
|
|
7
|
-
*/
|
|
8
|
-
staticMembers: TSMemberScope;
|
|
9
|
-
/**
|
|
10
|
-
* Scope for private instance members.
|
|
11
|
-
*/
|
|
12
|
-
instanceMembers: TSMemberScope;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Provides scopes for instance and static private members.
|
|
17
|
-
*/
|
|
18
|
-
export const PrivateScopeContext: ComponentContext<PrivateScopeContext> =
|
|
19
|
-
createContext<PrivateScopeContext>();
|
|
20
|
-
|
|
21
|
-
export function usePrivateScope() {
|
|
22
|
-
return useContext(PrivateScopeContext);
|
|
23
|
-
}
|
package/src/symbols/reference.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
memo,
|
|
3
|
-
OutputSymbolFlags,
|
|
4
|
-
Refkey,
|
|
5
|
-
resolve,
|
|
6
|
-
untrack,
|
|
7
|
-
useContext,
|
|
8
|
-
useMemberScope,
|
|
9
|
-
} from "@alloy-js/core";
|
|
10
|
-
import { usePackage } from "../components/PackageDirectory.jsx";
|
|
11
|
-
import { SourceFileContext } from "../components/SourceFile.jsx";
|
|
12
|
-
import {
|
|
13
|
-
PrivateScopeContext,
|
|
14
|
-
usePrivateScope,
|
|
15
|
-
} from "../context/private-scope.js";
|
|
16
|
-
import { isValidJSIdentifier } from "../utils.js";
|
|
17
|
-
import { TSOutputScope } from "./scopes.js";
|
|
18
|
-
import { TSMemberScope } from "./ts-member-scope.js";
|
|
19
|
-
import { TSModuleScope } from "./ts-module-scope.js";
|
|
20
|
-
import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
|
|
21
|
-
import { TSPackageScope } from "./ts-package-scope.js";
|
|
22
|
-
|
|
23
|
-
export interface RefOptions {
|
|
24
|
-
type?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export function ref(
|
|
27
|
-
refkey: Refkey,
|
|
28
|
-
options?: RefOptions,
|
|
29
|
-
): () => [string, TSOutputSymbol | undefined] {
|
|
30
|
-
const sourceFile = useContext(SourceFileContext);
|
|
31
|
-
const resolveResult = resolve<TSOutputScope, TSOutputSymbol>(
|
|
32
|
-
refkey as Refkey,
|
|
33
|
-
);
|
|
34
|
-
const currentScope = useMemberScope();
|
|
35
|
-
const currentPrivateScope = usePrivateScope();
|
|
36
|
-
|
|
37
|
-
return memo(() => {
|
|
38
|
-
if (resolveResult.value === undefined) {
|
|
39
|
-
return ["<Unresolved Symbol>", undefined];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const { targetDeclaration, pathDown, memberPath } = resolveResult.value;
|
|
43
|
-
// if we resolved a instance member, check if we should be able to access
|
|
44
|
-
// it.
|
|
45
|
-
if (targetDeclaration.flags & OutputSymbolFlags.InstanceMember) {
|
|
46
|
-
if (targetDeclaration.tsFlags & TSSymbolFlags.PrivateMember) {
|
|
47
|
-
if (currentPrivateScope?.instanceMembers !== targetDeclaration.scope) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
"Cannot resolve private member symbols from a different scope",
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
if (currentScope?.instanceMembers !== targetDeclaration.scope) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
"Cannot resolve member symbols from a different member scope",
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
validateSymbolReachable(pathDown, memberPath, currentPrivateScope);
|
|
62
|
-
|
|
63
|
-
// Where the target declaration is relative to the referencing scope.
|
|
64
|
-
// * package: target symbol is in a different package
|
|
65
|
-
// * module: target symbol is in a different module
|
|
66
|
-
// * local: target symbol is within the current module
|
|
67
|
-
const targetLocation = pathDown[0]?.kind ?? "local";
|
|
68
|
-
let localSymbol: TSOutputSymbol | undefined;
|
|
69
|
-
|
|
70
|
-
if (targetLocation === "package") {
|
|
71
|
-
// need package import
|
|
72
|
-
const pkg = usePackage();
|
|
73
|
-
const sourcePackage = pathDown[0] as TSPackageScope;
|
|
74
|
-
|
|
75
|
-
if (pkg && !sourcePackage.builtin) {
|
|
76
|
-
pkg.scope.addDependency(sourcePackage);
|
|
77
|
-
}
|
|
78
|
-
const symbolPath = [
|
|
79
|
-
...(pathDown.slice(2) as TSMemberScope[]).map((s) => s.owner),
|
|
80
|
-
targetDeclaration,
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
const importSymbol = symbolPath[0];
|
|
84
|
-
|
|
85
|
-
// find public dependency
|
|
86
|
-
for (const module of sourcePackage.exportedSymbols.values()) {
|
|
87
|
-
for (const refkey of importSymbol.refkeys) {
|
|
88
|
-
if (module.exportedSymbols.has(refkey)) {
|
|
89
|
-
localSymbol = untrack(() =>
|
|
90
|
-
sourceFile!.scope.addImport(importSymbol, module, {
|
|
91
|
-
type: options?.type,
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (!localSymbol) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"The symbol " +
|
|
102
|
-
targetDeclaration.name +
|
|
103
|
-
" is not exported from package",
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
} else if (targetLocation === "module") {
|
|
107
|
-
const symbolPath = [
|
|
108
|
-
...(pathDown.slice(1) as TSMemberScope[]).map((s) => s.owner),
|
|
109
|
-
targetDeclaration,
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
const importSymbol = symbolPath[0];
|
|
113
|
-
|
|
114
|
-
localSymbol = untrack(() =>
|
|
115
|
-
sourceFile!.scope.addImport(
|
|
116
|
-
importSymbol,
|
|
117
|
-
pathDown[0] as TSModuleScope,
|
|
118
|
-
{ type: options?.type },
|
|
119
|
-
),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (memberPath && memberPath.length > 0) {
|
|
124
|
-
if (localSymbol) {
|
|
125
|
-
memberPath[0] = localSymbol;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return [buildMemberExpression(memberPath), memberPath.at(-1)];
|
|
129
|
-
} else {
|
|
130
|
-
return [
|
|
131
|
-
buildMemberExpression([localSymbol ?? targetDeclaration]),
|
|
132
|
-
localSymbol ?? targetDeclaration,
|
|
133
|
-
];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function buildMemberExpression(path: TSOutputSymbol[]) {
|
|
139
|
-
let memberExpr = "";
|
|
140
|
-
|
|
141
|
-
const base = path[0];
|
|
142
|
-
if (base.flags & OutputSymbolFlags.InstanceMember) {
|
|
143
|
-
memberExpr += "this";
|
|
144
|
-
} else {
|
|
145
|
-
memberExpr += base.name;
|
|
146
|
-
path = path.slice(1);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
let prevNullish = base.tsFlags & TSSymbolFlags.Nullish;
|
|
150
|
-
for (const sym of path) {
|
|
151
|
-
const optional = prevNullish ? "?" : "";
|
|
152
|
-
if (sym.tsFlags & TSSymbolFlags.PrivateMember) {
|
|
153
|
-
memberExpr += `${optional}.#${sym.name}`;
|
|
154
|
-
} else if (
|
|
155
|
-
isValidJSIdentifier(sym.name) &&
|
|
156
|
-
!(sym.tsFlags & TSSymbolFlags.TypeSymbol)
|
|
157
|
-
) {
|
|
158
|
-
memberExpr += `${optional}.${sym.name}`;
|
|
159
|
-
} else {
|
|
160
|
-
const joiner = sym.tsFlags & TSSymbolFlags.Nullish ? "?." : "";
|
|
161
|
-
memberExpr += `${joiner}[${JSON.stringify(sym.name)}]`;
|
|
162
|
-
}
|
|
163
|
-
prevNullish = sym.tsFlags & TSSymbolFlags.Nullish;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return memberExpr;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function validateSymbolReachable(
|
|
170
|
-
path: TSOutputScope[],
|
|
171
|
-
memberPath: TSOutputSymbol[] | undefined,
|
|
172
|
-
currentPrivateScope: PrivateScopeContext | undefined,
|
|
173
|
-
) {
|
|
174
|
-
for (const scope of path) {
|
|
175
|
-
if (scope.kind === "function") {
|
|
176
|
-
throw new Error(
|
|
177
|
-
"Cannot reference a symbol inside a function from outside a function",
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (memberPath) {
|
|
183
|
-
for (const sym of memberPath) {
|
|
184
|
-
// make sure we're not trying to access a static private from outside
|
|
185
|
-
// the static member scope.
|
|
186
|
-
if (
|
|
187
|
-
sym.flags & OutputSymbolFlags.StaticMember &&
|
|
188
|
-
sym.tsFlags & TSSymbolFlags.PrivateMember &&
|
|
189
|
-
currentPrivateScope?.staticMembers !== sym.scope
|
|
190
|
-
) {
|
|
191
|
-
throw new Error(
|
|
192
|
-
"Cannot resolve private static member symbols from a different scope",
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|