@alloy-js/typescript 0.1.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/LICENSE.txt +7 -0
- package/api-extractor.json +4 -0
- package/babel.config.cjs +4 -0
- package/dist/src/builtins/index.d.ts +2 -0
- package/dist/src/builtins/index.d.ts.map +1 -0
- package/dist/src/builtins/index.js +1 -0
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/node.d.ts +183 -0
- package/dist/src/builtins/node.d.ts.map +1 -0
- package/dist/src/builtins/node.js +39 -0
- package/dist/src/builtins/node.js.map +1 -0
- package/dist/src/components/ArrayExpression.d.ts +7 -0
- package/dist/src/components/ArrayExpression.d.ts.map +1 -0
- package/dist/src/components/ArrayExpression.js +37 -0
- package/dist/src/components/ArrayExpression.js.map +1 -0
- package/dist/src/components/BarrelFile.d.ts +49 -0
- package/dist/src/components/BarrelFile.d.ts.map +1 -0
- package/dist/src/components/BarrelFile.js +73 -0
- package/dist/src/components/BarrelFile.js.map +1 -0
- package/dist/src/components/Block.d.ts +6 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +11 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts +64 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/ClassDeclaration.js +122 -0
- package/dist/src/components/ClassDeclaration.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +53 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +60 -0
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts +12 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/EnumDeclaration.js +48 -0
- package/dist/src/components/EnumDeclaration.js.map +1 -0
- package/dist/src/components/EnumMember.d.ts +28 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -0
- package/dist/src/components/EnumMember.js +28 -0
- package/dist/src/components/EnumMember.js.map +1 -0
- package/dist/src/components/ExportStatement.d.ts +7 -0
- package/dist/src/components/ExportStatement.d.ts.map +1 -0
- package/dist/src/components/ExportStatement.js +15 -0
- package/dist/src/components/ExportStatement.js.map +1 -0
- package/dist/src/components/FunctionCallExpression.d.ts +7 -0
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +14 -0
- package/dist/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts +29 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
- package/dist/src/components/FunctionDeclaration.js +91 -0
- package/dist/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts +11 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +92 -0
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +32 -0
- package/dist/src/components/Interface.d.ts.map +1 -0
- package/dist/src/components/Interface.js +50 -0
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +16 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -0
- package/dist/src/components/ObjectExpression.js +101 -0
- package/dist/src/components/ObjectExpression.js.map +1 -0
- package/dist/src/components/PackageDirectory.d.ts +23 -0
- package/dist/src/components/PackageDirectory.d.ts.map +1 -0
- package/dist/src/components/PackageDirectory.js +62 -0
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/PackageJson.d.ts +16 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -0
- package/dist/src/components/PackageJson.js +36 -0
- package/dist/src/components/PackageJson.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +8 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +15 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +62 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/TsConfigJson.d.ts +5 -0
- package/dist/src/components/TsConfigJson.d.ts.map +1 -0
- package/dist/src/components/TsConfigJson.js +53 -0
- package/dist/src/components/TsConfigJson.js.map +1 -0
- package/dist/src/components/TypeDeclaration.d.ts +5 -0
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -0
- package/dist/src/components/TypeDeclaration.js +14 -0
- package/dist/src/components/TypeDeclaration.js.map +1 -0
- package/dist/src/components/ValueExpression.d.ts +5 -0
- package/dist/src/components/ValueExpression.d.ts.map +1 -0
- package/dist/src/components/ValueExpression.js +32 -0
- package/dist/src/components/ValueExpression.js.map +1 -0
- package/dist/src/components/VarDeclaration.d.ts +11 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -0
- package/dist/src/components/VarDeclaration.js +29 -0
- package/dist/src/components/VarDeclaration.js.map +1 -0
- package/dist/src/components/index.d.ts +22 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +22 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +102 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +28 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/create-package.d.ts +33 -0
- package/dist/src/create-package.d.ts.map +1 -0
- package/dist/src/create-package.js +50 -0
- package/dist/src/create-package.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-conflict-resolver.d.ts +3 -0
- package/dist/src/name-conflict-resolver.d.ts.map +1 -0
- package/dist/src/name-conflict-resolver.js +15 -0
- package/dist/src/name-conflict-resolver.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +23 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/source-directory-data.d.ts +7 -0
- package/dist/src/source-directory-data.d.ts.map +1 -0
- package/dist/src/source-directory-data.js +13 -0
- package/dist/src/source-directory-data.js.map +1 -0
- package/dist/src/symbols/index.d.ts +7 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +7 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +3 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +75 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +16 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +5 -0
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/src/symbols/ts-member-scope.d.ts +9 -0
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-member-scope.js +10 -0
- package/dist/src/symbols/ts-member-scope.js.map +1 -0
- package/dist/src/symbols/ts-module-scope.d.ts +19 -0
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-module-scope.js +36 -0
- package/dist/src/symbols/ts-module-scope.js.map +1 -0
- package/dist/src/symbols/ts-output-symbol.d.ts +28 -0
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/ts-output-symbol.js +30 -0
- package/dist/src/symbols/ts-output-symbol.js.map +1 -0
- package/dist/src/symbols/ts-package-scope.d.ts +54 -0
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-package-scope.js +40 -0
- package/dist/src/symbols/ts-package-scope.js.map +1 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +7 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/array.test.d.ts +2 -0
- package/dist/test/array.test.d.ts.map +1 -0
- package/dist/test/barrel.test.d.ts +2 -0
- package/dist/test/barrel.test.d.ts.map +1 -0
- package/dist/test/basic.test.d.ts +2 -0
- package/dist/test/basic.test.d.ts.map +1 -0
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/enum.test.d.ts +2 -0
- package/dist/test/enum.test.d.ts.map +1 -0
- package/dist/test/externals.test.d.ts +2 -0
- package/dist/test/externals.test.d.ts.map +1 -0
- package/dist/test/function-call-expression.test.d.ts +2 -0
- package/dist/test/function-call-expression.test.d.ts.map +1 -0
- package/dist/test/function-declaration.test.d.ts +2 -0
- package/dist/test/function-declaration.test.d.ts.map +1 -0
- package/dist/test/imports.test.d.ts +2 -0
- package/dist/test/imports.test.d.ts.map +1 -0
- package/dist/test/interface.test.d.ts +2 -0
- package/dist/test/interface.test.d.ts.map +1 -0
- package/dist/test/name-policy.test.d.ts +2 -0
- package/dist/test/name-policy.test.d.ts.map +1 -0
- package/dist/test/package-external.test.d.ts +2 -0
- package/dist/test/package-external.test.d.ts.map +1 -0
- package/dist/test/package.test.d.ts +2 -0
- package/dist/test/package.test.d.ts.map +1 -0
- package/dist/test/reference.test.d.ts +2 -0
- package/dist/test/reference.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +5 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/values.test.d.ts +2 -0
- package/dist/test/values.test.d.ts.map +1 -0
- package/dist/test/var-declaration.test.d.ts +2 -0
- package/dist/test/var-declaration.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +49 -0
- package/src/builtins/index.ts +1 -0
- package/src/builtins/node.ts +219 -0
- package/src/components/ArrayExpression.tsx +41 -0
- package/src/components/BarrelFile.tsx +96 -0
- package/src/components/Block.tsx +12 -0
- package/src/components/ClassDeclaration.tsx +145 -0
- package/src/components/Declaration.tsx +105 -0
- package/src/components/EnumDeclaration.tsx +53 -0
- package/src/components/EnumMember.tsx +52 -0
- package/src/components/ExportStatement.tsx +21 -0
- package/src/components/FunctionCallExpression.tsx +15 -0
- package/src/components/FunctionDeclaration.tsx +132 -0
- package/src/components/ImportStatement.tsx +131 -0
- package/src/components/Interface.tsx +62 -0
- package/src/components/ObjectExpression.tsx +130 -0
- package/src/components/PackageDirectory.tsx +104 -0
- package/src/components/PackageJson.tsx +69 -0
- package/src/components/Reference.tsx +12 -0
- package/src/components/SourceFile.tsx +71 -0
- package/src/components/TsConfigJson.tsx +62 -0
- package/src/components/TypeDeclaration.tsx +10 -0
- package/src/components/ValueExpression.tsx +32 -0
- package/src/components/VarDeclaration.tsx +42 -0
- package/src/components/index.ts +21 -0
- package/src/components/stc/index.ts +28 -0
- package/src/create-package.ts +108 -0
- package/src/index.ts +6 -0
- package/src/name-conflict-resolver.ts +22 -0
- package/src/name-policy.ts +39 -0
- package/src/source-directory-data.ts +25 -0
- package/src/symbols/index.ts +6 -0
- package/src/symbols/reference.ts +120 -0
- package/src/symbols/scopes.ts +28 -0
- package/src/symbols/ts-member-scope.ts +23 -0
- package/src/symbols/ts-module-scope.ts +66 -0
- package/src/symbols/ts-output-symbol.ts +63 -0
- package/src/symbols/ts-package-scope.ts +112 -0
- package/src/utils.ts +7 -0
- package/temp/api.json +9866 -0
- package/test/array.test.tsx +14 -0
- package/test/barrel.test.tsx +46 -0
- package/test/basic.test.tsx +78 -0
- package/test/class.test.tsx +181 -0
- package/test/enum.test.tsx +132 -0
- package/test/externals.test.tsx +139 -0
- package/test/function-call-expression.test.tsx +49 -0
- package/test/function-declaration.test.tsx +201 -0
- package/test/imports.test.tsx +213 -0
- package/test/interface.test.tsx +124 -0
- package/test/name-policy.test.tsx +62 -0
- package/test/package-external.test.tsx +75 -0
- package/test/package.test.tsx +68 -0
- package/test/reference.test.tsx +59 -0
- package/test/utils.tsx +59 -0
- package/test/values.test.tsx +292 -0
- package/test/var-declaration.test.tsx +45 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +11 -0
- package/tsdoc-metadata.json +11 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { createPackage } from "../create-package.js";
|
|
2
|
+
|
|
3
|
+
export const path = createPackage({
|
|
4
|
+
name: "node:path",
|
|
5
|
+
version: "22.5.1",
|
|
6
|
+
builtin: true,
|
|
7
|
+
descriptor: {
|
|
8
|
+
".": {
|
|
9
|
+
default: "path",
|
|
10
|
+
named: [
|
|
11
|
+
"basename",
|
|
12
|
+
"delimeter",
|
|
13
|
+
"dirname",
|
|
14
|
+
"extname",
|
|
15
|
+
"format",
|
|
16
|
+
"matchesGlob",
|
|
17
|
+
"isAbsolute",
|
|
18
|
+
"join",
|
|
19
|
+
"normalize",
|
|
20
|
+
"parse",
|
|
21
|
+
"posix",
|
|
22
|
+
"relative",
|
|
23
|
+
"resolve",
|
|
24
|
+
"sep",
|
|
25
|
+
"toNamespacedPath",
|
|
26
|
+
"win32",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const fs = createPackage({
|
|
33
|
+
name: "node:fs",
|
|
34
|
+
version: "22.5.1",
|
|
35
|
+
builtin: true,
|
|
36
|
+
descriptor: {
|
|
37
|
+
".": {
|
|
38
|
+
default: "fs",
|
|
39
|
+
named: [
|
|
40
|
+
"access",
|
|
41
|
+
"appendFile",
|
|
42
|
+
"chmod",
|
|
43
|
+
"chown",
|
|
44
|
+
"close",
|
|
45
|
+
"copyFile",
|
|
46
|
+
"cp",
|
|
47
|
+
"createReadStream",
|
|
48
|
+
"createWriteStream",
|
|
49
|
+
"exists",
|
|
50
|
+
"fchmod",
|
|
51
|
+
"fchown",
|
|
52
|
+
"fdatasync",
|
|
53
|
+
"fstat",
|
|
54
|
+
"fsync",
|
|
55
|
+
"ftruncate",
|
|
56
|
+
"futimes",
|
|
57
|
+
"glob",
|
|
58
|
+
"lchmod",
|
|
59
|
+
"lchown",
|
|
60
|
+
"lutimes",
|
|
61
|
+
"link",
|
|
62
|
+
"lstat",
|
|
63
|
+
"mkdir",
|
|
64
|
+
"mkdtemp",
|
|
65
|
+
"open",
|
|
66
|
+
"openAsBlob",
|
|
67
|
+
"opendir",
|
|
68
|
+
"read",
|
|
69
|
+
"read",
|
|
70
|
+
"read",
|
|
71
|
+
"readdir",
|
|
72
|
+
"readFile",
|
|
73
|
+
"readlink",
|
|
74
|
+
"readv",
|
|
75
|
+
"realpath",
|
|
76
|
+
"realpath",
|
|
77
|
+
"rename",
|
|
78
|
+
"rmdir",
|
|
79
|
+
"rm",
|
|
80
|
+
"stat",
|
|
81
|
+
"statfs",
|
|
82
|
+
"symlink",
|
|
83
|
+
"truncate",
|
|
84
|
+
"unlink",
|
|
85
|
+
"unwatchFile",
|
|
86
|
+
"utimes",
|
|
87
|
+
"watch",
|
|
88
|
+
"watchFile",
|
|
89
|
+
"write",
|
|
90
|
+
"write",
|
|
91
|
+
"write",
|
|
92
|
+
"writeFile",
|
|
93
|
+
"writev",
|
|
94
|
+
"accessSync",
|
|
95
|
+
"appendFileSync",
|
|
96
|
+
"chmodSync",
|
|
97
|
+
"chownSync",
|
|
98
|
+
"closeSync",
|
|
99
|
+
"copyFileSync",
|
|
100
|
+
"cpSync",
|
|
101
|
+
"existsSync",
|
|
102
|
+
"fchmodSync",
|
|
103
|
+
"fchownSync",
|
|
104
|
+
"fdatasyncSync",
|
|
105
|
+
"fstatSync",
|
|
106
|
+
"fsyncSync",
|
|
107
|
+
"ftruncateSync",
|
|
108
|
+
"futimesSync",
|
|
109
|
+
"globSync",
|
|
110
|
+
"lchmodSync",
|
|
111
|
+
"lchownSync",
|
|
112
|
+
"lutimesSync",
|
|
113
|
+
"linkSync",
|
|
114
|
+
"lstatSync",
|
|
115
|
+
"mkdirSync",
|
|
116
|
+
"mkdtempSync",
|
|
117
|
+
"opendirSync",
|
|
118
|
+
"openSync",
|
|
119
|
+
"readdirSync",
|
|
120
|
+
"readFileSync",
|
|
121
|
+
"readlinkSync",
|
|
122
|
+
"readSync",
|
|
123
|
+
"readSync",
|
|
124
|
+
"readvSync",
|
|
125
|
+
"realpathSync",
|
|
126
|
+
"realpathSync",
|
|
127
|
+
"renameSync",
|
|
128
|
+
"rmdirSync",
|
|
129
|
+
"rmSync",
|
|
130
|
+
"statSync",
|
|
131
|
+
"statfsSync",
|
|
132
|
+
"symlinkSync",
|
|
133
|
+
"truncateSync",
|
|
134
|
+
"unlinkSync",
|
|
135
|
+
"utimesSync",
|
|
136
|
+
"writeFileSync",
|
|
137
|
+
"writeSync",
|
|
138
|
+
"writeSync",
|
|
139
|
+
"writeSync",
|
|
140
|
+
"writevSync",
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
"./promises": {
|
|
144
|
+
default: "fs",
|
|
145
|
+
named: [
|
|
146
|
+
"access",
|
|
147
|
+
"appendFile",
|
|
148
|
+
"chmod",
|
|
149
|
+
"chown",
|
|
150
|
+
"copyFile",
|
|
151
|
+
"cp",
|
|
152
|
+
"glob",
|
|
153
|
+
"lchmod",
|
|
154
|
+
"lchown",
|
|
155
|
+
"lutimes",
|
|
156
|
+
"link",
|
|
157
|
+
"lstat",
|
|
158
|
+
"mkdir",
|
|
159
|
+
"mkdtemp",
|
|
160
|
+
"open",
|
|
161
|
+
"opendir",
|
|
162
|
+
"readdir",
|
|
163
|
+
"readFile",
|
|
164
|
+
"readLink",
|
|
165
|
+
"realpath",
|
|
166
|
+
"rename",
|
|
167
|
+
"rmdir",
|
|
168
|
+
"rm",
|
|
169
|
+
"stat",
|
|
170
|
+
"statfs",
|
|
171
|
+
"symlink",
|
|
172
|
+
"truncate",
|
|
173
|
+
"unlink",
|
|
174
|
+
"utimes",
|
|
175
|
+
"watch",
|
|
176
|
+
"writeFile",
|
|
177
|
+
"constants",
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
export const util = createPackage({
|
|
184
|
+
name: "node:util",
|
|
185
|
+
version: "22.5.1",
|
|
186
|
+
builtin: true,
|
|
187
|
+
descriptor: {
|
|
188
|
+
".": {
|
|
189
|
+
default: "util",
|
|
190
|
+
named: [
|
|
191
|
+
"callbackify",
|
|
192
|
+
"debuglog",
|
|
193
|
+
"debug",
|
|
194
|
+
"deprecate",
|
|
195
|
+
"format",
|
|
196
|
+
"formatWithOptions",
|
|
197
|
+
"getSystemErrorName",
|
|
198
|
+
"getSystemErrorMap",
|
|
199
|
+
"inherits",
|
|
200
|
+
"inspect",
|
|
201
|
+
"isDeepStrictEqual",
|
|
202
|
+
"MIMEType",
|
|
203
|
+
"MIMEParams",
|
|
204
|
+
"parseArgs",
|
|
205
|
+
"parseEnv",
|
|
206
|
+
"promisify",
|
|
207
|
+
"stripVTControlCharacters",
|
|
208
|
+
"styleText",
|
|
209
|
+
"TextDecoder",
|
|
210
|
+
"TextEncoder",
|
|
211
|
+
"toUSVString",
|
|
212
|
+
"transferableAbortController",
|
|
213
|
+
"transferableAbortSignal",
|
|
214
|
+
"aborted",
|
|
215
|
+
"types",
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Children, computed, Indent, mapJoin, memo } from "@alloy-js/core";
|
|
2
|
+
import { ValueExpression } from "./ValueExpression.js";
|
|
3
|
+
|
|
4
|
+
export interface ArrayExpressionProps {
|
|
5
|
+
children?: Children;
|
|
6
|
+
jsValue?: unknown[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function ArrayExpression(props: ArrayExpressionProps) {
|
|
10
|
+
const elements = computed(() => {
|
|
11
|
+
const jsValue = props.jsValue;
|
|
12
|
+
let elements: any[] = [];
|
|
13
|
+
|
|
14
|
+
if (jsValue) {
|
|
15
|
+
elements = mapJoin(
|
|
16
|
+
jsValue,
|
|
17
|
+
(value) => {
|
|
18
|
+
return <ValueExpression jsValue={value} />;
|
|
19
|
+
},
|
|
20
|
+
{ joiner: ",\n" },
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (props.children) {
|
|
25
|
+
if (elements.length > 0) {
|
|
26
|
+
elements.push(",");
|
|
27
|
+
}
|
|
28
|
+
elements.push("\n", props.children);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return elements;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return memo(() => {
|
|
35
|
+
if (elements.value.length === 0) {
|
|
36
|
+
return "[]";
|
|
37
|
+
} else {
|
|
38
|
+
return ["[\n", <Indent>{elements.value}</Indent>, "\n]"];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mapJoin,
|
|
3
|
+
memo,
|
|
4
|
+
SourceDirectoryContext,
|
|
5
|
+
useContext,
|
|
6
|
+
} from "@alloy-js/core";
|
|
7
|
+
import { basename } from "pathe";
|
|
8
|
+
import { getSourceDirectoryData } from "../source-directory-data.js";
|
|
9
|
+
import { TSModuleScope } from "../symbols/index.js";
|
|
10
|
+
import { ExportStatement } from "./ExportStatement.js";
|
|
11
|
+
import { SourceFile } from "./SourceFile.js";
|
|
12
|
+
|
|
13
|
+
export interface BarrelFileProps {
|
|
14
|
+
/**
|
|
15
|
+
* The name of the source file
|
|
16
|
+
*/
|
|
17
|
+
path?: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Whether the source file is exported out of the package. When true, this
|
|
21
|
+
* source file with its source file relative to the project root. Otherwise,
|
|
22
|
+
* it will be exported with the specified path.
|
|
23
|
+
*/
|
|
24
|
+
export?: boolean | string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a source file which re-exports the exports in other files and nested
|
|
29
|
+
* barrel files in the source directory its placed in.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
*
|
|
33
|
+
* This component must be placed directly inside a {@link @alloy-js/core#SourceDirectory}
|
|
34
|
+
* component. It will only discover nested barrel files directly within nested
|
|
35
|
+
* source directories.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* Creating a barrel file which exports the two other source files in the same directory
|
|
40
|
+
*
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <Output>
|
|
43
|
+
* <SourceDirectory path="src">
|
|
44
|
+
* <SourceFile path="one.ts" />
|
|
45
|
+
* <SourceFile path="two.ts" />
|
|
46
|
+
* <BarrelFile />
|
|
47
|
+
* </SourceDirectory>
|
|
48
|
+
* </Output>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* The barrel file will contain the following contents:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* export * from "./one.js";
|
|
55
|
+
* export * from "./two.js";
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
*
|
|
59
|
+
* @see {@link @alloy-js/core#SourceDirectory}
|
|
60
|
+
* @see {@link SourceFile}
|
|
61
|
+
*/
|
|
62
|
+
export function BarrelFile(props: BarrelFileProps) {
|
|
63
|
+
const path = props.path ?? "index.ts";
|
|
64
|
+
const directory = useContext(SourceDirectoryContext)!;
|
|
65
|
+
const sdData = getSourceDirectoryData(directory);
|
|
66
|
+
|
|
67
|
+
const exports = memo(() => {
|
|
68
|
+
const subdirs = directory.contents.filter(
|
|
69
|
+
(c) => !(c as any).filetype,
|
|
70
|
+
) as SourceDirectoryContext[];
|
|
71
|
+
|
|
72
|
+
const nestedBarrels: TSModuleScope[] = [];
|
|
73
|
+
for (const subdir of subdirs) {
|
|
74
|
+
const nestedSdData = getSourceDirectoryData(subdir);
|
|
75
|
+
const nestedBarrel = Array.from(nestedSdData.modules).find(
|
|
76
|
+
(m) => basename(m.name) === "index.ts",
|
|
77
|
+
);
|
|
78
|
+
if (nestedBarrel) {
|
|
79
|
+
nestedBarrels.push(nestedBarrel);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const sourceFiles = Array.from(sdData.modules).filter(
|
|
84
|
+
(m) => basename(m.name) !== "index.ts",
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const allModules = [...sourceFiles, ...nestedBarrels];
|
|
88
|
+
return mapJoin(allModules, (module) => {
|
|
89
|
+
return <ExportStatement star from={module} />;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return <SourceFile path={path} export={props.export}>
|
|
94
|
+
{exports}
|
|
95
|
+
</SourceFile>;
|
|
96
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
MemberDeclaration,
|
|
4
|
+
MemberName,
|
|
5
|
+
Name,
|
|
6
|
+
OutputSymbolFlags,
|
|
7
|
+
Refkey,
|
|
8
|
+
Scope,
|
|
9
|
+
} from "@alloy-js/core";
|
|
10
|
+
import { useTSNamePolicy } from "../name-policy.js";
|
|
11
|
+
import { createTSSymbol, TSOutputSymbol } from "../symbols/ts-output-symbol.js";
|
|
12
|
+
import { BaseDeclarationProps, Declaration } from "./Declaration.jsx";
|
|
13
|
+
import {
|
|
14
|
+
FunctionDeclaration,
|
|
15
|
+
ParameterDescriptor,
|
|
16
|
+
} from "./FunctionDeclaration.jsx";
|
|
17
|
+
|
|
18
|
+
export interface ClassDeclarationProps extends BaseDeclarationProps {
|
|
19
|
+
extends?: Children;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a TypeScript class declaration.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const myPetRefkey = refkey();
|
|
31
|
+
* const Animal = refkey();
|
|
32
|
+
* const staticMember = refkey();
|
|
33
|
+
* const instanceMember = refkey();
|
|
34
|
+
*
|
|
35
|
+
* <ClassDeclaration name="Animal" refkey={Animal}>
|
|
36
|
+
* <ClassMember public static name="something" type="string" refkey={staticMember}>
|
|
37
|
+
* "hello"
|
|
38
|
+
* </ClassMember>
|
|
39
|
+
* <ClassMember public name="kind" type="string" />
|
|
40
|
+
* <ClassMember public name="name" type="string" refkey={instanceMember} />
|
|
41
|
+
* <ClassConstructor parameters="name: string">
|
|
42
|
+
* this.name = name;
|
|
43
|
+
* </ClassConstructor>
|
|
44
|
+
* </ClassDeclaration>
|
|
45
|
+
*
|
|
46
|
+
* <VarDeclaration const name="myPet" refkey={myPetRefkey}>
|
|
47
|
+
* new {Animal}();
|
|
48
|
+
* </VarDeclaration>
|
|
49
|
+
*
|
|
50
|
+
* {staticMember}; // Animal.something
|
|
51
|
+
* <MemberReference path={[myPetRefkey, instanceMember]} /> // myPet.name
|
|
52
|
+
* {member(myPetRefkey, instanceMember)} // other option?
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
56
|
+
const extendsPart = props.extends && <> extends {props.extends}</>;
|
|
57
|
+
const flags = OutputSymbolFlags.MemberContainer;
|
|
58
|
+
|
|
59
|
+
return <Declaration {...props} flags={flags} nameKind="class">
|
|
60
|
+
class <Name />{extendsPart} {"{"}
|
|
61
|
+
{props.children}
|
|
62
|
+
{"}"}
|
|
63
|
+
</Declaration>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ClassMemberProps {
|
|
67
|
+
name: string;
|
|
68
|
+
refkey?: Refkey;
|
|
69
|
+
public?: boolean;
|
|
70
|
+
private?: boolean;
|
|
71
|
+
protected?: boolean;
|
|
72
|
+
jsPrivate?: boolean;
|
|
73
|
+
static?: boolean;
|
|
74
|
+
children?: Children;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function ClassMember(props: ClassMemberProps) {
|
|
78
|
+
let sym: TSOutputSymbol | undefined;
|
|
79
|
+
const namer = useTSNamePolicy();
|
|
80
|
+
let name = namer.getName(props.name, "class-member-data");
|
|
81
|
+
|
|
82
|
+
if (props.refkey) {
|
|
83
|
+
let flags = OutputSymbolFlags.None;
|
|
84
|
+
if (props.static) {
|
|
85
|
+
flags |= OutputSymbolFlags.StaticMember;
|
|
86
|
+
} else {
|
|
87
|
+
flags |= OutputSymbolFlags.InstanceMember;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
sym = createTSSymbol({
|
|
91
|
+
name: props.jsPrivate ? `#${name}` : name,
|
|
92
|
+
refkey: props.refkey,
|
|
93
|
+
flags,
|
|
94
|
+
});
|
|
95
|
+
} else if (props.jsPrivate) {
|
|
96
|
+
// we won't be using the symbol name, so munge the name
|
|
97
|
+
name = `#${name}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return <MemberDeclaration symbol={sym} name={name} refkey={props.refkey}>
|
|
101
|
+
{
|
|
102
|
+
props.public && "public "
|
|
103
|
+
}{
|
|
104
|
+
props.private && "private "
|
|
105
|
+
}{
|
|
106
|
+
props.protected && "protected "
|
|
107
|
+
}{
|
|
108
|
+
props.static && "static "
|
|
109
|
+
}{props.children}
|
|
110
|
+
</MemberDeclaration>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ClassFieldProps extends ClassMemberProps {
|
|
114
|
+
type?: Children;
|
|
115
|
+
children?: Children;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function ClassField(props: ClassFieldProps) {
|
|
119
|
+
const typeSection = props.type && <>: {props.type}</>;
|
|
120
|
+
const initializerSection = props.children && <> = {props.children}</>;
|
|
121
|
+
|
|
122
|
+
return <ClassMember {...props}>
|
|
123
|
+
<MemberName />{typeSection}{initializerSection};
|
|
124
|
+
</ClassMember>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface ClassMethodProps extends ClassMemberProps {
|
|
128
|
+
async?: boolean;
|
|
129
|
+
parameters?: Record<string, Children | ParameterDescriptor>;
|
|
130
|
+
returnType?: Children;
|
|
131
|
+
children?: Children;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function ClassMethod(props: ClassMethodProps) {
|
|
135
|
+
const returnType = props.returnType && <>: {props.returnType}</>;
|
|
136
|
+
return <ClassMember {...props}>
|
|
137
|
+
{
|
|
138
|
+
props.async && "async "
|
|
139
|
+
}<MemberName /><Scope name={props.name} kind="function">
|
|
140
|
+
(<FunctionDeclaration.Parameters parameters={props.parameters} />){returnType} {"{"}
|
|
141
|
+
{props.children}
|
|
142
|
+
{"}"}
|
|
143
|
+
</Scope>
|
|
144
|
+
</ClassMember>;
|
|
145
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
Declaration as CoreDeclaration,
|
|
4
|
+
MemberScope,
|
|
5
|
+
OutputSymbolFlags,
|
|
6
|
+
refkey,
|
|
7
|
+
Refkey,
|
|
8
|
+
} from "@alloy-js/core";
|
|
9
|
+
import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
|
|
10
|
+
import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
11
|
+
|
|
12
|
+
// imports for documentation
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
import { TypeDeclaration } from "./TypeDeclaration.jsx";
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
import { EnumDeclaration } from "./EnumDeclaration.jsx";
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
import { InterfaceDeclaration } from "./Interface.jsx";
|
|
19
|
+
|
|
20
|
+
export interface BaseDeclarationProps {
|
|
21
|
+
/**
|
|
22
|
+
* The base name of this declaration. May change depending on naming policy
|
|
23
|
+
* and any conflicts.
|
|
24
|
+
*/
|
|
25
|
+
name: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The unique key for this declaration.
|
|
29
|
+
*/
|
|
30
|
+
refkey?: Refkey;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether to export this declaration from the module.
|
|
34
|
+
*/
|
|
35
|
+
export?: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether this is the default export of the module.
|
|
39
|
+
*/
|
|
40
|
+
default?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Flags for the symbol created by this component.
|
|
44
|
+
*/
|
|
45
|
+
flags?: OutputSymbolFlags;
|
|
46
|
+
|
|
47
|
+
children?: Children;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether this is a declaration of a type (e.g. interface, type alias) or a
|
|
51
|
+
* value (e.g. var, const, let).
|
|
52
|
+
*/
|
|
53
|
+
kind?: "type" | "value";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface DeclarationProps extends BaseDeclarationProps {
|
|
57
|
+
/**
|
|
58
|
+
* The name policy kind to apply to the declaration.
|
|
59
|
+
*/
|
|
60
|
+
nameKind: TypeScriptElements;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create a TypeScript declaration. Generally, this component shouldn't be used
|
|
65
|
+
* directly, and instead prefer components for specific declarations, e.g.
|
|
66
|
+
* {@link EnumDeclaration}, {@link InterfaceDeclaration},
|
|
67
|
+
* {@link TypeDeclaration}, etc.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
*
|
|
71
|
+
* This component will wrap its contents in a {@link @alloy-js/core#Declaration} component,
|
|
72
|
+
* so children can make use of declaration context. Additionally, if the
|
|
73
|
+
* provided symbol flags have {@link @alloy-js/core#OutputSymbolFlags.MemberContainer}, this
|
|
74
|
+
* component will create a {@link @alloy-js/core#MemberScope}.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
export function Declaration(props: DeclarationProps) {
|
|
78
|
+
const namePolicy = useTSNamePolicy();
|
|
79
|
+
|
|
80
|
+
let tsFlags: TSSymbolFlags = TSSymbolFlags.None;
|
|
81
|
+
if (props.kind && props.kind === "type") {
|
|
82
|
+
tsFlags &= TSSymbolFlags.TypeSymbol;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const sym = createTSSymbol({
|
|
86
|
+
name: namePolicy.getName(props.name, props.nameKind),
|
|
87
|
+
refkey: props.refkey ?? refkey(props.name),
|
|
88
|
+
export: props.export,
|
|
89
|
+
default: props.default,
|
|
90
|
+
flags: props.flags,
|
|
91
|
+
tsFlags,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
let children: Children;
|
|
95
|
+
|
|
96
|
+
if (sym.flags & OutputSymbolFlags.MemberContainer) {
|
|
97
|
+
children = <MemberScope owner={sym}>{props.children}</MemberScope>;
|
|
98
|
+
} else {
|
|
99
|
+
children = () => props.children;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return <CoreDeclaration symbol={sym}>
|
|
103
|
+
{props.export ? "export " : ""}{props.default ? "default " : ""}{children}
|
|
104
|
+
</CoreDeclaration>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Declaration as CoreDeclaration,
|
|
3
|
+
MemberScope,
|
|
4
|
+
Name,
|
|
5
|
+
OutputSymbolFlags,
|
|
6
|
+
mapJoin,
|
|
7
|
+
refkey,
|
|
8
|
+
useBinder,
|
|
9
|
+
} from "@alloy-js/core";
|
|
10
|
+
import { useTSNamePolicy } from "../name-policy.js";
|
|
11
|
+
import { createTSSymbol, useTSScope } from "../symbols/index.js";
|
|
12
|
+
import { BaseDeclarationProps } from "./Declaration.js";
|
|
13
|
+
import { EnumMember } from "./EnumMember.jsx";
|
|
14
|
+
export interface EnumDeclarationProps extends BaseDeclarationProps {
|
|
15
|
+
/**
|
|
16
|
+
* A JS object representing the enum member names and values.
|
|
17
|
+
*/
|
|
18
|
+
jsValue?: Record<string, string | number>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A TypeScript enum declaration.
|
|
23
|
+
*/
|
|
24
|
+
export function EnumDeclaration(props: EnumDeclarationProps) {
|
|
25
|
+
const name = useTSNamePolicy().getName(props.name, "enum");
|
|
26
|
+
const binder = useBinder();
|
|
27
|
+
const scope = useTSScope();
|
|
28
|
+
const sym = createTSSymbol({
|
|
29
|
+
binder,
|
|
30
|
+
scope,
|
|
31
|
+
name: name,
|
|
32
|
+
refkey: props.refkey ?? refkey(name),
|
|
33
|
+
default: props.default,
|
|
34
|
+
export: props.export,
|
|
35
|
+
flags: OutputSymbolFlags.StaticMemberContainer,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const jsValueMembers = mapJoin(
|
|
39
|
+
Object.entries(props.jsValue ?? {}),
|
|
40
|
+
([name, value]) => {
|
|
41
|
+
return <EnumMember name={name} jsValue={value} />;
|
|
42
|
+
},
|
|
43
|
+
{ joiner: ",\n" },
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return <CoreDeclaration symbol={sym}>
|
|
47
|
+
{props.export ? "export " : ""}{props.default ? "default " : ""}enum <Name /> {"{"}
|
|
48
|
+
<MemberScope owner={sym}>
|
|
49
|
+
{jsValueMembers}{jsValueMembers.length > 0 && props.children && ",\n"}{props.children}
|
|
50
|
+
</MemberScope>
|
|
51
|
+
{"}"}
|
|
52
|
+
</CoreDeclaration>;
|
|
53
|
+
}
|