@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,6 +7,7 @@ import {
|
|
|
7
7
|
shallowRef,
|
|
8
8
|
SourceDirectory,
|
|
9
9
|
SourceDirectoryContext,
|
|
10
|
+
splitProps,
|
|
10
11
|
useBinder,
|
|
11
12
|
useContext,
|
|
12
13
|
useScope,
|
|
@@ -14,17 +15,10 @@ import {
|
|
|
14
15
|
import { join } from "pathe";
|
|
15
16
|
import { createTSPackageScope, TSPackageScope } from "../symbols/index.js";
|
|
16
17
|
import { modulePath } from "../utils.js";
|
|
17
|
-
import {
|
|
18
|
-
ExportPath,
|
|
19
|
-
PackageExports,
|
|
20
|
-
PackageJsonFile,
|
|
21
|
-
PackageJsonFileProps,
|
|
22
|
-
} from "./PackageJson.js";
|
|
18
|
+
import { PackageJsonFile, PackageJsonFileProps } from "./PackageJson.js";
|
|
23
19
|
import { TSConfigJson } from "./TsConfigJson.js";
|
|
24
20
|
|
|
25
21
|
export interface PackageDirectoryProps extends PackageJsonFileProps {
|
|
26
|
-
dependencies?: Record<string, string>;
|
|
27
|
-
exports?: PackageExports | ExportPath;
|
|
28
22
|
tsConfig?: { outDir?: string };
|
|
29
23
|
children?: Children;
|
|
30
24
|
path?: string;
|
|
@@ -54,27 +48,23 @@ export function PackageDirectory(props: PackageDirectoryProps) {
|
|
|
54
48
|
props.path ?? ".",
|
|
55
49
|
);
|
|
56
50
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} else {
|
|
61
|
-
for (const ex of Object.entries(props.exports)) {
|
|
62
|
-
packageContext.scope.addRawExport(ex[0], ex[1]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
51
|
+
const devDeps = props.devDependencies ?? {};
|
|
52
|
+
if (!devDeps["typescript"]) {
|
|
53
|
+
devDeps["typescript"] = "^5.5.2";
|
|
65
54
|
}
|
|
66
55
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
56
|
+
const [_, pkgJsonProps] = splitProps(props, [
|
|
57
|
+
"tsConfig",
|
|
58
|
+
"children",
|
|
59
|
+
"path",
|
|
60
|
+
"devDependencies",
|
|
61
|
+
]);
|
|
72
62
|
|
|
73
63
|
return (
|
|
74
64
|
<SourceDirectory path={props.path ?? "."}>
|
|
75
65
|
<PackageContext.Provider value={packageContext}>
|
|
76
66
|
<Scope value={packageContext.scope}>
|
|
77
|
-
<PackageJsonFile {...
|
|
67
|
+
<PackageJsonFile {...pkgJsonProps} devDependencies={devDeps} />
|
|
78
68
|
<TSConfigJson {...props.tsConfig} />
|
|
79
69
|
{props.children}
|
|
80
70
|
</Scope>
|
|
@@ -3,10 +3,47 @@ import { modulePath } from "../utils.js";
|
|
|
3
3
|
import { usePackage } from "./PackageDirectory.js";
|
|
4
4
|
|
|
5
5
|
export interface PackageJsonFileProps {
|
|
6
|
+
/** The name of the package */
|
|
6
7
|
name: string;
|
|
8
|
+
|
|
9
|
+
/** The version of the package */
|
|
7
10
|
version: string;
|
|
11
|
+
|
|
12
|
+
/** The description of the package */
|
|
13
|
+
description?: string;
|
|
14
|
+
|
|
15
|
+
/** The license of the package */
|
|
16
|
+
license?: string;
|
|
17
|
+
|
|
18
|
+
/** The author of the package */
|
|
19
|
+
author?: string;
|
|
20
|
+
|
|
21
|
+
/** The homepage of the package */
|
|
22
|
+
homepage?: string;
|
|
23
|
+
|
|
24
|
+
/** The repository of the package */
|
|
25
|
+
repository?: string | { type: string; url: string };
|
|
26
|
+
|
|
27
|
+
/** The keywords of the package */
|
|
28
|
+
keywords?: string[];
|
|
29
|
+
|
|
30
|
+
/** Whether this is a commonjs or module. Defaults to module. */
|
|
8
31
|
type?: "module" | "commonjs";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The hard-coded dependencies of the package. References to external packages
|
|
35
|
+
* will add to the dependency list automatically. Only list dependencies here
|
|
36
|
+
* that are not referenced via refkey.
|
|
37
|
+
*/
|
|
38
|
+
dependencies?: Record<string, string>;
|
|
39
|
+
|
|
40
|
+
/** The hard-coded exports of the package. */
|
|
41
|
+
exports?: PackageExports | ExportPath;
|
|
42
|
+
|
|
43
|
+
/** The dev dependencies of the package. */
|
|
9
44
|
devDependencies?: Record<string, string>;
|
|
45
|
+
|
|
46
|
+
/** The scripts entries of the package. */
|
|
10
47
|
scripts?: Record<string, string>;
|
|
11
48
|
}
|
|
12
49
|
|
|
@@ -20,46 +57,68 @@ export interface PackageExports {
|
|
|
20
57
|
[key: string]: ExportPath;
|
|
21
58
|
}
|
|
22
59
|
|
|
60
|
+
/**
|
|
61
|
+
* A file containing a package.json that defines a package. When placed inside a
|
|
62
|
+
* {@link PackageDirectory}, it will contain dependencies and exports for
|
|
63
|
+
* symbols defined inside the package. Additional dependencies and exports can
|
|
64
|
+
* be provided.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* <PackageJsonFile name="my-package" version="1.0.0" />
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
23
71
|
export function PackageJsonFile(props: PackageJsonFileProps) {
|
|
24
72
|
const pkg = usePackage();
|
|
25
|
-
if (!pkg) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"Package json component needs to be inside a PackageDirectory",
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
73
|
|
|
31
74
|
const jsonContent = memo(() => {
|
|
32
75
|
const pkgJson = {
|
|
33
76
|
name: props.name,
|
|
34
77
|
version: props.version,
|
|
78
|
+
author: props.author,
|
|
79
|
+
description: props.description,
|
|
80
|
+
license: props.license,
|
|
81
|
+
homepage: props.homepage,
|
|
35
82
|
type: props.type ?? "module",
|
|
36
|
-
dependencies:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
83
|
+
dependencies:
|
|
84
|
+
props.dependencies || (pkg && pkg.scope.dependencies.size > 0) ?
|
|
85
|
+
Object.fromEntries([
|
|
86
|
+
...Object.entries(props.dependencies ?? {}),
|
|
87
|
+
...(pkg ?
|
|
88
|
+
Array.from(pkg.scope.dependencies).map((dependency) => [
|
|
89
|
+
dependency.name,
|
|
90
|
+
dependency.version,
|
|
91
|
+
])
|
|
92
|
+
: []),
|
|
93
|
+
])
|
|
94
|
+
: undefined,
|
|
95
|
+
devDependencies: props.devDependencies,
|
|
47
96
|
scripts: props.scripts,
|
|
48
97
|
exports: undefined as any,
|
|
49
98
|
};
|
|
50
99
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
100
|
+
if (typeof props.exports === "string") {
|
|
101
|
+
pkgJson.exports = props.exports;
|
|
102
|
+
} else {
|
|
103
|
+
const exportsEntries: [string, ExportPath][] = [];
|
|
104
|
+
for (const entry of Object.entries(props.exports ?? {})) {
|
|
105
|
+
exportsEntries.push(entry);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (pkg) {
|
|
109
|
+
for (const [publicPath, module] of pkg.scope.exportedSymbols) {
|
|
110
|
+
exportsEntries.push([
|
|
111
|
+
publicPath,
|
|
112
|
+
modulePath(pkg.outFileMapper.value(module.name)),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
58
116
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
117
|
+
pkgJson.exports =
|
|
118
|
+
exportsEntries.length === 0 ?
|
|
119
|
+
undefined
|
|
120
|
+
: Object.fromEntries(exportsEntries);
|
|
121
|
+
}
|
|
63
122
|
|
|
64
123
|
return JSON.stringify(pkgJson, null, 2);
|
|
65
124
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MemberDeclarationContext, useContext } from "@alloy-js/core";
|
|
2
|
+
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
3
|
+
import { isValidJSIdentifier } from "../utils.js";
|
|
4
|
+
|
|
5
|
+
export interface PropertyNameProps {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the property.
|
|
8
|
+
*/
|
|
9
|
+
name?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Whether the property is a private property. If `true`, the property will be
|
|
13
|
+
* prefixed with `#`.
|
|
14
|
+
*/
|
|
15
|
+
private?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A TypeScript property name for an interface, class, or object member. If the
|
|
20
|
+
* name is not a valid JavaScript identifier, it will be quoted. If a `name` prop
|
|
21
|
+
* is provided, it will be used as the property name. Otherwise, the name will be
|
|
22
|
+
* taken from the {@link (MemberDeclarationContext:variable)}.
|
|
23
|
+
*/
|
|
24
|
+
export function PropertyName(props: PropertyNameProps) {
|
|
25
|
+
if (props.name) {
|
|
26
|
+
if (props.private) {
|
|
27
|
+
return "#" + props.name;
|
|
28
|
+
}
|
|
29
|
+
return quoteIfNeeded(props.name);
|
|
30
|
+
} else {
|
|
31
|
+
const declSymbol = useContext(MemberDeclarationContext) as TSOutputSymbol;
|
|
32
|
+
if (!declSymbol) {
|
|
33
|
+
return "(no member declaration context)";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (declSymbol.tsFlags & TSSymbolFlags.PrivateMember) {
|
|
37
|
+
return <>#{declSymbol.name}</>;
|
|
38
|
+
} else {
|
|
39
|
+
return <>{quoteIfNeeded(declSymbol.name)}</>;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function quoteIfNeeded(name: string) {
|
|
45
|
+
if (isValidJSIdentifier(name)) {
|
|
46
|
+
return name;
|
|
47
|
+
} else {
|
|
48
|
+
return `"${name.replace(/"/g, '\\"')}"`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Prose } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
export interface SingleLineCommentBlockProps {
|
|
5
|
+
children: Children;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A single line comment block. The children are rendered as a prose element, which means that they
|
|
10
|
+
* are broken into multiple lines
|
|
11
|
+
*/
|
|
12
|
+
export function SingleLineCommentBlock(props: SingleLineCommentBlockProps) {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
//{" "}
|
|
16
|
+
<align string="// ">
|
|
17
|
+
<Prose>{props.children}</Prose>
|
|
18
|
+
</align>
|
|
19
|
+
</>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -17,6 +17,7 @@ import { createTSModuleScope, TSModuleScope } from "../symbols/index.js";
|
|
|
17
17
|
import { ImportStatements } from "./ImportStatement.js";
|
|
18
18
|
import { PackageContext } from "./PackageDirectory.js";
|
|
19
19
|
import { Reference } from "./Reference.js";
|
|
20
|
+
import { SingleLineCommentBlock } from "./SingleLineCommentBlock.jsx";
|
|
20
21
|
export interface SourceFileContext {
|
|
21
22
|
scope: TSModuleScope;
|
|
22
23
|
}
|
|
@@ -30,6 +31,8 @@ export function useSourceFile() {
|
|
|
30
31
|
export interface SourceFileProps {
|
|
31
32
|
path: string;
|
|
32
33
|
children?: Children;
|
|
34
|
+
header?: Children;
|
|
35
|
+
headerComment?: string;
|
|
33
36
|
export?: boolean | string;
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -59,11 +62,20 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
const header =
|
|
66
|
+
props.header || props.headerComment ?
|
|
67
|
+
<SourceFileHeader
|
|
68
|
+
header={props.header}
|
|
69
|
+
headerComment={props.headerComment}
|
|
70
|
+
/>
|
|
71
|
+
: undefined;
|
|
72
|
+
|
|
62
73
|
return (
|
|
63
74
|
<CoreSourceFile
|
|
64
75
|
path={props.path}
|
|
65
76
|
filetype="typescript"
|
|
66
77
|
reference={Reference}
|
|
78
|
+
header={header}
|
|
67
79
|
>
|
|
68
80
|
<Show when={scope.importedModules.size > 0}>
|
|
69
81
|
<ImportStatements records={scope.importedModules} />
|
|
@@ -76,3 +88,20 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
76
88
|
</CoreSourceFile>
|
|
77
89
|
);
|
|
78
90
|
}
|
|
91
|
+
|
|
92
|
+
export interface SourceFileHeaderProps {
|
|
93
|
+
header?: Children;
|
|
94
|
+
headerComment?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function SourceFileHeader(props: SourceFileHeaderProps) {
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
<Show when={props.headerComment !== undefined}>
|
|
101
|
+
<SingleLineCommentBlock>{props.headerComment}</SingleLineCommentBlock>
|
|
102
|
+
</Show>
|
|
103
|
+
<Show when={props.header !== undefined}>{props.header}</Show>
|
|
104
|
+
<hbr />
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Block, Indent, Match, Switch } from "@alloy-js/core";
|
|
2
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { BlockScope } from "./BlockScope.jsx";
|
|
4
|
+
import { ValueExpression } from "./ValueExpression.jsx";
|
|
5
|
+
|
|
6
|
+
export interface SwitchStatementProps {
|
|
7
|
+
expression: Children;
|
|
8
|
+
children: Children;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A switch statement.
|
|
13
|
+
*/
|
|
14
|
+
export function SwitchStatement(props: SwitchStatementProps) {
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
switch ({props.expression}) <Block>{props.children}</Block>
|
|
18
|
+
</>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CaseClausePropsBase {
|
|
23
|
+
children: Children;
|
|
24
|
+
block?: boolean;
|
|
25
|
+
break?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CaseClausePropsWithExpression extends CaseClausePropsBase {
|
|
29
|
+
expression: Children;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CaseClausePropsWithValue extends CaseClausePropsBase {
|
|
33
|
+
jsValue: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CaseClausePropsWithDefault extends CaseClausePropsBase {
|
|
37
|
+
default: true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type CaseClauseProps =
|
|
41
|
+
| CaseClausePropsWithExpression
|
|
42
|
+
| CaseClausePropsWithValue
|
|
43
|
+
| CaseClausePropsWithDefault;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A case clause in a switch statement. Provide either an expression or a JS
|
|
47
|
+
* value to compare to the switch expression. Can optionally be wrapped in a
|
|
48
|
+
* block. Pass `break` to finish with a break statement.
|
|
49
|
+
*/
|
|
50
|
+
export function CaseClause(props: CaseClauseProps) {
|
|
51
|
+
const Wrapper = props.block ? BlockScope : Indent;
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<Switch>
|
|
55
|
+
<Match when={"default" in props && props.default}>default </Match>
|
|
56
|
+
<Match else>
|
|
57
|
+
case{" "}
|
|
58
|
+
{"expression" in props ?
|
|
59
|
+
props.expression
|
|
60
|
+
: <ValueExpression
|
|
61
|
+
jsValue={(props as CaseClausePropsWithValue).jsValue}
|
|
62
|
+
/>
|
|
63
|
+
}
|
|
64
|
+
</Match>
|
|
65
|
+
</Switch>
|
|
66
|
+
{": "}
|
|
67
|
+
<Wrapper>
|
|
68
|
+
{props.children}
|
|
69
|
+
{props.break && (
|
|
70
|
+
<>
|
|
71
|
+
<hbr />
|
|
72
|
+
break;
|
|
73
|
+
</>
|
|
74
|
+
)}
|
|
75
|
+
</Wrapper>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { Name } from "@alloy-js/core";
|
|
1
|
+
import { Name, Show } from "@alloy-js/core";
|
|
2
2
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
3
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
3
4
|
|
|
4
5
|
export interface TypeDeclarationProps extends BaseDeclarationProps {}
|
|
5
6
|
|
|
6
7
|
export function TypeDeclaration(props: TypeDeclarationProps) {
|
|
7
8
|
return (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
<>
|
|
10
|
+
<Show when={Boolean(props.doc)}>
|
|
11
|
+
<JSDoc children={props.doc} />
|
|
12
|
+
<hbr />
|
|
13
|
+
</Show>
|
|
14
|
+
<Declaration {...props} nameKind="type">
|
|
15
|
+
type <Name /> = {props.children};
|
|
16
|
+
</Declaration>
|
|
17
|
+
</>
|
|
11
18
|
);
|
|
12
19
|
}
|
|
@@ -4,17 +4,18 @@ import {
|
|
|
4
4
|
Declaration as CoreDeclaration,
|
|
5
5
|
createAssignmentContext,
|
|
6
6
|
Name,
|
|
7
|
-
|
|
7
|
+
Show,
|
|
8
8
|
} from "@alloy-js/core";
|
|
9
9
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
10
10
|
import { createTSSymbol } from "../symbols/index.js";
|
|
11
11
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
12
|
+
import { JSDoc } from "./JSDoc.jsx";
|
|
12
13
|
|
|
13
14
|
export interface VarDeclarationProps extends BaseDeclarationProps {
|
|
14
15
|
const?: boolean;
|
|
15
16
|
let?: boolean;
|
|
16
17
|
var?: boolean;
|
|
17
|
-
|
|
18
|
+
initializer?: Children;
|
|
18
19
|
type?: Children;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -27,22 +28,29 @@ export function VarDeclaration(props: VarDeclarationProps) {
|
|
|
27
28
|
const name = useTSNamePolicy().getName(props.name, "variable");
|
|
28
29
|
const sym = createTSSymbol({
|
|
29
30
|
name: name,
|
|
30
|
-
refkey: props.refkey
|
|
31
|
+
refkey: props.refkey,
|
|
31
32
|
default: props.default,
|
|
32
33
|
export: props.export,
|
|
34
|
+
metadata: props.metadata,
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
const assignmentContext = createAssignmentContext(sym);
|
|
36
38
|
|
|
37
39
|
return (
|
|
38
|
-
|
|
39
|
-
{props.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
<
|
|
44
|
-
{props.
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
<>
|
|
41
|
+
<Show when={Boolean(props.doc)}>
|
|
42
|
+
<JSDoc children={props.doc} />
|
|
43
|
+
<hbr />
|
|
44
|
+
</Show>
|
|
45
|
+
<CoreDeclaration symbol={sym}>
|
|
46
|
+
{props.export ? "export " : ""}
|
|
47
|
+
{props.default ? "default " : ""}
|
|
48
|
+
{keyword} <Name />
|
|
49
|
+
{type} ={" "}
|
|
50
|
+
<AssignmentContext.Provider value={assignmentContext}>
|
|
51
|
+
{props.initializer ?? props.children}
|
|
52
|
+
</AssignmentContext.Provider>
|
|
53
|
+
</CoreDeclaration>
|
|
54
|
+
</>
|
|
47
55
|
);
|
|
48
56
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export * from "../parameter-descriptor.js";
|
|
1
2
|
export * from "./ArrayExpression.js";
|
|
2
3
|
export * from "./BarrelFile.js";
|
|
4
|
+
export * from "./BlockScope.js";
|
|
5
|
+
export * from "./CallSignature.jsx";
|
|
3
6
|
export * from "./ClassDeclaration.jsx";
|
|
4
7
|
export * from "./CommaList.jsx";
|
|
5
8
|
export * from "./Declaration.js";
|
|
@@ -10,12 +13,16 @@ export * from "./FunctionCallExpression.js";
|
|
|
10
13
|
export * from "./FunctionDeclaration.js";
|
|
11
14
|
export * from "./ImportStatement.js";
|
|
12
15
|
export * from "./Interface.js";
|
|
16
|
+
export * from "./JSDoc.jsx";
|
|
17
|
+
export * from "./JSDocComment.jsx";
|
|
18
|
+
export * from "./JSDocExample.jsx";
|
|
13
19
|
export * from "./MemberChainExpression.jsx";
|
|
14
20
|
export * from "./ObjectExpression.js";
|
|
15
21
|
export * from "./PackageDirectory.js";
|
|
16
22
|
export * from "./PackageJson.js";
|
|
17
23
|
export * from "./Reference.js";
|
|
18
24
|
export * from "./SourceFile.js";
|
|
25
|
+
export * from "./SwitchStatement.jsx";
|
|
19
26
|
export * from "./TsConfigJson.js";
|
|
20
27
|
export * from "./TypeDeclaration.js";
|
|
21
28
|
export * from "./ValueExpression.js";
|
|
@@ -3,10 +3,12 @@ import * as base from "../index.js";
|
|
|
3
3
|
|
|
4
4
|
export const ArrayExpression = stc(base.ArrayExpression);
|
|
5
5
|
export const BarrelFile = stc(base.BarrelFile);
|
|
6
|
+
export const CallSignature = stc(base.CallSignature);
|
|
6
7
|
export const ClassDeclaration = stc(base.ClassDeclaration);
|
|
7
8
|
export const ClassField = stc(base.ClassField);
|
|
8
9
|
export const ClassMember = stc(base.ClassMember);
|
|
9
10
|
export const ClassMethod = stc(base.ClassMethod);
|
|
11
|
+
export const CommaList = stc(base.CommaList);
|
|
10
12
|
export const Declaration = stc(base.Declaration);
|
|
11
13
|
export const EnumDeclaration = stc(base.EnumDeclaration);
|
|
12
14
|
export const EnumMember = stc(base.EnumMember);
|
|
@@ -18,13 +20,18 @@ export const ImportStatements = stc(base.ImportStatements);
|
|
|
18
20
|
export const InterfaceDeclaration = stc(base.InterfaceDeclaration);
|
|
19
21
|
export const InterfaceExpression = stc(base.InterfaceExpression);
|
|
20
22
|
export const InterfaceMember = stc(base.InterfaceMember);
|
|
21
|
-
export const
|
|
23
|
+
export const JSDoc = stc(base.JSDoc);
|
|
24
|
+
export const JSDocExample = stc(base.JSDocExample);
|
|
25
|
+
export const JSDocComment = stc(base.JSDocComment);
|
|
26
|
+
export const MemberChainExpression = stc(base.MemberChainExpression);
|
|
22
27
|
export const ObjectExpression = stc(base.ObjectExpression);
|
|
23
28
|
export const ObjectProperty = stc(base.ObjectProperty);
|
|
24
29
|
export const PackageDirectory = stc(base.PackageDirectory);
|
|
25
30
|
export const PackageJsonFile = stc(base.PackageJsonFile);
|
|
26
31
|
export const Reference = stc(base.Reference);
|
|
27
32
|
export const SourceFile = stc(base.SourceFile);
|
|
33
|
+
export const SwitchStatement = stc(base.SwitchStatement);
|
|
34
|
+
export const CaseClause = stc(base.CaseClause);
|
|
28
35
|
export const TSConfigJson = stc(base.TSConfigJson);
|
|
29
36
|
export const TypeDeclaration = stc(base.TypeDeclaration);
|
|
30
37
|
export const ValueExpression = stc(base.ValueExpression);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./private-scope.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentContext, createContext, useContext } from "@alloy-js/core";
|
|
2
|
+
import { TSMemberScope } from "../symbols/ts-member-scope.js";
|
|
3
|
+
|
|
4
|
+
export interface PrivateScopeContext {
|
|
5
|
+
/**
|
|
6
|
+
* Scope for private static members.
|
|
7
|
+
*/
|
|
8
|
+
staticMembers: TSMemberScope;
|
|
9
|
+
/**
|
|
10
|
+
* Scope for private instance members.
|
|
11
|
+
*/
|
|
12
|
+
instanceMembers: TSMemberScope;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Provides scopes for instance and static private members.
|
|
17
|
+
*/
|
|
18
|
+
export const PrivateScopeContext: ComponentContext<PrivateScopeContext> =
|
|
19
|
+
createContext<PrivateScopeContext>();
|
|
20
|
+
|
|
21
|
+
export function usePrivateScope() {
|
|
22
|
+
return useContext(PrivateScopeContext);
|
|
23
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Information for a TypeScript function parameter.
|
|
5
|
+
*/
|
|
6
|
+
export interface ParameterDescriptor {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the parameter.
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The type of the parameter.
|
|
14
|
+
*/
|
|
15
|
+
type?: Children;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The default value of the parameter.
|
|
19
|
+
*/
|
|
20
|
+
default?: Children;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The refkey for this parameter.
|
|
24
|
+
*/
|
|
25
|
+
refkey?: Refkey | Refkey[];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether the parameter is optional.
|
|
29
|
+
*/
|
|
30
|
+
optional?: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Arbitrary metadata for the parameter symbol.
|
|
34
|
+
*/
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Documentation for the parameter.
|
|
39
|
+
*/
|
|
40
|
+
doc?: Children;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Information for a TypeScript generic type parameter.
|
|
45
|
+
*/
|
|
46
|
+
export interface TypeParameterDescriptor {
|
|
47
|
+
/**
|
|
48
|
+
* The name of the type parameter.
|
|
49
|
+
*/
|
|
50
|
+
name: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The extends constraint for the type parameter.
|
|
54
|
+
*/
|
|
55
|
+
extends?: Children;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The default type of the type parameter.
|
|
59
|
+
*/
|
|
60
|
+
default?: Children;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A refkey or array of refkeys for this type parameter.
|
|
64
|
+
*/
|
|
65
|
+
refkey?: Refkey | Refkey[];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Arbitrary metadata for the type parameter symbol.
|
|
69
|
+
*/
|
|
70
|
+
metadata?: Record<string, unknown>;
|
|
71
|
+
}
|