@alloy-js/typescript 0.7.0 → 0.9.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 +35 -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 -8
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +39 -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 +18 -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/FunctionCallExpression.js +1 -1
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +21 -13
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +79 -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/MemberExpression.d.ts +62 -0
- package/dist/src/components/MemberExpression.d.ts.map +1 -0
- package/dist/src/components/MemberExpression.js +179 -0
- package/dist/src/components/MemberExpression.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 +9 -2
- package/dist/src/components/ObjectExpression.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 +19 -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 +50 -12
- 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 -4
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +11 -2
- package/dist/src/symbols/ts-output-symbol.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/member-expression.test.d.ts +2 -0
- package/dist/test/member-expression.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 -12
- 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 -27
- package/src/components/EnumDeclaration.tsx +26 -18
- package/src/components/EnumMember.tsx +24 -4
- package/src/components/FunctionCallExpression.tsx +1 -1
- package/src/components/FunctionDeclaration.tsx +106 -82
- 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/MemberExpression.tsx +237 -0
- package/src/components/ObjectExpression.tsx +8 -3
- 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 +19 -11
- 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 +70 -18
- package/src/symbols/ts-member-scope.ts +6 -2
- package/src/symbols/ts-output-symbol.ts +24 -11
- package/src/utils.ts +33 -0
- package/temp/api.json +3819 -1915
- package/test/array.test.tsx +60 -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/interface-jsdoc.test.tsx +164 -0
- package/test/interface.test.tsx +14 -0
- package/test/jscomment.test.tsx +104 -0
- package/test/jsdoc.test.tsx +9 -15
- package/test/jsdocparam.test.tsx +188 -0
- package/test/member-expression.test.tsx +297 -0
- package/test/name-conflict.test.tsx +105 -0
- package/test/name-policy.test.tsx +1 -1
- package/test/package-json.test.tsx +93 -0
- 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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Block,
|
|
3
|
+
BlockProps,
|
|
4
|
+
Scope,
|
|
5
|
+
ScopePropsWithInfo,
|
|
6
|
+
ScopePropsWithValue,
|
|
7
|
+
} from "@alloy-js/core";
|
|
8
|
+
|
|
9
|
+
export interface BlockScopePropsWithScopeValue
|
|
10
|
+
extends ScopePropsWithValue,
|
|
11
|
+
BlockProps {}
|
|
12
|
+
export interface BlockScopePropsWithScopeInfo
|
|
13
|
+
extends ScopePropsWithInfo,
|
|
14
|
+
BlockProps {}
|
|
15
|
+
|
|
16
|
+
export type BlockScopeProps =
|
|
17
|
+
| BlockScopePropsWithScopeValue
|
|
18
|
+
| BlockScopePropsWithScopeInfo;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a TypeScript block which includes a scope for any nested declarations.
|
|
22
|
+
* Can either provide the scope directly via the `value` prop, or else provide
|
|
23
|
+
* information about the scope.
|
|
24
|
+
*/
|
|
25
|
+
export function BlockScope(props: BlockScopeProps) {
|
|
26
|
+
return (
|
|
27
|
+
<Scope {...props}>
|
|
28
|
+
<Block {...props}>{props.children}</Block>
|
|
29
|
+
</Scope>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
ParameterDescriptor,
|
|
4
|
+
TypeParameterDescriptor,
|
|
5
|
+
} from "../parameter-descriptor.js";
|
|
6
|
+
import { FunctionDeclaration } from "./FunctionDeclaration.jsx";
|
|
7
|
+
|
|
8
|
+
export interface CallSignatureProps {
|
|
9
|
+
/**
|
|
10
|
+
* The parameters to the function. Can be an array of strings for parameters
|
|
11
|
+
* which don't have a type or a default value. Otherwise, it's an array of
|
|
12
|
+
* {@link ParameterDescriptor}s.
|
|
13
|
+
*/
|
|
14
|
+
parameters?: ParameterDescriptor[] | string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Raw content to be used as the parameter list.
|
|
18
|
+
*/
|
|
19
|
+
parametersChildren?: Children;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The type parameters for the function. Can be an array of strings for
|
|
23
|
+
* type parameters which don't have any constraints or a default type, otherwise
|
|
24
|
+
* it's an array of {@link TypeParameterDescriptor}s.
|
|
25
|
+
*/
|
|
26
|
+
typeParameters?: TypeParameterDescriptor[] | string[];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Raw content to be used as the type parameter list.
|
|
30
|
+
*/
|
|
31
|
+
typeParametersChildren?: Children;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The return type of the function.
|
|
35
|
+
*/
|
|
36
|
+
returnType?: Children;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A TypeScript call signature, e.g. the part after the `function` keyword in an
|
|
40
|
+
* anonymous function expression, or a call signature in an interface.
|
|
41
|
+
*
|
|
42
|
+
* Any parameters or type parameters declared in this signature will be placed
|
|
43
|
+
* in the current scope. This component does not make a scope to hold its
|
|
44
|
+
* parameters.
|
|
45
|
+
*/
|
|
46
|
+
export function CallSignature(props: CallSignatureProps) {
|
|
47
|
+
const sTypeParameters =
|
|
48
|
+
props.typeParametersChildren ?
|
|
49
|
+
<>
|
|
50
|
+
{"<"}
|
|
51
|
+
{props.typeParametersChildren}
|
|
52
|
+
{">"}
|
|
53
|
+
</>
|
|
54
|
+
: <FunctionDeclaration.TypeParameters parameters={props.typeParameters} />;
|
|
55
|
+
|
|
56
|
+
const sParams = props.parametersChildren ?? (
|
|
57
|
+
<FunctionDeclaration.Parameters parameters={props.parameters} />
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const sReturnType = props.returnType ? <>: {props.returnType}</> : undefined;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
{sTypeParameters}({sParams}){sReturnType}
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -2,19 +2,26 @@ import {
|
|
|
2
2
|
Block,
|
|
3
3
|
Children,
|
|
4
4
|
MemberDeclaration,
|
|
5
|
-
MemberName,
|
|
6
5
|
Name,
|
|
7
6
|
OutputSymbolFlags,
|
|
7
|
+
Prose,
|
|
8
8
|
Refkey,
|
|
9
9
|
Scope,
|
|
10
|
+
Show,
|
|
11
|
+
splitProps,
|
|
12
|
+
useMemberScope,
|
|
10
13
|
} from "@alloy-js/core";
|
|
14
|
+
|
|
15
|
+
import { usePrivateScope } from "../context/private-scope.js";
|
|
11
16
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
12
|
-
import {
|
|
17
|
+
import { TSOutputScope } from "../symbols/scopes.js";
|
|
18
|
+
import { createTSSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
19
|
+
import { getCallSignatureProps } from "../utils.js";
|
|
20
|
+
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
13
21
|
import { BaseDeclarationProps, Declaration } from "./Declaration.jsx";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "./FunctionDeclaration.jsx";
|
|
22
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
23
|
+
import { JSDocParams } from "./JSDocParam.jsx";
|
|
24
|
+
import { PropertyName } from "./PropertyName.jsx";
|
|
18
25
|
|
|
19
26
|
export interface ClassDeclarationProps extends BaseDeclarationProps {
|
|
20
27
|
extends?: Children;
|
|
@@ -54,14 +61,33 @@ export interface ClassDeclarationProps extends BaseDeclarationProps {
|
|
|
54
61
|
* ```
|
|
55
62
|
*/
|
|
56
63
|
export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
64
|
+
const namePolicy = useTSNamePolicy();
|
|
57
65
|
const extendsPart = props.extends && <> extends {props.extends}</>;
|
|
58
|
-
|
|
66
|
+
|
|
67
|
+
const sym = createTSSymbol({
|
|
68
|
+
name: namePolicy.getName(props.name!, "class"),
|
|
69
|
+
refkey: props.refkey,
|
|
70
|
+
export: props.export,
|
|
71
|
+
default: props.default,
|
|
72
|
+
flags:
|
|
73
|
+
(props.flags ?? OutputSymbolFlags.None) |
|
|
74
|
+
(OutputSymbolFlags.MemberContainer |
|
|
75
|
+
OutputSymbolFlags.StaticMemberContainer),
|
|
76
|
+
tsFlags: TSSymbolFlags.PrivateMemberContainer,
|
|
77
|
+
metadata: props.metadata,
|
|
78
|
+
});
|
|
59
79
|
|
|
60
80
|
return (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
<>
|
|
82
|
+
<Show when={Boolean(props.doc)}>
|
|
83
|
+
<JSDoc children={props.doc} />
|
|
84
|
+
<hbr />
|
|
85
|
+
</Show>
|
|
86
|
+
<Declaration symbol={sym} export={props.export} default={props.default}>
|
|
87
|
+
class <Name />
|
|
88
|
+
{extendsPart} <Block>{props.children}</Block>
|
|
89
|
+
</Declaration>
|
|
90
|
+
</>
|
|
65
91
|
);
|
|
66
92
|
}
|
|
67
93
|
|
|
@@ -74,39 +100,56 @@ export interface ClassMemberProps {
|
|
|
74
100
|
jsPrivate?: boolean;
|
|
75
101
|
static?: boolean;
|
|
76
102
|
children?: Children;
|
|
103
|
+
doc?: Children;
|
|
77
104
|
}
|
|
78
105
|
|
|
79
106
|
export function ClassMember(props: ClassMemberProps) {
|
|
80
|
-
let sym: TSOutputSymbol | undefined;
|
|
81
107
|
const namer = useTSNamePolicy();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
sym = createTSSymbol({
|
|
93
|
-
name: props.jsPrivate ? `#${name}` : name,
|
|
94
|
-
refkey: props.refkey,
|
|
95
|
-
flags,
|
|
96
|
-
});
|
|
97
|
-
} else if (props.jsPrivate) {
|
|
98
|
-
// we won't be using the symbol name, so munge the name
|
|
99
|
-
name = `#${name}`;
|
|
108
|
+
const name = namer.getName(props.name, "class-member-data");
|
|
109
|
+
|
|
110
|
+
let flags = OutputSymbolFlags.None;
|
|
111
|
+
|
|
112
|
+
if (props.static) {
|
|
113
|
+
flags |= OutputSymbolFlags.StaticMember;
|
|
114
|
+
} else {
|
|
115
|
+
flags |= OutputSymbolFlags.InstanceMember;
|
|
100
116
|
}
|
|
101
117
|
|
|
118
|
+
let scope: TSOutputScope;
|
|
119
|
+
if (props.jsPrivate) {
|
|
120
|
+
const memberScope = usePrivateScope()!;
|
|
121
|
+
scope =
|
|
122
|
+
props.static ? memberScope.staticMembers : memberScope.instanceMembers;
|
|
123
|
+
} else {
|
|
124
|
+
const memberScope = useMemberScope();
|
|
125
|
+
scope = (
|
|
126
|
+
props.static ?
|
|
127
|
+
memberScope.staticMembers!
|
|
128
|
+
: memberScope.instanceMembers!) as TSOutputScope;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const sym = createTSSymbol({
|
|
132
|
+
name,
|
|
133
|
+
scope,
|
|
134
|
+
refkey: props.refkey,
|
|
135
|
+
flags,
|
|
136
|
+
tsFlags: props.jsPrivate ? TSSymbolFlags.PrivateMember : TSSymbolFlags.None,
|
|
137
|
+
});
|
|
138
|
+
|
|
102
139
|
return (
|
|
103
|
-
|
|
104
|
-
{props.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
|
|
140
|
+
<>
|
|
141
|
+
<Show when={Boolean(props.doc)}>
|
|
142
|
+
<JSDoc children={props.doc} />
|
|
143
|
+
<hbr />
|
|
144
|
+
</Show>
|
|
145
|
+
<MemberDeclaration symbol={sym}>
|
|
146
|
+
{props.public && "public "}
|
|
147
|
+
{props.private && "private "}
|
|
148
|
+
{props.protected && "protected "}
|
|
149
|
+
{props.static && "static "}
|
|
150
|
+
{props.children}
|
|
151
|
+
</MemberDeclaration>
|
|
152
|
+
</>
|
|
110
153
|
);
|
|
111
154
|
}
|
|
112
155
|
|
|
@@ -121,30 +164,40 @@ export function ClassField(props: ClassFieldProps) {
|
|
|
121
164
|
|
|
122
165
|
return (
|
|
123
166
|
<ClassMember {...props}>
|
|
124
|
-
<
|
|
167
|
+
<PropertyName />
|
|
125
168
|
{typeSection}
|
|
126
169
|
{initializerSection}
|
|
127
170
|
</ClassMember>
|
|
128
171
|
);
|
|
129
172
|
}
|
|
130
173
|
|
|
131
|
-
export interface ClassMethodProps extends ClassMemberProps {
|
|
174
|
+
export interface ClassMethodProps extends ClassMemberProps, CallSignatureProps {
|
|
132
175
|
async?: boolean;
|
|
133
|
-
parameters?: Record<string, Children | ParameterDescriptor>;
|
|
134
|
-
returnType?: Children;
|
|
135
176
|
children?: Children;
|
|
136
177
|
}
|
|
137
178
|
|
|
138
179
|
export function ClassMethod(props: ClassMethodProps) {
|
|
139
|
-
const
|
|
180
|
+
const callProps = getCallSignatureProps(props);
|
|
181
|
+
const [_, rest] = splitProps(props, ["doc"]);
|
|
182
|
+
|
|
140
183
|
return (
|
|
141
|
-
|
|
142
|
-
{props.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
<>
|
|
185
|
+
<Show when={Boolean(props.doc)}>
|
|
186
|
+
<JSDoc>
|
|
187
|
+
{props.doc && <Prose children={props.doc} />}
|
|
188
|
+
{Array.isArray(rest.parameters) && (
|
|
189
|
+
<JSDocParams parameters={rest.parameters} />
|
|
190
|
+
)}
|
|
191
|
+
</JSDoc>
|
|
192
|
+
<hbr />
|
|
193
|
+
</Show>
|
|
194
|
+
<ClassMember {...rest}>
|
|
195
|
+
{props.async && "async "}
|
|
196
|
+
<PropertyName />
|
|
197
|
+
<Scope name={props.name} kind="function">
|
|
198
|
+
<CallSignature {...callProps} /> <Block>{props.children}</Block>
|
|
199
|
+
</Scope>
|
|
200
|
+
</ClassMember>
|
|
201
|
+
</>
|
|
149
202
|
);
|
|
150
203
|
}
|
|
@@ -6,11 +6,17 @@ import {
|
|
|
6
6
|
Refkey,
|
|
7
7
|
} from "@alloy-js/core";
|
|
8
8
|
import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
createTSSymbol,
|
|
11
|
+
TSOutputSymbol,
|
|
12
|
+
TSSymbolFlags,
|
|
13
|
+
} from "../symbols/index.js";
|
|
10
14
|
|
|
11
15
|
// imports for documentation
|
|
12
16
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
17
|
import { TypeDeclaration } from "./TypeDeclaration.jsx";
|
|
18
|
+
|
|
19
|
+
import { PrivateScopeContext } from "../context/private-scope.js";
|
|
14
20
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
21
|
import { EnumDeclaration } from "./EnumDeclaration.jsx";
|
|
16
22
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -24,14 +30,9 @@ export interface BaseDeclarationProps {
|
|
|
24
30
|
name: string;
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
|
-
* The
|
|
28
|
-
*/
|
|
29
|
-
refkey?: Refkey;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Multiple unique keys for this declaration.
|
|
33
|
+
* The refkey or array of refkeys for this declaration.
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
+
refkey?: Refkey | Refkey[];
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Whether to export this declaration from the module.
|
|
@@ -55,13 +56,33 @@ export interface BaseDeclarationProps {
|
|
|
55
56
|
* value (e.g. var, const, let).
|
|
56
57
|
*/
|
|
57
58
|
kind?: "type" | "value";
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Arbitrary metadata about this declaration.
|
|
62
|
+
*/
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Documentation for this declaration
|
|
67
|
+
*/
|
|
68
|
+
doc?: Children;
|
|
58
69
|
}
|
|
59
70
|
|
|
60
|
-
export interface DeclarationProps extends BaseDeclarationProps {
|
|
71
|
+
export interface DeclarationProps extends Omit<BaseDeclarationProps, "name"> {
|
|
72
|
+
/**
|
|
73
|
+
* The name of this declaration.
|
|
74
|
+
*/
|
|
75
|
+
name?: string;
|
|
76
|
+
|
|
61
77
|
/**
|
|
62
78
|
* The name policy kind to apply to the declaration.
|
|
63
79
|
*/
|
|
64
|
-
nameKind
|
|
80
|
+
nameKind?: TypeScriptElements;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The symbol to use for this declaration.
|
|
84
|
+
*/
|
|
85
|
+
symbol?: TSOutputSymbol;
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
/**
|
|
@@ -79,29 +100,53 @@ export interface DeclarationProps extends BaseDeclarationProps {
|
|
|
79
100
|
*
|
|
80
101
|
*/
|
|
81
102
|
export function Declaration(props: DeclarationProps) {
|
|
82
|
-
|
|
103
|
+
let sym: TSOutputSymbol;
|
|
104
|
+
|
|
105
|
+
if (props.symbol) {
|
|
106
|
+
sym = props.symbol;
|
|
107
|
+
} else {
|
|
108
|
+
const namePolicy = useTSNamePolicy();
|
|
109
|
+
|
|
110
|
+
let tsFlags: TSSymbolFlags = TSSymbolFlags.None;
|
|
111
|
+
if (props.kind && props.kind === "type") {
|
|
112
|
+
tsFlags &= TSSymbolFlags.TypeSymbol;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
sym = createTSSymbol({
|
|
116
|
+
name: namePolicy.getName(props.name!, props.nameKind!),
|
|
117
|
+
refkey: props.refkey,
|
|
118
|
+
export: props.export,
|
|
119
|
+
default: props.default,
|
|
120
|
+
flags: props.flags,
|
|
121
|
+
tsFlags,
|
|
122
|
+
metadata: props.metadata,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
83
125
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
tsFlags &= TSSymbolFlags.TypeSymbol;
|
|
126
|
+
function withMemberScope(children: Children) {
|
|
127
|
+
return <MemberScope owner={sym}>{children}</MemberScope>;
|
|
87
128
|
}
|
|
88
129
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
130
|
+
function withPrivateMemberScope(children: Children) {
|
|
131
|
+
const context: PrivateScopeContext = {
|
|
132
|
+
instanceMembers: sym.privateMemberScope!,
|
|
133
|
+
staticMembers: sym.privateStaticMemberScope!,
|
|
134
|
+
};
|
|
135
|
+
return (
|
|
136
|
+
<PrivateScopeContext.Provider value={context}>
|
|
137
|
+
{children}
|
|
138
|
+
</PrivateScopeContext.Provider>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
98
141
|
|
|
99
|
-
let children: Children;
|
|
142
|
+
let children: Children = () => props.children;
|
|
100
143
|
|
|
101
144
|
if (sym.flags & OutputSymbolFlags.MemberContainer) {
|
|
102
|
-
children =
|
|
103
|
-
}
|
|
104
|
-
|
|
145
|
+
children = withMemberScope(children);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (sym.tsFlags & TSSymbolFlags.PrivateMemberContainer) {
|
|
149
|
+
children = withPrivateMemberScope(children);
|
|
105
150
|
}
|
|
106
151
|
|
|
107
152
|
return (
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
MemberScope,
|
|
7
7
|
Name,
|
|
8
8
|
OutputSymbolFlags,
|
|
9
|
+
Show,
|
|
9
10
|
useBinder,
|
|
10
11
|
} from "@alloy-js/core";
|
|
11
12
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
12
13
|
import { createTSSymbol, useTSScope } from "../symbols/index.js";
|
|
13
14
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
14
15
|
import { EnumMember } from "./EnumMember.jsx";
|
|
16
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
15
17
|
export interface EnumDeclarationProps extends BaseDeclarationProps {
|
|
16
18
|
/**
|
|
17
19
|
* A JS object representing the enum member names and values.
|
|
@@ -31,30 +33,36 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
|
|
|
31
33
|
scope,
|
|
32
34
|
name: name,
|
|
33
35
|
refkey: props.refkey,
|
|
34
|
-
refkeys: props.refkeys,
|
|
35
36
|
default: props.default,
|
|
36
37
|
export: props.export,
|
|
37
38
|
flags: OutputSymbolFlags.StaticMemberContainer,
|
|
39
|
+
metadata: props.metadata,
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
const valueEntries = computed(() => Object.entries(props.jsValue ?? {}));
|
|
41
43
|
return (
|
|
42
|
-
|
|
43
|
-
{props.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
<>
|
|
45
|
+
<Show when={Boolean(props.doc)}>
|
|
46
|
+
<JSDoc children={props.doc} />
|
|
47
|
+
<hbr />
|
|
48
|
+
</Show>
|
|
49
|
+
<CoreDeclaration symbol={sym}>
|
|
50
|
+
{props.export ? "export " : ""}
|
|
51
|
+
{props.default ? "default " : ""}enum <Name />{" "}
|
|
52
|
+
<MemberScope owner={sym}>
|
|
53
|
+
<Block>
|
|
54
|
+
<For each={valueEntries} comma hardline enderPunctuation>
|
|
55
|
+
{([name, value]) => <EnumMember name={name} jsValue={value} />}
|
|
56
|
+
</For>
|
|
57
|
+
{props.children && (
|
|
58
|
+
<>
|
|
59
|
+
{valueEntries.value.length > 0 && <hbr />}
|
|
60
|
+
{props.children}
|
|
61
|
+
</>
|
|
62
|
+
)}
|
|
63
|
+
</Block>
|
|
64
|
+
</MemberScope>
|
|
65
|
+
</CoreDeclaration>
|
|
66
|
+
</>
|
|
59
67
|
);
|
|
60
68
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Children, OutputSymbolFlags, Refkey } from "@alloy-js/core";
|
|
1
|
+
import { Children, OutputSymbolFlags, Refkey, Show } from "@alloy-js/core";
|
|
2
2
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
3
3
|
import { createTSSymbol, TSOutputSymbol } from "../symbols/ts-output-symbol.js";
|
|
4
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
5
|
+
import { PropertyName } from "./PropertyName.jsx";
|
|
4
6
|
import { ValueExpression } from "./ValueExpression.jsx";
|
|
5
7
|
|
|
6
8
|
export interface EnumMemberProps {
|
|
@@ -27,6 +29,16 @@ export interface EnumMemberProps {
|
|
|
27
29
|
* The JS value of the enum member.
|
|
28
30
|
*/
|
|
29
31
|
jsValue?: string | number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Arbitrary symbol metadata for the enum member.
|
|
35
|
+
*/
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Documentation for the enum member.
|
|
40
|
+
*/
|
|
41
|
+
doc?: Children;
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
/**
|
|
@@ -41,15 +53,23 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
41
53
|
name,
|
|
42
54
|
refkey: props.refkey,
|
|
43
55
|
flags: OutputSymbolFlags.StaticMember,
|
|
56
|
+
metadata: props.metadata,
|
|
44
57
|
});
|
|
45
58
|
}
|
|
46
|
-
const
|
|
59
|
+
const actualName = sym ? sym.name : name;
|
|
47
60
|
const valueCode =
|
|
48
|
-
props.jsValue
|
|
61
|
+
props.jsValue !== undefined ?
|
|
62
|
+
<ValueExpression jsValue={props.jsValue} />
|
|
63
|
+
: props.value;
|
|
49
64
|
|
|
50
65
|
return (
|
|
51
66
|
<>
|
|
52
|
-
|
|
67
|
+
<Show when={Boolean(props.doc)}>
|
|
68
|
+
<JSDoc children={props.doc} />
|
|
69
|
+
<hbr />
|
|
70
|
+
</Show>
|
|
71
|
+
<PropertyName name={actualName} />
|
|
72
|
+
<Show when={valueCode !== undefined}> = {valueCode}</Show>
|
|
53
73
|
</>
|
|
54
74
|
);
|
|
55
75
|
}
|
|
@@ -12,7 +12,7 @@ export function FunctionCallExpression(props: FunctionCallExpressionProps) {
|
|
|
12
12
|
<Wrap
|
|
13
13
|
when={!!props.args && props.args.length > 1}
|
|
14
14
|
with={Indent}
|
|
15
|
-
props={{
|
|
15
|
+
props={{ softline: true, trailingBreak: true }}
|
|
16
16
|
>
|
|
17
17
|
<For each={props.args ?? []} comma line>
|
|
18
18
|
{(arg) => arg}
|