@alloy-js/typescript 0.23.0-dev.2 → 0.23.0-dev.5

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 (66) hide show
  1. package/dist/src/components/FunctionType.d.ts +1 -1
  2. package/dist/src/components/FunctionType.js +1 -1
  3. package/dist/src/components/FunctionType.js.map +1 -1
  4. package/dist/src/components/Interface.d.ts +1 -1
  5. package/dist/src/components/Interface.d.ts.map +1 -1
  6. package/dist/src/components/Interface.js +14 -9
  7. package/dist/src/components/Interface.js.map +1 -1
  8. package/dist/src/components/MemberExpression.d.ts +1 -1
  9. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  10. package/dist/src/components/MemberExpression.js +115 -330
  11. package/dist/src/components/MemberExpression.js.map +1 -1
  12. package/dist/src/components/MemberScope.d.ts.map +1 -1
  13. package/dist/src/components/MemberScope.js +6 -2
  14. package/dist/src/components/MemberScope.js.map +1 -1
  15. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  16. package/dist/src/components/PackageDirectory.js +2 -2
  17. package/dist/src/components/PackageDirectory.js.map +1 -1
  18. package/dist/src/components/SourceFile.d.ts.map +1 -1
  19. package/dist/src/components/SourceFile.js +4 -2
  20. package/dist/src/components/SourceFile.js.map +1 -1
  21. package/dist/src/components/TypeDeclaration.d.ts +1 -1
  22. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  23. package/dist/src/components/TypeDeclaration.js +1 -1
  24. package/dist/src/components/TypeDeclaration.js.map +1 -1
  25. package/dist/src/components/TypeRefContext.d.ts +1 -1
  26. package/dist/src/components/TypeRefContext.d.ts.map +1 -1
  27. package/dist/src/components/TypeRefContext.js +1 -1
  28. package/dist/src/components/TypeRefContext.js.map +1 -1
  29. package/dist/src/context/type-ref-context.d.ts.map +1 -1
  30. package/dist/src/context/type-ref-context.js +2 -2
  31. package/dist/src/context/type-ref-context.js.map +1 -1
  32. package/dist/src/create-package.d.ts.map +1 -1
  33. package/dist/src/create-package.js +7 -6
  34. package/dist/src/create-package.js.map +1 -1
  35. package/dist/src/symbols/index.d.ts.map +1 -1
  36. package/dist/src/symbols/index.js +47 -11
  37. package/dist/src/symbols/index.js.map +1 -1
  38. package/dist/src/symbols/ts-module-scope.d.ts +1 -0
  39. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  40. package/dist/src/symbols/ts-module-scope.js +14 -3
  41. package/dist/src/symbols/ts-module-scope.js.map +1 -1
  42. package/dist/src/symbols/ts-output-symbol.d.ts +1 -0
  43. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  44. package/dist/src/symbols/ts-output-symbol.js +20 -3
  45. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  46. package/dist/src/symbols/ts-package-scope.d.ts +1 -0
  47. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  48. package/dist/src/symbols/ts-package-scope.js +8 -0
  49. package/dist/src/symbols/ts-package-scope.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +9 -5
  52. package/src/components/FunctionType.tsx +1 -1
  53. package/src/components/Interface.tsx +24 -13
  54. package/src/components/MemberExpression.tsx +194 -454
  55. package/src/components/MemberScope.tsx +13 -3
  56. package/src/components/PackageDirectory.tsx +2 -1
  57. package/src/components/SourceFile.tsx +4 -1
  58. package/src/components/TypeDeclaration.tsx +15 -15
  59. package/src/components/TypeRefContext.tsx +2 -2
  60. package/src/context/type-ref-context.tsx +6 -2
  61. package/src/create-package.ts +29 -15
  62. package/src/symbols/index.ts +36 -10
  63. package/src/symbols/ts-module-scope.ts +36 -9
  64. package/src/symbols/ts-output-symbol.ts +21 -2
  65. package/src/symbols/ts-package-scope.ts +9 -0
  66. package/temp/api.json +162 -65
@@ -1,17 +1,11 @@
1
1
  import {
2
2
  Children,
3
- childrenArray,
4
3
  computed,
4
+ createAccessExpression,
5
5
  For,
6
- isComponentCreator,
7
6
  OutputSymbol,
8
- reactive,
9
- ref,
10
7
  Refkey,
11
8
  Show,
12
- takeSymbols,
13
- ToRefs,
14
- useBinder,
15
9
  } from "@alloy-js/core";
16
10
 
17
11
  import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
@@ -21,14 +15,14 @@ export interface MemberExpressionProps {
21
15
  children: Children;
22
16
  }
23
17
 
24
- interface PartDescriptorWithId extends PartDescriptorBase {
18
+ type PartDescriptorWithId = PartDescriptorBase & {
25
19
  id: Children;
26
- }
20
+ };
27
21
 
28
- interface PartDescriptorWithIndex extends PartDescriptorBase {
22
+ type PartDescriptorWithIndex = PartDescriptorBase & {
29
23
  index: number;
30
- }
31
- interface PartDescriptorBase {
24
+ };
25
+ type PartDescriptorBase = {
32
26
  accessStyle: "dot" | "bracket";
33
27
  jsPrivate: boolean;
34
28
  quoteId: boolean;
@@ -39,10 +33,131 @@ interface PartDescriptorBase {
39
33
  * Whether to await the value that results from this part of the member expression.
40
34
  */
41
35
  await?: boolean;
42
- }
36
+ };
43
37
 
44
38
  type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
45
39
 
40
+ const exclusiveParts: (keyof MemberExpressionPartProps)[] = [
41
+ "children",
42
+ "args",
43
+ "refkey",
44
+ "symbol",
45
+ "id",
46
+ ];
47
+
48
+ const { Expression, Part, registerOuterComponent } = createAccessExpression<
49
+ MemberExpressionPartProps,
50
+ PartDescriptor
51
+ >({
52
+ createDescriptor(partProps, sym, first) {
53
+ const foundProps = exclusiveParts.filter((key) => key in partProps);
54
+ if (foundProps.length > 1) {
55
+ throw new Error(
56
+ `Only one of ${foundProps.join(", ")} can be used for a MemberExpression part at a time`,
57
+ );
58
+ }
59
+
60
+ let id: Children;
61
+ if (partProps.args) {
62
+ id = undefined;
63
+ } else if (partProps.children !== undefined) {
64
+ id = partProps.children;
65
+ } else if (first && partProps.refkey) {
66
+ id = partProps.refkey;
67
+ } else if (partProps.id !== undefined) {
68
+ id =
69
+ isNumericIdentifier(partProps.id) ?
70
+ partProps.id
71
+ : escapeId(partProps.id);
72
+ } else if (partProps.index !== undefined) {
73
+ id = partProps.index;
74
+ } else if (sym) {
75
+ id = escapeId(sym.name);
76
+ } else {
77
+ id = "<unresolved symbol>";
78
+ }
79
+
80
+ let accessStyle: "dot" | "bracket";
81
+ if (partProps.children !== undefined) {
82
+ accessStyle =
83
+ typeof partProps.children === "string" ?
84
+ partProps.quoteId ?
85
+ "bracket"
86
+ : accessStyleForMemberName(partProps.children)
87
+ : "bracket";
88
+ } else if (partProps.args) {
89
+ accessStyle = "dot";
90
+ } else if (partProps.quoteId) {
91
+ accessStyle = "bracket";
92
+ } else if (partProps.id !== undefined) {
93
+ accessStyle =
94
+ isNumericIdentifier(partProps.id) ? "bracket" : (
95
+ accessStyleForMemberName(partProps.id)
96
+ );
97
+ } else if (partProps.index !== undefined) {
98
+ accessStyle = "bracket";
99
+ } else if (sym) {
100
+ accessStyle = accessStyleForMemberName(sym.name);
101
+ } else {
102
+ accessStyle = "dot";
103
+ }
104
+
105
+ return {
106
+ id,
107
+ accessStyle,
108
+ quoteId:
109
+ partProps.quoteId ? partProps.quoteId
110
+ : partProps.id !== undefined ?
111
+ isNumericIdentifier(partProps.id) ? false
112
+ : !isValidJSIdentifier(partProps.id)
113
+ : sym ? !isValidJSIdentifier(sym.name)
114
+ : false,
115
+ nullish:
116
+ partProps.nullish ? partProps.nullish
117
+ : sym ? isNullish(sym)
118
+ : false,
119
+ args: partProps.args === true ? [] : partProps.args,
120
+ jsPrivate: !!sym && (sym as TSOutputSymbol).isPrivateMemberSymbol,
121
+ type: !!sym && (sym as TSOutputSymbol).isTypeSymbol,
122
+ await: partProps.await,
123
+ } as PartDescriptor;
124
+ },
125
+
126
+ getBase(part) {
127
+ return isIdPartDescriptor(part) ? part.id : part.index;
128
+ },
129
+
130
+ formatPart(part, prevPart, _inCallChain) {
131
+ if (prevPart.type) {
132
+ return formatArrayAccess(prevPart, part);
133
+ } else if (part.args !== undefined) {
134
+ return formatCallExpr(prevPart, part);
135
+ } else if (part.accessStyle === "dot") {
136
+ return formatDotAccess(prevPart, part);
137
+ } else {
138
+ return formatArrayAccess(prevPart, part);
139
+ }
140
+ },
141
+
142
+ isCallPart(part) {
143
+ return part.args !== undefined;
144
+ },
145
+
146
+ canUseCallChains(parts) {
147
+ for (const part of parts) {
148
+ if (part.await) return false;
149
+ }
150
+ return true;
151
+ },
152
+
153
+ wrapPartResult(expression, part, _index, isLast) {
154
+ if (part.await) {
155
+ return isLast ? <>await {expression}</> : <>(await {expression})</>;
156
+ }
157
+ return expression;
158
+ },
159
+ });
160
+
46
161
  /**
47
162
  * Create a member expression from parts. Each part can provide one of
48
163
  * the following:
@@ -82,371 +197,80 @@ type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
82
197
  * ```
83
198
  */
84
199
  export function MemberExpression(props: MemberExpressionProps): Children {
85
- const children = flattenMemberExpression(childrenArray(() => props.children));
86
- const parts = childrenToPartDescriptors(children);
87
- // any symbols emitted from the children won't be relevant to
88
- // parent scopes. TODO: emit the proper symbol if we know it?
89
- takeSymbols();
90
-
91
- if (parts.length === 0) {
92
- return <></>;
93
- }
94
-
95
- const isCallChain = computed(() => {
96
- for (const part of parts) {
97
- if (part.await) return false;
98
- }
99
-
100
- let callCount = 0;
101
- for (const part of parts) {
102
- if (part.args !== undefined) callCount++;
103
- }
104
-
105
- return callCount > 1;
106
- });
107
-
108
- // construct a member expression from the parts. When a part is nullish,
109
- // and there is a subsequent part, we use `?.` instead of `.`. accessStyle determines
110
- // whether we use dot or bracket notation.
111
-
112
- return computed(() => {
113
- return isCallChain.value ?
114
- formatCallChain(parts)
115
- : formatNonCallChain(parts);
116
- });
200
+ return Expression(props);
117
201
  }
118
202
 
119
203
  /**
120
- * Build part descriptors from the children of a MemberExpression.
121
- */
122
- function childrenToPartDescriptors(children: Children[]): PartDescriptor[] {
123
- const parts: PartDescriptor[] = [];
124
- for (const child of children) {
125
- if (!isComponentCreator(child, MemberExpression.Part)) {
126
- // we ignore non-parts
127
- continue;
128
- }
129
-
130
- parts.push(
131
- createPartDescriptorFromProps(child.props, child === children[0]),
132
- );
133
- }
134
-
135
- return parts;
136
- }
137
-
138
- const exclusiveParts: (keyof MemberExpressionPartProps)[] = [
139
- "children",
140
- "args",
141
- "refkey",
142
- "symbol",
143
- "id",
144
- ];
145
- /**
146
- * Creates a reactive part descriptor from the given part props.
204
+ * A part of a member expression. Each part can provide one of the following
205
+ * props:
147
206
  *
148
- * @param partProps The props for the part.
149
- * @param first Whether this is the first part in the expression. Refkeys are
150
- * handled specially for the first part.
151
- */
152
- function createPartDescriptorFromProps(
153
- partProps: MemberExpressionPartProps,
154
- first: boolean,
155
- ) {
156
- const foundProps = exclusiveParts.filter((key) => {
157
- return key in partProps;
158
- });
159
-
160
- if (foundProps.length > 1) {
161
- throw new Error(
162
- `Only one of ${foundProps.join(", ")} can be used for a MemberExpression part at a time`,
163
- );
164
- }
165
-
166
- const symbolSource = computed(() => {
167
- if (partProps.refkey) {
168
- return getSymbolForRefkey(partProps.refkey).value;
169
- } else if (partProps.symbol) {
170
- return partProps.symbol;
171
- } else {
172
- return undefined;
173
- }
174
- });
175
-
176
- const part: ToRefs<PartDescriptor> = {
177
- id: computed(() => {
178
- if (partProps.args) {
179
- return undefined;
180
- } else if (partProps.children !== undefined) {
181
- return partProps.children;
182
- } else if (first && partProps.refkey) {
183
- return partProps.refkey;
184
- } else if (partProps.id !== undefined) {
185
- return isNumericIdentifier(partProps.id) ?
186
- partProps.id
187
- : escapeId(partProps.id);
188
- } else if (partProps.index !== undefined) {
189
- return partProps.index;
190
- } else if (symbolSource.value) {
191
- return escapeId(symbolSource.value.name);
192
- } else {
193
- return "<unresolved symbol>";
194
- }
195
- }),
196
- accessStyle: computed(() => {
197
- if (partProps.children !== undefined) {
198
- if (typeof partProps.children === "string") {
199
- return partProps.quoteId ? "bracket" : (
200
- accessStyleForMemberName(partProps.children)
201
- );
202
- }
203
-
204
- return "bracket";
205
- } else if (partProps.args) {
206
- // not used
207
- return "dot";
208
- } else if (partProps.quoteId) {
209
- return "bracket";
210
- } else if (partProps.id !== undefined) {
211
- return isNumericIdentifier(partProps.id) ? "bracket" : (
212
- accessStyleForMemberName(partProps.id)
213
- );
214
- } else if (partProps.index !== undefined) {
215
- return "bracket";
216
- } else if (symbolSource.value) {
217
- return accessStyleForMemberName(symbolSource.value.name);
218
- } else {
219
- return "dot";
220
- }
221
- }),
222
- quoteId: computed(() => {
223
- if (partProps.quoteId) {
224
- return partProps.quoteId;
225
- } else if (partProps.id !== undefined) {
226
- return isNumericIdentifier(partProps.id) ? false : (
227
- !isValidJSIdentifier(partProps.id)
228
- );
229
- } else if (symbolSource.value) {
230
- return !isValidJSIdentifier(symbolSource.value.name);
231
- } else {
232
- return false;
233
- }
234
- }),
235
- nullish: computed(() => {
236
- if (partProps.nullish) {
237
- return partProps.nullish;
238
- }
239
-
240
- if (symbolSource.value) {
241
- return isNullish(symbolSource.value);
242
- }
243
-
244
- return false;
245
- }),
246
- args: ref<any>(partProps.args === true ? [] : partProps.args),
247
- jsPrivate: computed(() => {
248
- return (
249
- !!symbolSource.value &&
250
- (symbolSource.value as TSOutputSymbol).isPrivateMemberSymbol
251
- );
252
- }),
253
- type: computed(() => {
254
- return (
255
- !!symbolSource.value &&
256
- (symbolSource.value as TSOutputSymbol).isTypeSymbol
257
- );
258
- }),
259
- await: computed(() => partProps.await),
260
- };
261
-
262
- return reactive(part);
263
- }
264
-
265
- /**
266
- * replaces quotes with escaped quotes
267
- */
268
- function escapeId(id: string) {
269
- return id.replace(/"/g, '\\"');
270
- }
271
-
272
- /**
273
- * Convert a refkey to a symbol ref using the current binder.
274
- */
275
- function getSymbolForRefkey(refkey: Refkey) {
276
- const binder = useBinder();
277
- return binder!.getSymbolForRefkey(refkey);
278
- }
279
-
280
- /**
281
- * Check if the given symbol is nullish.
282
- */
283
- function isNullish(symbol: OutputSymbol): boolean {
284
- return !!((symbol as TSOutputSymbol).tsFlags & TSSymbolFlags.Nullish);
285
- }
286
-
287
- /**
288
- * Formatting of call chains (i.e. member expressions which have more than one
289
- * call in them). The general approach is that line breaks occur after each
290
- * call, and there is only one call per line. When there are non-call elements,
291
- * they occur prior to the call part. The first part of the member expression
292
- * contains all but the last non-call part.
207
+ * * **id**: The identifier for the member expression part
208
+ * * **refkey**: A refkey for a symbol whose name becomes the identifier
209
+ * * **symbol**: a symbol whose name becomes the identifier part
210
+ * * **args**: create a method call with the given args
211
+ * * **children**: arbitrary contents for the identifier part
212
+ * * **await**: whether to await the value that results from this part of the member expression
293
213
  *
294
- * The following is an example of proper formatting:
214
+ * Each part can have a nullish prop, which indicates that the part may be null
215
+ * or undefined.
295
216
  *
296
- * ```ts
297
- * z.dummy // all but the last non-call part for the first element
298
- * .object({ // the first call part with line break after
299
- * a: 1,
300
- * })
301
- * .dummy.partial() // the next call part with non-call parts before it
302
- * ```
217
+ * Each part can also have a quoteId prop, which indicates that the identifier
218
+ * of the part should be quoted (i.e. `["foo"]` instead of `.foo`). This is only
219
+ * necessary when providing the children prop, otherwise it is determined
220
+ * automatically.
303
221
  */
304
- function formatCallChain(parts: PartDescriptor[]): Children {
305
- return computed(() => {
306
- const expression: Children[] = [];
307
-
308
- // break the expression into parts.
309
- const chunks: PartDescriptor[][] = [];
222
+ MemberExpression.Part = Part;
223
+ registerOuterComponent(MemberExpression);
310
224
 
311
- // the first part is all the non-call parts
312
- let partIndex = 0;
225
+ export interface MemberExpressionPartProps {
226
+ /**
227
+ * The identifier for this part of the member expression.
228
+ */
229
+ id?: string | number;
313
230
 
314
- function pushPart() {
315
- const part = parts[partIndex];
316
- if (!part) throw new Error("No part to push");
317
- chunks.at(-1)!.push(part);
318
- partIndex++;
319
- }
231
+ /**
232
+ * The index for this part of the member expression. This is used when
233
+ * the part is an array access (i.e. `foo[0]`).
234
+ */
235
+ index?: number;
320
236
 
321
- function pushChunk() {
322
- chunks.push([]);
323
- }
237
+ /**
238
+ * Whether the identifier should be quoted or not. Only needed when
239
+ * providing the `children` prop, otherwise it is determined automatically.
240
+ */
241
+ quoteId?: boolean;
324
242
 
325
- // For the first chunk, take all the non-call parts except the last one
326
- // and put them in a chunk.
327
- pushChunk();
328
- while (
329
- partIndex < parts.length &&
330
- (partIndex === parts.length - 1 ||
331
- chunks.at(-1)!.length === 0 ||
332
- parts[partIndex + 1].args === undefined)
333
- ) {
334
- pushPart();
335
- if (chunks.at(-1)!.at(-1)!.args !== undefined) {
336
- // the first segment always ends after we see a call
337
- // if we happen to take one
338
- break;
339
- }
340
- }
243
+ /**
244
+ * A refkey for a symbol whose name becomes the identifier.
245
+ */
246
+ refkey?: Refkey;
247
+ /**
248
+ * A symbol whose name becomes the identifier.
249
+ */
250
+ symbol?: OutputSymbol;
251
+ /**
252
+ * Arguments to construct a call expression.
253
+ */
254
+ args?: Children[] | boolean;
341
255
 
342
- // then for all remaining parts, collect all the non-call parts and end with
343
- // a call chunk
344
- while (partIndex < parts.length) {
345
- pushChunk();
346
- while (partIndex < parts.length && !parts[partIndex].args) {
347
- pushPart();
348
- }
349
- while (partIndex < parts.length && parts[partIndex].args) {
350
- pushPart();
351
- }
352
- }
256
+ /**
257
+ * Whether to await the value that results from this part of the member expression.
258
+ */
259
+ await?: boolean;
353
260
 
354
- for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
355
- const chunk = chunks[chunkIndex];
356
- const chunkExpression = [];
357
- for (let partIndex = 0; partIndex < chunk.length; partIndex++) {
358
- if (chunkIndex === 0 && partIndex === 0) {
359
- // first part is just gonna be the id
360
- const firstPart =
361
- isIdPartDescriptor(chunk[0]) ? chunk[0].id : chunk[0].index;
362
- chunkExpression.push(firstPart);
363
- continue;
364
- }
365
- const part = chunk[partIndex];
366
- const prevPart =
367
- partIndex === 0 ?
368
- chunks[chunkIndex - 1].at(-1)!
369
- : chunk[partIndex - 1];
370
-
371
- if (part.args !== undefined) {
372
- // For parts with only args (no name), append function call directly with appropriate nullish operator
373
- chunkExpression.push(formatCallExpr(prevPart, part));
374
- } else if (part.accessStyle === "dot") {
375
- chunkExpression.push(formatDotAccess(prevPart, part));
376
- } else {
377
- // bracket notation - don't include the dot
378
- chunkExpression.push(formatArrayAccess(prevPart, part));
379
- }
380
- }
381
-
382
- expression.push(
383
- chunkIndex === 0 ? chunkExpression : (
384
- <>
385
- <sbr />
386
- {chunkExpression}
387
- </>
388
- ),
389
- );
390
- }
261
+ /**
262
+ * This part is nullish. Subsequent parts use conditional access operators.
263
+ */
264
+ nullish?: boolean;
391
265
 
392
- return (
393
- <group>
394
- <indent>{expression}</indent>
395
- </group>
396
- );
397
- });
266
+ /**
267
+ * The contents of this part. When passed, overrides the other props except
268
+ * nullish.
269
+ */
270
+ children?: Children;
398
271
  }
399
272
 
400
- function formatNonCallChain(parts: PartDescriptor[]): Children {
401
- return computed(() => {
402
- let expression: Children = [];
403
-
404
- for (let i = 0; i < parts.length; i++) {
405
- const part = parts[i];
406
- const base = isIdPartDescriptor(part) ? part.id : part.index;
407
- if (i === 0) {
408
- (expression as Children[]).push(base);
409
- } else {
410
- // Determine if we should use nullish operator from previous part
411
- const prevPart = parts[i - 1];
412
- let partExpr;
413
-
414
- if (prevPart.type) {
415
- partExpr = formatArrayAccess(prevPart, part);
416
- } else if (part.args !== undefined) {
417
- // For parts with only args (no name), append function call directly with appropriate nullish operator
418
- partExpr = formatCallExpr(prevPart, part);
419
- } else if (part.accessStyle === "dot") {
420
- partExpr = formatDotAccess(prevPart, part);
421
- } else {
422
- // bracket notation - don't include the dot
423
- partExpr = formatArrayAccess(prevPart, part);
424
- }
425
-
426
- if (Array.isArray(expression)) {
427
- expression.push(partExpr);
428
- } else {
429
- expression = (
430
- <>
431
- {expression}
432
- {partExpr}
433
- </>
434
- );
435
- }
436
- }
437
-
438
- if (part.await) {
439
- if (i < parts.length - 1) {
440
- expression = <>(await {expression})</>;
441
- } else {
442
- expression = <>await {expression}</>;
443
- }
444
- }
445
- }
446
-
447
- return expression;
448
- });
449
- }
273
+ // --- Formatting helpers ---
450
274
 
451
275
  function formatArrayAccess(prevPart: PartDescriptor, part: PartDescriptor) {
452
276
  return (
@@ -502,104 +326,20 @@ function formatCallExpr(prevPart: PartDescriptor, part: PartDescriptor) {
502
326
  );
503
327
  }
504
328
 
505
- function accessStyleForMemberName(name: string) {
506
- if (isValidJSIdentifier(name)) {
507
- return "dot";
508
- }
509
- return "bracket";
510
- }
329
+ // --- Utilities ---
511
330
 
512
- function flattenMemberExpression(children: Children[]): Children[] {
513
- const flattened: Children[] = [];
514
- for (const child of children) {
515
- if (isComponentCreator(child, MemberExpression)) {
516
- flattened.push(
517
- ...flattenMemberExpression(childrenArray(() => child.props.children)),
518
- );
519
- } else {
520
- flattened.push(child);
521
- }
522
- }
523
- return flattened;
331
+ function escapeId(id: string) {
332
+ return id.replace(/"/g, '\\"');
524
333
  }
525
334
 
526
- export interface MemberExpressionPartProps {
527
- /**
528
- * The identifier for this part of the member expression.
529
- */
530
- id?: string | number;
531
-
532
- /**
533
- * The index for this part of the member expression. This is used when
534
- * the part is an array access (i.e. `foo[0]`).
535
- */
536
- index?: number;
537
-
538
- /**
539
- * Whether the identifier should be quoted or not. Only needed when
540
- * providing the `children` prop, otherwise it is determined automatically.
541
- */
542
- quoteId?: boolean;
543
-
544
- /**
545
- * A refkey for a symbol whose name becomes the identifier.
546
- */
547
- refkey?: Refkey;
548
- /**
549
- * A symbol whose name becomes the identifier.
550
- */
551
- symbol?: OutputSymbol;
552
- /**
553
- * Arguments to construct a call expression.
554
- */
555
- args?: Children[] | boolean;
556
-
557
- /**
558
- * Whether to await the value that results from this part of the member expression.
559
- */
560
- await?: boolean;
561
-
562
- /**
563
- * This part is nullish. Subsequent parts use conditional access operators.
564
- */
565
- nullish?: boolean;
335
+ function isNullish(symbol: OutputSymbol): boolean {
336
+ return !!((symbol as TSOutputSymbol).tsFlags & TSSymbolFlags.Nullish);
337
+ }
566
338
 
567
- /**
568
- * The contents of this part. When passed, overrides the other props except
569
- * nullish.
570
- */
571
- children?: Children;
339
+ function accessStyleForMemberName(name: string) {
340
+ return isValidJSIdentifier(name) ? "dot" : "bracket";
572
341
  }
573
- /**
574
- * A part of a member expression. Each part can provide one of the following
575
- * props:
576
- *
577
- * * **id**: The identifier for the member expression part
578
- * * **refkey**: A refkey for a symbol whose name becomes the identifier
579
- * * **symbol**: a symbol whose name becomes the identifier part
580
- * * **args**: create a method call with the given args
581
- * * **children**: arbitrary contents for the identifier part
582
- * * **await**: whether to await the value that results from this part of the member expression
583
- *
584
- * Each part can have a nullish prop, which indicates that the part may be null
585
- * or undefined.
586
- *
587
- * Each part can also have a quoteId prop, which indicates that the identifier
588
- * of the part should be quoted (i.e. `["foo"]` instead of `.foo`). This is only
589
- * necessary when providing the children prop, otherwise it is determined
590
- * automatically.
591
- */
592
- MemberExpression.Part = function (props: MemberExpressionPartProps) {
593
- /**
594
- * This component does nothing except hold props which are retrieved by
595
- * the `MemberExpression` component.
596
- */
597
- };
598
342
 
599
- /**
600
- * Check if the given id is a numeric identifier.
601
- *
602
- */
603
343
  function isNumericIdentifier(id: Children) {
604
344
  return typeof id === "number";
605
345
  }