@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
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
|
-
import { expect, it } from "vitest";
|
|
4
|
-
import { MemberChainExpression } from "../src/components/MemberChainExpression.js";
|
|
5
|
-
import { FunctionCallExpression, ValueExpression } from "../src/index.js";
|
|
6
|
-
import { toSourceText } from "./utils.js";
|
|
7
|
-
it("works", () => {
|
|
8
|
-
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
9
|
-
get children() {
|
|
10
|
-
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
11
|
-
target: "string"
|
|
12
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
13
|
-
target: "array"
|
|
14
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
15
|
-
target: "min",
|
|
16
|
-
args: [5]
|
|
17
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
18
|
-
target: "max",
|
|
19
|
-
args: [10]
|
|
20
|
-
})];
|
|
21
|
-
}
|
|
22
|
-
}), {
|
|
23
|
-
printWidth: 10
|
|
24
|
-
})).toBe(d`
|
|
25
|
-
z.string()
|
|
26
|
-
.array()
|
|
27
|
-
.min(5)
|
|
28
|
-
.max(10)
|
|
29
|
-
`);
|
|
30
|
-
});
|
|
31
|
-
it("works with args which break", () => {
|
|
32
|
-
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
33
|
-
get children() {
|
|
34
|
-
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
35
|
-
target: "object",
|
|
36
|
-
get args() {
|
|
37
|
-
return [_$createComponent(ValueExpression, {
|
|
38
|
-
jsValue: {
|
|
39
|
-
a: 1,
|
|
40
|
-
b: 2
|
|
41
|
-
}
|
|
42
|
-
})];
|
|
43
|
-
}
|
|
44
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
45
|
-
target: "array"
|
|
46
|
-
})];
|
|
47
|
-
}
|
|
48
|
-
}), {
|
|
49
|
-
printWidth: 10
|
|
50
|
-
})).toBe(d`
|
|
51
|
-
z.object({
|
|
52
|
-
a: 1,
|
|
53
|
-
b: 2,
|
|
54
|
-
})
|
|
55
|
-
.array()
|
|
56
|
-
`);
|
|
57
|
-
});
|
|
58
|
-
it("works with args when it doesn't break", () => {
|
|
59
|
-
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
60
|
-
get children() {
|
|
61
|
-
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
62
|
-
target: "object",
|
|
63
|
-
get args() {
|
|
64
|
-
return [_$createComponent(ValueExpression, {
|
|
65
|
-
jsValue: {
|
|
66
|
-
a: 1,
|
|
67
|
-
b: 2
|
|
68
|
-
}
|
|
69
|
-
})];
|
|
70
|
-
}
|
|
71
|
-
})];
|
|
72
|
-
}
|
|
73
|
-
}))).toBe(d`
|
|
74
|
-
z.object({
|
|
75
|
-
a: 1,
|
|
76
|
-
b: 2,
|
|
77
|
-
})
|
|
78
|
-
`);
|
|
79
|
-
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
80
|
-
get children() {
|
|
81
|
-
return [["z"], ["z2"], ["z3"], _$createComponent(FunctionCallExpression, {
|
|
82
|
-
target: "object",
|
|
83
|
-
get args() {
|
|
84
|
-
return [_$createComponent(ValueExpression, {
|
|
85
|
-
jsValue: {
|
|
86
|
-
a: 1,
|
|
87
|
-
b: 2
|
|
88
|
-
}
|
|
89
|
-
})];
|
|
90
|
-
}
|
|
91
|
-
})];
|
|
92
|
-
}
|
|
93
|
-
}))).toBe(d`
|
|
94
|
-
z.z2.z3.object({
|
|
95
|
-
a: 1,
|
|
96
|
-
b: 2,
|
|
97
|
-
})
|
|
98
|
-
`);
|
|
99
|
-
});
|
|
100
|
-
it("works with nested call member chains", () => {
|
|
101
|
-
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
102
|
-
get children() {
|
|
103
|
-
return [["z"], _$createComponent(FunctionCallExpression, {
|
|
104
|
-
target: "string"
|
|
105
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
106
|
-
target: "array"
|
|
107
|
-
}), _$createComponent(MemberChainExpression, {
|
|
108
|
-
get children() {
|
|
109
|
-
return [_$createComponent(FunctionCallExpression, {
|
|
110
|
-
target: "min",
|
|
111
|
-
args: [5]
|
|
112
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
113
|
-
target: "max",
|
|
114
|
-
args: [10]
|
|
115
|
-
})];
|
|
116
|
-
}
|
|
117
|
-
}), _$createComponent(FunctionCallExpression, {
|
|
118
|
-
target: "array"
|
|
119
|
-
})];
|
|
120
|
-
}
|
|
121
|
-
}), {
|
|
122
|
-
printWidth: 10
|
|
123
|
-
})).toBe(d`
|
|
124
|
-
z.string()
|
|
125
|
-
.array()
|
|
126
|
-
.min(5)
|
|
127
|
-
.max(10)
|
|
128
|
-
.array()
|
|
129
|
-
`);
|
|
130
|
-
});
|
|
131
|
-
it("works without function call expressions", () => {
|
|
132
|
-
expect(toSourceText(_$createComponent(MemberChainExpression, {
|
|
133
|
-
get children() {
|
|
134
|
-
return [["z"], ["string"], ["min"]];
|
|
135
|
-
}
|
|
136
|
-
}), {
|
|
137
|
-
printWidth: 5
|
|
138
|
-
})).toBe(d`
|
|
139
|
-
z.string.min
|
|
140
|
-
`);
|
|
141
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { childrenArray, computed, For, List, Show } from "@alloy-js/core";
|
|
2
|
-
import { Children, isComponentCreator } from "@alloy-js/core/jsx-runtime";
|
|
3
|
-
import { FunctionCallExpression } from "./FunctionCallExpression.jsx";
|
|
4
|
-
|
|
5
|
-
export interface MemberChainExpressionProps {
|
|
6
|
-
children: Children;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create a member chain expression, which is a member expression comprised of
|
|
11
|
-
* either children, {@link FunctionCallExpression} components, or nested member
|
|
12
|
-
* chain expression components. Other component types are ignored.
|
|
13
|
-
*/
|
|
14
|
-
export function MemberChainExpression(props: MemberChainExpressionProps) {
|
|
15
|
-
// chunks are constructed by consuming as many non-call expressions as
|
|
16
|
-
// possible, then placing an indent and soft line break before and after the
|
|
17
|
-
// any subsequent call expressions
|
|
18
|
-
|
|
19
|
-
const chunks = computed(() => {
|
|
20
|
-
const children = flattenCallChains(childrenArray(() => props.children));
|
|
21
|
-
const chunks: Children[][] = [];
|
|
22
|
-
|
|
23
|
-
let currentChunk: Children[] = [];
|
|
24
|
-
|
|
25
|
-
for (const child of children) {
|
|
26
|
-
if (
|
|
27
|
-
isComponentCreator(child) &&
|
|
28
|
-
child.component === FunctionCallExpression
|
|
29
|
-
) {
|
|
30
|
-
if (currentChunk.length > 0) {
|
|
31
|
-
chunks.push(currentChunk);
|
|
32
|
-
currentChunk = [];
|
|
33
|
-
}
|
|
34
|
-
chunks.push([child]);
|
|
35
|
-
} else {
|
|
36
|
-
currentChunk.push(child);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (currentChunk.length > 0) {
|
|
41
|
-
chunks.push(currentChunk);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return [chunks[0], chunks.slice(1)];
|
|
45
|
-
});
|
|
46
|
-
const groupId = Symbol();
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<group>
|
|
50
|
-
<group id={groupId}>
|
|
51
|
-
<List joiner="." children={chunks.value[0]} />
|
|
52
|
-
</group>
|
|
53
|
-
<Show when={chunks.value[1].length === 1}>
|
|
54
|
-
<For each={chunks.value[1]} softline>
|
|
55
|
-
{(chunk) => (
|
|
56
|
-
<>
|
|
57
|
-
.<List joiner="." children={chunk} />
|
|
58
|
-
</>
|
|
59
|
-
)}
|
|
60
|
-
</For>
|
|
61
|
-
</Show>
|
|
62
|
-
<Show when={chunks.value[1].length > 1}>
|
|
63
|
-
<indent>
|
|
64
|
-
<For each={chunks.value[1]} softline>
|
|
65
|
-
{(chunk) => (
|
|
66
|
-
<>
|
|
67
|
-
.<List joiner="." children={chunk} />
|
|
68
|
-
</>
|
|
69
|
-
)}
|
|
70
|
-
</For>
|
|
71
|
-
</indent>
|
|
72
|
-
</Show>
|
|
73
|
-
</group>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function flattenCallChains(children: Children[]): Children[] {
|
|
78
|
-
const flatChildren = [];
|
|
79
|
-
for (const child of children) {
|
|
80
|
-
if (
|
|
81
|
-
isComponentCreator(child) &&
|
|
82
|
-
child.component === MemberChainExpression
|
|
83
|
-
) {
|
|
84
|
-
flatChildren.push(...flattenCallChains(child.props.children));
|
|
85
|
-
} else {
|
|
86
|
-
flatChildren.push(child);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return flatChildren;
|
|
91
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { d } from "@alloy-js/core/testing";
|
|
2
|
-
import { expect, it } from "vitest";
|
|
3
|
-
import { MemberChainExpression } from "../src/components/MemberChainExpression.jsx";
|
|
4
|
-
import { FunctionCallExpression, ValueExpression } from "../src/index.js";
|
|
5
|
-
import { toSourceText } from "./utils.js";
|
|
6
|
-
|
|
7
|
-
it("works", () => {
|
|
8
|
-
expect(
|
|
9
|
-
toSourceText(
|
|
10
|
-
<MemberChainExpression>
|
|
11
|
-
<>z</>
|
|
12
|
-
<FunctionCallExpression target="string" />
|
|
13
|
-
<FunctionCallExpression target="array" />
|
|
14
|
-
<FunctionCallExpression target="min" args={[5]} />
|
|
15
|
-
<FunctionCallExpression target="max" args={[10]} />
|
|
16
|
-
</MemberChainExpression>,
|
|
17
|
-
{ printWidth: 10 },
|
|
18
|
-
),
|
|
19
|
-
).toBe(d`
|
|
20
|
-
z.string()
|
|
21
|
-
.array()
|
|
22
|
-
.min(5)
|
|
23
|
-
.max(10)
|
|
24
|
-
`);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("works with args which break", () => {
|
|
28
|
-
expect(
|
|
29
|
-
toSourceText(
|
|
30
|
-
<MemberChainExpression>
|
|
31
|
-
<>z</>
|
|
32
|
-
<FunctionCallExpression
|
|
33
|
-
target="object"
|
|
34
|
-
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
35
|
-
/>
|
|
36
|
-
<FunctionCallExpression target="array" />
|
|
37
|
-
</MemberChainExpression>,
|
|
38
|
-
{ printWidth: 10 },
|
|
39
|
-
),
|
|
40
|
-
).toBe(d`
|
|
41
|
-
z.object({
|
|
42
|
-
a: 1,
|
|
43
|
-
b: 2,
|
|
44
|
-
})
|
|
45
|
-
.array()
|
|
46
|
-
`);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("works with args when it doesn't break", () => {
|
|
50
|
-
expect(
|
|
51
|
-
toSourceText(
|
|
52
|
-
<MemberChainExpression>
|
|
53
|
-
<>z</>
|
|
54
|
-
<FunctionCallExpression
|
|
55
|
-
target="object"
|
|
56
|
-
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
57
|
-
/>
|
|
58
|
-
</MemberChainExpression>,
|
|
59
|
-
),
|
|
60
|
-
).toBe(d`
|
|
61
|
-
z.object({
|
|
62
|
-
a: 1,
|
|
63
|
-
b: 2,
|
|
64
|
-
})
|
|
65
|
-
`);
|
|
66
|
-
|
|
67
|
-
expect(
|
|
68
|
-
toSourceText(
|
|
69
|
-
<MemberChainExpression>
|
|
70
|
-
<>z</>
|
|
71
|
-
<>z2</>
|
|
72
|
-
<>z3</>
|
|
73
|
-
<FunctionCallExpression
|
|
74
|
-
target="object"
|
|
75
|
-
args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
|
|
76
|
-
/>
|
|
77
|
-
</MemberChainExpression>,
|
|
78
|
-
),
|
|
79
|
-
).toBe(d`
|
|
80
|
-
z.z2.z3.object({
|
|
81
|
-
a: 1,
|
|
82
|
-
b: 2,
|
|
83
|
-
})
|
|
84
|
-
`);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("works with nested call member chains", () => {
|
|
88
|
-
expect(
|
|
89
|
-
toSourceText(
|
|
90
|
-
<MemberChainExpression>
|
|
91
|
-
<>z</>
|
|
92
|
-
<FunctionCallExpression target="string" />
|
|
93
|
-
<FunctionCallExpression target="array" />
|
|
94
|
-
<MemberChainExpression>
|
|
95
|
-
<FunctionCallExpression target="min" args={[5]} />
|
|
96
|
-
<FunctionCallExpression target="max" args={[10]} />
|
|
97
|
-
</MemberChainExpression>
|
|
98
|
-
<FunctionCallExpression target="array" />
|
|
99
|
-
</MemberChainExpression>,
|
|
100
|
-
{ printWidth: 10 },
|
|
101
|
-
),
|
|
102
|
-
).toBe(d`
|
|
103
|
-
z.string()
|
|
104
|
-
.array()
|
|
105
|
-
.min(5)
|
|
106
|
-
.max(10)
|
|
107
|
-
.array()
|
|
108
|
-
`);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("works without function call expressions", () => {
|
|
112
|
-
expect(
|
|
113
|
-
toSourceText(
|
|
114
|
-
<MemberChainExpression>
|
|
115
|
-
<>z</>
|
|
116
|
-
<>string</>
|
|
117
|
-
<>min</>
|
|
118
|
-
</MemberChainExpression>,
|
|
119
|
-
{ printWidth: 5 },
|
|
120
|
-
),
|
|
121
|
-
).toBe(d`
|
|
122
|
-
z.string.min
|
|
123
|
-
`);
|
|
124
|
-
});
|