@alloy-js/typescript 0.15.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.
- package/CHANGELOG.md +12 -0
- package/dist/src/components/MemberExpression.d.ts +21 -4
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +302 -88
- package/dist/src/components/index.d.ts +0 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +0 -1
- package/dist/src/components/stc/index.d.ts +0 -1
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +0 -1
- package/dist/test/member-expression.test.js +285 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/MemberExpression.tsx +364 -103
- package/src/components/index.ts +0 -1
- package/src/components/stc/index.ts +0 -1
- package/temp/api.json +56 -94
- package/test/member-expression.test.tsx +221 -8
- package/dist/src/components/MemberChainExpression.d.ts +0 -11
- package/dist/src/components/MemberChainExpression.d.ts.map +0 -1
- package/dist/src/components/MemberChainExpression.js +0 -98
- package/dist/test/member-chain.test.d.ts +0 -2
- package/dist/test/member-chain.test.d.ts.map +0 -1
- package/dist/test/member-chain.test.js +0 -141
- package/src/components/MemberChainExpression.tsx +0 -91
- package/test/member-chain.test.tsx +0 -124
|
@@ -5,12 +5,14 @@ import {
|
|
|
5
5
|
For,
|
|
6
6
|
isComponentCreator,
|
|
7
7
|
OutputSymbol,
|
|
8
|
-
|
|
8
|
+
reactive,
|
|
9
9
|
ref,
|
|
10
10
|
Refkey,
|
|
11
|
-
|
|
11
|
+
Show,
|
|
12
|
+
ToRefs,
|
|
12
13
|
useBinder,
|
|
13
14
|
} from "@alloy-js/core";
|
|
15
|
+
|
|
14
16
|
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
15
17
|
import { isValidJSIdentifier } from "../utils.js";
|
|
16
18
|
|
|
@@ -19,10 +21,11 @@ export interface MemberExpressionProps {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
interface PartDescriptor {
|
|
22
|
-
|
|
23
|
-
accessStyle:
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
id: Children;
|
|
25
|
+
accessStyle: "dot" | "bracket";
|
|
26
|
+
quoteId: boolean;
|
|
27
|
+
nullish: boolean;
|
|
28
|
+
args?: Children[];
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -30,12 +33,18 @@ interface PartDescriptor {
|
|
|
30
33
|
* the following:
|
|
31
34
|
*
|
|
32
35
|
* * **id**: The identifier for the member expression part
|
|
33
|
-
* * **refkey**:
|
|
36
|
+
* * **refkey**: a refkey for a symbol whose name becomes the identifier
|
|
34
37
|
* * **symbol**: a symbol whose name becomes the identifier part
|
|
35
38
|
* * **args**: create a method call with the given args
|
|
39
|
+
* * **children**: arbitrary contents for the identifier part.
|
|
40
|
+
*
|
|
41
|
+
* Each part can have a nullish prop, which indicates that the part may be null
|
|
42
|
+
* or undefined.
|
|
36
43
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
44
|
+
* Each part can also have a quoteId prop, which indicates that the identifier
|
|
45
|
+
* of the part should be quoted (i.e. `["foo"]` instead of `.foo`). This is only
|
|
46
|
+
* necessary when providing the children prop, otherwise it is determined
|
|
47
|
+
* automatically.
|
|
39
48
|
*
|
|
40
49
|
* @example
|
|
41
50
|
*
|
|
@@ -45,6 +54,7 @@ interface PartDescriptor {
|
|
|
45
54
|
* <MemberExpression.Part refkey={rk} nullish />
|
|
46
55
|
* <MemberExpression.Part symbol={sym} />
|
|
47
56
|
* <MemberExpression.Part args={["hello", "world"]} />
|
|
57
|
+
* <MemberExpression.Part>SomeValue</MemberExpression.Part>
|
|
48
58
|
* </MemberExpression>
|
|
49
59
|
* ```
|
|
50
60
|
*
|
|
@@ -52,11 +62,41 @@ interface PartDescriptor {
|
|
|
52
62
|
* with a name of "prop2", this will render:
|
|
53
63
|
*
|
|
54
64
|
* ```ts
|
|
55
|
-
* base.prop1?.prop2("hello", "world")
|
|
65
|
+
* base.prop1?.prop2("hello", "world").SomeValue
|
|
56
66
|
* ```
|
|
57
67
|
*/
|
|
58
68
|
export function MemberExpression(props: MemberExpressionProps): Children {
|
|
59
69
|
const children = flattenMemberExpression(childrenArray(() => props.children));
|
|
70
|
+
const parts = childrenToPartDescriptors(children);
|
|
71
|
+
|
|
72
|
+
if (parts.length === 0) {
|
|
73
|
+
return <></>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isCallChain = computed(() => {
|
|
77
|
+
let callCount = 0;
|
|
78
|
+
for (const part of parts) {
|
|
79
|
+
if (part.args !== undefined) callCount++;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return callCount > 1;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// construct a member expression from the parts. When a part is nullish,
|
|
86
|
+
// and there is a subsequent part, we use `?.` instead of `.`. accessStyle determines
|
|
87
|
+
// whether we use dot or bracket notation.
|
|
88
|
+
|
|
89
|
+
return computed(() => {
|
|
90
|
+
return isCallChain.value ?
|
|
91
|
+
formatCallChain(parts)
|
|
92
|
+
: formatNonCallChain(parts);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Build part descriptors from the children of a MemberExpression.
|
|
98
|
+
*/
|
|
99
|
+
function childrenToPartDescriptors(children: Children[]): PartDescriptor[] {
|
|
60
100
|
const parts: PartDescriptor[] = [];
|
|
61
101
|
for (const child of children) {
|
|
62
102
|
if (!isComponentCreator(child, MemberExpression.Part)) {
|
|
@@ -64,121 +104,320 @@ export function MemberExpression(props: MemberExpressionProps): Children {
|
|
|
64
104
|
continue;
|
|
65
105
|
}
|
|
66
106
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
parts.push(
|
|
108
|
+
createPartDescriptorFromProps(child.props, child === children[0]),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return parts;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const exclusiveParts: (keyof MemberExpressionPartProps)[] = [
|
|
116
|
+
"children",
|
|
117
|
+
"args",
|
|
118
|
+
"refkey",
|
|
119
|
+
"symbol",
|
|
120
|
+
"id",
|
|
121
|
+
];
|
|
122
|
+
/**
|
|
123
|
+
* Creates a reactive part descriptor from the given part props.
|
|
124
|
+
*
|
|
125
|
+
* @param partProps The props for the part.
|
|
126
|
+
* @param first Whether this is the first part in the expression. Refkeys are
|
|
127
|
+
* handled specially for the first part.
|
|
128
|
+
*/
|
|
129
|
+
function createPartDescriptorFromProps(
|
|
130
|
+
partProps: MemberExpressionPartProps,
|
|
131
|
+
first: boolean,
|
|
132
|
+
) {
|
|
133
|
+
const foundProps = exclusiveParts.filter((key) => {
|
|
134
|
+
return key in partProps;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (foundProps.length > 1) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`Only one of ${foundProps.join(", ")} can be used for a MemberExpression part at a time`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const symbolSource = computed(() => {
|
|
144
|
+
if (partProps.refkey) {
|
|
145
|
+
return getSymbolForRefkey(partProps.refkey).value;
|
|
93
146
|
} else if (partProps.symbol) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
part.accessStyle = computed(() => {
|
|
98
|
-
return accessStyleForMemberName(partProps.symbol!.name);
|
|
99
|
-
});
|
|
100
|
-
part.base = toRef(partProps.symbol, "name");
|
|
101
|
-
} else if (partProps.args) {
|
|
102
|
-
part.args = partProps.args;
|
|
147
|
+
return partProps.symbol;
|
|
148
|
+
} else {
|
|
149
|
+
return undefined;
|
|
103
150
|
}
|
|
151
|
+
});
|
|
104
152
|
|
|
105
|
-
|
|
106
|
-
|
|
153
|
+
const part: ToRefs<PartDescriptor> = {
|
|
154
|
+
id: computed(() => {
|
|
155
|
+
if (partProps.args) {
|
|
156
|
+
return undefined;
|
|
157
|
+
} else if ("children" in partProps && partProps.children !== undefined) {
|
|
158
|
+
return partProps.children;
|
|
159
|
+
} else if (first && partProps.refkey) {
|
|
160
|
+
return partProps.refkey;
|
|
161
|
+
} else if (partProps.id) {
|
|
162
|
+
return escapeId(partProps.id);
|
|
163
|
+
} else if (symbolSource.value) {
|
|
164
|
+
return escapeId(symbolSource.value.name);
|
|
165
|
+
} else {
|
|
166
|
+
return "<unresolved symbol>";
|
|
167
|
+
}
|
|
168
|
+
}),
|
|
169
|
+
accessStyle: computed(() => {
|
|
170
|
+
if (partProps.args) {
|
|
171
|
+
// not used
|
|
172
|
+
return "dot";
|
|
173
|
+
} else if (partProps.quoteId) {
|
|
174
|
+
return "bracket";
|
|
175
|
+
} else if (partProps.id) {
|
|
176
|
+
return accessStyleForMemberName(partProps.id);
|
|
177
|
+
} else if (symbolSource.value) {
|
|
178
|
+
return accessStyleForMemberName(symbolSource.value.name);
|
|
179
|
+
} else {
|
|
180
|
+
return "dot";
|
|
181
|
+
}
|
|
182
|
+
}),
|
|
183
|
+
quoteId: computed(() => {
|
|
184
|
+
if (partProps.quoteId) {
|
|
185
|
+
return partProps.quoteId;
|
|
186
|
+
} else if (partProps.id) {
|
|
187
|
+
return !isValidJSIdentifier(partProps.id);
|
|
188
|
+
} else if (symbolSource.value) {
|
|
189
|
+
return !isValidJSIdentifier(symbolSource.value.name);
|
|
190
|
+
} else {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}),
|
|
194
|
+
nullish: computed(() => {
|
|
195
|
+
if (partProps.nullish) {
|
|
196
|
+
return partProps.nullish;
|
|
197
|
+
}
|
|
107
198
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
199
|
+
if (symbolSource.value) {
|
|
200
|
+
return isNullish(symbolSource.value);
|
|
201
|
+
}
|
|
111
202
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
203
|
+
return false;
|
|
204
|
+
}),
|
|
205
|
+
args: ref<any>(partProps.args === true ? [] : partProps.args),
|
|
206
|
+
};
|
|
115
207
|
|
|
116
|
-
|
|
208
|
+
return reactive(part);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* replaces quotes with escaped quotes
|
|
213
|
+
*/
|
|
214
|
+
function escapeId(id: string) {
|
|
215
|
+
return id.replace(/"/g, '\\"');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Convert a refkey to a symbol ref using the current binder.
|
|
220
|
+
*/
|
|
221
|
+
function getSymbolForRefkey(refkey: Refkey) {
|
|
222
|
+
const binder = useBinder();
|
|
223
|
+
return binder.getSymbolForRefkey(refkey);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Check if the given symbol is nullish.
|
|
228
|
+
*/
|
|
229
|
+
function isNullish(symbol: OutputSymbol): boolean {
|
|
230
|
+
return !!((symbol as TSOutputSymbol).tsFlags & TSSymbolFlags.Nullish);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Formatting of call chains (i.e. member expressions which have more than one
|
|
235
|
+
* call in them). The general approach is that line breaks occur after each
|
|
236
|
+
* call, and there is only one call per line. When there are non-call elements,
|
|
237
|
+
* they occur prior to the call part. The first part of the member expression
|
|
238
|
+
* contains all but the last non-call part.
|
|
239
|
+
*
|
|
240
|
+
* The following is an example of proper formatting:
|
|
241
|
+
*
|
|
242
|
+
* ```ts
|
|
243
|
+
* z.dummy // all but the last non-call part for the first element
|
|
244
|
+
* .object({ // the first call part with line break after
|
|
245
|
+
* a: 1,
|
|
246
|
+
* })
|
|
247
|
+
* .dummy.partial() // the next call part with non-call parts before it
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
function formatCallChain(parts: PartDescriptor[]): Children {
|
|
251
|
+
return computed(() => {
|
|
252
|
+
const expression: Children[] = [];
|
|
253
|
+
|
|
254
|
+
// break the expression into parts.
|
|
255
|
+
const chunks: PartDescriptor[][] = [];
|
|
256
|
+
|
|
257
|
+
// the first part is all the non-call parts
|
|
258
|
+
let partIndex = 0;
|
|
259
|
+
|
|
260
|
+
function pushPart() {
|
|
261
|
+
const part = parts[partIndex];
|
|
262
|
+
if (!part) throw new Error("No part to push");
|
|
263
|
+
chunks.at(-1)!.push(part);
|
|
264
|
+
partIndex++;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function pushChunk() {
|
|
268
|
+
chunks.push([]);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// For the first chunk, take all the non-call parts except the last one
|
|
272
|
+
// and put them in a chunk.
|
|
273
|
+
pushChunk();
|
|
274
|
+
while (
|
|
275
|
+
partIndex < parts.length &&
|
|
276
|
+
(partIndex === parts.length - 1 ||
|
|
277
|
+
chunks.at(-1)!.length === 0 ||
|
|
278
|
+
parts[partIndex + 1].args === undefined)
|
|
279
|
+
) {
|
|
280
|
+
pushPart();
|
|
281
|
+
if (chunks.at(-1)!.at(-1)!.args !== undefined) {
|
|
282
|
+
// the first segment always ends after we see a call
|
|
283
|
+
// if we happen to take one
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// then for all remaining parts, collect all the non-call parts and end with
|
|
289
|
+
// a call chunk
|
|
290
|
+
while (partIndex < parts.length) {
|
|
291
|
+
pushChunk();
|
|
292
|
+
while (partIndex < parts.length && !parts[partIndex].args) {
|
|
293
|
+
pushPart();
|
|
294
|
+
}
|
|
295
|
+
while (partIndex < parts.length && parts[partIndex].args) {
|
|
296
|
+
pushPart();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
|
|
301
|
+
const chunk = chunks[chunkIndex];
|
|
302
|
+
const chunkExpression = [];
|
|
303
|
+
for (let partIndex = 0; partIndex < chunk.length; partIndex++) {
|
|
304
|
+
if (chunkIndex === 0 && partIndex === 0) {
|
|
305
|
+
// first part is just gonna be the id
|
|
306
|
+
chunkExpression.push(chunk[0].id);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
const part = chunk[partIndex];
|
|
310
|
+
const prevPart =
|
|
311
|
+
partIndex === 0 ?
|
|
312
|
+
chunks[chunkIndex - 1].at(-1)!
|
|
313
|
+
: chunk[partIndex - 1];
|
|
314
|
+
|
|
315
|
+
if (part.args !== undefined) {
|
|
316
|
+
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
317
|
+
chunkExpression.push(formatCallExpr(prevPart, part));
|
|
318
|
+
} else if (part.accessStyle === "dot") {
|
|
319
|
+
chunkExpression.push(formatDotAccess(prevPart, part));
|
|
320
|
+
} else {
|
|
321
|
+
// bracket notation - don't include the dot
|
|
322
|
+
chunkExpression.push(formatArrayAccess(prevPart, part));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
expression.push(
|
|
327
|
+
chunkIndex === 0 ? chunkExpression : (
|
|
328
|
+
<>
|
|
329
|
+
<sbr />
|
|
330
|
+
{chunkExpression}
|
|
331
|
+
</>
|
|
332
|
+
),
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return (
|
|
337
|
+
<group>
|
|
338
|
+
<indent>{expression}</indent>
|
|
339
|
+
</group>
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function formatNonCallChain(parts: PartDescriptor[]): Children {
|
|
345
|
+
return computed(() => {
|
|
117
346
|
const expression: Children[] = [];
|
|
118
347
|
|
|
119
348
|
for (let i = 0; i < parts.length; i++) {
|
|
120
349
|
const part = parts[i];
|
|
121
|
-
const base =
|
|
122
|
-
const hasName = base !== "";
|
|
123
|
-
|
|
350
|
+
const base = part.id;
|
|
124
351
|
if (i === 0) {
|
|
125
352
|
expression.push(base);
|
|
126
353
|
} else {
|
|
127
354
|
// Determine if we should use nullish operator from previous part
|
|
128
355
|
const prevPart = parts[i - 1];
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// Handle parts with name vs. parts with only args differently
|
|
132
|
-
if (hasName) {
|
|
133
|
-
// Apply dot or bracket notation based on accessStyle for named parts
|
|
134
|
-
if (part.accessStyle.value === "dot") {
|
|
135
|
-
expression.push(
|
|
136
|
-
<group>
|
|
137
|
-
<indent>
|
|
138
|
-
<sbr />
|
|
139
|
-
{isNullish ? "?." : "."}
|
|
140
|
-
{base}
|
|
141
|
-
</indent>
|
|
142
|
-
</group>,
|
|
143
|
-
);
|
|
144
|
-
} else {
|
|
145
|
-
// bracket notation - don't include the dot
|
|
146
|
-
expression.push(
|
|
147
|
-
<group>
|
|
148
|
-
{isNullish ? "?." : ""}[
|
|
149
|
-
<indent>
|
|
150
|
-
<sbr />
|
|
151
|
-
{JSON.stringify(base)}
|
|
152
|
-
</indent>
|
|
153
|
-
<sbr />]
|
|
154
|
-
</group>,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
} else if (part.args !== undefined) {
|
|
356
|
+
|
|
357
|
+
if (part.args !== undefined) {
|
|
158
358
|
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
159
|
-
expression.push(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
each={typeof part.args === "boolean" ? [] : (part.args ?? [])}
|
|
166
|
-
comma
|
|
167
|
-
line
|
|
168
|
-
>
|
|
169
|
-
{(arg) => arg}
|
|
170
|
-
</For>
|
|
171
|
-
)
|
|
172
|
-
</group>
|
|
173
|
-
</group>,
|
|
174
|
-
);
|
|
359
|
+
expression.push(formatCallExpr(prevPart, part));
|
|
360
|
+
} else if (part.accessStyle === "dot") {
|
|
361
|
+
expression.push(formatDotAccess(prevPart, part));
|
|
362
|
+
} else {
|
|
363
|
+
// bracket notation - don't include the dot
|
|
364
|
+
expression.push(formatArrayAccess(prevPart, part));
|
|
175
365
|
}
|
|
176
366
|
}
|
|
177
367
|
}
|
|
178
368
|
|
|
179
369
|
return expression;
|
|
180
370
|
});
|
|
181
|
-
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function formatArrayAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
374
|
+
return (
|
|
375
|
+
<group>
|
|
376
|
+
{prevPart.nullish ? "?." : ""}[
|
|
377
|
+
<indent>
|
|
378
|
+
<sbr />
|
|
379
|
+
{part.quoteId && '"'}
|
|
380
|
+
{part.id}
|
|
381
|
+
{part.quoteId && '"'}
|
|
382
|
+
</indent>
|
|
383
|
+
<sbr />]
|
|
384
|
+
</group>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function formatDotAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
389
|
+
return (
|
|
390
|
+
<group>
|
|
391
|
+
<indent>
|
|
392
|
+
<sbr />
|
|
393
|
+
{prevPart.nullish ? "?." : "."}
|
|
394
|
+
{part.id}
|
|
395
|
+
</indent>
|
|
396
|
+
</group>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function formatCallExpr(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
401
|
+
const args = computed(() => {
|
|
402
|
+
return typeof part.args === "boolean" ? [] : (part.args ?? []);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<group>
|
|
407
|
+
{prevPart.nullish ? "?." : ""}(
|
|
408
|
+
<Show when={args.value.length <= 1}>{args.value[0]}</Show>
|
|
409
|
+
<Show when={args.value.length > 1}>
|
|
410
|
+
<indent>
|
|
411
|
+
<sbr />
|
|
412
|
+
<For each={args} comma line>
|
|
413
|
+
{(arg) => arg}
|
|
414
|
+
</For>
|
|
415
|
+
</indent>
|
|
416
|
+
<sbr />
|
|
417
|
+
</Show>
|
|
418
|
+
)
|
|
419
|
+
</group>
|
|
420
|
+
);
|
|
182
421
|
}
|
|
183
422
|
|
|
184
423
|
function accessStyleForMemberName(name: string) {
|
|
@@ -207,6 +446,13 @@ export interface MemberExpressionPartProps {
|
|
|
207
446
|
* The identifier for this part of the member expression.
|
|
208
447
|
*/
|
|
209
448
|
id?: string;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Whether the identifier should be quoted or not. Only needed when
|
|
452
|
+
* providing the `children` prop, otherwise it is determined automatically.
|
|
453
|
+
*/
|
|
454
|
+
quoteId?: boolean;
|
|
455
|
+
|
|
210
456
|
/**
|
|
211
457
|
* A refkey for a symbol whose name becomes the identifier.
|
|
212
458
|
*/
|
|
@@ -224,6 +470,12 @@ export interface MemberExpressionPartProps {
|
|
|
224
470
|
* This part is nullish. Subsequent parts use conditional access operators.
|
|
225
471
|
*/
|
|
226
472
|
nullish?: boolean;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* The contents of this part. When passed, overrides the other props except
|
|
476
|
+
* nullish.
|
|
477
|
+
*/
|
|
478
|
+
children?: Children;
|
|
227
479
|
}
|
|
228
480
|
/**
|
|
229
481
|
* A part of a member expression. Each part can provide one of the following
|
|
@@ -233,6 +485,15 @@ export interface MemberExpressionPartProps {
|
|
|
233
485
|
* * **refkey**: A refkey for a symbol whose name becomes the identifier
|
|
234
486
|
* * **symbol**: a symbol whose name becomes the identifier part
|
|
235
487
|
* * **args**: create a method call with the given args
|
|
488
|
+
* * **children**: arbitrary contents for the identifier part.
|
|
489
|
+
*
|
|
490
|
+
* Each part can have a nullish prop, which indicates that the part may be null
|
|
491
|
+
* or undefined.
|
|
492
|
+
*
|
|
493
|
+
* Each part can also have a quoteId prop, which indicates that the identifier
|
|
494
|
+
* of the part should be quoted (i.e. `["foo"]` instead of `.foo`). This is only
|
|
495
|
+
* necessary when providing the children prop, otherwise it is determined
|
|
496
|
+
* automatically.
|
|
236
497
|
*/
|
|
237
498
|
MemberExpression.Part = function (props: MemberExpressionPartProps) {
|
|
238
499
|
/**
|
package/src/components/index.ts
CHANGED
|
@@ -26,7 +26,6 @@ export * from "./InterfaceMethod.jsx";
|
|
|
26
26
|
export * from "./JSDoc.jsx";
|
|
27
27
|
export * from "./JSDocComment.jsx";
|
|
28
28
|
export * from "./JSDocExample.jsx";
|
|
29
|
-
export * from "./MemberChainExpression.jsx";
|
|
30
29
|
export * from "./MemberExpression.jsx";
|
|
31
30
|
export * from "./ObjectExpression.js";
|
|
32
31
|
export * from "./PackageDirectory.js";
|
|
@@ -30,7 +30,6 @@ export const JSDoc = stc(base.JSDoc);
|
|
|
30
30
|
export const JSDocExample = stc(base.JSDocExample);
|
|
31
31
|
export const JSDocComment = stc(base.JSDocComment);
|
|
32
32
|
export const MemberExpression = stc(base.MemberExpression);
|
|
33
|
-
export const MemberChainExpression = stc(base.MemberChainExpression);
|
|
34
33
|
export const ObjectExpression = stc(base.ObjectExpression);
|
|
35
34
|
export const ObjectProperty = stc(base.ObjectProperty);
|
|
36
35
|
export const PackageDirectory = stc(base.PackageDirectory);
|