@alloy-js/typescript 0.5.0 → 0.7.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 +28 -0
- package/dist/src/components/ArrayExpression.d.ts +1 -1
- package/dist/src/components/ArrayExpression.d.ts.map +1 -1
- package/dist/src/components/ArrayExpression.js +18 -28
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BarrelFile.d.ts.map +1 -1
- package/dist/src/components/BarrelFile.js +11 -9
- package/dist/src/components/BarrelFile.js.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +8 -9
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/CommaList.d.ts +12 -0
- package/dist/src/components/CommaList.d.ts.map +1 -0
- package/dist/src/components/CommaList.js +19 -0
- package/dist/src/components/CommaList.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +4 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -2
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +21 -18
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +3 -1
- package/dist/src/components/ExportStatement.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.d.ts +2 -2
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionCallExpression.js +26 -9
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +10 -2
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +136 -33
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +25 -31
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/components/Interface.d.ts +1 -1
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +5 -5
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts +10 -0
- package/dist/src/components/JSDoc.d.ts.map +1 -0
- package/dist/src/components/JSDoc.js +24 -0
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.d.ts +11 -0
- package/dist/src/components/JSDocComment.d.ts.map +1 -0
- package/dist/src/components/JSDocComment.js +16 -0
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.d.ts +12 -0
- package/dist/src/components/JSDocExample.d.ts.map +1 -0
- package/dist/src/components/JSDocExample.js +26 -0
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParagraph.d.ts +10 -0
- package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
- package/dist/src/components/JSDocParagraph.js +23 -0
- package/dist/src/components/JSDocParagraph.js.map +1 -0
- package/dist/src/components/MemberChainExpression.d.ts +11 -0
- package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
- package/dist/src/components/MemberChainExpression.js +100 -0
- package/dist/src/components/MemberChainExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +1 -1
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +45 -42
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PackageDirectory.d.ts +1 -3
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +9 -16
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts +39 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js +30 -12
- package/dist/src/components/PackageJson.js.map +1 -1
- package/dist/src/components/Reference.js +1 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +13 -6
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TsConfigJson.js.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/ValueExpression.d.ts.map +1 -1
- package/dist/src/components/ValueExpression.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +5 -4
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +21 -21
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +5 -2
- package/dist/src/symbols/reference.js.map +1 -1
- 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 +4 -1
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts +0 -15
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +0 -8
- package/dist/src/symbols/ts-package-scope.js.map +1 -1
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/jsdoc.test.d.ts +2 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -0
- package/dist/test/member-chain.test.d.ts +2 -0
- package/dist/test/member-chain.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/ArrayExpression.tsx +22 -32
- package/src/components/BarrelFile.tsx +7 -13
- package/src/components/ClassDeclaration.tsx +33 -28
- package/src/components/CommaList.tsx +23 -0
- package/src/components/Declaration.tsx +14 -5
- package/src/components/EnumDeclaration.tsx +23 -16
- package/src/components/EnumMember.tsx +7 -4
- package/src/components/ExportStatement.tsx +9 -2
- package/src/components/FunctionCallExpression.tsx +18 -9
- package/src/components/FunctionDeclaration.tsx +173 -56
- package/src/components/ImportStatement.tsx +6 -9
- package/src/components/Interface.tsx +20 -13
- package/src/components/JSDoc.tsx +28 -0
- package/src/components/JSDocComment.tsx +23 -0
- package/src/components/JSDocExample.tsx +30 -0
- package/src/components/JSDocParagraph.tsx +35 -0
- package/src/components/MemberChainExpression.tsx +91 -0
- package/src/components/ObjectExpression.tsx +53 -48
- package/src/components/PackageDirectory.tsx +22 -30
- package/src/components/PackageJson.tsx +91 -29
- package/src/components/SourceFile.tsx +15 -8
- package/src/components/TsConfigJson.tsx +5 -3
- package/src/components/TypeDeclaration.tsx +5 -3
- package/src/components/ValueExpression.tsx +3 -1
- package/src/components/VarDeclaration.tsx +13 -7
- package/src/components/index.ts +2 -1
- package/src/components/stc/index.ts +1 -1
- package/src/symbols/reference.ts +7 -4
- package/src/symbols/ts-output-symbol.ts +6 -2
- package/src/symbols/ts-package-scope.ts +0 -28
- package/temp/api.json +802 -395
- package/test/array.test.tsx +40 -7
- package/test/basic.test.tsx +26 -21
- package/test/class.test.tsx +65 -53
- package/test/enum.test.tsx +18 -13
- package/test/externals.test.tsx +6 -7
- package/test/function-call-expression.test.tsx +39 -17
- package/test/function-declaration.test.tsx +96 -78
- package/test/imports.test.tsx +115 -75
- package/test/interface.test.tsx +32 -22
- package/test/jsdoc.test.tsx +154 -0
- package/test/member-chain.test.tsx +124 -0
- package/test/name-policy.test.tsx +33 -26
- package/test/package-external.test.tsx +106 -7
- package/test/package.test.tsx +57 -5
- package/test/reference.test.tsx +2 -6
- package/test/utils.tsx +3 -1
- package/test/value-expression.test.tsx +2 -6
- package/test/values.test.tsx +67 -73
- package/test/var-declaration.test.tsx +11 -5
- package/test/vitest.d.ts +6 -1
- package/tsconfig.json +8 -1
- package/dist/src/components/Block.d.ts +0 -6
- package/dist/src/components/Block.d.ts.map +0 -1
- package/dist/src/components/Block.js +0 -11
- package/dist/src/components/Block.js.map +0 -1
- package/src/components/Block.tsx +0 -12
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Block,
|
|
2
3
|
childrenArray,
|
|
3
4
|
code,
|
|
4
5
|
findKeyedChild,
|
|
5
6
|
findUnkeyedChildren,
|
|
6
|
-
|
|
7
|
+
For,
|
|
8
|
+
Indent,
|
|
7
9
|
Name,
|
|
8
10
|
Refkey,
|
|
9
11
|
refkey,
|
|
10
12
|
Scope,
|
|
13
|
+
Show,
|
|
11
14
|
taggedComponent,
|
|
12
15
|
} from "@alloy-js/core";
|
|
13
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
16
|
+
import { Children, onCleanup } from "@alloy-js/core/jsx-runtime";
|
|
14
17
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
15
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
createTSSymbol,
|
|
20
|
+
TSOutputSymbol,
|
|
21
|
+
TSSymbolFlags,
|
|
22
|
+
} from "../symbols/index.js";
|
|
16
23
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
17
24
|
|
|
18
25
|
export interface ParameterDescriptor {
|
|
19
|
-
type
|
|
20
|
-
refkey
|
|
26
|
+
type?: Children;
|
|
27
|
+
refkey?: Refkey;
|
|
28
|
+
refkeys?: Refkey[];
|
|
21
29
|
optional?: boolean;
|
|
22
30
|
}
|
|
23
31
|
|
|
@@ -31,36 +39,54 @@ function isParameterDescriptor(
|
|
|
31
39
|
export interface FunctionDeclarationProps extends BaseDeclarationProps {
|
|
32
40
|
async?: boolean;
|
|
33
41
|
parameters?: Record<string, Children | ParameterDescriptor>;
|
|
42
|
+
typeParameters?: Record<string, Children | ParameterDescriptor> | string[];
|
|
34
43
|
returnType?: Children;
|
|
35
44
|
children?: Children;
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
export const functionParametersTag = Symbol();
|
|
48
|
+
export const functionTypeParametersTag = Symbol();
|
|
39
49
|
export const functionBodyTag = Symbol();
|
|
40
50
|
|
|
41
51
|
export function FunctionDeclaration(props: FunctionDeclarationProps) {
|
|
42
52
|
const children = childrenArray(() => props.children);
|
|
53
|
+
const typeParametersChild = findKeyedChild(
|
|
54
|
+
children,
|
|
55
|
+
functionTypeParametersTag,
|
|
56
|
+
);
|
|
43
57
|
const parametersChild = findKeyedChild(children, functionParametersTag);
|
|
44
58
|
const bodyChild = findKeyedChild(children, functionBodyTag);
|
|
45
59
|
const filteredChildren = findUnkeyedChildren(children);
|
|
46
60
|
const returnType = getReturnType(props.returnType, { async: props.async });
|
|
47
61
|
const sReturnType = returnType ? <>: {returnType}</> : undefined;
|
|
48
62
|
|
|
49
|
-
const
|
|
50
|
-
|
|
63
|
+
const sTypeParameters =
|
|
64
|
+
typeParametersChild ?
|
|
65
|
+
<>
|
|
66
|
+
{"<"}
|
|
67
|
+
{typeParametersChild}
|
|
68
|
+
{">"}
|
|
69
|
+
</>
|
|
70
|
+
: <FunctionDeclaration.TypeParameters parameters={props.typeParameters} />;
|
|
71
|
+
|
|
72
|
+
const sParams = parametersChild ?? (
|
|
73
|
+
<FunctionDeclaration.Parameters parameters={props.parameters} />
|
|
74
|
+
);
|
|
51
75
|
|
|
52
|
-
const sBody =
|
|
53
|
-
|
|
76
|
+
const sBody = bodyChild ?? (
|
|
77
|
+
<FunctionDeclaration.Body>{filteredChildren}</FunctionDeclaration.Body>
|
|
78
|
+
);
|
|
54
79
|
|
|
55
80
|
const asyncKwd = props.async ? "async " : "";
|
|
56
81
|
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
82
|
+
return (
|
|
83
|
+
<Declaration {...props} nameKind="function">
|
|
84
|
+
{asyncKwd}function <Name />
|
|
85
|
+
<Scope name={props.name} kind="function">
|
|
86
|
+
{sTypeParameters}({sParams}){sReturnType} {sBody}
|
|
62
87
|
</Scope>
|
|
63
|
-
</Declaration
|
|
88
|
+
</Declaration>
|
|
89
|
+
);
|
|
64
90
|
}
|
|
65
91
|
|
|
66
92
|
function getReturnType(
|
|
@@ -71,6 +97,108 @@ function getReturnType(
|
|
|
71
97
|
return options.async ? code`Promise<${returnType}>` : returnType;
|
|
72
98
|
}
|
|
73
99
|
}
|
|
100
|
+
|
|
101
|
+
interface DeclaredParameterDescriptor extends ParameterDescriptor {
|
|
102
|
+
symbol: TSOutputSymbol;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function normalizeAndDeclareParameters(
|
|
106
|
+
parameters: Record<string, Children | ParameterDescriptor> | string[],
|
|
107
|
+
flags: TSSymbolFlags = TSSymbolFlags.ParameterSymbol,
|
|
108
|
+
): DeclaredParameterDescriptor[] {
|
|
109
|
+
const namePolicy = useTSNamePolicy();
|
|
110
|
+
if (Array.isArray(parameters)) {
|
|
111
|
+
return parameters.map((paramName) => {
|
|
112
|
+
const symbol = createTSSymbol({
|
|
113
|
+
name: namePolicy.getName(
|
|
114
|
+
paramName,
|
|
115
|
+
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
116
|
+
),
|
|
117
|
+
refkey: refkey(),
|
|
118
|
+
tsFlags: flags,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return { refkeys: symbol.refkeys, symbol };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return Object.entries(parameters).map(([paramName, value]) => {
|
|
126
|
+
const descriptor: DeclaredParameterDescriptor =
|
|
127
|
+
isParameterDescriptor(value) ? value : (
|
|
128
|
+
({
|
|
129
|
+
refkey: refkey(),
|
|
130
|
+
type: value,
|
|
131
|
+
} as any)
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const symbol = createTSSymbol({
|
|
135
|
+
name: namePolicy.getName(
|
|
136
|
+
paramName,
|
|
137
|
+
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
138
|
+
),
|
|
139
|
+
refkey: descriptor.refkey,
|
|
140
|
+
refkeys: descriptor.refkeys,
|
|
141
|
+
tsFlags: flags,
|
|
142
|
+
});
|
|
143
|
+
descriptor.symbol = symbol;
|
|
144
|
+
return descriptor;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface FunctionTypeParametersProps {
|
|
149
|
+
parameters?: Record<string, Children | ParameterDescriptor> | string[];
|
|
150
|
+
children?: Children;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
FunctionDeclaration.TypeParameters = taggedComponent(
|
|
154
|
+
functionTypeParametersTag,
|
|
155
|
+
function TypeParameters(props: FunctionTypeParametersProps) {
|
|
156
|
+
if (props.children) {
|
|
157
|
+
return props.children;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!props.parameters) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const typeParameters = normalizeAndDeclareParameters(props.parameters);
|
|
165
|
+
|
|
166
|
+
onCleanup(() => {
|
|
167
|
+
for (const param of typeParameters) {
|
|
168
|
+
param.symbol.binder.deleteSymbol(param.symbol);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<>
|
|
174
|
+
{"<"}
|
|
175
|
+
<group>
|
|
176
|
+
<Indent break="soft">
|
|
177
|
+
<For each={typeParameters} comma line>
|
|
178
|
+
{(param) => typeParameter(param)}
|
|
179
|
+
</For>
|
|
180
|
+
<ifBreak>,</ifBreak>
|
|
181
|
+
</Indent>
|
|
182
|
+
</group>
|
|
183
|
+
{">"}
|
|
184
|
+
</>
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
function typeParameter(param: DeclaredParameterDescriptor) {
|
|
190
|
+
return (
|
|
191
|
+
<group>
|
|
192
|
+
{param.symbol.name}
|
|
193
|
+
<Show when={!!param.type}>
|
|
194
|
+
{" "}
|
|
195
|
+
extends
|
|
196
|
+
<indent> {param.type}</indent>
|
|
197
|
+
</Show>
|
|
198
|
+
</group>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
74
202
|
export interface FunctionParametersProps {
|
|
75
203
|
parameters?: Record<string, Children | ParameterDescriptor>;
|
|
76
204
|
children?: Children;
|
|
@@ -79,54 +207,43 @@ export interface FunctionParametersProps {
|
|
|
79
207
|
FunctionDeclaration.Parameters = taggedComponent(
|
|
80
208
|
functionParametersTag,
|
|
81
209
|
function Parameters(props: FunctionParametersProps) {
|
|
82
|
-
const namePolicy = useTSNamePolicy();
|
|
83
|
-
|
|
84
|
-
let value;
|
|
85
|
-
|
|
86
210
|
if (props.children) {
|
|
87
|
-
|
|
88
|
-
} else if (props.parameters) {
|
|
89
|
-
const scope = useTSScope();
|
|
90
|
-
if (scope.kind !== "function") {
|
|
91
|
-
throw new Error(
|
|
92
|
-
"Can't declare function parameter in non-function scope",
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
value = mapJoin(
|
|
97
|
-
new Map(Object.entries(props.parameters)),
|
|
98
|
-
(key, value) => {
|
|
99
|
-
const descriptor: ParameterDescriptor = isParameterDescriptor(value) ?
|
|
100
|
-
value
|
|
101
|
-
: {
|
|
102
|
-
refkey: refkey(),
|
|
103
|
-
type: value,
|
|
104
|
-
};
|
|
105
|
-
const optionality = descriptor.optional ? "?" : "";
|
|
106
|
-
const sym = createTSSymbol({
|
|
107
|
-
name: key,
|
|
108
|
-
refkey: descriptor.refkey,
|
|
109
|
-
tsFlags: TSSymbolFlags.ParameterSymbol,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return <>{namePolicy.getName(sym.name, "parameter")}{optionality}: {descriptor.type}</>;
|
|
113
|
-
},
|
|
114
|
-
{ joiner: ", " },
|
|
115
|
-
);
|
|
116
|
-
} else {
|
|
117
|
-
value = undefined;
|
|
211
|
+
return props.children;
|
|
118
212
|
}
|
|
119
213
|
|
|
120
|
-
|
|
214
|
+
const parameters = normalizeAndDeclareParameters(props.parameters ?? {});
|
|
215
|
+
return (
|
|
216
|
+
<group>
|
|
217
|
+
<Indent break="soft">
|
|
218
|
+
<For each={parameters} comma line>
|
|
219
|
+
{(param) => parameter(param)}
|
|
220
|
+
</For>
|
|
221
|
+
<ifBreak>,</ifBreak>
|
|
222
|
+
</Indent>
|
|
223
|
+
</group>
|
|
224
|
+
);
|
|
121
225
|
},
|
|
122
226
|
);
|
|
123
227
|
|
|
228
|
+
function parameter(param: DeclaredParameterDescriptor) {
|
|
229
|
+
return (
|
|
230
|
+
<group>
|
|
231
|
+
{param.symbol.name}
|
|
232
|
+
<Show when={!!param.optional}>?</Show>
|
|
233
|
+
<Show when={!!param.type}>
|
|
234
|
+
<indent>: {param.type}</indent>
|
|
235
|
+
</Show>
|
|
236
|
+
</group>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
124
240
|
export interface FunctionBodyProps {
|
|
125
241
|
children?: Children;
|
|
126
242
|
}
|
|
127
243
|
|
|
128
|
-
FunctionDeclaration.Body = taggedComponent(
|
|
129
|
-
|
|
130
|
-
) {
|
|
131
|
-
|
|
132
|
-
}
|
|
244
|
+
FunctionDeclaration.Body = taggedComponent(
|
|
245
|
+
functionBodyTag,
|
|
246
|
+
function Body(props: FunctionBodyProps) {
|
|
247
|
+
return <Block>{props.children}</Block>;
|
|
248
|
+
},
|
|
249
|
+
);
|
|
@@ -20,12 +20,9 @@ export interface ImportStatementsProps {
|
|
|
20
20
|
export function ImportStatements(props: ImportStatementsProps) {
|
|
21
21
|
const pkg = usePackage();
|
|
22
22
|
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
27
|
-
props.records.size;
|
|
28
|
-
return mapJoin(props.records, (module, importedSymbols) => {
|
|
23
|
+
return mapJoin(
|
|
24
|
+
() => props.records,
|
|
25
|
+
(module, importedSymbols) => {
|
|
29
26
|
let targetPath: string;
|
|
30
27
|
|
|
31
28
|
if (
|
|
@@ -60,8 +57,8 @@ export function ImportStatements(props: ImportStatementsProps) {
|
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
return <ImportStatement path={targetPath} symbols={importedSymbols} />;
|
|
63
|
-
}
|
|
64
|
-
|
|
60
|
+
},
|
|
61
|
+
);
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
export interface ImportStatementProps {
|
|
@@ -96,7 +93,7 @@ export function ImportStatement(props: ImportStatementProps) {
|
|
|
96
93
|
parts.push("{ ");
|
|
97
94
|
parts.push(
|
|
98
95
|
mapJoin(
|
|
99
|
-
namedImportSymbols,
|
|
96
|
+
() => namedImportSymbols,
|
|
100
97
|
(nis) => <ImportBinding importedSymbol={nis} />,
|
|
101
98
|
{ joiner: ", " },
|
|
102
99
|
),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Block, Children, Name } from "@alloy-js/core";
|
|
2
2
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
3
3
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
4
4
|
|
|
@@ -18,11 +18,12 @@ export interface InterfaceDeclarationProps extends BaseDeclarationProps {
|
|
|
18
18
|
export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
|
|
19
19
|
const extendsPart = props.extends ? <> extends {props.extends}</> : "";
|
|
20
20
|
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
return (
|
|
22
|
+
<Declaration {...props} nameKind="interface">
|
|
23
|
+
interface <Name />
|
|
24
|
+
{extendsPart} <InterfaceExpression>{props.children}</InterfaceExpression>
|
|
25
|
+
</Declaration>
|
|
26
|
+
);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface InterfaceExpressionProps {
|
|
@@ -30,11 +31,7 @@ export interface InterfaceExpressionProps {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export function InterfaceExpression(props: InterfaceExpressionProps) {
|
|
33
|
-
return
|
|
34
|
-
{
|
|
35
|
-
${props.children}
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
34
|
+
return <Block>{props.children}</Block>;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
export interface InterfaceMemberProps {
|
|
@@ -55,8 +52,18 @@ export function InterfaceMember(props: InterfaceMemberProps) {
|
|
|
55
52
|
const optionality = props.optional ? "?" : "";
|
|
56
53
|
const readonly = props.readonly ? "readonly " : "";
|
|
57
54
|
if (props.indexer) {
|
|
58
|
-
return
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
[{props.indexer}]: {type}
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
59
60
|
} else {
|
|
60
|
-
return
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{readonly}
|
|
64
|
+
{namer.getName(props.name!, "interface-member")}
|
|
65
|
+
{optionality}: {type}
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { List, childrenArray } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { JSDocComment } from "./JSDocComment.jsx";
|
|
4
|
+
|
|
5
|
+
export interface JSDocProps {
|
|
6
|
+
children: Children;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A JSDoc comment. The children of this component are joined with two hard
|
|
11
|
+
* linebreaks. This is useful for creating JSDoc comments with multiple paragraphs.
|
|
12
|
+
*/
|
|
13
|
+
export function JSDoc(props: JSDocProps) {
|
|
14
|
+
return (
|
|
15
|
+
<JSDocComment>
|
|
16
|
+
<List
|
|
17
|
+
joiner={
|
|
18
|
+
<>
|
|
19
|
+
<hbr />
|
|
20
|
+
<hbr />
|
|
21
|
+
</>
|
|
22
|
+
}
|
|
23
|
+
>
|
|
24
|
+
{childrenArray(() => props.children)}
|
|
25
|
+
</List>
|
|
26
|
+
</JSDocComment>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
export interface JSDocCommentProps {
|
|
4
|
+
children: Children;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A JSDoc comment block. This is a low-level component that merely creates the
|
|
9
|
+
* block. Consider using {@link JSDoc} if you want to create more complex
|
|
10
|
+
* comments.
|
|
11
|
+
*/
|
|
12
|
+
export function JSDocComment(props: JSDocCommentProps) {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
/**
|
|
16
|
+
<align string=" * ">
|
|
17
|
+
<hbr />
|
|
18
|
+
{props.children}
|
|
19
|
+
</align>
|
|
20
|
+
<hbr /> **/
|
|
21
|
+
</>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Show } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
export interface JSDocExampleProps {
|
|
5
|
+
fenced?: boolean;
|
|
6
|
+
language?: string;
|
|
7
|
+
children: Children;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create a JSDoc example set off with `@example`. When the `fenced` prop is true, a `language` prop can
|
|
12
|
+
* also be set.
|
|
13
|
+
*/
|
|
14
|
+
export function JSDocExample(props: JSDocExampleProps) {
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
@example
|
|
18
|
+
<hbr />
|
|
19
|
+
<Show when={props.fenced}>
|
|
20
|
+
```{props.language}
|
|
21
|
+
<hbr />
|
|
22
|
+
</Show>
|
|
23
|
+
{props.children}
|
|
24
|
+
<Show when={props.fenced}>
|
|
25
|
+
<hbr />
|
|
26
|
+
```
|
|
27
|
+
</Show>
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { childrenArray, computed } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
export interface JSDocParagraphProps {
|
|
5
|
+
children: Children;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a paragraph in a JSDoc comment. The text of this component is word
|
|
10
|
+
* wrapped.
|
|
11
|
+
*/
|
|
12
|
+
export function JSDocParagraph(props: JSDocParagraphProps) {
|
|
13
|
+
const brokenChildren = computed(() => {
|
|
14
|
+
const children = childrenArray(() => props.children);
|
|
15
|
+
return children
|
|
16
|
+
.map((child) => {
|
|
17
|
+
if (typeof child === "string") {
|
|
18
|
+
return child
|
|
19
|
+
.trim()
|
|
20
|
+
.split(/\s+/)
|
|
21
|
+
.map((word) => (
|
|
22
|
+
<>
|
|
23
|
+
{word}
|
|
24
|
+
<br />
|
|
25
|
+
</>
|
|
26
|
+
));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return child;
|
|
30
|
+
})
|
|
31
|
+
.flat(2);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return <fill>{brokenChildren.value}</fill>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { childrenArray, computed, For, List, Show } from "@alloy-js/core";
|
|
2
|
+
import { Children, isComponentCreator } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { FunctionCallExpression } from "./FunctionCallExpression.jsx";
|
|
4
|
+
|
|
5
|
+
export interface MemberChainExpressionProps {
|
|
6
|
+
children: Children;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a member chain expression, which is a member expression comprised of
|
|
11
|
+
* either children, {@link FunctionCallExpression} components, or nested member
|
|
12
|
+
* chain expression components. Other component types are ignored.
|
|
13
|
+
*/
|
|
14
|
+
export function MemberChainExpression(props: MemberChainExpressionProps) {
|
|
15
|
+
// chunks are constructed by consuming as many non-call expressions as
|
|
16
|
+
// possible, then placing an indent and soft line break before and after the
|
|
17
|
+
// any subsequent call expressions
|
|
18
|
+
|
|
19
|
+
const chunks = computed(() => {
|
|
20
|
+
const children = flattenCallChains(childrenArray(() => props.children));
|
|
21
|
+
const chunks: Children[][] = [];
|
|
22
|
+
|
|
23
|
+
let currentChunk: Children[] = [];
|
|
24
|
+
|
|
25
|
+
for (const child of children) {
|
|
26
|
+
if (
|
|
27
|
+
isComponentCreator(child) &&
|
|
28
|
+
child.component === FunctionCallExpression
|
|
29
|
+
) {
|
|
30
|
+
if (currentChunk.length > 0) {
|
|
31
|
+
chunks.push(currentChunk);
|
|
32
|
+
currentChunk = [];
|
|
33
|
+
}
|
|
34
|
+
chunks.push([child]);
|
|
35
|
+
} else {
|
|
36
|
+
currentChunk.push(child);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (currentChunk.length > 0) {
|
|
41
|
+
chunks.push(currentChunk);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [chunks[0], chunks.slice(1)];
|
|
45
|
+
});
|
|
46
|
+
const groupId = Symbol();
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<group>
|
|
50
|
+
<group id={groupId}>
|
|
51
|
+
<List joiner="." children={chunks.value[0]} />
|
|
52
|
+
</group>
|
|
53
|
+
<Show when={chunks.value[1].length === 1}>
|
|
54
|
+
<For each={chunks.value[1]} softline>
|
|
55
|
+
{(chunk) => (
|
|
56
|
+
<>
|
|
57
|
+
.<List joiner="." children={chunk} />
|
|
58
|
+
</>
|
|
59
|
+
)}
|
|
60
|
+
</For>
|
|
61
|
+
</Show>
|
|
62
|
+
<Show when={chunks.value[1].length > 1}>
|
|
63
|
+
<indent>
|
|
64
|
+
<For each={chunks.value[1]} softline>
|
|
65
|
+
{(chunk) => (
|
|
66
|
+
<>
|
|
67
|
+
.<List joiner="." children={chunk} />
|
|
68
|
+
</>
|
|
69
|
+
)}
|
|
70
|
+
</For>
|
|
71
|
+
</indent>
|
|
72
|
+
</Show>
|
|
73
|
+
</group>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function flattenCallChains(children: Children[]): Children[] {
|
|
78
|
+
const flatChildren = [];
|
|
79
|
+
for (const child of children) {
|
|
80
|
+
if (
|
|
81
|
+
isComponentCreator(child) &&
|
|
82
|
+
child.component === MemberChainExpression
|
|
83
|
+
) {
|
|
84
|
+
flatChildren.push(...flattenCallChains(child.props.children));
|
|
85
|
+
} else {
|
|
86
|
+
flatChildren.push(child);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return flatChildren;
|
|
91
|
+
}
|