@alloy-js/csharp 0.20.0-dev.6 → 0.20.0-dev.8
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/dist/src/components/access-expression/access-expression.d.ts +54 -0
- package/dist/src/components/access-expression/access-expression.d.ts.map +1 -0
- package/dist/src/components/access-expression/access-expression.js +277 -0
- package/dist/src/components/access-expression/access-expression.js.map +1 -0
- package/dist/src/components/access-expression/access-expression.test.d.ts +2 -0
- package/dist/src/components/access-expression/access-expression.test.d.ts.map +1 -0
- package/dist/src/components/access-expression/access-expression.test.js +336 -0
- package/dist/src/components/access-expression/access-expression.test.js.map +1 -0
- package/dist/src/components/access-expression/part-descriptors.d.ts +32 -0
- package/dist/src/components/access-expression/part-descriptors.d.ts.map +1 -0
- package/dist/src/components/access-expression/part-descriptors.js +99 -0
- package/dist/src/components/access-expression/part-descriptors.js.map +1 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/invocation-expression/invocation-expression.d.ts +29 -0
- package/dist/src/components/invocation-expression/invocation-expression.d.ts.map +1 -0
- package/dist/src/components/invocation-expression/invocation-expression.js +70 -0
- package/dist/src/components/invocation-expression/invocation-expression.js.map +1 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.d.ts +2 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.d.ts.map +1 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.js +105 -0
- package/dist/src/components/invocation-expression/invocation-expression.test.js.map +1 -0
- package/dist/src/components/parameters/parameters.d.ts +1 -2
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +2 -1
- package/dist/src/components/parameters/parameters.js.map +1 -1
- package/dist/src/components/parameters/parameters.test.js +66 -0
- package/dist/src/components/parameters/parameters.test.js.map +1 -1
- package/dist/src/components/property/property.d.ts +2 -2
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +10 -3
- package/dist/src/components/property/property.js.map +1 -1
- package/dist/src/scopes/csharp.d.ts +2 -0
- package/dist/src/scopes/csharp.d.ts.map +1 -1
- package/dist/src/scopes/csharp.js +3 -0
- package/dist/src/scopes/csharp.js.map +1 -1
- package/dist/src/symbols/csharp.d.ts +11 -0
- package/dist/src/symbols/csharp.d.ts.map +1 -1
- package/dist/src/symbols/csharp.js +23 -0
- package/dist/src/symbols/csharp.js.map +1 -1
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +17 -5
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/access-expression/access-expression.test.tsx +284 -0
- package/src/components/access-expression/access-expression.tsx +375 -0
- package/src/components/access-expression/part-descriptors.ts +175 -0
- package/src/components/index.ts +1 -0
- package/src/components/invocation-expression/invocation-expression.test.tsx +101 -0
- package/src/components/invocation-expression/invocation-expression.tsx +60 -0
- package/src/components/parameters/parameters.test.tsx +46 -0
- package/src/components/parameters/parameters.tsx +2 -2
- package/src/components/property/property.tsx +8 -2
- package/src/scopes/csharp.ts +5 -0
- package/src/symbols/csharp.ts +32 -0
- package/src/symbols/{reference.ts → reference.tsx} +11 -9
- package/temp/api.json +268 -33
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Children, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { CSharpSymbol } from "../../symbols/csharp.js";
|
|
3
|
+
export interface AccessExpressionProps {
|
|
4
|
+
children: Children;
|
|
5
|
+
}
|
|
6
|
+
export declare function AccessExpression(props: AccessExpressionProps): string | number | boolean | void | (() => Children) | import("@vue/reactivity").Ref<any, any> | import("@alloy-js/core").SymbolRefkey | import("@alloy-js/core").MemberRefkey | import("@alloy-js/core").CustomContext | import("@alloy-js/core").IndentIntrinsicElement | import("@alloy-js/core").IndentIfBreakIntrinsicElement | import("@alloy-js/core").BrIntrinsicElement | import("@alloy-js/core").LineIntrinsicElement | import("@alloy-js/core").HbrIntrinsicElement | import("@alloy-js/core").HardlineIntrinsicElement | import("@alloy-js/core").SbrIntrinsicElement | import("@alloy-js/core").SoftlineIntrinsicElement | import("@alloy-js/core").GroupIntrinsicElement | import("@alloy-js/core").AlignIntrinsicElement | import("@alloy-js/core").FillIntrinsicElement | import("@alloy-js/core").BreakParentIntrinsicElement | import("@alloy-js/core").LineSuffixIntrinsicElement | import("@alloy-js/core").LineSuffixBoundaryIntrinsicElement | import("@alloy-js/core").DedentIntrinsicElement | import("@alloy-js/core").LiterallineIntrinsicElement | import("@alloy-js/core").LbrIntrinsicElement | import("@alloy-js/core").DedentToRootIntrinsicElement | import("@alloy-js/core").MarkAsRootIntrinsicElement | import("@alloy-js/core").IfBreakIntrinsicElement | Children[] | import("@vue/reactivity").ComputedRef<Children> | null;
|
|
7
|
+
export declare namespace AccessExpression {
|
|
8
|
+
var Part: (props: AccessExpressionPartProps) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface AccessExpressionPartProps {
|
|
11
|
+
children?: Children;
|
|
12
|
+
/**
|
|
13
|
+
* Whether this part should use conditional access.
|
|
14
|
+
*/
|
|
15
|
+
conditional?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Emit a function call.
|
|
18
|
+
*/
|
|
19
|
+
args?: boolean | Children[];
|
|
20
|
+
/**
|
|
21
|
+
* Type arguments to pass to a member access.
|
|
22
|
+
*/
|
|
23
|
+
typeArgs?: Children[];
|
|
24
|
+
/**
|
|
25
|
+
* A refkey for the symbol whose name becomes this part's identifier. When a refkey is provided for the first
|
|
26
|
+
* part, it will be fully resolved. Otherwise, just the symbol's name is used.
|
|
27
|
+
*/
|
|
28
|
+
refkey?: Refkey;
|
|
29
|
+
/**
|
|
30
|
+
* The symbol whose name becomes this part's identifier.
|
|
31
|
+
*/
|
|
32
|
+
symbol?: CSharpSymbol;
|
|
33
|
+
/**
|
|
34
|
+
* The identifier to use for this part.
|
|
35
|
+
*/
|
|
36
|
+
id?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Create an element access part with a single indexer argument. Mutually
|
|
39
|
+
* exclusive with the `indexerArgs` prop.
|
|
40
|
+
*/
|
|
41
|
+
index?: Children;
|
|
42
|
+
/**
|
|
43
|
+
* Create an element access part with multiple indexer arguments. Mutually
|
|
44
|
+
* exclusive with the `index` prop.
|
|
45
|
+
*/
|
|
46
|
+
indexerArgs?: Children[];
|
|
47
|
+
/**
|
|
48
|
+
* Whether this part could possibly be null. Will guard member and element
|
|
49
|
+
* access with a conditional access operator. Passing this is not necessary if
|
|
50
|
+
* you provide a symbol or refkey and the symbol's nullable flag is set.
|
|
51
|
+
*/
|
|
52
|
+
nullable?: boolean;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=access-expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-expression.d.ts","sourceRoot":"","sources":["../../../../src/components/access-expression/access-expression.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAMR,MAAM,EAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAWvD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,qyCA6B5D;yBA7Be,gBAAgB;sBAoGS,yBAAyB;;AApDlE,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;IAEtB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { createIntrinsic as _$createIntrinsic, createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { childrenArray, computed, For, isComponentCreator, Show, takeSymbols } from "@alloy-js/core";
|
|
3
|
+
import { childrenToPartDescriptors, isArgsPart, isIdPart } from "./part-descriptors.js";
|
|
4
|
+
export function AccessExpression(props) {
|
|
5
|
+
const children = flattenAccessExpression(childrenArray(() => props.children));
|
|
6
|
+
const parts = childrenToPartDescriptors(children);
|
|
7
|
+
|
|
8
|
+
// any symbols emitted from the children won't be relevant to parent scopes.
|
|
9
|
+
takeSymbols();
|
|
10
|
+
if (parts.length === 0) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const isCallChain = computed(() => {
|
|
14
|
+
let callCount = 0;
|
|
15
|
+
for (const part of parts) {
|
|
16
|
+
if (isArgsPart(part)) callCount++;
|
|
17
|
+
}
|
|
18
|
+
return callCount > 1;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// construct a member expression from the parts. When a part is nullish,
|
|
22
|
+
// and there is a subsequent part, we use `?.` instead of `.`. accessStyle determines
|
|
23
|
+
// whether we use dot or bracket notation.
|
|
24
|
+
|
|
25
|
+
return computed(() => {
|
|
26
|
+
return isCallChain.value ? formatCallChain(parts) : formatNonCallChain(parts);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Flattens nested access expressions into a single array of parts.
|
|
32
|
+
*/
|
|
33
|
+
function flattenAccessExpression(children) {
|
|
34
|
+
const flattened = [];
|
|
35
|
+
for (const child of children) {
|
|
36
|
+
if (isComponentCreator(child, AccessExpression)) {
|
|
37
|
+
flattened.push(...flattenAccessExpression(childrenArray(() => child.props.children)));
|
|
38
|
+
} else {
|
|
39
|
+
flattened.push(child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return flattened;
|
|
43
|
+
}
|
|
44
|
+
AccessExpression.Part = function (props) {
|
|
45
|
+
/** renders nothing, the parent AccessExpression will use these args */
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Formatting of call chains (i.e. member expressions which have more than one
|
|
50
|
+
* call in them). The general approach is that line breaks occur after each
|
|
51
|
+
* call, and there is only one call per line. When there are non-call elements,
|
|
52
|
+
* they occur prior to the call part. The first part of the member expression
|
|
53
|
+
* contains all but the last non-call part.
|
|
54
|
+
*
|
|
55
|
+
* The following is an example of proper formatting:
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* z.dummy // all but the last non-call part for the first element
|
|
59
|
+
* .object({ // the first call part with line break after
|
|
60
|
+
* a: 1,
|
|
61
|
+
* })
|
|
62
|
+
* .dummy.partial() // the next call part with non-call parts before it
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function formatCallChain(parts) {
|
|
66
|
+
return computed(() => {
|
|
67
|
+
const expression = [];
|
|
68
|
+
|
|
69
|
+
// break the expression into parts.
|
|
70
|
+
const chunks = [];
|
|
71
|
+
|
|
72
|
+
// the first part is all the non-call parts
|
|
73
|
+
let partIndex = 0;
|
|
74
|
+
function pushPart() {
|
|
75
|
+
const part = parts[partIndex];
|
|
76
|
+
if (!part) throw new Error("No part to push");
|
|
77
|
+
chunks.at(-1).push(part);
|
|
78
|
+
partIndex++;
|
|
79
|
+
}
|
|
80
|
+
function pushChunk() {
|
|
81
|
+
chunks.push([]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// For the first chunk, take all the non-call parts except the last one
|
|
85
|
+
// and put them in a chunk.
|
|
86
|
+
pushChunk();
|
|
87
|
+
while (partIndex < parts.length && (partIndex === parts.length - 1 || chunks.at(-1).length === 0 || !isArgsPart(parts[partIndex + 1]))) {
|
|
88
|
+
pushPart();
|
|
89
|
+
if (isArgsPart(chunks.at(-1).at(-1))) {
|
|
90
|
+
// the first segment always ends after we see a call
|
|
91
|
+
// if we happen to take one
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// then for all remaining parts, collect all the non-call parts and end with
|
|
97
|
+
// a call chunk
|
|
98
|
+
while (partIndex < parts.length) {
|
|
99
|
+
pushChunk();
|
|
100
|
+
while (partIndex < parts.length && !isArgsPart(parts[partIndex])) {
|
|
101
|
+
pushPart();
|
|
102
|
+
}
|
|
103
|
+
while (partIndex < parts.length && isArgsPart(parts[partIndex])) {
|
|
104
|
+
pushPart();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
|
|
108
|
+
const chunk = chunks[chunkIndex];
|
|
109
|
+
const chunkExpression = [];
|
|
110
|
+
for (let partIndex = 0; partIndex < chunk.length; partIndex++) {
|
|
111
|
+
if (chunkIndex === 0 && partIndex === 0) {
|
|
112
|
+
// first part is just gonna be the id
|
|
113
|
+
const firstPart = isIdPart(chunk[0]) ? chunk[0].id : chunk[0].indexerArgs;
|
|
114
|
+
chunkExpression.push(firstPart);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const part = chunk[partIndex];
|
|
118
|
+
const prevPart = partIndex === 0 ? chunks[chunkIndex - 1].at(-1) : chunk[partIndex - 1];
|
|
119
|
+
if (isArgsPart(part)) {
|
|
120
|
+
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
121
|
+
chunkExpression.push(formatCallExpr(prevPart, part));
|
|
122
|
+
} else if (isIdPart(part)) {
|
|
123
|
+
chunkExpression.push(formatMemberAccess(prevPart, part, true));
|
|
124
|
+
} else {
|
|
125
|
+
// bracket notation - don't include the dot
|
|
126
|
+
chunkExpression.push(formatElementAccess(prevPart, part));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
expression.push(chunkIndex === 0 ? chunkExpression : [_$createIntrinsic("sbr", {}), chunkExpression]);
|
|
130
|
+
}
|
|
131
|
+
return _$createIntrinsic("group", {
|
|
132
|
+
get children() {
|
|
133
|
+
return _$createIntrinsic("indent", {
|
|
134
|
+
children: expression
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function formatNonCallChain(parts) {
|
|
141
|
+
return computed(() => {
|
|
142
|
+
const expression = [];
|
|
143
|
+
for (let i = 0; i < parts.length; i++) {
|
|
144
|
+
const part = parts[i];
|
|
145
|
+
const base = isIdPart(part) ? part.id : part.indexerArgs;
|
|
146
|
+
if (i === 0) {
|
|
147
|
+
expression.push(base, _$createComponent(TypeArgs, {
|
|
148
|
+
get args() {
|
|
149
|
+
return part.typeArgs;
|
|
150
|
+
}
|
|
151
|
+
}));
|
|
152
|
+
} else {
|
|
153
|
+
// Determine if we should use nullish operator from previous part
|
|
154
|
+
const prevPart = parts[i - 1];
|
|
155
|
+
if (isArgsPart(part)) {
|
|
156
|
+
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
157
|
+
expression.push(formatCallExpr(prevPart, part));
|
|
158
|
+
} else if (isIdPart(part)) {
|
|
159
|
+
expression.push(formatMemberAccess(prevPart, part));
|
|
160
|
+
} else {
|
|
161
|
+
// bracket notation - don't include the dot
|
|
162
|
+
expression.push(formatElementAccess(prevPart, part));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return expression;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function formatElementAccess(prevPart, part) {
|
|
170
|
+
return _$createIntrinsic("group", {
|
|
171
|
+
get children() {
|
|
172
|
+
return [_$memo(() => part.conditional || "nullable" in prevPart && prevPart.nullable ? "?" : ""), "[", _$createIntrinsic("indent", {
|
|
173
|
+
get children() {
|
|
174
|
+
return [_$createIntrinsic("sbr", {}), _$createComponent(For, {
|
|
175
|
+
get each() {
|
|
176
|
+
return part.indexerArgs;
|
|
177
|
+
},
|
|
178
|
+
comma: true,
|
|
179
|
+
line: true,
|
|
180
|
+
children: arg => arg
|
|
181
|
+
})];
|
|
182
|
+
}
|
|
183
|
+
}), _$createIntrinsic("sbr", {}), "]"];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function formatMemberAccess(prevPart, part, noIndent = false) {
|
|
188
|
+
let Wrapping;
|
|
189
|
+
if (noIndent) {
|
|
190
|
+
Wrapping = function (props) {
|
|
191
|
+
return _$createIntrinsic("group", {
|
|
192
|
+
get children() {
|
|
193
|
+
return [_$createIntrinsic("sbr", {}), _$memo(() => props.children)];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
} else {
|
|
198
|
+
Wrapping = function (props) {
|
|
199
|
+
return _$createIntrinsic("group", {
|
|
200
|
+
get children() {
|
|
201
|
+
return _$createIntrinsic("indent", {
|
|
202
|
+
get children() {
|
|
203
|
+
return [_$createIntrinsic("sbr", {}), _$memo(() => props.children)];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return _$createComponent(Wrapping, {
|
|
211
|
+
get children() {
|
|
212
|
+
return [_$memo(() => part.conditional || "nullable" in prevPart && prevPart.nullable ? "?." : "."), _$memo(() => isIdPart(part) ? part.id : part.indexerArgs), _$createComponent(TypeArgs, {
|
|
213
|
+
get args() {
|
|
214
|
+
return part.typeArgs;
|
|
215
|
+
}
|
|
216
|
+
})];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function TypeArgs(props) {
|
|
221
|
+
return _$createComponent(Show, {
|
|
222
|
+
get when() {
|
|
223
|
+
return props.args && props.args.length > 0;
|
|
224
|
+
},
|
|
225
|
+
get children() {
|
|
226
|
+
return ["<", _$createIntrinsic("group", {
|
|
227
|
+
get children() {
|
|
228
|
+
return [_$createIntrinsic("indent", {
|
|
229
|
+
get children() {
|
|
230
|
+
return [_$createIntrinsic("sbr", {}), _$createComponent(For, {
|
|
231
|
+
get each() {
|
|
232
|
+
return props.args;
|
|
233
|
+
},
|
|
234
|
+
comma: true,
|
|
235
|
+
line: true,
|
|
236
|
+
children: arg => arg
|
|
237
|
+
})];
|
|
238
|
+
}
|
|
239
|
+
}), _$createIntrinsic("sbr", {})];
|
|
240
|
+
}
|
|
241
|
+
}), ">"];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function formatCallExpr(prevPart, part) {
|
|
246
|
+
return _$createIntrinsic("group", {
|
|
247
|
+
get children() {
|
|
248
|
+
return ["(", _$createComponent(Show, {
|
|
249
|
+
get when() {
|
|
250
|
+
return part.args.length <= 1;
|
|
251
|
+
},
|
|
252
|
+
get children() {
|
|
253
|
+
return part.args[0];
|
|
254
|
+
}
|
|
255
|
+
}), _$createComponent(Show, {
|
|
256
|
+
get when() {
|
|
257
|
+
return part.args.length > 1;
|
|
258
|
+
},
|
|
259
|
+
get children() {
|
|
260
|
+
return [_$createIntrinsic("indent", {
|
|
261
|
+
get children() {
|
|
262
|
+
return [_$createIntrinsic("sbr", {}), _$createComponent(For, {
|
|
263
|
+
get each() {
|
|
264
|
+
return part.args;
|
|
265
|
+
},
|
|
266
|
+
comma: true,
|
|
267
|
+
line: true,
|
|
268
|
+
children: arg => arg
|
|
269
|
+
})];
|
|
270
|
+
}
|
|
271
|
+
}), _$createIntrinsic("sbr", {})];
|
|
272
|
+
}
|
|
273
|
+
}), ")"];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=access-expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["childrenArray","computed","For","isComponentCreator","Show","takeSymbols","childrenToPartDescriptors","isArgsPart","isIdPart","AccessExpression","props","children","flattenAccessExpression","parts","length","isCallChain","callCount","part","value","formatCallChain","formatNonCallChain","flattened","child","push","Part","expression","chunks","partIndex","pushPart","Error","at","pushChunk","chunkIndex","chunk","chunkExpression","firstPart","id","indexerArgs","prevPart","formatCallExpr","formatMemberAccess","formatElementAccess","_$createIntrinsic","i","base","_$createComponent","TypeArgs","args","typeArgs","_$memo","conditional","nullable","each","comma","line","arg","noIndent","Wrapping","when"],"sources":["../../../../src/components/access-expression/access-expression.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAEEA,aAAa,EAEbC,QAAQ,EACRC,GAAG,EACHC,kBAAkB,EAElBC,IAAI,EACJC,WAAW,QACN,gBAAgB;AAEvB,SACEC,yBAAyB,EACzBC,UAAU,EACVC,QAAQ,QAKH,uBAAuB;AAM9B,OAAO,SAASC,gBAAgBA,CAACC,KAA4B,EAAE;EAC7D,MAAMC,QAAQ,GAAGC,uBAAuB,CAACZ,aAAa,CAAC,MAAMU,KAAK,CAACC,QAAQ,CAAC,CAAC;EAC7E,MAAME,KAAK,GAAGP,yBAAyB,CAACK,QAAQ,CAAC;;EAEjD;EACAN,WAAW,CAAC,CAAC;EAEb,IAAIQ,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;IACtB;EACF;EAEA,MAAMC,WAAW,GAAGd,QAAQ,CAAC,MAAM;IACjC,IAAIe,SAAS,GAAG,CAAC;IACjB,KAAK,MAAMC,IAAI,IAAIJ,KAAK,EAAE;MACxB,IAAIN,UAAU,CAACU,IAAI,CAAC,EAAED,SAAS,EAAE;IACnC;IAEA,OAAOA,SAAS,GAAG,CAAC;EACtB,CAAC,CAAC;;EAEF;EACA;EACA;;EAEA,OAAOf,QAAQ,CAAC,MAAM;IACpB,OAAOc,WAAW,CAACG,KAAK,GACpBC,eAAe,CAACN,KA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SAAA;MAAA,QAC5C,GAAG,EAAA+B,iBAAA;QAAA,IAAA/B,SAAA;UAAA,QAAA+B,iBAAA;YAAA,IAAA/B,SAAA;cAAA,QAAA+B,iBAAA,aAAAG,iBAAA,CAIC3C,GAAG;gBAAA,IAACkD,IAAIA,CAAA;kBAAA,OAAE1C,KAAK,CAACqC,IAAI;gBAAA;gBAAGM,KAAK;gBAACC,IAAI;gBAAA3C,QAAA,EAC9B4C,GAAG,IAAKA;cAAG;YAAA;UAAA,IAAAb,iBAAA;QAAA;MAAA,IAKlB,GAAG;IAAA;EAAA;AAGV;AAEA,SAASH,cAAcA,CACrBD,QAAwB,EACxBrB,IAA4B,EAC5B;EACA,OAAAyB,iBAAA;IAAA,IAAA/B,SAAA;MAAA,aAAAkC,iBAAA,CAEMzC,IAAI;QAAA,IAACsD,IAAIA,CAAA;UAAA,OAAEzC,IAAI,CAAC8B,IAAI,CAACjC,MAAM,IAAI,CAAC;QAAA;QAAA,IAAAH,SAAA;UAAA,OAAGM,IAAI,CAAC8B,IAAI,CAAC,CAAC,CAAC;QAAA;MAAA,IAAAF,iBAAA,CAChDzC,IAAI;QAAA,IAACsD,IAAIA,CAAA;UAAA,OAAEzC,IAAI,CAAC8B,IAAI,CAACjC,MAAM,GAAG,CAAC;QAAA;QAAA,IAAAH,SAAA;UAAA,QAAA+B,iBAAA;YAAA,IAAA/B,SAAA;cAAA,QAAA+B,iBAAA,aAAAG,iBAAA,CAG3B3C,GAAG;gBAAA,IAACkD,IAAIA,CAAA;kBAAA,OAAEnC,IAAI,CAAC8B,IAAI;gBAAA;gBAAEM,KAAK;gBAACC,IAAI;gBAAA3C,QAAA,EAC5B4C,GAAG,IAAKA;cAAG;YAAA;UAAA,IAAAb,iBAAA;QAAA;MAAA;IAAA;EAAA;AAQzB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-expression.test.d.ts","sourceRoot":"","sources":["../../../../src/components/access-expression/access-expression.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { ClassDeclaration } from "#components/class/declaration.js";
|
|
3
|
+
import { Method } from "#components/method/method.js";
|
|
4
|
+
import { TestNamespace } from "#test/utils.js";
|
|
5
|
+
import { List, namekey, printTree, renderTree } from "@alloy-js/core";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { CSharpSymbol } from "../../symbols/csharp.js";
|
|
8
|
+
import { AccessExpression } from "./access-expression.js";
|
|
9
|
+
it("makes a member access expression", () => {
|
|
10
|
+
const template = _$createComponent(AccessExpression, {
|
|
11
|
+
get children() {
|
|
12
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
13
|
+
id: "Foo"
|
|
14
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
15
|
+
id: "Bar"
|
|
16
|
+
})];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
expect(template).toRenderTo(`Foo.Bar`);
|
|
20
|
+
});
|
|
21
|
+
it("makes an element access expression", () => {
|
|
22
|
+
const template = _$createComponent(AccessExpression, {
|
|
23
|
+
get children() {
|
|
24
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
25
|
+
id: "Foo"
|
|
26
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
27
|
+
index: 1
|
|
28
|
+
})];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
expect(template).toRenderTo(`Foo[1]`);
|
|
32
|
+
});
|
|
33
|
+
it("makes a call expression", () => {
|
|
34
|
+
const template = _$createComponent(AccessExpression, {
|
|
35
|
+
get children() {
|
|
36
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
37
|
+
id: "Foo"
|
|
38
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
39
|
+
args: [1, 2, 3]
|
|
40
|
+
})];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
expect(template).toRenderTo(`Foo(1, 2, 3)`);
|
|
44
|
+
});
|
|
45
|
+
it("makes an id part from a symbol", () => {
|
|
46
|
+
const symbol = new CSharpSymbol("Symbol", undefined);
|
|
47
|
+
const template = _$createComponent(AccessExpression, {
|
|
48
|
+
get children() {
|
|
49
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
50
|
+
id: "Foo"
|
|
51
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
52
|
+
symbol: symbol
|
|
53
|
+
})];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
expect(template).toRenderTo(`Foo.Symbol`);
|
|
57
|
+
});
|
|
58
|
+
it("makes an id part from a symbol reactively", () => {
|
|
59
|
+
const symbol = new CSharpSymbol("Symbol", undefined);
|
|
60
|
+
const tree = renderTree(_$createComponent(AccessExpression, {
|
|
61
|
+
get children() {
|
|
62
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
63
|
+
id: "Foo"
|
|
64
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
65
|
+
symbol: symbol
|
|
66
|
+
})];
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
expect(printTree(tree)).toEqual("Foo.Symbol");
|
|
70
|
+
symbol.name = "Bar";
|
|
71
|
+
expect(printTree(tree)).toEqual("Foo.Bar");
|
|
72
|
+
});
|
|
73
|
+
it("makes an id part from refkey, where the first part is a full reference, and subsequent parts are just the id", () => {
|
|
74
|
+
const methodKey = namekey("method");
|
|
75
|
+
const template = _$createComponent(TestNamespace, {
|
|
76
|
+
get children() {
|
|
77
|
+
return _$createComponent(List, {
|
|
78
|
+
get children() {
|
|
79
|
+
return [_$createComponent(ClassDeclaration, {
|
|
80
|
+
name: "MyClass",
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(Method, {
|
|
83
|
+
name: methodKey
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}), _$createComponent(AccessExpression, {
|
|
87
|
+
get children() {
|
|
88
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
89
|
+
refkey: methodKey
|
|
90
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
91
|
+
refkey: methodKey
|
|
92
|
+
})];
|
|
93
|
+
}
|
|
94
|
+
})];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
expect(template).toRenderTo(`
|
|
100
|
+
class MyClass
|
|
101
|
+
{
|
|
102
|
+
void Method() {}
|
|
103
|
+
}
|
|
104
|
+
MyClass.Method.Method
|
|
105
|
+
`);
|
|
106
|
+
});
|
|
107
|
+
it("takes type args", () => {
|
|
108
|
+
const template = _$createComponent(AccessExpression, {
|
|
109
|
+
get children() {
|
|
110
|
+
return _$createComponent(AccessExpression.Part, {
|
|
111
|
+
id: "Foo",
|
|
112
|
+
typeArgs: ["Foo", "Bar"]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
expect(template).toRenderTo(`Foo<Foo, Bar>`);
|
|
117
|
+
});
|
|
118
|
+
it("takes multiple indexer arguments", () => {
|
|
119
|
+
const template = _$createComponent(AccessExpression, {
|
|
120
|
+
get children() {
|
|
121
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
122
|
+
id: "Foo"
|
|
123
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
124
|
+
indexerArgs: ["arg1", "arg2"]
|
|
125
|
+
})];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
expect(template).toRenderTo(`Foo[arg1, arg2]`);
|
|
129
|
+
});
|
|
130
|
+
it("allows nullable member access", () => {
|
|
131
|
+
const template = _$createComponent(AccessExpression, {
|
|
132
|
+
get children() {
|
|
133
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
134
|
+
id: "Foo",
|
|
135
|
+
nullable: true
|
|
136
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
137
|
+
id: "Bar"
|
|
138
|
+
})];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
expect(template).toRenderTo(`Foo?.Bar`);
|
|
142
|
+
});
|
|
143
|
+
it("allows conditional member access", () => {
|
|
144
|
+
const template = _$createComponent(AccessExpression, {
|
|
145
|
+
get children() {
|
|
146
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
147
|
+
id: "Foo"
|
|
148
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
149
|
+
id: "Bar",
|
|
150
|
+
conditional: true
|
|
151
|
+
})];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
expect(template).toRenderTo(`Foo?.Bar`);
|
|
155
|
+
});
|
|
156
|
+
it("allows nullable element access", () => {
|
|
157
|
+
const template = _$createComponent(AccessExpression, {
|
|
158
|
+
get children() {
|
|
159
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
160
|
+
id: "Foo",
|
|
161
|
+
nullable: true
|
|
162
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
163
|
+
index: 1
|
|
164
|
+
})];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
expect(template).toRenderTo(`Foo?[1]`);
|
|
168
|
+
});
|
|
169
|
+
it("allows conditional element access", () => {
|
|
170
|
+
const template = _$createComponent(AccessExpression, {
|
|
171
|
+
get children() {
|
|
172
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
173
|
+
id: "Foo"
|
|
174
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
175
|
+
index: 1,
|
|
176
|
+
conditional: true
|
|
177
|
+
})];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
expect(template).toRenderTo(`Foo?[1]`);
|
|
181
|
+
});
|
|
182
|
+
it("uses symbol information for nullability", () => {
|
|
183
|
+
const symbol = new CSharpSymbol("Symbol", undefined, {
|
|
184
|
+
isNullable: true
|
|
185
|
+
});
|
|
186
|
+
const typeSymbol = new CSharpSymbol("SomeType", undefined, {
|
|
187
|
+
isNullable: true
|
|
188
|
+
});
|
|
189
|
+
const typedSymbol = new CSharpSymbol("SomeValue", undefined, {
|
|
190
|
+
type: typeSymbol
|
|
191
|
+
});
|
|
192
|
+
const template = _$createComponent(AccessExpression, {
|
|
193
|
+
get children() {
|
|
194
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
195
|
+
symbol: symbol
|
|
196
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
197
|
+
symbol: typedSymbol
|
|
198
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
199
|
+
id: "Foo"
|
|
200
|
+
})];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
expect(template).toRenderTo(`Symbol?.SomeValue?.Foo`);
|
|
204
|
+
});
|
|
205
|
+
describe("formatting", () => {
|
|
206
|
+
it("breaks long identifier chains", () => {
|
|
207
|
+
const template = _$createComponent(AccessExpression, {
|
|
208
|
+
get children() {
|
|
209
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
210
|
+
id: "Foo"
|
|
211
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
212
|
+
id: "Foo"
|
|
213
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
214
|
+
id: "Foo"
|
|
215
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
216
|
+
id: "Foo"
|
|
217
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
218
|
+
id: "Foo"
|
|
219
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
220
|
+
id: "Foo"
|
|
221
|
+
})];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
expect(template).toRenderTo(`
|
|
225
|
+
Foo.Foo
|
|
226
|
+
.Foo.Foo
|
|
227
|
+
.Foo.Foo
|
|
228
|
+
`, {
|
|
229
|
+
printWidth: 10
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
it("breaks long call expressions", () => {
|
|
233
|
+
const template = _$createComponent(AccessExpression, {
|
|
234
|
+
get children() {
|
|
235
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
236
|
+
id: "Foo"
|
|
237
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
238
|
+
id: "Bar"
|
|
239
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
240
|
+
args: ["variable1", "variable2", "variable3"]
|
|
241
|
+
})];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
expect(template).toRenderTo(`
|
|
245
|
+
Foo.Bar(
|
|
246
|
+
variable1,
|
|
247
|
+
variable2,
|
|
248
|
+
variable3
|
|
249
|
+
)
|
|
250
|
+
`, {
|
|
251
|
+
printWidth: 10
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
it("breaks long type args", () => {
|
|
255
|
+
const template = _$createComponent(AccessExpression, {
|
|
256
|
+
get children() {
|
|
257
|
+
return _$createComponent(AccessExpression.Part, {
|
|
258
|
+
id: "Foo",
|
|
259
|
+
typeArgs: ["Foo", "Bar", "Baz", "Qux"]
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
expect(template).toRenderTo(`
|
|
264
|
+
Foo<
|
|
265
|
+
Foo,
|
|
266
|
+
Bar,
|
|
267
|
+
Baz,
|
|
268
|
+
Qux
|
|
269
|
+
>
|
|
270
|
+
`, {
|
|
271
|
+
printWidth: 10
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
it("breaks long type args for second member", () => {
|
|
275
|
+
const template = _$createComponent(AccessExpression, {
|
|
276
|
+
get children() {
|
|
277
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
278
|
+
id: "Foo"
|
|
279
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
280
|
+
id: "Bar",
|
|
281
|
+
typeArgs: ["Foo", "Bar", "Baz", "Qux"]
|
|
282
|
+
})];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
expect(template).toRenderTo(`
|
|
286
|
+
Foo
|
|
287
|
+
.Bar<
|
|
288
|
+
Foo,
|
|
289
|
+
Bar,
|
|
290
|
+
Baz,
|
|
291
|
+
Qux
|
|
292
|
+
>
|
|
293
|
+
`, {
|
|
294
|
+
printWidth: 10
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
it("formats builder pattern", () => {
|
|
298
|
+
const template = _$createComponent(AccessExpression, {
|
|
299
|
+
get children() {
|
|
300
|
+
return [_$createComponent(AccessExpression.Part, {
|
|
301
|
+
id: "Foo"
|
|
302
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
303
|
+
id: "Bar"
|
|
304
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
305
|
+
id: "Baz"
|
|
306
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
307
|
+
args: true
|
|
308
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
309
|
+
id: "Qux"
|
|
310
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
311
|
+
id: "Quux",
|
|
312
|
+
typeArgs: ["TTypeOne", "TTypeTwo"]
|
|
313
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
314
|
+
indexerArgs: ["arg1", "arg2"]
|
|
315
|
+
}), _$createComponent(AccessExpression.Part, {
|
|
316
|
+
args: true
|
|
317
|
+
})];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
expect(template).toRenderTo(`
|
|
321
|
+
Foo.Bar
|
|
322
|
+
.Baz()
|
|
323
|
+
.Qux
|
|
324
|
+
.Quux<
|
|
325
|
+
TTypeOne,
|
|
326
|
+
TTypeTwo
|
|
327
|
+
>[
|
|
328
|
+
arg1,
|
|
329
|
+
arg2
|
|
330
|
+
]()
|
|
331
|
+
`, {
|
|
332
|
+
printWidth: 10
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
//# sourceMappingURL=access-expression.test.js.map
|