@alloy-js/typescript 0.13.0 → 0.15.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 +17 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +6 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +8 -2
- package/dist/src/components/Interface.js +1 -1
- package/dist/src/components/ObjectExpression.d.ts +6 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +17 -1
- package/dist/src/parameter-descriptor.d.ts +9 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +3 -1
- package/dist/test/arrow-function.test.js +17 -0
- package/dist/test/basic.test.js +1 -1
- package/dist/test/externals.test.js +3 -3
- package/dist/test/function-declaration.test.js +18 -0
- package/dist/test/function-expression.test.js +17 -0
- package/dist/test/function-type.test.js +14 -0
- package/dist/test/imports.test.js +187 -4
- package/dist/test/interface.test.js +2 -1
- package/dist/test/object.test.d.ts +2 -0
- package/dist/test/object.test.d.ts.map +1 -0
- package/dist/test/object.test.js +57 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/FunctionBase.tsx +1 -0
- package/src/components/ImportStatement.tsx +12 -2
- package/src/components/Interface.tsx +1 -1
- package/src/components/ObjectExpression.tsx +21 -1
- package/src/parameter-descriptor.ts +10 -0
- package/src/symbols/reference.ts +3 -1
- package/temp/api.json +175 -0
- package/test/arrow-function.test.tsx +22 -0
- package/test/basic.test.tsx +1 -1
- package/test/externals.test.tsx +3 -3
- package/test/function-declaration.test.tsx +22 -0
- package/test/function-expression.test.tsx +22 -0
- package/test/function-type.test.tsx +17 -0
- package/test/imports.test.tsx +132 -4
- package/test/interface.test.tsx +2 -2
- package/test/object.test.tsx +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog - @alloy-js/typescript
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#146](https://github.com/alloy-framework/alloy/pull/146) Add support for rest parameters in function components
|
|
8
|
+
- [#146](https://github.com/alloy-framework/alloy/pull/146) Add support for object spread properties
|
|
9
|
+
- [#145](https://github.com/alloy-framework/alloy/pull/145) Sort import statements and named imports
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## 0.14.0
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- [#141](https://github.com/alloy-framework/alloy/pull/141) Fix type import from a package not adding `type` modifier
|
|
17
|
+
- [#140](https://github.com/alloy-framework/alloy/pull/140) Include readonly for indexers
|
|
18
|
+
|
|
19
|
+
|
|
3
20
|
## 0.13.0
|
|
4
21
|
|
|
5
22
|
No changes, version bump only.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionBase.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionBase.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAYrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,iBAAiB;IACjB,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,mBAAmB;IACnB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,iEAAiE;AACjE,MAAM,WAAW,2BA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,EAAE,QAAQ,CAAC;CAC9B;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,UAAU,CAAC,EAAE,uBAAuB,EAAE,GAAG,MAAM,EAAE,CAAC;IAClD,mBAAmB;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,sIAKxB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,kJAmB9B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,0JAmBlC,CAAC;AAgGF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0IAkC1B,CAAC;AAkBF,wBAAgB,aAAa,CAC3B,UAAU,EAAE,QAAQ,GAAG,SAAS,EAChC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAqB,YAKhD"}
|
|
@@ -90,7 +90,12 @@ export const FunctionTypeParameters = taggedComponent(functionParametersTag, fun
|
|
|
90
90
|
function parameter(param) {
|
|
91
91
|
return _$createIntrinsic("group", {
|
|
92
92
|
get children() {
|
|
93
|
-
return [_$
|
|
93
|
+
return [_$createComponent(Show, {
|
|
94
|
+
get when() {
|
|
95
|
+
return param.rest;
|
|
96
|
+
},
|
|
97
|
+
children: "..."
|
|
98
|
+
}), _$memo(() => param.symbol.name), _$createComponent(Show, {
|
|
94
99
|
get when() {
|
|
95
100
|
return !!param.optional;
|
|
96
101
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportStatement.d.ts","sourceRoot":"","sources":["../../../src/components/ImportStatement.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImportStatement.d.ts","sourceRoot":"","sources":["../../../src/components/ImportStatement.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,qBAAqB,CAAC;AAI7B,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,6CAgD5D;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC9B;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAqD1D"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { mapJoin, memo, SourceDirectoryContext, useContext } from "@alloy-js/core";
|
|
2
|
+
import { computed, mapJoin, memo, SourceDirectoryContext, useContext } from "@alloy-js/core";
|
|
3
3
|
import { relative } from "pathe";
|
|
4
4
|
import { TSSymbolFlags } from "../symbols/index.js";
|
|
5
5
|
import { modulePath } from "../utils.js";
|
|
6
6
|
import { usePackage } from "./PackageDirectory.js";
|
|
7
7
|
export function ImportStatements(props) {
|
|
8
8
|
const pkg = usePackage();
|
|
9
|
-
|
|
9
|
+
const imports = computed(() => [...props.records].sort(([a], [b]) => {
|
|
10
|
+
return a.name.localeCompare(b.name);
|
|
11
|
+
}));
|
|
12
|
+
return mapJoin(() => imports.value, ([module, importedSymbols]) => {
|
|
10
13
|
let targetPath;
|
|
11
14
|
if (pkg && pkg.scope !== module.parent || !pkg && module.parent.kind !== "global") {
|
|
12
15
|
// importing from another package, so let's calculate the import.
|
|
@@ -58,6 +61,9 @@ export function ImportStatement(props) {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
if (namedImportSymbols.length > 0) {
|
|
64
|
+
namedImportSymbols.sort((a, b) => {
|
|
65
|
+
return a.local.name.localeCompare(b.local.name);
|
|
66
|
+
});
|
|
61
67
|
const allNamedImportsAreTypes = namedImportSymbols.every(nis => nis.local.tsFlags & TSSymbolFlags.TypeSymbol);
|
|
62
68
|
if (allNamedImportsAreTypes) {
|
|
63
69
|
parts.push("type ");
|
|
@@ -80,7 +80,7 @@ export function InterfaceMember(props) {
|
|
|
80
80
|
const optionality = props.optional ? "?" : "";
|
|
81
81
|
const readonly = props.readonly ? "readonly " : "";
|
|
82
82
|
if (props.indexer) {
|
|
83
|
-
return ["[", _$memo(() => props.indexer), "]: ", type];
|
|
83
|
+
return [readonly, "[", _$memo(() => props.indexer), "]: ", type];
|
|
84
84
|
} else {
|
|
85
85
|
const namer = useTSNamePolicy();
|
|
86
86
|
const name = namer.getName(props.name, "interface-member");
|
|
@@ -13,4 +13,10 @@ export interface ObjectPropertyProps {
|
|
|
13
13
|
refkey?: Refkey | Refkey[];
|
|
14
14
|
}
|
|
15
15
|
export declare function ObjectProperty(props: ObjectPropertyProps): Children;
|
|
16
|
+
export interface ObjectSpreadPropertyProps {
|
|
17
|
+
value?: Children;
|
|
18
|
+
jsValue?: unknown;
|
|
19
|
+
children?: Children;
|
|
20
|
+
}
|
|
21
|
+
export declare function ObjectSpreadProperty(props: ObjectSpreadPropertyProps): Children;
|
|
16
22
|
//# sourceMappingURL=ObjectExpression.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectExpression.d.ts","sourceRoot":"","sources":["../../../src/components/ObjectExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EAQR,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EACJ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GACnB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,YA0D5D;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YA0CxD"}
|
|
1
|
+
{"version":3,"file":"ObjectExpression.d.ts","sourceRoot":"","sources":["../../../src/components/ObjectExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EAQR,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EACJ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GACnB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,YA0D5D;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YA0CxD;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,YAYpE"}
|
|
@@ -90,7 +90,7 @@ export function ObjectProperty(props) {
|
|
|
90
90
|
let value;
|
|
91
91
|
if (props.value) {
|
|
92
92
|
value = props.value;
|
|
93
|
-
} else if (Object.
|
|
93
|
+
} else if (Object.hasOwn(props, "jsValue")) {
|
|
94
94
|
// need the hasOwnProperty check because the value might be falsy.
|
|
95
95
|
value = _$createComponent(ValueExpression, {
|
|
96
96
|
get jsValue() {
|
|
@@ -105,4 +105,20 @@ export function ObjectProperty(props) {
|
|
|
105
105
|
value: assignmentContext,
|
|
106
106
|
children: value
|
|
107
107
|
})];
|
|
108
|
+
}
|
|
109
|
+
export function ObjectSpreadProperty(props) {
|
|
110
|
+
let value;
|
|
111
|
+
if (props.value) {
|
|
112
|
+
value = props.value;
|
|
113
|
+
} else if (Object.hasOwn(props, "jsValue")) {
|
|
114
|
+
// need the hasOwnProperty check because the value might be falsy.
|
|
115
|
+
value = _$createComponent(ValueExpression, {
|
|
116
|
+
get jsValue() {
|
|
117
|
+
return props.jsValue;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
} else if (props.children) {
|
|
121
|
+
value = props.children;
|
|
122
|
+
}
|
|
123
|
+
return ["...", value];
|
|
108
124
|
}
|
|
@@ -19,6 +19,15 @@ export interface ParameterDescriptorBase {
|
|
|
19
19
|
* Whether the parameter is optional.
|
|
20
20
|
*/
|
|
21
21
|
readonly optional?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Weather the parameter is rest parameter.
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* ...args: string[]
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
readonly rest?: boolean;
|
|
22
31
|
/**
|
|
23
32
|
* Whether the parameter is can be null or undefined.
|
|
24
33
|
* when optional is true, this will be set to true by default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter-descriptor.d.ts","sourceRoot":"","sources":["../../src/parameter-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElD;;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@
|
|
|
1
|
-
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAcxB,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAcxB,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM,CAyGtE"}
|
|
@@ -54,7 +54,9 @@ export function ref(refkey, options) {
|
|
|
54
54
|
for (const module of sourcePackage.exportedSymbols.values()) {
|
|
55
55
|
for (const refkey of importSymbol.refkeys) {
|
|
56
56
|
if (module.exportedSymbols.has(refkey)) {
|
|
57
|
-
localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, module
|
|
57
|
+
localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, module, {
|
|
58
|
+
type: options?.type
|
|
59
|
+
}));
|
|
58
60
|
break;
|
|
59
61
|
}
|
|
60
62
|
}
|
|
@@ -191,4 +191,21 @@ describe("symbols", () => {
|
|
|
191
191
|
}
|
|
192
192
|
`);
|
|
193
193
|
});
|
|
194
|
+
it("create rest parameters", () => {
|
|
195
|
+
const paramDesc = {
|
|
196
|
+
name: "foo",
|
|
197
|
+
refkey: refkey(),
|
|
198
|
+
type: "any[]",
|
|
199
|
+
rest: true
|
|
200
|
+
};
|
|
201
|
+
const decl = [_$createComponent(ArrowFunction, {
|
|
202
|
+
parameters: [paramDesc],
|
|
203
|
+
children: "console.log(foo);"
|
|
204
|
+
})];
|
|
205
|
+
expect(toSourceText(decl)).toBe(d`
|
|
206
|
+
(...foo: any[]) => {
|
|
207
|
+
console.log(foo);
|
|
208
|
+
}
|
|
209
|
+
`);
|
|
210
|
+
});
|
|
194
211
|
});
|
package/dist/test/basic.test.js
CHANGED
|
@@ -83,7 +83,7 @@ it("works", () => {
|
|
|
83
83
|
}
|
|
84
84
|
`);
|
|
85
85
|
expect(findFile(res, "test2.ts").contents).toEqual(d`
|
|
86
|
-
import {
|
|
86
|
+
import { sayGoodbye, sayHello } from "./test1.js";
|
|
87
87
|
|
|
88
88
|
console.log(sayHello("world"));
|
|
89
89
|
console.log(sayGoodbye("world"));
|
|
@@ -51,8 +51,8 @@ it("can import builtins", () => {
|
|
|
51
51
|
}
|
|
52
52
|
`,
|
|
53
53
|
"index.ts": `
|
|
54
|
-
import { nice } from "testLib/subpath";
|
|
55
54
|
import { readFile } from "node:fs/promises";
|
|
55
|
+
import { nice } from "testLib/subpath";
|
|
56
56
|
|
|
57
57
|
nice;
|
|
58
58
|
await readFile();
|
|
@@ -86,8 +86,8 @@ it("can import builtins without a package", () => {
|
|
|
86
86
|
}));
|
|
87
87
|
assertFileContents(res, {
|
|
88
88
|
"index.ts": `
|
|
89
|
-
import { nice } from "testLib/subpath";
|
|
90
89
|
import { readFile } from "node:fs/promises";
|
|
90
|
+
import { nice } from "testLib/subpath";
|
|
91
91
|
|
|
92
92
|
nice;
|
|
93
93
|
await readFile();
|
|
@@ -131,8 +131,8 @@ it("can import builtins without a package", () => {
|
|
|
131
131
|
}));
|
|
132
132
|
assertFileContents(res, {
|
|
133
133
|
"index.ts": `
|
|
134
|
-
import { nice } from "testLib/subpath";
|
|
135
134
|
import { readFile } from "node:fs/promises";
|
|
135
|
+
import { nice } from "testLib/subpath";
|
|
136
136
|
|
|
137
137
|
function foo() {
|
|
138
138
|
function bar() {
|
|
@@ -225,4 +225,22 @@ describe("symbols", () => {
|
|
|
225
225
|
}
|
|
226
226
|
`);
|
|
227
227
|
});
|
|
228
|
+
it("create optional parameters", () => {
|
|
229
|
+
const paramDesc = {
|
|
230
|
+
name: "foo",
|
|
231
|
+
refkey: refkey(),
|
|
232
|
+
type: "any[]",
|
|
233
|
+
rest: true
|
|
234
|
+
};
|
|
235
|
+
const decl = [_$createComponent(FunctionDeclaration, {
|
|
236
|
+
name: "foo",
|
|
237
|
+
parameters: [paramDesc],
|
|
238
|
+
children: "console.log(foo);"
|
|
239
|
+
})];
|
|
240
|
+
expect(toSourceText(decl)).toBe(d`
|
|
241
|
+
function foo(...foo: any[]) {
|
|
242
|
+
console.log(foo);
|
|
243
|
+
}
|
|
244
|
+
`);
|
|
245
|
+
});
|
|
228
246
|
});
|
|
@@ -191,4 +191,21 @@ describe("symbols", () => {
|
|
|
191
191
|
}
|
|
192
192
|
`);
|
|
193
193
|
});
|
|
194
|
+
it("create rest parameters", () => {
|
|
195
|
+
const paramDesc = {
|
|
196
|
+
name: "foo",
|
|
197
|
+
refkey: refkey(),
|
|
198
|
+
type: "any[]",
|
|
199
|
+
rest: true
|
|
200
|
+
};
|
|
201
|
+
const decl = [_$createComponent(FunctionExpression, {
|
|
202
|
+
parameters: [paramDesc],
|
|
203
|
+
children: "console.log(foo);"
|
|
204
|
+
})];
|
|
205
|
+
expect(toSourceText(decl)).toBe(d`
|
|
206
|
+
function (...foo: any[]) {
|
|
207
|
+
console.log(foo);
|
|
208
|
+
}
|
|
209
|
+
`);
|
|
210
|
+
});
|
|
194
211
|
});
|
|
@@ -119,4 +119,18 @@ describe("symbols", () => {
|
|
|
119
119
|
(foo?: any) => void
|
|
120
120
|
`);
|
|
121
121
|
});
|
|
122
|
+
it("create rest parameters", () => {
|
|
123
|
+
const paramDesc = {
|
|
124
|
+
name: "foo",
|
|
125
|
+
refkey: refkey(),
|
|
126
|
+
type: "any[]",
|
|
127
|
+
rest: true
|
|
128
|
+
};
|
|
129
|
+
const decl = [_$createComponent(FunctionType, {
|
|
130
|
+
parameters: [paramDesc]
|
|
131
|
+
})];
|
|
132
|
+
expect(toSourceText(decl)).toBe(d`
|
|
133
|
+
(...foo: any[]) => void
|
|
134
|
+
`);
|
|
135
|
+
});
|
|
122
136
|
});
|
|
@@ -5,6 +5,7 @@ import { describe, it } from "vitest";
|
|
|
5
5
|
import * as ts from "../src/components/index.js";
|
|
6
6
|
import { Reference } from "../src/components/Reference.js";
|
|
7
7
|
import { TypeRefContext } from "../src/context/type-ref-context.js";
|
|
8
|
+
import { createPackage } from "../src/create-package.js";
|
|
8
9
|
import { tsNameConflictResolver } from "../src/name-conflict-resolver.js";
|
|
9
10
|
import { assertFileContents } from "./utils.js";
|
|
10
11
|
it("works with default imports", () => {
|
|
@@ -82,6 +83,116 @@ it("works with named imports", () => {
|
|
|
82
83
|
`
|
|
83
84
|
});
|
|
84
85
|
});
|
|
86
|
+
it("sort named imports", () => {
|
|
87
|
+
const res = render(_$createComponent(Output, {
|
|
88
|
+
get children() {
|
|
89
|
+
return [_$createComponent(ts.SourceFile, {
|
|
90
|
+
path: "test1.ts",
|
|
91
|
+
get children() {
|
|
92
|
+
return _$createComponent(List, {
|
|
93
|
+
get children() {
|
|
94
|
+
return [[_$createComponent(ts.ClassDeclaration, {
|
|
95
|
+
"export": true,
|
|
96
|
+
name: "B",
|
|
97
|
+
get refkey() {
|
|
98
|
+
return refkey("B");
|
|
99
|
+
}
|
|
100
|
+
})], [_$createComponent(ts.FunctionDeclaration, {
|
|
101
|
+
"export": true,
|
|
102
|
+
name: "a",
|
|
103
|
+
get refkey() {
|
|
104
|
+
return refkey("a");
|
|
105
|
+
}
|
|
106
|
+
})]];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}), _$createComponent(ts.SourceFile, {
|
|
111
|
+
path: "test2.ts",
|
|
112
|
+
get children() {
|
|
113
|
+
return _$createComponent(List, {
|
|
114
|
+
get children() {
|
|
115
|
+
return [["const b = ", _$createComponent(Reference, {
|
|
116
|
+
get refkey() {
|
|
117
|
+
return refkey("B");
|
|
118
|
+
}
|
|
119
|
+
}), ";"], ["const a = ", _$createComponent(Reference, {
|
|
120
|
+
get refkey() {
|
|
121
|
+
return refkey("a");
|
|
122
|
+
}
|
|
123
|
+
}), ";"]];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
})];
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
assertFileContents(res, {
|
|
131
|
+
"test2.ts": `
|
|
132
|
+
import { a, B } from "./test1.js";
|
|
133
|
+
|
|
134
|
+
const b = B;
|
|
135
|
+
const a = a;
|
|
136
|
+
`
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it("sort statements by import paths", () => {
|
|
140
|
+
const res = render(_$createComponent(Output, {
|
|
141
|
+
get children() {
|
|
142
|
+
return [_$createComponent(ts.SourceFile, {
|
|
143
|
+
path: "a.ts",
|
|
144
|
+
get children() {
|
|
145
|
+
return _$createComponent(ts.ClassDeclaration, {
|
|
146
|
+
"export": true,
|
|
147
|
+
"default": true,
|
|
148
|
+
name: "A",
|
|
149
|
+
get refkey() {
|
|
150
|
+
return refkey("A");
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}), _$createComponent(ts.SourceFile, {
|
|
155
|
+
path: "b.ts",
|
|
156
|
+
get children() {
|
|
157
|
+
return _$createComponent(ts.ClassDeclaration, {
|
|
158
|
+
"export": true,
|
|
159
|
+
"default": true,
|
|
160
|
+
name: "B",
|
|
161
|
+
get refkey() {
|
|
162
|
+
return refkey("B");
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}), _$createComponent(ts.SourceFile, {
|
|
167
|
+
path: "test2.ts",
|
|
168
|
+
get children() {
|
|
169
|
+
return _$createComponent(List, {
|
|
170
|
+
get children() {
|
|
171
|
+
return [["const b = ", _$createComponent(Reference, {
|
|
172
|
+
get refkey() {
|
|
173
|
+
return refkey("B");
|
|
174
|
+
}
|
|
175
|
+
}), ";"], ["const a = ", _$createComponent(Reference, {
|
|
176
|
+
get refkey() {
|
|
177
|
+
return refkey("A");
|
|
178
|
+
}
|
|
179
|
+
}), ";"]];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
})];
|
|
184
|
+
}
|
|
185
|
+
}));
|
|
186
|
+
assertFileContents(res, {
|
|
187
|
+
"test2.ts": `
|
|
188
|
+
import A from "./a.js";
|
|
189
|
+
import B from "./b.js";
|
|
190
|
+
|
|
191
|
+
const b = B;
|
|
192
|
+
const a = A;
|
|
193
|
+
`
|
|
194
|
+
});
|
|
195
|
+
});
|
|
85
196
|
it("works with default and named imports", () => {
|
|
86
197
|
const res = render(_$createComponent(Output, {
|
|
87
198
|
get children() {
|
|
@@ -300,9 +411,9 @@ it("works with importing the same name many times from different files with the
|
|
|
300
411
|
}));
|
|
301
412
|
assertFileContents(res, {
|
|
302
413
|
"test-import.ts": `
|
|
303
|
-
import { type MyInterface
|
|
304
|
-
import {
|
|
305
|
-
import {
|
|
414
|
+
import { conflict, type MyInterface } from "./test1.js";
|
|
415
|
+
import { conflict as conflict_2, type MyInterface as MyInterface_2 } from "./test2.js";
|
|
416
|
+
import { conflict as conflict_3, type MyInterface as MyInterface_3 } from "./test3.js";
|
|
306
417
|
|
|
307
418
|
const one: MyInterface = conflict;
|
|
308
419
|
const two: MyInterface_2 = conflict_2;
|
|
@@ -574,7 +685,7 @@ describe("type imports", () => {
|
|
|
574
685
|
}));
|
|
575
686
|
assertFileContents(res, {
|
|
576
687
|
"test2.ts": `
|
|
577
|
-
import { type TypeA
|
|
688
|
+
import { ClassA, type TypeA } from "./test1.js";
|
|
578
689
|
|
|
579
690
|
type A = TypeA
|
|
580
691
|
class B extends ClassA {}
|
|
@@ -683,6 +794,44 @@ describe("type imports", () => {
|
|
|
683
794
|
`
|
|
684
795
|
});
|
|
685
796
|
});
|
|
797
|
+
it("value reference from another file doesn't affect a type only reference", () => {
|
|
798
|
+
const {
|
|
799
|
+
component,
|
|
800
|
+
ClassA
|
|
801
|
+
} = mkTestFile("test1.ts");
|
|
802
|
+
const res = render(_$createComponent(Output, {
|
|
803
|
+
get children() {
|
|
804
|
+
return [component, _$createComponent(ts.SourceFile, {
|
|
805
|
+
path: "test2.ts",
|
|
806
|
+
get children() {
|
|
807
|
+
return ["type A = ", _$createComponent(Reference, {
|
|
808
|
+
refkey: ClassA,
|
|
809
|
+
type: true
|
|
810
|
+
})];
|
|
811
|
+
}
|
|
812
|
+
}), _$createComponent(ts.SourceFile, {
|
|
813
|
+
path: "test3.ts",
|
|
814
|
+
get children() {
|
|
815
|
+
return ["class B extends ", _$createComponent(Reference, {
|
|
816
|
+
refkey: ClassA
|
|
817
|
+
}), " ", "{}"];
|
|
818
|
+
}
|
|
819
|
+
})];
|
|
820
|
+
}
|
|
821
|
+
}));
|
|
822
|
+
assertFileContents(res, {
|
|
823
|
+
"test2.ts": `
|
|
824
|
+
import type { ClassA } from "./test1.js";
|
|
825
|
+
|
|
826
|
+
type A = ClassA
|
|
827
|
+
`,
|
|
828
|
+
"test3.ts": `
|
|
829
|
+
import { ClassA } from "./test1.js";
|
|
830
|
+
|
|
831
|
+
class B extends ClassA {}
|
|
832
|
+
`
|
|
833
|
+
});
|
|
834
|
+
});
|
|
686
835
|
it("infer if a type reference from the typescript context", () => {
|
|
687
836
|
const {
|
|
688
837
|
component,
|
|
@@ -722,4 +871,38 @@ describe("type imports", () => {
|
|
|
722
871
|
`
|
|
723
872
|
});
|
|
724
873
|
});
|
|
874
|
+
it("reference from a package", () => {
|
|
875
|
+
const pkg1 = createPackage({
|
|
876
|
+
name: "test",
|
|
877
|
+
version: "^1.0.0",
|
|
878
|
+
descriptor: {
|
|
879
|
+
".": {
|
|
880
|
+
named: ["Foo"]
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
const res = render(_$createComponent(Output, {
|
|
885
|
+
externals: [pkg1],
|
|
886
|
+
get children() {
|
|
887
|
+
return _$createComponent(ts.SourceFile, {
|
|
888
|
+
path: "test2.ts",
|
|
889
|
+
get children() {
|
|
890
|
+
return ["type A = ", _$createComponent(Reference, {
|
|
891
|
+
get refkey() {
|
|
892
|
+
return pkg1.Foo;
|
|
893
|
+
},
|
|
894
|
+
type: true
|
|
895
|
+
})];
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}));
|
|
900
|
+
assertFileContents(res, {
|
|
901
|
+
"test2.ts": `
|
|
902
|
+
import type { Foo } from "test";
|
|
903
|
+
|
|
904
|
+
type A = Foo
|
|
905
|
+
`
|
|
906
|
+
});
|
|
907
|
+
});
|
|
725
908
|
});
|
|
@@ -132,6 +132,7 @@ it("can create readonly members", () => {
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
}), _$createComponent(ts.InterfaceMember, {
|
|
135
|
+
readonly: true,
|
|
135
136
|
indexer: "str: string",
|
|
136
137
|
type: "number"
|
|
137
138
|
})];
|
|
@@ -143,7 +144,7 @@ it("can create readonly members", () => {
|
|
|
143
144
|
interface Foo {
|
|
144
145
|
readonly member: string;
|
|
145
146
|
circular: Foo;
|
|
146
|
-
[str: string]: number;
|
|
147
|
+
readonly [str: string]: number;
|
|
147
148
|
}
|
|
148
149
|
`);
|
|
149
150
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.test.d.ts","sourceRoot":"","sources":["../../test/object.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { ObjectExpression, ObjectProperty, ObjectSpreadProperty } from "../src/index.js";
|
|
6
|
+
import { toSourceText } from "./utils.js";
|
|
7
|
+
it("from js value", () => {
|
|
8
|
+
expect(toSourceText(_$createComponent(ObjectExpression, {
|
|
9
|
+
jsValue: {
|
|
10
|
+
a: 1,
|
|
11
|
+
b: 2
|
|
12
|
+
}
|
|
13
|
+
}))).toBe(d`
|
|
14
|
+
{
|
|
15
|
+
a: 1,
|
|
16
|
+
b: 2,
|
|
17
|
+
}
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
it("from object property", () => {
|
|
21
|
+
const comp = _$createComponent(ObjectExpression, {
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(List, {
|
|
24
|
+
joiner: ",\n",
|
|
25
|
+
get children() {
|
|
26
|
+
return [_$createComponent(ObjectProperty, {
|
|
27
|
+
name: "a",
|
|
28
|
+
value: 1
|
|
29
|
+
}), _$createComponent(ObjectProperty, {
|
|
30
|
+
name: "b",
|
|
31
|
+
value: 2
|
|
32
|
+
})];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
expect(toSourceText(comp)).toBe(d`
|
|
38
|
+
{
|
|
39
|
+
a: 1,
|
|
40
|
+
b: 2
|
|
41
|
+
}
|
|
42
|
+
`);
|
|
43
|
+
});
|
|
44
|
+
it("spread property", () => {
|
|
45
|
+
const comp = _$createComponent(ObjectExpression, {
|
|
46
|
+
get children() {
|
|
47
|
+
return _$createComponent(ObjectSpreadProperty, {
|
|
48
|
+
children: "abc"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
expect(toSourceText(comp)).toBe(d`
|
|
53
|
+
{
|
|
54
|
+
...abc
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
|
+
});
|