@alloy-js/typescript 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/src/components/ClassDeclaration.d.ts +2 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +14 -2
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +13 -3
- package/dist/src/components/FunctionType.d.ts +7 -8
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +29 -25
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +9 -2
- package/dist/src/components/Interface.d.ts +3 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +8 -4
- package/dist/src/components/JSDocComment.js +1 -1
- package/dist/src/components/MemberDeclaration.d.ts +4 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +1 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +3 -2
- package/dist/src/components/Reference.d.ts +8 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +7 -2
- package/dist/src/components/TypeDeclaration.d.ts +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js +3 -2
- package/dist/src/components/TypeRefContext.d.ts +22 -0
- package/dist/src/components/TypeRefContext.d.ts.map +1 -0
- package/dist/src/components/TypeRefContext.js +41 -0
- package/dist/src/components/VarDeclaration.d.ts +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +9 -3
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/stc/index.d.ts +1 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -0
- package/dist/src/context/type-ref-context.d.ts +15 -0
- package/dist/src/context/type-ref-context.d.ts.map +1 -0
- package/dist/src/context/type-ref-context.js +12 -0
- package/dist/src/parameter-descriptor.d.ts +6 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/symbols/reference.d.ts +4 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +11 -5
- package/dist/src/symbols/ts-module-scope.d.ts +4 -1
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +10 -3
- package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +1 -0
- package/dist/test/class.test.js +4 -4
- package/dist/test/enum-jsdoc.test.js +6 -6
- package/dist/test/function-declaration-jsdoc.test.js +3 -3
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +208 -2
- package/dist/test/interface-jsdoc.test.js +9 -9
- package/dist/test/jsdoc.test.js +5 -5
- package/dist/test/jsdocparam.test.js +8 -8
- package/dist/test/member-expression.test.js +218 -2
- package/dist/test/var-declaration-jsdoc.test.js +3 -3
- package/dist/test/var-declaration.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/ClassDeclaration.tsx +19 -3
- package/src/components/FunctionBase.tsx +14 -3
- package/src/components/FunctionType.tsx +45 -40
- package/src/components/ImportStatement.tsx +30 -3
- package/src/components/Interface.tsx +41 -34
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +7 -1
- package/src/components/MemberExpression.tsx +7 -2
- package/src/components/Reference.tsx +12 -2
- package/src/components/TypeDeclaration.tsx +16 -13
- package/src/components/TypeRefContext.tsx +49 -0
- package/src/components/VarDeclaration.tsx +6 -2
- package/src/components/index.ts +1 -0
- package/src/components/stc/index.ts +1 -0
- package/src/context/type-ref-context.tsx +19 -0
- package/src/parameter-descriptor.ts +7 -0
- package/src/symbols/reference.ts +17 -5
- package/src/symbols/ts-module-scope.ts +19 -4
- package/src/symbols/ts-output-symbol.ts +1 -0
- package/temp/api.json +613 -220
- package/test/class.test.tsx +4 -4
- package/test/enum-jsdoc.test.tsx +6 -6
- package/test/function-declaration-jsdoc.test.tsx +3 -3
- package/test/imports.test.tsx +165 -1
- package/test/interface-jsdoc.test.tsx +9 -9
- package/test/jsdoc.test.tsx +5 -5
- package/test/jsdocparam.test.tsx +8 -8
- package/test/member-expression.test.tsx +171 -2
- package/test/var-declaration-jsdoc.test.tsx +3 -3
- package/test/var-declaration.test.tsx +1 -1
package/src/symbols/reference.ts
CHANGED
|
@@ -20,7 +20,10 @@ import { TSModuleScope } from "./ts-module-scope.js";
|
|
|
20
20
|
import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
|
|
21
21
|
import { TSPackageScope } from "./ts-package-scope.js";
|
|
22
22
|
|
|
23
|
-
export
|
|
23
|
+
export interface RefOptions {
|
|
24
|
+
type?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export function ref(refkey: Refkey, options?: RefOptions): () => string {
|
|
24
27
|
const sourceFile = useContext(SourceFileContext);
|
|
25
28
|
const resolveResult = resolve<TSOutputScope, TSOutputSymbol>(
|
|
26
29
|
refkey as Refkey,
|
|
@@ -103,8 +106,13 @@ export function ref(refkey: Refkey): () => string {
|
|
|
103
106
|
];
|
|
104
107
|
|
|
105
108
|
const importSymbol = symbolPath[0];
|
|
109
|
+
|
|
106
110
|
localSymbol = untrack(() =>
|
|
107
|
-
sourceFile!.scope.addImport(
|
|
111
|
+
sourceFile!.scope.addImport(
|
|
112
|
+
importSymbol,
|
|
113
|
+
pathDown[0] as TSModuleScope,
|
|
114
|
+
{ type: options?.type },
|
|
115
|
+
),
|
|
108
116
|
);
|
|
109
117
|
}
|
|
110
118
|
|
|
@@ -131,17 +139,21 @@ function buildMemberExpression(path: TSOutputSymbol[]) {
|
|
|
131
139
|
path = path.slice(1);
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
let prevNullish = base.tsFlags & TSSymbolFlags.Nullish;
|
|
134
143
|
for (const sym of path) {
|
|
144
|
+
const optional = prevNullish ? "?" : "";
|
|
135
145
|
if (sym.tsFlags & TSSymbolFlags.PrivateMember) {
|
|
136
|
-
memberExpr +=
|
|
146
|
+
memberExpr += `${optional}.#${sym.name}`;
|
|
137
147
|
} else if (
|
|
138
148
|
isValidJSIdentifier(sym.name) &&
|
|
139
149
|
!(sym.tsFlags & TSSymbolFlags.TypeSymbol)
|
|
140
150
|
) {
|
|
141
|
-
memberExpr +=
|
|
151
|
+
memberExpr += `${optional}.${sym.name}`;
|
|
142
152
|
} else {
|
|
143
|
-
|
|
153
|
+
const joiner = sym.tsFlags & TSSymbolFlags.Nullish ? "?." : "";
|
|
154
|
+
memberExpr += `${joiner}[${JSON.stringify(sym.name)}]`;
|
|
144
155
|
}
|
|
156
|
+
prevNullish = sym.tsFlags & TSSymbolFlags.Nullish;
|
|
145
157
|
}
|
|
146
158
|
|
|
147
159
|
return memberExpr;
|
|
@@ -11,6 +11,10 @@ export interface ImportedSymbol {
|
|
|
11
11
|
}
|
|
12
12
|
export type ImportRecords = Map<TSModuleScope, Set<ImportedSymbol>>;
|
|
13
13
|
|
|
14
|
+
export interface AddImportOptions {
|
|
15
|
+
type?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
export interface TSModuleScope extends OutputScope {
|
|
15
19
|
kind: "module";
|
|
16
20
|
exportedSymbols: Map<Refkey, TSOutputSymbol>;
|
|
@@ -19,7 +23,11 @@ export interface TSModuleScope extends OutputScope {
|
|
|
19
23
|
*/
|
|
20
24
|
importedSymbols: Map<TSOutputSymbol, TSOutputSymbol>;
|
|
21
25
|
importedModules: ImportRecords;
|
|
22
|
-
addImport(
|
|
26
|
+
addImport(
|
|
27
|
+
symbol: TSOutputSymbol,
|
|
28
|
+
module: TSModuleScope,
|
|
29
|
+
options?: AddImportOptions,
|
|
30
|
+
): TSOutputSymbol;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export function createTSModuleScope(
|
|
@@ -34,9 +42,13 @@ export function createTSModuleScope(
|
|
|
34
42
|
exportedSymbols: new Map(),
|
|
35
43
|
importedSymbols: new Map(),
|
|
36
44
|
importedModules: new Map(),
|
|
37
|
-
addImport(this: TSModuleScope, targetSymbol, targetModule) {
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
addImport(this: TSModuleScope, targetSymbol, targetModule, options) {
|
|
46
|
+
const existing = this.importedSymbols.get(targetSymbol);
|
|
47
|
+
if (existing) {
|
|
48
|
+
if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
|
|
49
|
+
existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
|
|
50
|
+
}
|
|
51
|
+
return existing;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
if (targetModule.kind !== "module") {
|
|
@@ -54,6 +66,9 @@ export function createTSModuleScope(
|
|
|
54
66
|
refkey: refkey({}),
|
|
55
67
|
tsFlags: TSSymbolFlags.LocalImportSymbol,
|
|
56
68
|
});
|
|
69
|
+
if (options?.type) {
|
|
70
|
+
localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
71
|
+
}
|
|
57
72
|
|
|
58
73
|
this.importedSymbols.set(targetSymbol, localSymbol);
|
|
59
74
|
this.importedModules.get(targetModule)!.add({
|