@alloy-js/typescript 0.20.0-dev.0 → 0.20.0-dev.2
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/index.js +2 -1
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/node.d.ts +1 -1
- package/dist/src/builtins/node.js +2 -1
- package/dist/src/builtins/node.js.map +1 -0
- package/dist/src/components/ArrayExpression.js +2 -1
- package/dist/src/components/ArrayExpression.js.map +1 -0
- package/dist/src/components/ArrowFunction.d.ts.map +1 -1
- package/dist/src/components/ArrowFunction.js +9 -14
- package/dist/src/components/ArrowFunction.js.map +1 -0
- package/dist/src/components/BarrelFile.js +2 -1
- package/dist/src/components/BarrelFile.js.map +1 -0
- package/dist/src/components/BlockScope.d.ts.map +1 -1
- package/dist/src/components/BlockScope.js +5 -3
- package/dist/src/components/BlockScope.js.map +1 -0
- package/dist/src/components/CallSignature.js +2 -1
- package/dist/src/components/CallSignature.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +22 -31
- package/dist/src/components/ClassDeclaration.js.map +1 -0
- package/dist/src/components/CommaList.js +2 -1
- package/dist/src/components/CommaList.js.map +1 -0
- 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 +22 -44
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +7 -10
- package/dist/src/components/EnumDeclaration.js.map +1 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +5 -5
- package/dist/src/components/EnumMember.js.map +1 -0
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +4 -2
- package/dist/src/components/ExportStatement.js.map +1 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +17 -13
- package/dist/src/components/FunctionBase.js.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +2 -1
- package/dist/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +5 -4
- package/dist/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/src/components/FunctionExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionExpression.js +9 -14
- package/dist/src/components/FunctionExpression.js.map +1 -0
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +5 -4
- package/dist/src/components/FunctionType.js.map +1 -0
- package/dist/src/components/IfStatement.d.ts.map +1 -1
- package/dist/src/components/IfStatement.js +4 -2
- package/dist/src/components/IfStatement.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +5 -5
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +16 -14
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
- package/dist/src/components/InterfaceMethod.js +6 -4
- package/dist/src/components/InterfaceMethod.js.map +1 -0
- package/dist/src/components/JSDoc.js +2 -1
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.js +2 -1
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.js +2 -1
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParam.js +2 -1
- package/dist/src/components/JSDocParam.js.map +1 -0
- 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 +25 -0
- package/dist/src/components/LexicalScope.js.map +1 -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 +5 -8
- package/dist/src/components/MemberDeclaration.js.map +1 -0
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +15 -6
- package/dist/src/components/MemberExpression.js.map +1 -0
- 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 +18 -0
- package/dist/src/components/MemberScope.js.map +1 -0
- package/dist/src/components/NewExpression.d.ts.map +1 -1
- package/dist/src/components/NewExpression.js +7 -6
- package/dist/src/components/NewExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +12 -15
- package/dist/src/components/ObjectExpression.js.map +1 -0
- package/dist/src/components/PackageDirectory.js +2 -1
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/PackageJson.js +2 -1
- package/dist/src/components/PackageJson.js.map +1 -0
- package/dist/src/components/PropertyName.js +3 -3
- package/dist/src/components/PropertyName.js.map +1 -0
- package/dist/src/components/Reference.js +2 -1
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SingleLineCommentBlock.js +2 -1
- package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +5 -3
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/SwitchStatement.js +2 -1
- package/dist/src/components/SwitchStatement.js.map +1 -0
- package/dist/src/components/TsConfigJson.js +2 -1
- package/dist/src/components/TsConfigJson.js.map +1 -0
- package/dist/src/components/TypeDeclaration.js +2 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -0
- package/dist/src/components/TypeRefContext.js +2 -1
- package/dist/src/components/TypeRefContext.js.map +1 -0
- package/dist/src/components/ValueExpression.js +2 -1
- package/dist/src/components/ValueExpression.js.map +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +16 -27
- package/dist/src/components/VarDeclaration.js.map +1 -0
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/interface/expression.test.js +2 -1
- package/dist/src/components/interface/expression.test.js.map +1 -0
- package/dist/src/components/stc/index.js +2 -1
- package/dist/src/components/stc/index.js.map +1 -0
- 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 +2 -1
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/type-ref-context.js +2 -1
- package/dist/src/context/type-ref-context.js.map +1 -0
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +13 -34
- package/dist/src/create-package.js.map +1 -0
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-conflict-resolver.js +2 -1
- package/dist/src/name-conflict-resolver.js.map +1 -0
- package/dist/src/name-policy.js +2 -1
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/parameter-descriptor.js +2 -1
- package/dist/src/parameter-descriptor.js.map +1 -0
- package/dist/src/source-directory-data.js +2 -1
- package/dist/src/source-directory-data.js.map +1 -0
- 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 +73 -1
- package/dist/src/symbols/index.js.map +1 -0
- 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 +69 -70
- package/dist/src/symbols/reference.js.map +1 -0
- 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 +28 -1
- package/dist/src/symbols/scopes.js.map +1 -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 +17 -0
- package/dist/src/symbols/ts-lexical-scope.js.map +1 -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 +17 -7
- package/dist/src/symbols/ts-member-scope.js.map +1 -0
- 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 +31 -19
- package/dist/src/symbols/ts-module-scope.js.map +1 -0
- 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 +62 -38
- package/dist/src/symbols/ts-output-symbol.js.map +1 -0
- 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 +6 -6
- package/dist/src/symbols/ts-package-scope.js.map +1 -0
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +25 -2
- package/dist/src/utils.js.map +1 -0
- package/dist/test/array.test.js +2 -1
- package/dist/test/array.test.js.map +1 -0
- package/dist/test/arrow-function.test.js +2 -1
- package/dist/test/arrow-function.test.js.map +1 -0
- package/dist/test/barrel.test.js +26 -17
- package/dist/test/barrel.test.js.map +1 -0
- package/dist/test/basic.test.js +22 -26
- package/dist/test/basic.test.js.map +1 -0
- package/dist/test/block-scope.test.js +2 -1
- package/dist/test/block-scope.test.js.map +1 -0
- package/dist/test/class.test.js +24 -18
- package/dist/test/class.test.js.map +1 -0
- package/dist/test/enum-jsdoc.test.js +2 -1
- package/dist/test/enum-jsdoc.test.js.map +1 -0
- package/dist/test/enum.test.js +2 -1
- package/dist/test/enum.test.js.map +1 -0
- package/dist/test/externals.test.js +12 -51
- package/dist/test/externals.test.js.map +1 -0
- package/dist/test/function-call-expression.test.js +9 -8
- package/dist/test/function-call-expression.test.js.map +1 -0
- package/dist/test/function-declaration-jsdoc.test.js +2 -1
- package/dist/test/function-declaration-jsdoc.test.js.map +1 -0
- package/dist/test/function-declaration.test.js +2 -1
- package/dist/test/function-declaration.test.js.map +1 -0
- package/dist/test/function-expression.test.js +2 -1
- package/dist/test/function-expression.test.js.map +1 -0
- package/dist/test/function-type.test.js +2 -1
- package/dist/test/function-type.test.js.map +1 -0
- package/dist/test/if-statement.test.js +2 -1
- package/dist/test/if-statement.test.js.map +1 -0
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +62 -60
- package/dist/test/imports.test.js.map +1 -0
- package/dist/test/interface-jsdoc.test.js +2 -1
- package/dist/test/interface-jsdoc.test.js.map +1 -0
- package/dist/test/interface.test.js +2 -1
- package/dist/test/interface.test.js.map +1 -0
- package/dist/test/jscomment.test.js +2 -1
- package/dist/test/jscomment.test.js.map +1 -0
- package/dist/test/jsdoc.test.js +2 -1
- package/dist/test/jsdoc.test.js.map +1 -0
- package/dist/test/jsdocparam.test.js +2 -1
- package/dist/test/jsdocparam.test.js.map +1 -0
- package/dist/test/member-expression.test.js +8 -7
- package/dist/test/member-expression.test.js.map +1 -0
- package/dist/test/name-conflict.test.js +5 -7
- package/dist/test/name-conflict.test.js.map +1 -0
- package/dist/test/name-policy.test.js +9 -13
- package/dist/test/name-policy.test.js.map +1 -0
- package/dist/test/new-expression.test.js +6 -7
- package/dist/test/new-expression.test.js.map +1 -0
- package/dist/test/object.test.js +2 -1
- package/dist/test/object.test.js.map +1 -0
- package/dist/test/package-external.test.js +71 -66
- package/dist/test/package-external.test.js.map +1 -0
- package/dist/test/package-json.test.js +8 -10
- package/dist/test/package-json.test.js.map +1 -0
- package/dist/test/package.test.js +12 -12
- package/dist/test/package.test.js.map +1 -0
- package/dist/test/reference.test.js +10 -12
- package/dist/test/reference.test.js.map +1 -0
- package/dist/test/source-file.test.js +7 -10
- package/dist/test/source-file.test.js.map +1 -0
- package/dist/test/switch-statement.test.js +2 -1
- package/dist/test/switch-statement.test.js.map +1 -0
- package/dist/test/utils.js +6 -2
- package/dist/test/utils.js.map +1 -0
- package/dist/test/value-expression.test.js +2 -1
- package/dist/test/value-expression.test.js.map +1 -0
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/test/values.test.js +11 -8
- package/dist/test/values.test.js.map +1 -0
- package/dist/test/var-declaration-jsdoc.test.js +2 -1
- package/dist/test/var-declaration-jsdoc.test.js.map +1 -0
- package/dist/test/var-declaration.test.d.ts.map +1 -1
- package/dist/test/var-declaration.test.js +21 -12
- package/dist/test/var-declaration.test.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- 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/barrel.test.tsx +24 -18
- package/test/basic.test.tsx +20 -29
- package/test/class.test.tsx +28 -18
- package/test/externals.test.tsx +10 -57
- package/test/function-call-expression.test.tsx +6 -7
- package/test/imports.test.tsx +57 -74
- package/test/member-expression.test.tsx +5 -13
- package/test/name-conflict.test.tsx +4 -7
- package/test/name-policy.test.tsx +7 -15
- package/test/new-expression.test.tsx +4 -7
- package/test/package-external.test.tsx +69 -73
- package/test/package-json.test.tsx +6 -11
- package/test/package.test.tsx +8 -11
- package/test/reference.test.tsx +10 -15
- package/test/source-file.test.tsx +5 -11
- package/test/utils.tsx +1 -1
- package/test/values.test.tsx +8 -8
- package/test/var-declaration.test.tsx +19 -20
- 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/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
|
-
}
|