@alloy-js/typescript 0.14.0 → 0.16.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  3. package/dist/src/components/FunctionBase.js +6 -1
  4. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  5. package/dist/src/components/ImportStatement.js +8 -2
  6. package/dist/src/components/MemberExpression.d.ts +21 -4
  7. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  8. package/dist/src/components/MemberExpression.js +302 -88
  9. package/dist/src/components/ObjectExpression.d.ts +6 -0
  10. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  11. package/dist/src/components/ObjectExpression.js +17 -1
  12. package/dist/src/components/index.d.ts +0 -1
  13. package/dist/src/components/index.d.ts.map +1 -1
  14. package/dist/src/components/index.js +0 -1
  15. package/dist/src/components/stc/index.d.ts +0 -1
  16. package/dist/src/components/stc/index.d.ts.map +1 -1
  17. package/dist/src/components/stc/index.js +0 -1
  18. package/dist/src/parameter-descriptor.d.ts +9 -0
  19. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  20. package/dist/test/arrow-function.test.js +17 -0
  21. package/dist/test/basic.test.js +1 -1
  22. package/dist/test/externals.test.js +3 -3
  23. package/dist/test/function-declaration.test.js +18 -0
  24. package/dist/test/function-expression.test.js +17 -0
  25. package/dist/test/function-type.test.js +14 -0
  26. package/dist/test/imports.test.js +114 -4
  27. package/dist/test/member-expression.test.js +285 -5
  28. package/dist/test/object.test.d.ts +2 -0
  29. package/dist/test/object.test.d.ts.map +1 -0
  30. package/dist/test/object.test.js +57 -0
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +3 -3
  33. package/src/components/FunctionBase.tsx +1 -0
  34. package/src/components/ImportStatement.tsx +12 -2
  35. package/src/components/MemberExpression.tsx +364 -103
  36. package/src/components/ObjectExpression.tsx +21 -1
  37. package/src/components/index.ts +0 -1
  38. package/src/components/stc/index.ts +0 -1
  39. package/src/parameter-descriptor.ts +10 -0
  40. package/temp/api.json +231 -94
  41. package/test/arrow-function.test.tsx +22 -0
  42. package/test/basic.test.tsx +1 -1
  43. package/test/externals.test.tsx +3 -3
  44. package/test/function-declaration.test.tsx +22 -0
  45. package/test/function-expression.test.tsx +22 -0
  46. package/test/function-type.test.tsx +17 -0
  47. package/test/imports.test.tsx +75 -4
  48. package/test/member-expression.test.tsx +221 -8
  49. package/test/object.test.tsx +48 -0
  50. package/dist/src/components/MemberChainExpression.d.ts +0 -11
  51. package/dist/src/components/MemberChainExpression.d.ts.map +0 -1
  52. package/dist/src/components/MemberChainExpression.js +0 -98
  53. package/dist/test/member-chain.test.d.ts +0 -2
  54. package/dist/test/member-chain.test.d.ts.map +0 -1
  55. package/dist/test/member-chain.test.js +0 -141
  56. package/src/components/MemberChainExpression.tsx +0 -91
  57. package/test/member-chain.test.tsx +0 -124
@@ -21,7 +21,6 @@ export * from "./InterfaceMethod.js";
21
21
  export * from "./JSDoc.js";
22
22
  export * from "./JSDocComment.js";
23
23
  export * from "./JSDocExample.js";
24
- export * from "./MemberChainExpression.js";
25
24
  export * from "./MemberExpression.js";
26
25
  export * from "./ObjectExpression.js";
27
26
  export * from "./PackageDirectory.js";
@@ -28,7 +28,6 @@ export declare const JSDoc: import("@alloy-js/core").StcSignature<base.JSDocProp
28
28
  export declare const JSDocExample: import("@alloy-js/core").StcSignature<base.JSDocExampleProps>;
29
29
  export declare const JSDocComment: import("@alloy-js/core").StcSignature<base.JSDocCommentProps>;
30
30
  export declare const MemberExpression: import("@alloy-js/core").StcSignature<base.MemberExpressionProps>;
31
- export declare const MemberChainExpression: import("@alloy-js/core").StcSignature<base.MemberChainExpressionProps>;
32
31
  export declare const ObjectExpression: import("@alloy-js/core").StcSignature<base.ObjectExpressionProps>;
33
32
  export declare const ObjectProperty: import("@alloy-js/core").StcSignature<base.ObjectPropertyProps>;
34
33
  export declare const PackageDirectory: import("@alloy-js/core").StcSignature<base.PackageDirectoryProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/stc/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,eAAO,MAAM,eAAe,kEAA4B,CAAC;AACzD,eAAO,MAAM,aAAa,gEAA0B,CAAC;AACrD,eAAO,MAAM,UAAU,6DAAuB,CAAC;AAC/C,eAAO,MAAM,aAAa,gEAA0B,CAAC;AACrD,eAAO,MAAM,gBAAgB,mEAA6B,CAAC;AAC3D,eAAO,MAAM,UAAU,6DAAuB,CAAC;AAC/C,eAAO,MAAM,WAAW,8DAAwB,CAAC;AACjD,eAAO,MAAM,WAAW,8DAAwB,CAAC;AACjD,eAAO,MAAM,SAAS,4DAAsB,CAAC;AAC7C,eAAO,MAAM,WAAW,8DAAwB,CAAC;AACjD,eAAO,MAAM,eAAe,kEAA4B,CAAC;AACzD,eAAO,MAAM,UAAU,6DAAuB,CAAC;AAC/C,eAAO,MAAM,eAAe,kEAA4B,CAAC;AACzD,eAAO,MAAM,sBAAsB,yEAAmC,CAAC;AACvE,eAAO,MAAM,mBAAmB,sEAAgC,CAAC;AACjE,eAAO,MAAM,kBAAkB,qEAA+B,CAAC;AAC/D,eAAO,MAAM,WAAW,8DAAwB,CAAC;AACjD,eAAO,MAAM,UAAU,6DAAuB,CAAC;AAC/C,eAAO,MAAM,YAAY,+DAAyB,CAAC;AACnD,eAAO,MAAM,eAAe,kEAA4B,CAAC;AACzD,eAAO,MAAM,gBAAgB,mEAA6B,CAAC;AAC3D,eAAO,MAAM,oBAAoB,uEAAiC,CAAC;AACnE,eAAO,MAAM,mBAAmB,sEAAgC,CAAC;AACjE,eAAO,MAAM,eAAe,kEAA4B,CAAC;AACzD,eAAO,MAAM,eAAe,kEAA4B,CAAC;AACzD,eAAO,MAAM,KAAK,wDAAkB,CAAC;AACrC,eAAO,MAAM,YAA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;AACzD,eAAO,MAAM,cAAc,iEAA2B,CAAC"}
@@ -29,7 +29,6 @@ export const JSDoc = stc(base.JSDoc);
29
29
  export const JSDocExample = stc(base.JSDocExample);
30
30
  export const JSDocComment = stc(base.JSDocComment);
31
31
  export const MemberExpression = stc(base.MemberExpression);
32
- export const MemberChainExpression = stc(base.MemberChainExpression);
33
32
  export const ObjectExpression = stc(base.ObjectExpression);
34
33
  export const ObjectProperty = stc(base.ObjectProperty);
35
34
  export const PackageDirectory = stc(base.PackageDirectory);
@@ -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;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5C;;OAEG;IACH,QAA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,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5C;;OAEG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IAClE;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,+BACf,SAAQ,uBAAuB;CAAG;AAEpC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C"}
@@ -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
  });
@@ -83,7 +83,7 @@ it("works", () => {
83
83
  }
84
84
  `);
85
85
  expect(findFile(res, "test2.ts").contents).toEqual(d`
86
- import { sayHello, sayGoodbye } from "./test1.js";
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
  });
@@ -83,6 +83,116 @@ it("works with named imports", () => {
83
83
  `
84
84
  });
85
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
+ });
86
196
  it("works with default and named imports", () => {
87
197
  const res = render(_$createComponent(Output, {
88
198
  get children() {
@@ -301,9 +411,9 @@ it("works with importing the same name many times from different files with the
301
411
  }));
302
412
  assertFileContents(res, {
303
413
  "test-import.ts": `
304
- import { type MyInterface, conflict } from "./test1.js";
305
- import { type MyInterface as MyInterface_2, conflict as conflict_2 } from "./test2.js";
306
- import { type MyInterface as MyInterface_3, conflict as conflict_3 } from "./test3.js";
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";
307
417
 
308
418
  const one: MyInterface = conflict;
309
419
  const two: MyInterface_2 = conflict_2;
@@ -575,7 +685,7 @@ describe("type imports", () => {
575
685
  }));
576
686
  assertFileContents(res, {
577
687
  "test2.ts": `
578
- import { type TypeA, ClassA } from "./test1.js";
688
+ import { ClassA, type TypeA } from "./test1.js";
579
689
 
580
690
  type A = TypeA
581
691
  class B extends ClassA {}
@@ -1,12 +1,12 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { code, List, refkey, StatementList } from "@alloy-js/core";
2
+ import { code, List, Output, refkey, render, StatementList } from "@alloy-js/core";
3
3
  import { d } from "@alloy-js/core/testing";
4
4
  import { describe, expect, it } from "vitest";
5
+ import { InterfaceMember, ObjectExpression } from "../src/components/index.js";
5
6
  import { MemberExpression } from "../src/components/MemberExpression.js";
6
- import { InterfaceMember, ObjectExpression } from "../src/components/stc/index.js";
7
7
  import { VarDeclaration } from "../src/components/VarDeclaration.js";
8
- import { ClassDeclaration, ClassField, FunctionDeclaration, InterfaceDeclaration } from "../src/index.js";
9
- import { toSourceText } from "./utils.js";
8
+ import { ClassDeclaration, ClassField, FunctionDeclaration, InterfaceDeclaration, ObjectProperty, SourceFile } from "../src/index.js";
9
+ import { assertFileContents, toSourceText } from "./utils.js";
10
10
  it("renders basic member expression with dot notation", () => {
11
11
  expect(toSourceText(_$createComponent(MemberExpression, {
12
12
  get children() {
@@ -33,6 +33,19 @@ it("renders member expression with bracket notation for invalid identifiers", ()
33
33
  obj["property-name"]
34
34
  `);
35
35
  });
36
+ it("renders member expressions with quotes", () => {
37
+ expect(toSourceText(_$createComponent(MemberExpression, {
38
+ get children() {
39
+ return [_$createComponent(MemberExpression.Part, {
40
+ id: "obj"
41
+ }), _$createComponent(MemberExpression.Part, {
42
+ id: `property-"name"`
43
+ })];
44
+ }
45
+ }))).toBe(d`
46
+ obj["property-\\"name\\""]
47
+ `);
48
+ });
36
49
  it("handles nullish chaining", () => {
37
50
  expect(toSourceText(_$createComponent(MemberExpression, {
38
51
  get children() {
@@ -77,6 +90,19 @@ it("ignores non-part children", () => {
77
90
  obj.property
78
91
  `);
79
92
  });
93
+ it("ignores allows parts to define children", () => {
94
+ expect(toSourceText(_$createComponent(MemberExpression, {
95
+ get children() {
96
+ return [_$createComponent(MemberExpression.Part, {
97
+ children: "well"
98
+ }), _$createComponent(MemberExpression.Part, {
99
+ children: "hello"
100
+ })];
101
+ }
102
+ }))).toBe(d`
103
+ well.hello
104
+ `);
105
+ });
80
106
  it("flattens nested member expressions", () => {
81
107
  expect(toSourceText(_$createComponent(MemberExpression, {
82
108
  get children() {
@@ -136,6 +162,59 @@ it("handles nullish chaining at multiple levels", () => {
136
162
  a.b?.c.d?.e
137
163
  `);
138
164
  });
165
+ it("throws an error when providing conflicting part props", () => {
166
+ expect(() => toSourceText(_$createComponent(MemberExpression, {
167
+ get children() {
168
+ return [_$createComponent(MemberExpression.Part, {
169
+ id: "obj"
170
+ }), _$createComponent(MemberExpression.Part, {
171
+ id: "property",
172
+ nullish: true,
173
+ args: [1, 2]
174
+ })];
175
+ }
176
+ }))).toThrowError(`Only one of args, id can be used for a MemberExpression part at a time`);
177
+ });
178
+ it("takes children for the id part", () => {
179
+ expect(toSourceText(_$createComponent(List, {
180
+ get children() {
181
+ return [_$createComponent(MemberExpression, {
182
+ get children() {
183
+ return [_$createComponent(MemberExpression.Part, {
184
+ children: "child1"
185
+ }), _$createComponent(MemberExpression.Part, {
186
+ quoteId: true,
187
+ children: "child2"
188
+ })];
189
+ }
190
+ }), _$createComponent(MemberExpression, {
191
+ get children() {
192
+ return [_$createComponent(MemberExpression.Part, {
193
+ children: "child1"
194
+ }), _$createComponent(MemberExpression.Part, {
195
+ quoteId: true,
196
+ children: "child2"
197
+ }), _$createComponent(MemberExpression.Part, {
198
+ args: true
199
+ }), _$createComponent(MemberExpression.Part, {
200
+ quoteId: true,
201
+ nullish: true,
202
+ children: "child3"
203
+ }), _$createComponent(MemberExpression.Part, {
204
+ args: true
205
+ }), _$createComponent(MemberExpression.Part, {
206
+ children: "[\"foo\" + 1]"
207
+ }), _$createComponent(MemberExpression.Part, {
208
+ args: true
209
+ })];
210
+ }
211
+ })];
212
+ }
213
+ }))).toBe(d`
214
+ child1["child2"]
215
+ child1["child2"]()["child3"]?.().["foo" + 1]()
216
+ `);
217
+ });
139
218
  describe("with refkeys", () => {
140
219
  it("handles symbols correctly", () => {
141
220
  const rk1 = refkey();
@@ -410,6 +489,64 @@ describe("with refkeys", () => {
410
489
  const test1_2 = 2;
411
490
  `);
412
491
  });
492
+ it("creates a full reference to the first refkey", () => {
493
+ const rk1 = refkey();
494
+ const res = render(_$createComponent(Output, {
495
+ get children() {
496
+ return [_$createComponent(SourceFile, {
497
+ path: "source.ts",
498
+ get children() {
499
+ return _$createComponent(VarDeclaration, {
500
+ name: "importMe",
501
+ get children() {
502
+ return _$createComponent(ObjectExpression, {
503
+ get children() {
504
+ return _$createComponent(ObjectProperty, {
505
+ name: "prop",
506
+ refkey: rk1
507
+ });
508
+ }
509
+ });
510
+ }
511
+ });
512
+ }
513
+ }), _$createComponent(SourceFile, {
514
+ path: "index.ts",
515
+ get children() {
516
+ return _$createComponent(StatementList, {
517
+ get children() {
518
+ return [_$createComponent(MemberExpression, {
519
+ get children() {
520
+ return [_$createComponent(MemberExpression.Part, {
521
+ refkey: rk1
522
+ }), _$createComponent(MemberExpression.Part, {
523
+ id: "foo"
524
+ })];
525
+ }
526
+ }), _$createComponent(MemberExpression, {
527
+ get children() {
528
+ return [_$createComponent(MemberExpression.Part, {
529
+ children: rk1
530
+ }), _$createComponent(MemberExpression.Part, {
531
+ id: "foo"
532
+ })];
533
+ }
534
+ })];
535
+ }
536
+ });
537
+ }
538
+ })];
539
+ }
540
+ }));
541
+ assertFileContents(res, {
542
+ "index.ts": d`
543
+ import { importMe } from "./source.js";
544
+
545
+ importMe.prop.foo;
546
+ importMe.prop.foo;
547
+ `
548
+ });
549
+ });
413
550
  });
414
551
  describe("with function calls", () => {
415
552
  it("handles simple function calls correctly", () => {
@@ -466,6 +603,22 @@ describe("with function calls", () => {
466
603
  myFunction(1, 2)?.prop
467
604
  `);
468
605
  });
606
+ it("handles function calls returning nullish correctly", () => {
607
+ expect(toSourceText(_$createComponent(MemberExpression, {
608
+ get children() {
609
+ return [_$createComponent(MemberExpression.Part, {
610
+ id: "myFunction"
611
+ }), _$createComponent(MemberExpression.Part, {
612
+ args: [1, 2],
613
+ nullish: true
614
+ }), _$createComponent(MemberExpression.Part, {
615
+ id: "prop"
616
+ })];
617
+ }
618
+ }))).toBe(d`
619
+ myFunction(1, 2)?.prop
620
+ `);
621
+ });
469
622
  });
470
623
  describe("formatting", () => {
471
624
  describe("simple chains", () => {
@@ -540,7 +693,41 @@ describe("formatting", () => {
540
693
  })
541
694
  `);
542
695
  });
543
- it.skip("handles multiple calls", () => {
696
+ it("handles single calls with multiple parameters", () => {
697
+ expect(toSourceText(_$createComponent(MemberExpression, {
698
+ get children() {
699
+ return [_$createComponent(MemberExpression.Part, {
700
+ id: "z"
701
+ }), _$createComponent(MemberExpression.Part, {
702
+ id: "object"
703
+ }), _$createComponent(MemberExpression.Part, {
704
+ get args() {
705
+ return [_$createComponent(ObjectExpression, {
706
+ jsValue: {
707
+ x: 1
708
+ }
709
+ }), _$createComponent(ObjectExpression, {
710
+ jsValue: {
711
+ y: 2
712
+ }
713
+ })];
714
+ }
715
+ })];
716
+ }
717
+ }), {
718
+ printWidth: 12
719
+ })).toBe(d`
720
+ z.object(
721
+ {
722
+ x: 1,
723
+ },
724
+ {
725
+ y: 2,
726
+ }
727
+ )
728
+ `);
729
+ });
730
+ it("handles multiple calls", () => {
544
731
  expect(toSourceText(_$createComponent(MemberExpression, {
545
732
  get children() {
546
733
  return [_$createComponent(MemberExpression.Part, {
@@ -571,5 +758,98 @@ describe("formatting", () => {
571
758
  .partial()
572
759
  `);
573
760
  });
761
+ it("renders multiple calls on the same line when there are no breaks and they fit", () => {
762
+ expect(toSourceText(_$createComponent(MemberExpression, {
763
+ get children() {
764
+ return [_$createComponent(MemberExpression.Part, {
765
+ id: "z"
766
+ }), _$createComponent(MemberExpression.Part, {
767
+ id: "object"
768
+ }), _$createComponent(MemberExpression.Part, {
769
+ args: true
770
+ }), _$createComponent(MemberExpression.Part, {
771
+ id: "partial"
772
+ }), _$createComponent(MemberExpression.Part, {
773
+ args: true
774
+ }), _$createComponent(MemberExpression.Part, {
775
+ id: "optional"
776
+ }), _$createComponent(MemberExpression.Part, {
777
+ args: true
778
+ })];
779
+ }
780
+ }))).toBe(d`
781
+ z.object().partial().optional()
782
+ `);
783
+ });
784
+ it("handles multiple calls with id parts", () => {
785
+ expect(toSourceText(_$createComponent(MemberExpression, {
786
+ get children() {
787
+ return [_$createComponent(MemberExpression.Part, {
788
+ id: "z"
789
+ }), _$createComponent(MemberExpression.Part, {
790
+ id: "z1",
791
+ nullish: true
792
+ }), _$createComponent(MemberExpression.Part, {
793
+ id: "object"
794
+ }), _$createComponent(MemberExpression.Part, {
795
+ get args() {
796
+ return [_$createComponent(ObjectExpression, {
797
+ jsValue: {
798
+ x: 1
799
+ }
800
+ })];
801
+ }
802
+ }), _$createComponent(MemberExpression.Part, {
803
+ id: "foo"
804
+ }), _$createComponent(MemberExpression.Part, {
805
+ id: "partial"
806
+ }), _$createComponent(MemberExpression.Part, {
807
+ args: []
808
+ })];
809
+ }
810
+ }))).toBe(d`
811
+ z.z1
812
+ ?.object({
813
+ x: 1,
814
+ })
815
+ .foo.partial()
816
+ `);
817
+ });
818
+ it("handles the first part being a call", () => {
819
+ expect(toSourceText(_$createComponent(MemberExpression, {
820
+ get children() {
821
+ return [_$createComponent(MemberExpression.Part, {
822
+ id: "z"
823
+ }), _$createComponent(MemberExpression.Part, {
824
+ args: true
825
+ }), _$createComponent(MemberExpression.Part, {
826
+ id: "z1",
827
+ nullish: true
828
+ }), _$createComponent(MemberExpression.Part, {
829
+ id: "object"
830
+ }), _$createComponent(MemberExpression.Part, {
831
+ get args() {
832
+ return [_$createComponent(ObjectExpression, {
833
+ jsValue: {
834
+ x: 1
835
+ }
836
+ })];
837
+ }
838
+ }), _$createComponent(MemberExpression.Part, {
839
+ id: "foo"
840
+ }), _$createComponent(MemberExpression.Part, {
841
+ id: "partial"
842
+ }), _$createComponent(MemberExpression.Part, {
843
+ args: []
844
+ })];
845
+ }
846
+ }))).toBe(d`
847
+ z()
848
+ .z1?.object({
849
+ x: 1,
850
+ })
851
+ .foo.partial()
852
+ `);
853
+ });
574
854
  });
575
855
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=object.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.test.d.ts","sourceRoot":"","sources":["../../test/object.test.tsx"],"names":[],"mappings":""}