@alloy-js/typescript 0.10.0 → 0.11.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 +15 -0
- package/dist/src/builtins/node.js +1 -2
- package/dist/src/components/ArrayExpression.js +2 -5
- package/dist/src/components/ArrowFunction.d.ts +40 -0
- package/dist/src/components/ArrowFunction.d.ts.map +1 -0
- package/dist/src/components/ArrowFunction.js +67 -0
- package/dist/src/components/BarrelFile.js +1 -2
- package/dist/src/components/BlockScope.js +2 -4
- package/dist/src/components/CallSignature.js +2 -4
- package/dist/src/components/ClassDeclaration.js +2 -6
- package/dist/src/components/CommaList.js +2 -5
- package/dist/src/components/Declaration.js +3 -5
- package/dist/src/components/EnumDeclaration.js +2 -5
- package/dist/src/components/EnumMember.js +2 -4
- package/dist/src/components/ExportStatement.js +1 -2
- package/dist/src/components/FunctionBase.d.ts +60 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -0
- package/dist/src/components/FunctionBase.js +207 -0
- package/dist/src/components/FunctionCallExpression.js +2 -5
- package/dist/src/components/FunctionDeclaration.d.ts +3 -18
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +9 -157
- package/dist/src/components/FunctionExpression.d.ts +39 -0
- package/dist/src/components/FunctionExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionExpression.js +66 -0
- package/dist/src/components/FunctionType.d.ts +39 -0
- package/dist/src/components/FunctionType.d.ts.map +1 -0
- package/dist/src/components/FunctionType.js +73 -0
- package/dist/src/components/IfStatement.js +2 -4
- package/dist/src/components/ImportStatement.js +1 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +32 -11
- package/dist/src/components/InterfaceMethod.d.ts +43 -0
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -0
- package/dist/src/components/InterfaceMethod.js +87 -0
- package/dist/src/components/JSDoc.js +1 -2
- package/dist/src/components/JSDocComment.js +2 -4
- package/dist/src/components/JSDocExample.js +2 -5
- package/dist/src/components/JSDocParam.js +2 -5
- package/dist/src/components/MemberChainExpression.js +2 -4
- package/dist/src/components/MemberDeclaration.d.ts +30 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -0
- package/dist/src/components/MemberDeclaration.js +29 -0
- package/dist/src/components/MemberExpression.js +2 -5
- package/dist/src/components/ObjectExpression.js +2 -5
- package/dist/src/components/PackageDirectory.js +2 -5
- package/dist/src/components/PackageJson.js +1 -2
- package/dist/src/components/PropertyName.js +1 -2
- package/dist/src/components/Reference.js +1 -2
- package/dist/src/components/SingleLineCommentBlock.js +2 -4
- package/dist/src/components/SourceFile.js +2 -4
- package/dist/src/components/SwitchStatement.js +2 -5
- package/dist/src/components/TsConfigJson.js +1 -2
- package/dist/src/components/TypeDeclaration.js +2 -6
- package/dist/src/components/ValueExpression.js +1 -2
- package/dist/src/components/VarDeclaration.js +2 -5
- package/dist/src/components/index.d.ts +6 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +6 -1
- package/dist/src/components/stc/index.d.ts +7 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +8 -2
- package/dist/src/context/private-scope.js +1 -2
- package/dist/src/create-package.js +1 -2
- package/dist/src/index.js +1 -2
- package/dist/src/name-conflict-resolver.js +1 -2
- package/dist/src/name-policy.js +1 -2
- package/dist/src/parameter-descriptor.d.ts +27 -17
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/source-directory-data.js +1 -2
- package/dist/src/symbols/index.js +1 -2
- package/dist/src/symbols/reference.js +2 -3
- package/dist/src/symbols/scopes.js +1 -2
- package/dist/src/symbols/ts-member-scope.js +1 -2
- package/dist/src/symbols/ts-module-scope.js +1 -2
- package/dist/src/symbols/ts-output-symbol.js +1 -2
- package/dist/src/symbols/ts-package-scope.js +1 -2
- package/dist/src/utils.js +1 -2
- package/dist/test/array.test.js +105 -0
- package/dist/test/arrow-function.test.d.ts +2 -0
- package/dist/test/arrow-function.test.d.ts.map +1 -0
- package/dist/test/arrow-function.test.js +194 -0
- package/dist/test/barrel.test.js +53 -0
- package/dist/test/basic.test.js +91 -0
- package/dist/test/block-scope.test.js +30 -0
- package/dist/test/class.test.js +438 -0
- package/dist/test/enum-jsdoc.test.js +88 -0
- package/dist/test/enum.test.js +247 -0
- package/dist/test/externals.test.js +145 -0
- package/dist/test/function-call-expression.test.js +87 -0
- package/dist/test/function-declaration-jsdoc.test.js +91 -0
- package/dist/test/function-declaration.test.js +228 -0
- package/dist/test/function-expression.test.d.ts +2 -0
- package/dist/test/function-expression.test.d.ts.map +1 -0
- package/dist/test/function-expression.test.js +194 -0
- package/dist/test/function-type.test.d.ts +2 -0
- package/dist/test/function-type.test.d.ts.map +1 -0
- package/dist/test/function-type.test.js +122 -0
- package/dist/test/if-statement.test.js +25 -0
- package/dist/test/imports.test.js +434 -0
- package/dist/test/interface-jsdoc.test.js +178 -0
- package/dist/test/interface.test.d.ts.map +1 -1
- package/dist/test/interface.test.js +490 -0
- package/dist/test/jscomment.test.js +70 -0
- package/dist/test/jsdoc.test.js +134 -0
- package/dist/test/jsdocparam.test.js +164 -0
- package/dist/test/member-chain.test.js +141 -0
- package/dist/test/member-expression.test.js +359 -0
- package/dist/test/name-conflict.test.js +108 -0
- package/dist/test/name-policy.test.js +122 -0
- package/dist/test/package-external.test.js +196 -0
- package/dist/test/package-json.test.js +93 -0
- package/dist/test/package.test.js +136 -0
- package/dist/test/reference.test.js +81 -0
- package/dist/test/source-file.test.js +36 -0
- package/dist/test/switch-statement.test.js +61 -0
- package/dist/test/utils.js +45 -0
- package/dist/test/value-expression.test.js +30 -0
- package/dist/test/values.test.js +351 -0
- package/dist/test/var-declaration-jsdoc.test.js +50 -0
- package/dist/test/var-declaration.test.js +63 -0
- package/dist/test/vitest.d.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -17
- package/src/components/ArrowFunction.tsx +87 -0
- package/src/components/Declaration.tsx +1 -1
- package/src/components/FunctionBase.tsx +271 -0
- package/src/components/FunctionDeclaration.tsx +13 -195
- package/src/components/FunctionExpression.tsx +86 -0
- package/src/components/FunctionType.tsx +88 -0
- package/src/components/Interface.tsx +33 -5
- package/src/components/InterfaceMethod.tsx +96 -0
- package/src/components/MemberDeclaration.tsx +70 -0
- package/src/components/index.ts +10 -0
- package/src/components/stc/index.ts +7 -0
- package/src/parameter-descriptor.ts +29 -18
- package/src/symbols/reference.ts +4 -1
- package/temp/api.json +2605 -680
- package/test/arrow-function.test.tsx +188 -0
- package/test/class.test.tsx +1 -2
- package/test/function-call-expression.test.tsx +1 -2
- package/test/function-declaration.test.tsx +1 -2
- package/test/function-expression.test.tsx +195 -0
- package/test/function-type.test.tsx +118 -0
- package/test/interface.test.tsx +256 -6
- package/tsdoc-metadata.json +1 -1
- package/babel.config.cjs +0 -4
- package/dist/src/builtins/index.js.map +0 -1
- package/dist/src/builtins/node.js.map +0 -1
- package/dist/src/components/ArrayExpression.js.map +0 -1
- package/dist/src/components/BarrelFile.js.map +0 -1
- package/dist/src/components/BlockScope.js.map +0 -1
- package/dist/src/components/CallSignature.js.map +0 -1
- package/dist/src/components/ClassDeclaration.js.map +0 -1
- package/dist/src/components/CommaList.js.map +0 -1
- package/dist/src/components/Declaration.js.map +0 -1
- package/dist/src/components/EnumDeclaration.js.map +0 -1
- package/dist/src/components/EnumMember.js.map +0 -1
- package/dist/src/components/ExportStatement.js.map +0 -1
- package/dist/src/components/FunctionCallExpression.js.map +0 -1
- package/dist/src/components/FunctionDeclaration.js.map +0 -1
- package/dist/src/components/IfStatement.js.map +0 -1
- package/dist/src/components/ImportStatement.js.map +0 -1
- package/dist/src/components/Interface.js.map +0 -1
- package/dist/src/components/JSDoc.js.map +0 -1
- package/dist/src/components/JSDocComment.js.map +0 -1
- package/dist/src/components/JSDocExample.js.map +0 -1
- package/dist/src/components/JSDocParam.js.map +0 -1
- package/dist/src/components/MemberChainExpression.js.map +0 -1
- package/dist/src/components/MemberExpression.js.map +0 -1
- package/dist/src/components/ObjectExpression.js.map +0 -1
- package/dist/src/components/PackageDirectory.js.map +0 -1
- package/dist/src/components/PackageJson.js.map +0 -1
- package/dist/src/components/PropertyName.js.map +0 -1
- package/dist/src/components/Reference.js.map +0 -1
- package/dist/src/components/SingleLineCommentBlock.js.map +0 -1
- package/dist/src/components/SourceFile.js.map +0 -1
- package/dist/src/components/SwitchStatement.js.map +0 -1
- package/dist/src/components/TsConfigJson.js.map +0 -1
- package/dist/src/components/TypeDeclaration.js.map +0 -1
- package/dist/src/components/ValueExpression.js.map +0 -1
- package/dist/src/components/VarDeclaration.js.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/components/stc/index.js.map +0 -1
- package/dist/src/context/index.js.map +0 -1
- package/dist/src/context/private-scope.js.map +0 -1
- package/dist/src/create-package.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/name-conflict-resolver.js.map +0 -1
- package/dist/src/name-policy.js.map +0 -1
- package/dist/src/parameter-descriptor.js.map +0 -1
- package/dist/src/source-directory-data.js.map +0 -1
- package/dist/src/symbols/index.js.map +0 -1
- package/dist/src/symbols/reference.js.map +0 -1
- package/dist/src/symbols/scopes.js.map +0 -1
- package/dist/src/symbols/ts-member-scope.js.map +0 -1
- package/dist/src/symbols/ts-module-scope.js.map +0 -1
- package/dist/src/symbols/ts-output-symbol.js.map +0 -1
- package/dist/src/symbols/ts-package-scope.js.map +0 -1
- package/dist/src/utils.js.map +0 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, SourceDirectory, StatementList, refkey, render } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { it } from "vitest";
|
|
5
|
+
import * as ts from "../src/components/index.js";
|
|
6
|
+
import { Reference } from "../src/components/Reference.js";
|
|
7
|
+
import { tsNameConflictResolver } from "../src/name-conflict-resolver.js";
|
|
8
|
+
import { assertFileContents } from "./utils.js";
|
|
9
|
+
it("works with default imports", () => {
|
|
10
|
+
const res = render(_$createComponent(Output, {
|
|
11
|
+
get children() {
|
|
12
|
+
return [_$createComponent(ts.SourceFile, {
|
|
13
|
+
path: "test1.ts",
|
|
14
|
+
get children() {
|
|
15
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
16
|
+
"export": true,
|
|
17
|
+
"default": true,
|
|
18
|
+
name: "asdf",
|
|
19
|
+
get refkey() {
|
|
20
|
+
return refkey("test");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}), _$createComponent(ts.SourceFile, {
|
|
25
|
+
path: "test2.ts",
|
|
26
|
+
get children() {
|
|
27
|
+
return ["const v = ", _$createComponent(Reference, {
|
|
28
|
+
get refkey() {
|
|
29
|
+
return refkey("test");
|
|
30
|
+
}
|
|
31
|
+
}), ";"];
|
|
32
|
+
}
|
|
33
|
+
})];
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
assertFileContents(res, {
|
|
37
|
+
"test1.ts": `
|
|
38
|
+
export default function asdf() {}
|
|
39
|
+
`,
|
|
40
|
+
"test2.ts": `
|
|
41
|
+
import asdf from "./test1.js";
|
|
42
|
+
|
|
43
|
+
const v = asdf;
|
|
44
|
+
`
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it("works with named imports", () => {
|
|
48
|
+
const res = render(_$createComponent(Output, {
|
|
49
|
+
get children() {
|
|
50
|
+
return [_$createComponent(ts.SourceFile, {
|
|
51
|
+
path: "test1.ts",
|
|
52
|
+
get children() {
|
|
53
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
54
|
+
"export": true,
|
|
55
|
+
name: "test",
|
|
56
|
+
get refkey() {
|
|
57
|
+
return refkey("test");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}), _$createComponent(ts.SourceFile, {
|
|
62
|
+
path: "test2.ts",
|
|
63
|
+
get children() {
|
|
64
|
+
return ["const v = ", _$createComponent(Reference, {
|
|
65
|
+
get refkey() {
|
|
66
|
+
return refkey("test");
|
|
67
|
+
}
|
|
68
|
+
}), ";"];
|
|
69
|
+
}
|
|
70
|
+
})];
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
assertFileContents(res, {
|
|
74
|
+
"test1.ts": `
|
|
75
|
+
export function test() {}
|
|
76
|
+
`,
|
|
77
|
+
"test2.ts": `
|
|
78
|
+
import { test } from "./test1.js";
|
|
79
|
+
|
|
80
|
+
const v = test;
|
|
81
|
+
`
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it("works with default and named imports", () => {
|
|
85
|
+
const res = render(_$createComponent(Output, {
|
|
86
|
+
get children() {
|
|
87
|
+
return [_$createComponent(ts.SourceFile, {
|
|
88
|
+
path: "test1.ts",
|
|
89
|
+
get children() {
|
|
90
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
91
|
+
"export": true,
|
|
92
|
+
"default": true,
|
|
93
|
+
name: "test1",
|
|
94
|
+
get refkey() {
|
|
95
|
+
return refkey("test1");
|
|
96
|
+
}
|
|
97
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
98
|
+
"export": true,
|
|
99
|
+
name: "test2",
|
|
100
|
+
get refkey() {
|
|
101
|
+
return refkey("test2");
|
|
102
|
+
}
|
|
103
|
+
})];
|
|
104
|
+
}
|
|
105
|
+
}), _$createComponent(ts.SourceFile, {
|
|
106
|
+
path: "test2.ts",
|
|
107
|
+
get children() {
|
|
108
|
+
return ["const v1 = ", _$createComponent(Reference, {
|
|
109
|
+
get refkey() {
|
|
110
|
+
return refkey("test1");
|
|
111
|
+
}
|
|
112
|
+
}), ";", _$createIntrinsic("hbr", {}), "const v2 = ", _$createComponent(Reference, {
|
|
113
|
+
get refkey() {
|
|
114
|
+
return refkey("test2");
|
|
115
|
+
}
|
|
116
|
+
}), ";"];
|
|
117
|
+
}
|
|
118
|
+
})];
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
assertFileContents(res, {
|
|
122
|
+
"test1.ts": `
|
|
123
|
+
export default function test1() {}
|
|
124
|
+
export function test2() {}
|
|
125
|
+
`,
|
|
126
|
+
"test2.ts": `
|
|
127
|
+
import test1, { test2 } from "./test1.js";
|
|
128
|
+
|
|
129
|
+
const v1 = test1;
|
|
130
|
+
const v2 = test2;
|
|
131
|
+
`
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
it("works with default and named imports and name conflicts", () => {
|
|
135
|
+
const res = render(_$createComponent(Output, {
|
|
136
|
+
nameConflictResolver: tsNameConflictResolver,
|
|
137
|
+
get children() {
|
|
138
|
+
return [_$createComponent(ts.SourceFile, {
|
|
139
|
+
path: "test1.ts",
|
|
140
|
+
get children() {
|
|
141
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
142
|
+
"export": true,
|
|
143
|
+
"default": true,
|
|
144
|
+
name: "test1",
|
|
145
|
+
get refkey() {
|
|
146
|
+
return refkey("test1");
|
|
147
|
+
}
|
|
148
|
+
}), _$createIntrinsic("br", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
149
|
+
"export": true,
|
|
150
|
+
name: "test2",
|
|
151
|
+
get refkey() {
|
|
152
|
+
return refkey("test2");
|
|
153
|
+
}
|
|
154
|
+
})];
|
|
155
|
+
}
|
|
156
|
+
}), _$createComponent(ts.SourceFile, {
|
|
157
|
+
path: "test2.ts",
|
|
158
|
+
get children() {
|
|
159
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
160
|
+
"export": true,
|
|
161
|
+
"default": true,
|
|
162
|
+
name: "test1",
|
|
163
|
+
get refkey() {
|
|
164
|
+
return refkey("test3");
|
|
165
|
+
}
|
|
166
|
+
}), _$createIntrinsic("br", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
167
|
+
"export": true,
|
|
168
|
+
name: "test2",
|
|
169
|
+
get refkey() {
|
|
170
|
+
return refkey("test4");
|
|
171
|
+
}
|
|
172
|
+
})];
|
|
173
|
+
}
|
|
174
|
+
}), _$createComponent(ts.SourceFile, {
|
|
175
|
+
path: "test3.ts",
|
|
176
|
+
get children() {
|
|
177
|
+
return _$createComponent(StatementList, {
|
|
178
|
+
get children() {
|
|
179
|
+
return [["const v1 = ", _$createComponent(Reference, {
|
|
180
|
+
get refkey() {
|
|
181
|
+
return refkey("test1");
|
|
182
|
+
}
|
|
183
|
+
})], ["const v1_1 = ", _$createComponent(Reference, {
|
|
184
|
+
get refkey() {
|
|
185
|
+
return refkey("test2");
|
|
186
|
+
}
|
|
187
|
+
})], ["const v2 = ", _$createComponent(Reference, {
|
|
188
|
+
get refkey() {
|
|
189
|
+
return refkey("test3");
|
|
190
|
+
}
|
|
191
|
+
})], ["const v3 = ", _$createComponent(Reference, {
|
|
192
|
+
get refkey() {
|
|
193
|
+
return refkey("test3");
|
|
194
|
+
}
|
|
195
|
+
})], ["const v4 = ", _$createComponent(Reference, {
|
|
196
|
+
get refkey() {
|
|
197
|
+
return refkey("test4");
|
|
198
|
+
}
|
|
199
|
+
})]];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
})];
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
assertFileContents(res, {
|
|
207
|
+
"test1.ts": `
|
|
208
|
+
export default function test1() {}
|
|
209
|
+
export function test2() {}
|
|
210
|
+
`,
|
|
211
|
+
"test2.ts": `
|
|
212
|
+
export default function test1() {}
|
|
213
|
+
export function test2() {}
|
|
214
|
+
`,
|
|
215
|
+
"test3.ts": `
|
|
216
|
+
import test1_1, { test2 as test2_1 } from "./test1.js";
|
|
217
|
+
import test1_2, { test2 as test2_2 } from "./test2.js";
|
|
218
|
+
|
|
219
|
+
const v1 = test1_1;
|
|
220
|
+
const v1_1 = test2_1;
|
|
221
|
+
const v2 = test1_2;
|
|
222
|
+
const v3 = test1_2;
|
|
223
|
+
const v4 = test2_2;
|
|
224
|
+
`
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
it("works with default and named imports and name conflicts and references in nested scopes", () => {
|
|
228
|
+
const res = render(_$createComponent(Output, {
|
|
229
|
+
nameConflictResolver: tsNameConflictResolver,
|
|
230
|
+
get children() {
|
|
231
|
+
return [_$createComponent(ts.SourceFile, {
|
|
232
|
+
path: "test1.ts",
|
|
233
|
+
get children() {
|
|
234
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
235
|
+
"export": true,
|
|
236
|
+
"default": true,
|
|
237
|
+
name: "test1",
|
|
238
|
+
get refkey() {
|
|
239
|
+
return refkey("test1");
|
|
240
|
+
}
|
|
241
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
242
|
+
"export": true,
|
|
243
|
+
name: "test2",
|
|
244
|
+
get refkey() {
|
|
245
|
+
return refkey("test2");
|
|
246
|
+
}
|
|
247
|
+
})];
|
|
248
|
+
}
|
|
249
|
+
}), _$createComponent(ts.SourceFile, {
|
|
250
|
+
path: "test2.ts",
|
|
251
|
+
get children() {
|
|
252
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
253
|
+
"export": true,
|
|
254
|
+
"default": true,
|
|
255
|
+
name: "test1",
|
|
256
|
+
get refkey() {
|
|
257
|
+
return refkey("test3");
|
|
258
|
+
}
|
|
259
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
260
|
+
"export": true,
|
|
261
|
+
name: "test2",
|
|
262
|
+
get refkey() {
|
|
263
|
+
return refkey("test4");
|
|
264
|
+
}
|
|
265
|
+
})];
|
|
266
|
+
}
|
|
267
|
+
}), _$createComponent(ts.SourceFile, {
|
|
268
|
+
path: "test3.ts",
|
|
269
|
+
get children() {
|
|
270
|
+
return [_$createComponent(StatementList, {
|
|
271
|
+
get children() {
|
|
272
|
+
return [["const v1 = ", _$createComponent(Reference, {
|
|
273
|
+
get refkey() {
|
|
274
|
+
return refkey("test1");
|
|
275
|
+
}
|
|
276
|
+
})], ["const v1_1 = ", _$createComponent(Reference, {
|
|
277
|
+
get refkey() {
|
|
278
|
+
return refkey("test2");
|
|
279
|
+
}
|
|
280
|
+
})]];
|
|
281
|
+
}
|
|
282
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
283
|
+
name: "foo",
|
|
284
|
+
get children() {
|
|
285
|
+
return _$createComponent(StatementList, {
|
|
286
|
+
get children() {
|
|
287
|
+
return [["const v2 = ", _$createComponent(Reference, {
|
|
288
|
+
get refkey() {
|
|
289
|
+
return refkey("test3");
|
|
290
|
+
}
|
|
291
|
+
})], ["const v3 = ", _$createComponent(Reference, {
|
|
292
|
+
get refkey() {
|
|
293
|
+
return refkey("test3");
|
|
294
|
+
}
|
|
295
|
+
})], ["const v4 = ", _$createComponent(Reference, {
|
|
296
|
+
get refkey() {
|
|
297
|
+
return refkey("test4");
|
|
298
|
+
}
|
|
299
|
+
})]];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
})];
|
|
304
|
+
}
|
|
305
|
+
})];
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
308
|
+
assertFileContents(res, {
|
|
309
|
+
"test1.ts": `
|
|
310
|
+
export default function test1() {}
|
|
311
|
+
export function test2() {}
|
|
312
|
+
`,
|
|
313
|
+
"test2.ts": `
|
|
314
|
+
export default function test1() {}
|
|
315
|
+
export function test2() {}
|
|
316
|
+
`,
|
|
317
|
+
"test3.ts": `
|
|
318
|
+
import test1_1, { test2 as test2_1 } from "./test1.js";
|
|
319
|
+
import test1_2, { test2 as test2_2 } from "./test2.js";
|
|
320
|
+
|
|
321
|
+
const v1 = test1_1;
|
|
322
|
+
const v1_1 = test2_1;
|
|
323
|
+
function foo() {
|
|
324
|
+
const v2 = test1_2;
|
|
325
|
+
const v3 = test1_2;
|
|
326
|
+
const v4 = test2_2;
|
|
327
|
+
}
|
|
328
|
+
`
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
it("works with imports from different directories", () => {
|
|
332
|
+
const res = render(_$createComponent(Output, {
|
|
333
|
+
get children() {
|
|
334
|
+
return [_$createComponent(SourceDirectory, {
|
|
335
|
+
path: "src",
|
|
336
|
+
get children() {
|
|
337
|
+
return _$createComponent(ts.SourceFile, {
|
|
338
|
+
path: "test1.ts",
|
|
339
|
+
get children() {
|
|
340
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
341
|
+
"export": true,
|
|
342
|
+
name: "test",
|
|
343
|
+
get refkey() {
|
|
344
|
+
return refkey("test");
|
|
345
|
+
}
|
|
346
|
+
}), _$createIntrinsic("hbr", {}), "const v = ", _$createComponent(Reference, {
|
|
347
|
+
get refkey() {
|
|
348
|
+
return refkey("test2");
|
|
349
|
+
}
|
|
350
|
+
}), ";"];
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}), _$createComponent(ts.SourceFile, {
|
|
355
|
+
path: "test2.ts",
|
|
356
|
+
get children() {
|
|
357
|
+
return ["const v = ", _$createComponent(Reference, {
|
|
358
|
+
get refkey() {
|
|
359
|
+
return refkey("test");
|
|
360
|
+
}
|
|
361
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
362
|
+
"export": true,
|
|
363
|
+
name: "test2",
|
|
364
|
+
get refkey() {
|
|
365
|
+
return refkey("test2");
|
|
366
|
+
}
|
|
367
|
+
})];
|
|
368
|
+
}
|
|
369
|
+
})];
|
|
370
|
+
}
|
|
371
|
+
}));
|
|
372
|
+
assertFileContents(res, {
|
|
373
|
+
"src/test1.ts": `
|
|
374
|
+
import { test2 } from "../test2.js";
|
|
375
|
+
|
|
376
|
+
export function test() {}
|
|
377
|
+
const v = test2;
|
|
378
|
+
`,
|
|
379
|
+
"test2.ts": `
|
|
380
|
+
import { test } from "./src/test1.js";
|
|
381
|
+
|
|
382
|
+
const v = test;
|
|
383
|
+
export function test2() {}
|
|
384
|
+
`
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
it("handles conflicts with local declarations", () => {
|
|
388
|
+
const res = render(_$createComponent(Output, {
|
|
389
|
+
nameConflictResolver: tsNameConflictResolver,
|
|
390
|
+
get children() {
|
|
391
|
+
return [_$createComponent(SourceDirectory, {
|
|
392
|
+
path: "src",
|
|
393
|
+
get children() {
|
|
394
|
+
return _$createComponent(ts.SourceFile, {
|
|
395
|
+
path: "test1.ts",
|
|
396
|
+
get children() {
|
|
397
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
398
|
+
"export": true,
|
|
399
|
+
name: "test",
|
|
400
|
+
get refkey() {
|
|
401
|
+
return refkey("test");
|
|
402
|
+
}
|
|
403
|
+
}), _$createIntrinsic("hbr", {}), "const v = ", _$createComponent(Reference, {
|
|
404
|
+
get refkey() {
|
|
405
|
+
return refkey("test2");
|
|
406
|
+
}
|
|
407
|
+
}), ";"];
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}), _$createComponent(ts.SourceFile, {
|
|
412
|
+
path: "test2.ts",
|
|
413
|
+
get children() {
|
|
414
|
+
return ["const v = ", _$createComponent(Reference, {
|
|
415
|
+
get refkey() {
|
|
416
|
+
return refkey("test");
|
|
417
|
+
}
|
|
418
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
419
|
+
"export": true,
|
|
420
|
+
name: "test"
|
|
421
|
+
})];
|
|
422
|
+
}
|
|
423
|
+
})];
|
|
424
|
+
}
|
|
425
|
+
}));
|
|
426
|
+
assertFileContents(res, {
|
|
427
|
+
"test2.ts": `
|
|
428
|
+
import { test as test_1 } from "./src/test1.js";
|
|
429
|
+
|
|
430
|
+
const v = test_1;
|
|
431
|
+
export function test() {}
|
|
432
|
+
`
|
|
433
|
+
});
|
|
434
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { StatementList } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as ts from "../src/index.js";
|
|
6
|
+
import { toSourceText } from "./utils.js";
|
|
7
|
+
it("renders an interface declaration with documentation", () => {
|
|
8
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
9
|
+
name: "Person",
|
|
10
|
+
doc: "Interface representing a person",
|
|
11
|
+
get children() {
|
|
12
|
+
return _$createComponent(StatementList, {
|
|
13
|
+
get children() {
|
|
14
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
15
|
+
name: "name",
|
|
16
|
+
type: "string"
|
|
17
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
18
|
+
name: "age",
|
|
19
|
+
type: "number"
|
|
20
|
+
})];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
expect(res).toEqual(d`
|
|
26
|
+
/**
|
|
27
|
+
* Interface representing a person
|
|
28
|
+
**/
|
|
29
|
+
interface Person {
|
|
30
|
+
name: string;
|
|
31
|
+
age: number;
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
it("renders an interface declaration with docs from a string array with single element", () => {
|
|
36
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
37
|
+
name: "Person",
|
|
38
|
+
doc: ["Interface representing a person"],
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(StatementList, {
|
|
41
|
+
get children() {
|
|
42
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
43
|
+
name: "name",
|
|
44
|
+
type: "string"
|
|
45
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
46
|
+
name: "age",
|
|
47
|
+
type: "number"
|
|
48
|
+
})];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
expect(res).toEqual(d`
|
|
54
|
+
/**
|
|
55
|
+
* Interface representing a person
|
|
56
|
+
**/
|
|
57
|
+
interface Person {
|
|
58
|
+
name: string;
|
|
59
|
+
age: number;
|
|
60
|
+
}
|
|
61
|
+
`);
|
|
62
|
+
});
|
|
63
|
+
it("renders an interface declaration with docs from a string array", () => {
|
|
64
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
65
|
+
name: "Person",
|
|
66
|
+
doc: ["Interface representing a person", "This should be another paragraph"],
|
|
67
|
+
get children() {
|
|
68
|
+
return _$createComponent(StatementList, {
|
|
69
|
+
get children() {
|
|
70
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
71
|
+
name: "name",
|
|
72
|
+
type: "string"
|
|
73
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
74
|
+
name: "age",
|
|
75
|
+
type: "number"
|
|
76
|
+
})];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
expect(res).toEqual(d`
|
|
82
|
+
/**
|
|
83
|
+
* Interface representing a person
|
|
84
|
+
*
|
|
85
|
+
* This should be another paragraph
|
|
86
|
+
**/
|
|
87
|
+
interface Person {
|
|
88
|
+
name: string;
|
|
89
|
+
age: number;
|
|
90
|
+
}
|
|
91
|
+
`);
|
|
92
|
+
});
|
|
93
|
+
it("renders an interface declaration with documented properties", () => {
|
|
94
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
95
|
+
"export": true,
|
|
96
|
+
name: "APIResponse",
|
|
97
|
+
doc: "Standard API response format",
|
|
98
|
+
get children() {
|
|
99
|
+
return _$createComponent(StatementList, {
|
|
100
|
+
get children() {
|
|
101
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
102
|
+
name: "success",
|
|
103
|
+
type: "boolean",
|
|
104
|
+
doc: "Wether or not the request completed successfully"
|
|
105
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
106
|
+
name: "data",
|
|
107
|
+
type: "unknown",
|
|
108
|
+
doc: "the response payload"
|
|
109
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
110
|
+
name: "error",
|
|
111
|
+
optional: true,
|
|
112
|
+
type: "string"
|
|
113
|
+
})];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
expect(res).toEqual(d`
|
|
119
|
+
/**
|
|
120
|
+
* Standard API response format
|
|
121
|
+
**/
|
|
122
|
+
export interface APIResponse {
|
|
123
|
+
/**
|
|
124
|
+
* Wether or not the request completed successfully
|
|
125
|
+
**/
|
|
126
|
+
success: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* the response payload
|
|
129
|
+
**/
|
|
130
|
+
data: unknown;
|
|
131
|
+
error?: string;
|
|
132
|
+
}
|
|
133
|
+
`);
|
|
134
|
+
});
|
|
135
|
+
it("renders an interface declaration with array documented properties ", () => {
|
|
136
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
137
|
+
"export": true,
|
|
138
|
+
name: "APIResponse",
|
|
139
|
+
doc: "Standard API response format",
|
|
140
|
+
get children() {
|
|
141
|
+
return _$createComponent(StatementList, {
|
|
142
|
+
get children() {
|
|
143
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
144
|
+
name: "success",
|
|
145
|
+
type: "boolean",
|
|
146
|
+
doc: ["Wether or not the request completed successfully", "This is another paragraph"]
|
|
147
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
148
|
+
name: "data",
|
|
149
|
+
type: "unknown",
|
|
150
|
+
doc: "the response payload"
|
|
151
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
152
|
+
name: "error",
|
|
153
|
+
optional: true,
|
|
154
|
+
type: "string"
|
|
155
|
+
})];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
expect(res).toEqual(d`
|
|
161
|
+
/**
|
|
162
|
+
* Standard API response format
|
|
163
|
+
**/
|
|
164
|
+
export interface APIResponse {
|
|
165
|
+
/**
|
|
166
|
+
* Wether or not the request completed successfully
|
|
167
|
+
*
|
|
168
|
+
* This is another paragraph
|
|
169
|
+
**/
|
|
170
|
+
success: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* the response payload
|
|
173
|
+
**/
|
|
174
|
+
data: unknown;
|
|
175
|
+
error?: string;
|
|
176
|
+
}
|
|
177
|
+
`);
|
|
178
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.test.d.ts","sourceRoot":"","sources":["../../test/interface.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interface.test.d.ts","sourceRoot":"","sources":["../../test/interface.test.tsx"],"names":[],"mappings":"AAMA,OAAO,wBAAwB,CAAC"}
|