@alloy-js/typescript 0.6.0 → 0.8.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 +41 -0
- package/dist/src/components/ArrayExpression.d.ts.map +1 -1
- package/dist/src/components/ArrayExpression.js +9 -3
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BlockScope.d.ts +13 -0
- package/dist/src/components/BlockScope.d.ts.map +1 -0
- package/dist/src/components/BlockScope.js +20 -0
- package/dist/src/components/BlockScope.js.map +1 -0
- package/dist/src/components/CallSignature.d.ts +38 -0
- package/dist/src/components/CallSignature.d.ts.map +1 -0
- package/dist/src/components/CallSignature.js +26 -0
- package/dist/src/components/CallSignature.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts +3 -4
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +99 -41
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/Declaration.d.ts +21 -4
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +40 -21
- 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 +19 -6
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts +8 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +27 -5
- 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.js +1 -1
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +21 -12
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +80 -45
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/IfStatement.d.ts +25 -0
- package/dist/src/components/IfStatement.d.ts.map +1 -0
- package/dist/src/components/IfStatement.js +34 -0
- package/dist/src/components/IfStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +10 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +66 -6
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts.map +1 -1
- package/dist/src/components/JSDoc.js +1 -5
- package/dist/src/components/JSDoc.js.map +1 -1
- package/dist/src/components/JSDocParam.d.ts +22 -0
- package/dist/src/components/JSDocParam.d.ts.map +1 -0
- package/dist/src/components/JSDocParam.js +121 -0
- package/dist/src/components/JSDocParam.js.map +1 -0
- package/dist/src/components/MemberChainExpression.d.ts +2 -2
- package/dist/src/components/MemberChainExpression.d.ts.map +1 -1
- package/dist/src/components/MemberChainExpression.js +43 -7
- package/dist/src/components/MemberChainExpression.js.map +1 -1
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +9 -2
- 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/PropertyName.d.ts +19 -0
- package/dist/src/components/PropertyName.d.ts.map +1 -0
- package/dist/src/components/PropertyName.js +36 -0
- package/dist/src/components/PropertyName.js.map +1 -0
- package/dist/src/components/SingleLineCommentBlock.d.ts +10 -0
- package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -0
- package/dist/src/components/SingleLineCommentBlock.js +20 -0
- package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +6 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +31 -0
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/SwitchStatement.d.ts +31 -0
- package/dist/src/components/SwitchStatement.d.ts.map +1 -0
- package/dist/src/components/SwitchStatement.js +48 -0
- package/dist/src/components/SwitchStatement.js.map +1 -0
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js +16 -3
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +20 -6
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +7 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +35 -112
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +8 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/context/index.d.ts +2 -0
- package/dist/src/context/index.d.ts.map +1 -0
- package/dist/src/context/index.js +1 -0
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/private-scope.d.ts +18 -0
- package/dist/src/context/private-scope.d.ts.map +1 -0
- package/dist/src/context/private-scope.js +9 -0
- package/dist/src/context/private-scope.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts +60 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -0
- package/dist/src/parameter-descriptor.js +1 -0
- package/dist/src/parameter-descriptor.js.map +1 -0
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +55 -14
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/symbols/ts-member-scope.d.ts +1 -1
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +2 -0
- package/dist/src/symbols/ts-member-scope.js.map +1 -1
- package/dist/src/symbols/ts-output-symbol.d.ts +7 -3
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +14 -2
- 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/src/utils.d.ts +7 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +17 -0
- package/dist/src/utils.js.map +1 -1
- package/dist/test/block-scope.test.d.ts +2 -0
- package/dist/test/block-scope.test.d.ts.map +1 -0
- package/dist/test/enum-jsdoc.test.d.ts +2 -0
- package/dist/test/enum-jsdoc.test.d.ts.map +1 -0
- package/dist/test/function-declaration-jsdoc.test.d.ts +2 -0
- package/dist/test/function-declaration-jsdoc.test.d.ts.map +1 -0
- package/dist/test/if-statement.test.d.ts +2 -0
- package/dist/test/if-statement.test.d.ts.map +1 -0
- package/dist/test/interface-jsdoc.test.d.ts +2 -0
- package/dist/test/interface-jsdoc.test.d.ts.map +1 -0
- package/dist/test/jscomment.test.d.ts +2 -0
- package/dist/test/jscomment.test.d.ts.map +1 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -1
- package/dist/test/jsdocparam.test.d.ts +2 -0
- package/dist/test/jsdocparam.test.d.ts.map +1 -0
- package/dist/test/name-conflict.test.d.ts +2 -0
- package/dist/test/name-conflict.test.d.ts.map +1 -0
- package/dist/test/package-json.test.d.ts +2 -0
- package/dist/test/package-json.test.d.ts.map +1 -0
- package/dist/test/source-file.test.d.ts +2 -0
- package/dist/test/source-file.test.d.ts.map +1 -0
- package/dist/test/switch-statement.test.d.ts +2 -0
- package/dist/test/switch-statement.test.d.ts.map +1 -0
- package/dist/test/var-declaration-jsdoc.test.d.ts +2 -0
- package/dist/test/var-declaration-jsdoc.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/ArrayExpression.tsx +13 -8
- package/src/components/BlockScope.tsx +31 -0
- package/src/components/CallSignature.tsx +67 -0
- package/src/components/ClassDeclaration.tsx +103 -50
- package/src/components/Declaration.tsx +72 -22
- package/src/components/EnumDeclaration.tsx +27 -19
- package/src/components/EnumMember.tsx +24 -4
- package/src/components/ExportStatement.tsx +3 -1
- package/src/components/FunctionCallExpression.tsx +1 -1
- package/src/components/FunctionDeclaration.tsx +107 -81
- package/src/components/IfStatement.tsx +51 -0
- package/src/components/Interface.tsx +61 -14
- package/src/components/JSDoc.tsx +1 -10
- package/src/components/JSDocParam.tsx +115 -0
- package/src/components/MemberChainExpression.tsx +37 -5
- package/src/components/ObjectExpression.tsx +7 -2
- package/src/components/PackageDirectory.tsx +12 -22
- package/src/components/PackageJson.tsx +86 -27
- package/src/components/PropertyName.tsx +50 -0
- package/src/components/SingleLineCommentBlock.tsx +21 -0
- package/src/components/SourceFile.tsx +29 -0
- package/src/components/SwitchStatement.tsx +78 -0
- package/src/components/TypeDeclaration.tsx +11 -4
- package/src/components/VarDeclaration.tsx +20 -12
- package/src/components/index.ts +7 -0
- package/src/components/stc/index.ts +8 -1
- package/src/context/index.ts +1 -0
- package/src/context/private-scope.ts +23 -0
- package/src/index.ts +1 -0
- package/src/parameter-descriptor.ts +71 -0
- package/src/symbols/reference.ts +77 -22
- package/src/symbols/ts-member-scope.ts +6 -2
- package/src/symbols/ts-output-symbol.ts +27 -10
- package/src/symbols/ts-package-scope.ts +0 -28
- package/src/utils.ts +33 -0
- package/temp/api.json +5372 -3410
- package/test/array.test.tsx +72 -0
- package/test/basic.test.tsx +2 -2
- package/test/block-scope.test.tsx +29 -0
- package/test/class.test.tsx +173 -5
- package/test/enum-jsdoc.test.tsx +74 -0
- package/test/enum.test.tsx +50 -3
- package/test/function-call-expression.test.tsx +5 -2
- package/test/function-declaration-jsdoc.test.tsx +89 -0
- package/test/function-declaration.test.tsx +13 -9
- package/test/if-statement.test.tsx +28 -0
- package/test/imports.test.tsx +25 -10
- package/test/interface-jsdoc.test.tsx +164 -0
- package/test/interface.test.tsx +17 -3
- package/test/jscomment.test.tsx +104 -0
- package/test/jsdoc.test.tsx +9 -15
- package/test/jsdocparam.test.tsx +188 -0
- package/test/member-chain.test.tsx +77 -0
- package/test/name-conflict.test.tsx +105 -0
- package/test/name-policy.test.tsx +1 -1
- package/test/package-external.test.tsx +98 -3
- package/test/package-json.test.tsx +93 -0
- package/test/package.test.tsx +56 -3
- package/test/reference.test.tsx +6 -2
- package/test/source-file.test.tsx +38 -0
- package/test/switch-statement.test.tsx +50 -0
- package/test/value-expression.test.tsx +9 -0
- package/test/var-declaration-jsdoc.test.tsx +70 -0
- package/test/var-declaration.test.tsx +1 -1
- package/tsconfig.json +1 -8
- package/vitest.config.ts +2 -10
- package/dist/src/components/JSDocParagraph.d.ts +0 -10
- package/dist/src/components/JSDocParagraph.d.ts.map +0 -1
- package/dist/src/components/JSDocParagraph.js +0 -23
- package/dist/src/components/JSDocParagraph.js.map +0 -1
- package/src/components/JSDocParagraph.tsx +0 -35
|
@@ -7,39 +7,32 @@ import {
|
|
|
7
7
|
For,
|
|
8
8
|
Indent,
|
|
9
9
|
Name,
|
|
10
|
-
|
|
11
|
-
refkey,
|
|
10
|
+
Prose,
|
|
12
11
|
Scope,
|
|
13
12
|
Show,
|
|
14
13
|
taggedComponent,
|
|
15
14
|
} from "@alloy-js/core";
|
|
16
15
|
import { Children, onCleanup } from "@alloy-js/core/jsx-runtime";
|
|
17
16
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
17
|
+
import {
|
|
18
|
+
ParameterDescriptor,
|
|
19
|
+
TypeParameterDescriptor,
|
|
20
|
+
} from "../parameter-descriptor.js";
|
|
18
21
|
import {
|
|
19
22
|
createTSSymbol,
|
|
20
23
|
TSOutputSymbol,
|
|
21
24
|
TSSymbolFlags,
|
|
22
25
|
} from "../symbols/index.js";
|
|
26
|
+
import { getCallSignatureProps } from "../utils.js";
|
|
27
|
+
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
23
28
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
29
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
30
|
+
import { JSDocParams } from "./JSDocParam.jsx";
|
|
24
31
|
|
|
25
|
-
export interface
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
optional?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function isParameterDescriptor(
|
|
32
|
-
value: Children | ParameterDescriptor,
|
|
33
|
-
): value is ParameterDescriptor {
|
|
34
|
-
return (
|
|
35
|
-
typeof value === "object" && value !== null && Object.hasOwn(value, "type")
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
export interface FunctionDeclarationProps extends BaseDeclarationProps {
|
|
32
|
+
export interface FunctionDeclarationProps
|
|
33
|
+
extends BaseDeclarationProps,
|
|
34
|
+
CallSignatureProps {
|
|
39
35
|
async?: boolean;
|
|
40
|
-
parameters?: Record<string, Children | ParameterDescriptor>;
|
|
41
|
-
typeParameters?: Record<string, Children | ParameterDescriptor> | string[];
|
|
42
|
-
returnType?: Children;
|
|
43
36
|
children?: Children;
|
|
44
37
|
}
|
|
45
38
|
|
|
@@ -47,44 +40,62 @@ export const functionParametersTag = Symbol();
|
|
|
47
40
|
export const functionTypeParametersTag = Symbol();
|
|
48
41
|
export const functionBodyTag = Symbol();
|
|
49
42
|
|
|
43
|
+
/**
|
|
44
|
+
* A TypeScript function declaration.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
*
|
|
48
|
+
* Providing parameters and type parameters can be accomplished in one of three
|
|
49
|
+
* ways:
|
|
50
|
+
*
|
|
51
|
+
* 1. As an array of {@link ParameterDescriptor}s or
|
|
52
|
+
* {@link TypeParameterDescriptor}s.
|
|
53
|
+
* 2. As raw content via the `parametersChildren` or `typeParametersChildren`
|
|
54
|
+
* props.
|
|
55
|
+
* 3. As a child of this component via the
|
|
56
|
+
* {@link (FunctionDeclaration:namespace).Parameters} or
|
|
57
|
+
* {@link (FunctionDeclaration:namespace).TypeParameters} components.
|
|
58
|
+
*/
|
|
50
59
|
export function FunctionDeclaration(props: FunctionDeclarationProps) {
|
|
51
60
|
const children = childrenArray(() => props.children);
|
|
52
|
-
const
|
|
53
|
-
children,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const bodyChild = findKeyedChild(children, functionBodyTag);
|
|
61
|
+
const typeParametersChildren =
|
|
62
|
+
findKeyedChild(children, functionTypeParametersTag) ?? undefined;
|
|
63
|
+
const parametersChildren =
|
|
64
|
+
findKeyedChild(children, functionParametersTag) ?? undefined;
|
|
65
|
+
const bodyChildren = findKeyedChild(children, functionBodyTag) ?? undefined;
|
|
58
66
|
const filteredChildren = findUnkeyedChildren(children);
|
|
59
67
|
const returnType = getReturnType(props.returnType, { async: props.async });
|
|
60
|
-
const sReturnType = returnType ? <>: {returnType}</> : undefined;
|
|
61
68
|
|
|
62
|
-
const
|
|
63
|
-
typeParametersChild ?
|
|
64
|
-
<>
|
|
65
|
-
{"<"}
|
|
66
|
-
{typeParametersChild}
|
|
67
|
-
{">"}
|
|
68
|
-
</>
|
|
69
|
-
: <FunctionDeclaration.TypeParameters parameters={props.typeParameters} />;
|
|
70
|
-
|
|
71
|
-
const sParams = parametersChild ?? (
|
|
72
|
-
<FunctionDeclaration.Parameters parameters={props.parameters} />
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const sBody = bodyChild ?? (
|
|
69
|
+
const sBody = bodyChildren ?? (
|
|
76
70
|
<FunctionDeclaration.Body>{filteredChildren}</FunctionDeclaration.Body>
|
|
77
71
|
);
|
|
78
72
|
|
|
79
73
|
const asyncKwd = props.async ? "async " : "";
|
|
80
74
|
|
|
75
|
+
const callSignatureProps = getCallSignatureProps(props, {
|
|
76
|
+
parametersChildren,
|
|
77
|
+
typeParametersChildren,
|
|
78
|
+
});
|
|
79
|
+
|
|
81
80
|
return (
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
<>
|
|
82
|
+
<Show when={Boolean(props.doc)}>
|
|
83
|
+
<JSDoc>
|
|
84
|
+
{props.doc && <Prose children={props.doc} />}
|
|
85
|
+
{Array.isArray(props.parameters) && (
|
|
86
|
+
<JSDocParams parameters={props.parameters} />
|
|
87
|
+
)}
|
|
88
|
+
</JSDoc>
|
|
89
|
+
<hbr />
|
|
90
|
+
</Show>
|
|
91
|
+
<Declaration {...props} nameKind="function">
|
|
92
|
+
{asyncKwd}function <Name />
|
|
93
|
+
<Scope name={props.name} kind="function">
|
|
94
|
+
<CallSignature {...callSignatureProps} returnType={returnType} />{" "}
|
|
95
|
+
{sBody}
|
|
96
|
+
</Scope>
|
|
97
|
+
</Declaration>
|
|
98
|
+
</>
|
|
88
99
|
);
|
|
89
100
|
}
|
|
90
101
|
|
|
@@ -97,54 +108,69 @@ function getReturnType(
|
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
|
|
100
|
-
interface DeclaredParameterDescriptor
|
|
111
|
+
interface DeclaredParameterDescriptor
|
|
112
|
+
extends Omit<ParameterDescriptor, "name"> {
|
|
101
113
|
symbol: TSOutputSymbol;
|
|
102
114
|
}
|
|
103
115
|
|
|
116
|
+
interface DeclaredTypeParameterDescriptor
|
|
117
|
+
extends Omit<TypeParameterDescriptor, "name"> {
|
|
118
|
+
symbol: TSOutputSymbol;
|
|
119
|
+
}
|
|
120
|
+
function normalizeAndDeclareParameters(
|
|
121
|
+
parameters: TypeParameterDescriptor[] | string[],
|
|
122
|
+
flags?: TSSymbolFlags,
|
|
123
|
+
): DeclaredTypeParameterDescriptor[];
|
|
124
|
+
function normalizeAndDeclareParameters(
|
|
125
|
+
parameters: ParameterDescriptor[] | string[],
|
|
126
|
+
flags?: TSSymbolFlags,
|
|
127
|
+
): DeclaredParameterDescriptor[];
|
|
104
128
|
function normalizeAndDeclareParameters(
|
|
105
|
-
parameters:
|
|
129
|
+
parameters: string[],
|
|
130
|
+
flags?: TSSymbolFlags,
|
|
131
|
+
): DeclaredParameterDescriptor[] | DeclaredTypeParameterDescriptor[];
|
|
132
|
+
function normalizeAndDeclareParameters(
|
|
133
|
+
parameters: ParameterDescriptor[] | TypeParameterDescriptor[] | string[],
|
|
106
134
|
flags: TSSymbolFlags = TSSymbolFlags.ParameterSymbol,
|
|
107
|
-
): DeclaredParameterDescriptor[] {
|
|
135
|
+
): DeclaredParameterDescriptor[] | DeclaredTypeParameterDescriptor[] {
|
|
108
136
|
const namePolicy = useTSNamePolicy();
|
|
109
|
-
if (
|
|
110
|
-
return
|
|
137
|
+
if (parameters.length === 0) {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
if (typeof parameters[0] === "string") {
|
|
141
|
+
return (parameters as string[]).map((paramName) => {
|
|
111
142
|
const symbol = createTSSymbol({
|
|
112
143
|
name: namePolicy.getName(
|
|
113
144
|
paramName,
|
|
114
145
|
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
115
146
|
),
|
|
116
|
-
refkey: refkey(),
|
|
117
147
|
tsFlags: flags,
|
|
118
148
|
});
|
|
119
149
|
|
|
120
|
-
return {
|
|
150
|
+
return { refkeys: symbol.refkeys, symbol };
|
|
121
151
|
});
|
|
122
|
-
}
|
|
152
|
+
} else {
|
|
153
|
+
return (parameters as ParameterDescriptor[]).map((param) => {
|
|
154
|
+
const symbol = createTSSymbol({
|
|
155
|
+
name: namePolicy.getName(
|
|
156
|
+
param.name,
|
|
157
|
+
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
158
|
+
),
|
|
159
|
+
refkey: param.refkey,
|
|
160
|
+
tsFlags: flags,
|
|
161
|
+
metadata: param.metadata,
|
|
162
|
+
});
|
|
123
163
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
refkey: refkey(),
|
|
129
|
-
type: value,
|
|
130
|
-
} as any)
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const symbol = createTSSymbol({
|
|
134
|
-
name: namePolicy.getName(
|
|
135
|
-
paramName,
|
|
136
|
-
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
137
|
-
),
|
|
138
|
-
refkey: descriptor.refkey,
|
|
139
|
-
tsFlags: flags,
|
|
164
|
+
return {
|
|
165
|
+
...param,
|
|
166
|
+
symbol,
|
|
167
|
+
};
|
|
140
168
|
});
|
|
141
|
-
|
|
142
|
-
return descriptor;
|
|
143
|
-
});
|
|
169
|
+
}
|
|
144
170
|
}
|
|
145
171
|
|
|
146
172
|
export interface FunctionTypeParametersProps {
|
|
147
|
-
parameters?:
|
|
173
|
+
parameters?: ParameterDescriptor[] | string[];
|
|
148
174
|
children?: Children;
|
|
149
175
|
}
|
|
150
176
|
|
|
@@ -171,7 +197,7 @@ FunctionDeclaration.TypeParameters = taggedComponent(
|
|
|
171
197
|
<>
|
|
172
198
|
{"<"}
|
|
173
199
|
<group>
|
|
174
|
-
<Indent
|
|
200
|
+
<Indent softline>
|
|
175
201
|
<For each={typeParameters} comma line>
|
|
176
202
|
{(param) => typeParameter(param)}
|
|
177
203
|
</For>
|
|
@@ -184,21 +210,21 @@ FunctionDeclaration.TypeParameters = taggedComponent(
|
|
|
184
210
|
},
|
|
185
211
|
);
|
|
186
212
|
|
|
187
|
-
function typeParameter(param:
|
|
213
|
+
function typeParameter(param: DeclaredTypeParameterDescriptor) {
|
|
188
214
|
return (
|
|
189
215
|
<group>
|
|
190
216
|
{param.symbol.name}
|
|
191
|
-
<Show when={!!param.
|
|
217
|
+
<Show when={!!param.extends}>
|
|
192
218
|
{" "}
|
|
193
219
|
extends
|
|
194
|
-
<indent> {param.
|
|
220
|
+
<indent> {param.extends}</indent>
|
|
195
221
|
</Show>
|
|
196
222
|
</group>
|
|
197
223
|
);
|
|
198
224
|
}
|
|
199
225
|
|
|
200
226
|
export interface FunctionParametersProps {
|
|
201
|
-
parameters?:
|
|
227
|
+
parameters?: ParameterDescriptor[] | string[];
|
|
202
228
|
children?: Children;
|
|
203
229
|
}
|
|
204
230
|
|
|
@@ -209,10 +235,10 @@ FunctionDeclaration.Parameters = taggedComponent(
|
|
|
209
235
|
return props.children;
|
|
210
236
|
}
|
|
211
237
|
|
|
212
|
-
const parameters = normalizeAndDeclareParameters(props.parameters ??
|
|
238
|
+
const parameters = normalizeAndDeclareParameters(props.parameters ?? []);
|
|
213
239
|
return (
|
|
214
240
|
<group>
|
|
215
|
-
<Indent
|
|
241
|
+
<Indent softline trailingBreak>
|
|
216
242
|
<For each={parameters} comma line>
|
|
217
243
|
{(param) => parameter(param)}
|
|
218
244
|
</For>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Block } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
export interface IfStatementProps {
|
|
5
|
+
condition: Children;
|
|
6
|
+
children: Children;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An if statement.
|
|
11
|
+
*/
|
|
12
|
+
export function IfStatement(props: IfStatementProps) {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
if ({props.condition}) <Block>{props.children}</Block>
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ElseIfClauseProps {
|
|
21
|
+
condition: Children;
|
|
22
|
+
children: Children;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An else clause with an if statement.
|
|
27
|
+
*/
|
|
28
|
+
export function ElseIfClause(props: ElseIfClauseProps) {
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
{" "}
|
|
32
|
+
else if ({props.condition}) <Block>{props.children}</Block>
|
|
33
|
+
</>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ElseClauseProps {
|
|
38
|
+
children: Children;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The else clause of an if statement.
|
|
43
|
+
*/
|
|
44
|
+
export function ElseClause(props: ElseClauseProps) {
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
{" "}
|
|
48
|
+
else <Block>{props.children}</Block>
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
Children,
|
|
4
|
+
MemberDeclaration,
|
|
5
|
+
Name,
|
|
6
|
+
OutputSymbolFlags,
|
|
7
|
+
Refkey,
|
|
8
|
+
Show,
|
|
9
|
+
} from "@alloy-js/core";
|
|
2
10
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
3
11
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
12
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
13
|
+
|
|
14
|
+
import { PropertyName } from "./PropertyName.jsx";
|
|
4
15
|
|
|
5
16
|
export interface InterfaceDeclarationProps extends BaseDeclarationProps {
|
|
6
17
|
extends?: Children;
|
|
@@ -17,12 +28,20 @@ export interface InterfaceDeclarationProps extends BaseDeclarationProps {
|
|
|
17
28
|
*/
|
|
18
29
|
export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
|
|
19
30
|
const extendsPart = props.extends ? <> extends {props.extends}</> : "";
|
|
31
|
+
const flags = OutputSymbolFlags.StaticMemberContainer;
|
|
20
32
|
|
|
21
33
|
return (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
<>
|
|
35
|
+
<Show when={Boolean(props.doc)}>
|
|
36
|
+
<JSDoc children={props.doc} />
|
|
37
|
+
<hbr />
|
|
38
|
+
</Show>
|
|
39
|
+
<Declaration {...props} nameKind="interface" flags={flags}>
|
|
40
|
+
interface <Name />
|
|
41
|
+
{extendsPart}{" "}
|
|
42
|
+
<InterfaceExpression>{props.children}</InterfaceExpression>
|
|
43
|
+
</Declaration>
|
|
44
|
+
</>
|
|
26
45
|
);
|
|
27
46
|
}
|
|
28
47
|
|
|
@@ -41,16 +60,24 @@ export interface InterfaceMemberProps {
|
|
|
41
60
|
children?: Children;
|
|
42
61
|
optional?: boolean;
|
|
43
62
|
readonly?: boolean;
|
|
63
|
+
doc?: Children;
|
|
64
|
+
refkey?: Refkey | Refkey[];
|
|
44
65
|
}
|
|
45
66
|
|
|
46
67
|
/**
|
|
47
|
-
* Create a TypeScript interface
|
|
68
|
+
* Create a TypeScript interface member.
|
|
69
|
+
*
|
|
70
|
+
* An interface member can either provide a `name` prop to create a named
|
|
71
|
+
* property, or an `indexer` prop to define an indexer for the interface.
|
|
72
|
+
*
|
|
73
|
+
* The type of the member can be provided either as the `type` prop or as the
|
|
74
|
+
* children of the component.
|
|
48
75
|
*/
|
|
49
76
|
export function InterfaceMember(props: InterfaceMemberProps) {
|
|
50
|
-
const namer = useTSNamePolicy();
|
|
51
77
|
const type = props.type ?? props.children;
|
|
52
78
|
const optionality = props.optional ? "?" : "";
|
|
53
79
|
const readonly = props.readonly ? "readonly " : "";
|
|
80
|
+
|
|
54
81
|
if (props.indexer) {
|
|
55
82
|
return (
|
|
56
83
|
<>
|
|
@@ -58,12 +85,32 @@ export function InterfaceMember(props: InterfaceMemberProps) {
|
|
|
58
85
|
</>
|
|
59
86
|
);
|
|
60
87
|
} else {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
88
|
+
const namer = useTSNamePolicy();
|
|
89
|
+
const name = namer.getName(props.name!, "interface-member");
|
|
90
|
+
if (props.refkey) {
|
|
91
|
+
return (
|
|
92
|
+
<MemberDeclaration static name={name} refkey={props.refkey}>
|
|
93
|
+
<Show when={Boolean(props.doc)}>
|
|
94
|
+
<JSDoc children={props.doc} />
|
|
95
|
+
<hbr />
|
|
96
|
+
</Show>
|
|
97
|
+
{readonly}
|
|
98
|
+
<PropertyName />
|
|
99
|
+
{optionality}: {type}
|
|
100
|
+
</MemberDeclaration>
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
return (
|
|
104
|
+
<>
|
|
105
|
+
<Show when={Boolean(props.doc)}>
|
|
106
|
+
<JSDoc children={props.doc} />
|
|
107
|
+
<hbr />
|
|
108
|
+
</Show>
|
|
109
|
+
{readonly}
|
|
110
|
+
<PropertyName name={name} />
|
|
111
|
+
{optionality}: {type}
|
|
112
|
+
</>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
68
115
|
}
|
|
69
116
|
}
|
package/src/components/JSDoc.tsx
CHANGED
|
@@ -13,16 +13,7 @@ export interface JSDocProps {
|
|
|
13
13
|
export function JSDoc(props: JSDocProps) {
|
|
14
14
|
return (
|
|
15
15
|
<JSDocComment>
|
|
16
|
-
<List
|
|
17
|
-
joiner={
|
|
18
|
-
<>
|
|
19
|
-
<hbr />
|
|
20
|
-
<hbr />
|
|
21
|
-
</>
|
|
22
|
-
}
|
|
23
|
-
>
|
|
24
|
-
{childrenArray(() => props.children)}
|
|
25
|
-
</List>
|
|
16
|
+
<List doubleHardline>{childrenArray(() => props.children)}</List>
|
|
26
17
|
</JSDocComment>
|
|
27
18
|
);
|
|
28
19
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { For, Prose, Show } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { ParameterDescriptor } from "../parameter-descriptor.js";
|
|
4
|
+
|
|
5
|
+
export interface JSDocParamsProps {
|
|
6
|
+
parameters: ParameterDescriptor[] | string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A component that creates a JSDoc block with `@param` tags for each parameter.
|
|
11
|
+
*/
|
|
12
|
+
export function JSDocParams(props: JSDocParamsProps) {
|
|
13
|
+
const parameters = normalizeParametersForDoc(props.parameters);
|
|
14
|
+
return (
|
|
15
|
+
<For each={parameters}>
|
|
16
|
+
{(param) => (
|
|
17
|
+
<JSDocParam
|
|
18
|
+
name={param.name}
|
|
19
|
+
type={param.type}
|
|
20
|
+
optional={param.optional}
|
|
21
|
+
hyphen
|
|
22
|
+
>
|
|
23
|
+
{param.doc}
|
|
24
|
+
</JSDocParam>
|
|
25
|
+
)}
|
|
26
|
+
</For>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeParametersForDoc(
|
|
31
|
+
parameters: ParameterDescriptor[] | string[],
|
|
32
|
+
): ParameterDescriptor[] {
|
|
33
|
+
if (parameters.some((p) => typeof p === "string")) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return parameters as ParameterDescriptor[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface JSDocParamProps {
|
|
41
|
+
name: Children;
|
|
42
|
+
type?: Children;
|
|
43
|
+
children?: Children;
|
|
44
|
+
hyphen?: boolean;
|
|
45
|
+
optional?: boolean;
|
|
46
|
+
defaultValue?: Children;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create a JSDoc parameter set off with `@param`.
|
|
51
|
+
*/
|
|
52
|
+
export function JSDocParam(props: JSDocParamProps) {
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
{"@param "}
|
|
56
|
+
<JSDocParamType type={props.type} />
|
|
57
|
+
<JSDocParamName
|
|
58
|
+
name={props.name}
|
|
59
|
+
optional={props.optional}
|
|
60
|
+
defaultValue={props.defaultValue}
|
|
61
|
+
/>
|
|
62
|
+
<JSDocParamDescription hyphen={props.hyphen} children={props.children} />
|
|
63
|
+
</>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface JSDocParamTypeProps {
|
|
68
|
+
type?: Children;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function JSDocParamType(props: JSDocParamTypeProps) {
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<Show when={Boolean(props.type)}>
|
|
75
|
+
{"{"}
|
|
76
|
+
{props.type}
|
|
77
|
+
{"} "}
|
|
78
|
+
</Show>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface JSDocParamNameProps {
|
|
84
|
+
name: Children;
|
|
85
|
+
optional?: boolean;
|
|
86
|
+
defaultValue?: Children;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function JSDocParamName(props: JSDocParamNameProps) {
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<Show when={props.optional}>{"["}</Show>
|
|
93
|
+
{props.name}
|
|
94
|
+
<Show when={Boolean(props.defaultValue)}>={props.defaultValue}</Show>
|
|
95
|
+
<Show when={props.optional}>{"]"}</Show>
|
|
96
|
+
</>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface JSDocParamDescriptionProps {
|
|
101
|
+
children?: Children;
|
|
102
|
+
hyphen?: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function JSDocParamDescription(props: JSDocParamDescriptionProps) {
|
|
106
|
+
return (
|
|
107
|
+
<Show when={Boolean(props.children)}>
|
|
108
|
+
<Show when={props.hyphen} children={" - "} />
|
|
109
|
+
<Show when={!props.hyphen} children={" "} />
|
|
110
|
+
<align width={2}>
|
|
111
|
+
<Prose>{props.children}</Prose>
|
|
112
|
+
</align>
|
|
113
|
+
</Show>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -8,8 +8,8 @@ export interface MemberChainExpressionProps {
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Create a member chain expression, which is a member expression comprised of
|
|
11
|
-
* either children
|
|
12
|
-
*
|
|
11
|
+
* either children, {@link FunctionCallExpression} components, or nested member
|
|
12
|
+
* chain expression components. Other component types are ignored.
|
|
13
13
|
*/
|
|
14
14
|
export function MemberChainExpression(props: MemberChainExpressionProps) {
|
|
15
15
|
// chunks are constructed by consuming as many non-call expressions as
|
|
@@ -17,7 +17,7 @@ export function MemberChainExpression(props: MemberChainExpressionProps) {
|
|
|
17
17
|
// any subsequent call expressions
|
|
18
18
|
|
|
19
19
|
const chunks = computed(() => {
|
|
20
|
-
const children = childrenArray(() => props.children);
|
|
20
|
+
const children = flattenCallChains(childrenArray(() => props.children));
|
|
21
21
|
const chunks: Children[][] = [];
|
|
22
22
|
|
|
23
23
|
let currentChunk: Children[] = [];
|
|
@@ -37,13 +37,29 @@ export function MemberChainExpression(props: MemberChainExpressionProps) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
if (currentChunk.length > 0) {
|
|
41
|
+
chunks.push(currentChunk);
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
return [chunks[0], chunks.slice(1)];
|
|
41
45
|
});
|
|
46
|
+
const groupId = Symbol();
|
|
42
47
|
|
|
43
48
|
return (
|
|
44
49
|
<group>
|
|
45
|
-
<
|
|
46
|
-
|
|
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}>
|
|
47
63
|
<indent>
|
|
48
64
|
<For each={chunks.value[1]} softline>
|
|
49
65
|
{(chunk) => (
|
|
@@ -57,3 +73,19 @@ export function MemberChainExpression(props: MemberChainExpressionProps) {
|
|
|
57
73
|
</group>
|
|
58
74
|
);
|
|
59
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
|
+
}
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
Switch,
|
|
14
14
|
Wrap,
|
|
15
15
|
} from "@alloy-js/core";
|
|
16
|
+
import { useTSNamePolicy } from "../name-policy.js";
|
|
16
17
|
import { createTSSymbol } from "../symbols/index.js";
|
|
18
|
+
import { PropertyName } from "./PropertyName.jsx";
|
|
17
19
|
import { ValueExpression } from "./ValueExpression.js";
|
|
18
20
|
|
|
19
21
|
export interface ObjectExpressionProps {
|
|
@@ -96,7 +98,10 @@ export interface ObjectPropertyProps {
|
|
|
96
98
|
export function ObjectProperty(props: ObjectPropertyProps) {
|
|
97
99
|
let name;
|
|
98
100
|
if (props.name) {
|
|
99
|
-
|
|
101
|
+
const namer = useTSNamePolicy();
|
|
102
|
+
name = (
|
|
103
|
+
<PropertyName name={namer.getName(props.name, "object-member-data")} />
|
|
104
|
+
);
|
|
100
105
|
} else if (props.nameExpression) {
|
|
101
106
|
name = <>[{props.nameExpression}]</>;
|
|
102
107
|
} else {
|
|
@@ -126,7 +131,7 @@ export function ObjectProperty(props: ObjectPropertyProps) {
|
|
|
126
131
|
sym ? createAssignmentContext(sym) : undefined;
|
|
127
132
|
return (
|
|
128
133
|
<>
|
|
129
|
-
{
|
|
134
|
+
{name}:{" "}
|
|
130
135
|
<AssignmentContext.Provider value={assignmentContext}>
|
|
131
136
|
{value}
|
|
132
137
|
</AssignmentContext.Provider>
|