@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,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
OutputSpace,
|
|
3
3
|
OutputSymbol,
|
|
4
4
|
OutputSymbolOptions,
|
|
5
5
|
track,
|
|
6
6
|
TrackOpTypes,
|
|
7
7
|
trigger,
|
|
8
8
|
TriggerOpTypes,
|
|
9
|
+
watch,
|
|
9
10
|
} from "@alloy-js/core";
|
|
10
11
|
import { TSOutputScope } from "./scopes.js";
|
|
11
|
-
import {
|
|
12
|
+
import { TSModuleScope } from "./ts-module-scope.js";
|
|
12
13
|
|
|
13
14
|
// prettier-ignore
|
|
14
15
|
export enum TSSymbolFlags {
|
|
@@ -16,51 +17,85 @@ export enum TSSymbolFlags {
|
|
|
16
17
|
LocalImportSymbol = 1 << 0,
|
|
17
18
|
TypeSymbol = 1 << 1,
|
|
18
19
|
ParameterSymbol = 1 << 2,
|
|
19
|
-
|
|
20
|
-
PrivateMemberContainer = 1 << 4,
|
|
21
|
-
Nullish = 1 << 5,
|
|
20
|
+
Nullish = 1 << 3,
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export interface CreateTsSymbolOptions extends OutputSymbolOptions {
|
|
25
|
-
scope?: TSOutputScope;
|
|
26
|
-
owner?: TSOutputSymbol;
|
|
27
24
|
export?: boolean;
|
|
28
25
|
default?: boolean;
|
|
29
26
|
tsFlags?: TSSymbolFlags;
|
|
27
|
+
hasInstanceMembers?: boolean;
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
export class TSOutputSymbol extends OutputSymbol {
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
static readonly memberSpaces = [
|
|
32
|
+
"static",
|
|
33
|
+
"instance",
|
|
34
|
+
"private-static",
|
|
35
|
+
"private-instance",
|
|
36
|
+
] as const;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
name: string,
|
|
40
|
+
spaces: OutputSpace[] | OutputSpace | undefined,
|
|
41
|
+
options: CreateTsSymbolOptions = {},
|
|
42
|
+
) {
|
|
43
|
+
super(name, spaces, options);
|
|
35
44
|
this.#export = !!options.export;
|
|
36
45
|
this.#default = !!options.default;
|
|
37
46
|
this.#tsFlags = options.tsFlags ?? TSSymbolFlags.None;
|
|
38
|
-
this.#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.#
|
|
48
|
-
"private static members",
|
|
49
|
-
{
|
|
50
|
-
flags: OutputScopeFlags.StaticMemberScope,
|
|
51
|
-
binder: this.binder,
|
|
52
|
-
owner: this,
|
|
53
|
-
},
|
|
54
|
-
);
|
|
47
|
+
this.#hasInstanceMembers = !!options.hasInstanceMembers;
|
|
48
|
+
if (
|
|
49
|
+
this.ownerSymbol?.isTypeSymbol ||
|
|
50
|
+
(this.spaces.some((s) => s.key === "types") &&
|
|
51
|
+
!this.spaces.some((s) => s.key === "values"))
|
|
52
|
+
) {
|
|
53
|
+
// Classes and enums are both types and values. The check above will treat them as values
|
|
54
|
+
// exclusively so that referencing occurs properly. This should instead use type or value
|
|
55
|
+
// referencing based on type context.
|
|
56
|
+
this.#tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
if (options.export && this.scope.kind === "module") {
|
|
58
|
+
if (options.export && this.scope && this.scope instanceof TSModuleScope) {
|
|
58
59
|
for (const refkey of this.refkeys) {
|
|
59
60
|
this.scope.exportedSymbols.set(refkey, this);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
get ownerSymbol() {
|
|
66
|
+
return super.ownerSymbol as TSOutputSymbol | undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
copy() {
|
|
70
|
+
const copy = new TSOutputSymbol(this.name, undefined, {
|
|
71
|
+
binder: this.binder,
|
|
72
|
+
aliasTarget: this.aliasTarget,
|
|
73
|
+
default: this.default,
|
|
74
|
+
export: this.export,
|
|
75
|
+
tsFlags: this.tsFlags,
|
|
76
|
+
metadata: this.metadata,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
this.initializeCopy(copy);
|
|
80
|
+
|
|
81
|
+
watch(
|
|
82
|
+
() => this.default,
|
|
83
|
+
(def) => (copy.default = def),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
watch(
|
|
87
|
+
() => this.export,
|
|
88
|
+
(exp) => (copy.export = exp),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
watch(
|
|
92
|
+
() => this.tsFlags,
|
|
93
|
+
(flags) => (copy.tsFlags = flags),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return copy;
|
|
97
|
+
}
|
|
98
|
+
|
|
64
99
|
#export: boolean;
|
|
65
100
|
get export() {
|
|
66
101
|
track(this, TrackOpTypes.GET, "export");
|
|
@@ -94,6 +129,13 @@ export class TSOutputSymbol extends OutputSymbol {
|
|
|
94
129
|
track(this, TrackOpTypes.GET, "tsFlags");
|
|
95
130
|
return this.#tsFlags;
|
|
96
131
|
}
|
|
132
|
+
|
|
133
|
+
#hasInstanceMembers: boolean = false;
|
|
134
|
+
get hasInstanceMembers() {
|
|
135
|
+
track(this, TrackOpTypes.GET, "hasInstanceMembers");
|
|
136
|
+
return this.#hasInstanceMembers;
|
|
137
|
+
}
|
|
138
|
+
|
|
97
139
|
set tsFlags(value: TSSymbolFlags) {
|
|
98
140
|
const oldValue = this.#tsFlags;
|
|
99
141
|
if (oldValue === value) {
|
|
@@ -103,37 +145,57 @@ export class TSOutputSymbol extends OutputSymbol {
|
|
|
103
145
|
trigger(this, TriggerOpTypes.SET, "tsFlags", value, oldValue);
|
|
104
146
|
}
|
|
105
147
|
|
|
106
|
-
get scope() {
|
|
107
|
-
return super.scope as TSOutputScope;
|
|
148
|
+
get scope(): TSOutputScope | undefined {
|
|
149
|
+
return super.scope as TSOutputScope | undefined;
|
|
108
150
|
}
|
|
109
|
-
|
|
110
|
-
|
|
151
|
+
|
|
152
|
+
get staticMembers() {
|
|
153
|
+
return this.memberSpaceFor("static")!;
|
|
111
154
|
}
|
|
112
155
|
|
|
113
|
-
get
|
|
114
|
-
return
|
|
156
|
+
get instanceMembers() {
|
|
157
|
+
return this.memberSpaceFor("instance")!;
|
|
115
158
|
}
|
|
116
159
|
|
|
117
|
-
get
|
|
118
|
-
return
|
|
160
|
+
get privateInstanceMembers() {
|
|
161
|
+
return this.memberSpaceFor("private-instance")!;
|
|
119
162
|
}
|
|
120
163
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return this.#privateMemberScope;
|
|
164
|
+
get privateStaticMembers() {
|
|
165
|
+
return this.memberSpaceFor("private-static")!;
|
|
124
166
|
}
|
|
125
167
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
168
|
+
get isPrivateMemberSymbol() {
|
|
169
|
+
return (
|
|
170
|
+
this.spaces.length > 0 &&
|
|
171
|
+
this.spaces.filter(
|
|
172
|
+
(s) => s.key === "private-static" || s.key === "private-instance",
|
|
173
|
+
).length > 0
|
|
174
|
+
);
|
|
129
175
|
}
|
|
130
176
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
177
|
+
get isPublicMemberSymbol() {
|
|
178
|
+
return !this.isPrivateMemberSymbol;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
get isStaticMemberSymbol() {
|
|
182
|
+
return !this.isInstanceMemberSymbol;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
get isInstanceMemberSymbol() {
|
|
186
|
+
return (
|
|
187
|
+
this.spaces.length > 0 &&
|
|
188
|
+
this.spaces.filter(
|
|
189
|
+
(s) => s.key === "instance" || s.key === "private-instance",
|
|
190
|
+
).length > 0
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
get isTypeSymbol() {
|
|
195
|
+
return !!(this.tsFlags & TSSymbolFlags.TypeSymbol);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
get isValueSymbol() {
|
|
199
|
+
return this.spaces.some((s) => s.key === "values");
|
|
138
200
|
}
|
|
139
201
|
}
|
|
@@ -12,10 +12,6 @@ export interface TSPackageScopeOptions extends OutputScopeOptions {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class TSPackageScope extends OutputScope {
|
|
15
|
-
get kind() {
|
|
16
|
-
return "package" as const;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
15
|
/**
|
|
20
16
|
* The version of the this package.
|
|
21
17
|
*/
|
|
@@ -74,7 +70,7 @@ export class TSPackageScope extends OutputScope {
|
|
|
74
70
|
path: string,
|
|
75
71
|
options: TSPackageScopeOptions = {},
|
|
76
72
|
) {
|
|
77
|
-
super(name, options);
|
|
73
|
+
super(name, undefined, options);
|
|
78
74
|
this.#version = version;
|
|
79
75
|
this.#path = path;
|
|
80
76
|
this.#builtin = !!options.builtin;
|
|
@@ -99,4 +95,8 @@ export class TSPackageScope extends OutputScope {
|
|
|
99
95
|
|
|
100
96
|
return null;
|
|
101
97
|
}
|
|
98
|
+
|
|
99
|
+
copyTo(): TSPackageScope {
|
|
100
|
+
throw new Error("Not supported");
|
|
101
|
+
}
|
|
102
102
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
defaultProps,
|
|
3
|
+
splitProps,
|
|
4
|
+
useMemberContext,
|
|
5
|
+
useScope,
|
|
6
|
+
} from "@alloy-js/core";
|
|
2
7
|
import { CallSignatureProps } from "./components/CallSignature.jsx";
|
|
8
|
+
import { TSLexicalScope } from "./symbols/ts-lexical-scope.js";
|
|
9
|
+
import { TSOutputSymbol } from "./symbols/ts-output-symbol.js";
|
|
3
10
|
|
|
4
11
|
export function modulePath(path: string) {
|
|
5
12
|
if (path[0] !== ".") {
|
|
@@ -38,3 +45,33 @@ const identifierRegex =
|
|
|
38
45
|
export function isValidJSIdentifier(str: string) {
|
|
39
46
|
return identifierRegex.test(str);
|
|
40
47
|
}
|
|
48
|
+
|
|
49
|
+
export function useLexicalScope(): TSLexicalScope | undefined {
|
|
50
|
+
const scope = useScope();
|
|
51
|
+
if (!scope) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!(scope instanceof TSLexicalScope)) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"A lexical scope is required but the current scope is not a lexical scope",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return scope;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useMemberOwner(): TSOutputSymbol {
|
|
65
|
+
const memberScope = useMemberContext();
|
|
66
|
+
if (!memberScope) {
|
|
67
|
+
throw new Error("A member owner is required but no member scope was found");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!(memberScope.ownerSymbol instanceof TSOutputSymbol)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"A member owner is required but the current owner is not a TSOutputSymbol",
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return memberScope.ownerSymbol;
|
|
77
|
+
}
|