ripple 0.3.72 → 0.3.74
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 +66 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +2 -8
- package/src/runtime/index-client.js +3 -13
- package/src/runtime/internal/client/blocks.js +3 -25
- package/src/runtime/internal/client/for.js +80 -5
- package/src/runtime/internal/client/index.js +0 -2
- package/src/runtime/internal/client/types.d.ts +0 -10
- package/tests/client/__snapshots__/computed-properties.test.tsrx.snap +8 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +22 -0
- package/tests/client/__snapshots__/html.test.tsrx.snap +4 -0
- package/tests/client/array/array.copy-within.test.tsrx +19 -19
- package/tests/client/array/array.derived.test.tsrx +97 -109
- package/tests/client/array/array.iteration.test.tsrx +28 -28
- package/tests/client/array/array.mutations.test.tsrx +68 -68
- package/tests/client/array/array.static.test.tsrx +82 -92
- package/tests/client/array/array.to-methods.test.tsrx +15 -15
- package/tests/client/async-suspend.test.tsrx +180 -179
- package/tests/client/basic/__snapshots__/basic.attributes.test.tsrx.snap +2 -0
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +4 -0
- package/tests/client/basic/basic.attributes.test.tsrx +273 -317
- package/tests/client/basic/basic.collections.test.tsrx +55 -61
- package/tests/client/basic/basic.components.test.tsrx +196 -218
- package/tests/client/basic/basic.errors.test.tsrx +70 -76
- package/tests/client/basic/basic.events.test.tsrx +80 -85
- package/tests/client/basic/basic.get-set.test.tsrx +54 -64
- package/tests/client/basic/basic.hmr.test.tsrx +15 -19
- package/tests/client/basic/basic.reactivity.test.tsrx +121 -135
- package/tests/client/basic/basic.rendering.test.tsrx +273 -178
- package/tests/client/basic/basic.utilities.test.tsrx +8 -10
- package/tests/client/boundaries.test.tsrx +18 -18
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -76
- package/tests/client/compiler/compiler.attributes.test.tsrx +18 -14
- package/tests/client/compiler/compiler.basic.test.tsrx +357 -288
- package/tests/client/compiler/compiler.regex.test.tsrx +40 -44
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +57 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +4 -3
- package/tests/client/composite/composite.dynamic-components.test.tsrx +41 -44
- package/tests/client/composite/composite.generics.test.tsrx +165 -167
- package/tests/client/composite/composite.props.test.tsrx +66 -74
- package/tests/client/composite/composite.reactivity.test.tsrx +132 -166
- package/tests/client/composite/composite.render.test.tsrx +92 -101
- package/tests/client/computed-properties.test.tsrx +14 -18
- package/tests/client/context.test.tsrx +14 -18
- package/tests/client/css/global-additional-cases.test.tsrx +491 -437
- package/tests/client/css/global-advanced-selectors.test.tsrx +169 -153
- package/tests/client/css/global-at-rules.test.tsrx +71 -66
- package/tests/client/css/global-basic.test.tsrx +105 -98
- package/tests/client/css/global-classes-ids.test.tsrx +128 -114
- package/tests/client/css/global-combinators.test.tsrx +83 -78
- package/tests/client/css/global-complex-nesting.test.tsrx +134 -120
- package/tests/client/css/global-edge-cases.test.tsrx +138 -120
- package/tests/client/css/global-keyframes.test.tsrx +108 -96
- package/tests/client/css/global-nested.test.tsrx +88 -78
- package/tests/client/css/global-pseudo.test.tsrx +104 -98
- package/tests/client/css/global-scoping.test.tsrx +145 -125
- package/tests/client/css/style-identifier.test.tsrx +62 -69
- package/tests/client/date.test.tsrx +83 -83
- package/tests/client/dynamic-elements.test.tsrx +227 -283
- package/tests/client/events.test.tsrx +252 -266
- package/tests/client/for.test.tsrx +120 -127
- package/tests/client/head.test.tsrx +40 -48
- package/tests/client/html.test.tsrx +37 -49
- package/tests/client/input-value.test.tsrx +1125 -1354
- package/tests/client/lazy-array.test.tsrx +10 -16
- package/tests/client/lazy-destructuring.test.tsrx +169 -221
- package/tests/client/map.test.tsrx +39 -41
- package/tests/client/media-query.test.tsrx +15 -19
- package/tests/client/object.test.tsrx +46 -56
- package/tests/client/portal.test.tsrx +31 -37
- package/tests/client/ref.test.tsrx +173 -193
- package/tests/client/return.test.tsrx +62 -37
- package/tests/client/set.test.tsrx +33 -33
- package/tests/client/svg.test.tsrx +195 -215
- package/tests/client/switch.test.tsrx +201 -191
- package/tests/client/track-async-hydration.test.tsrx +14 -18
- package/tests/client/tracked-index-access.test.tsrx +18 -28
- package/tests/client/try.test.tsrx +494 -619
- package/tests/client/tsx.test.tsrx +286 -292
- package/tests/client/typescript-generics.test.tsrx +121 -129
- package/tests/client/url/url.derived.test.tsrx +21 -25
- package/tests/client/url/url.parsing.test.tsrx +35 -35
- package/tests/client/url/url.partial-removal.test.tsrx +32 -32
- package/tests/client/url/url.reactivity.test.tsrx +68 -72
- package/tests/client/url/url.serialization.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +21 -27
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +16 -16
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +37 -37
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +56 -60
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +32 -34
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +9 -9
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +10 -10
- package/tests/hydration/compiled/client/basic.js +390 -319
- package/tests/hydration/compiled/client/composite.js +52 -44
- package/tests/hydration/compiled/client/for.js +734 -604
- package/tests/hydration/compiled/client/head.js +183 -103
- package/tests/hydration/compiled/client/html.js +93 -86
- package/tests/hydration/compiled/client/if-children.js +95 -71
- package/tests/hydration/compiled/client/if.js +113 -89
- package/tests/hydration/compiled/client/mixed-control-flow.js +225 -209
- package/tests/hydration/compiled/client/nested-control-flow.js +94 -98
- package/tests/hydration/compiled/client/reactivity.js +26 -24
- package/tests/hydration/compiled/client/return.js +8 -42
- package/tests/hydration/compiled/client/switch.js +208 -173
- package/tests/hydration/compiled/client/track-async-serialization.js +176 -128
- package/tests/hydration/compiled/client/try.js +29 -21
- package/tests/hydration/compiled/server/basic.js +210 -221
- package/tests/hydration/compiled/server/composite.js +13 -14
- package/tests/hydration/compiled/server/for.js +427 -444
- package/tests/hydration/compiled/server/head.js +199 -189
- package/tests/hydration/compiled/server/html.js +33 -41
- package/tests/hydration/compiled/server/if-children.js +114 -117
- package/tests/hydration/compiled/server/if.js +77 -83
- package/tests/hydration/compiled/server/mixed-control-flow.js +145 -150
- package/tests/hydration/compiled/server/nested-control-flow.js +10 -0
- package/tests/hydration/compiled/server/reactivity.js +24 -22
- package/tests/hydration/compiled/server/return.js +6 -18
- package/tests/hydration/compiled/server/switch.js +179 -176
- package/tests/hydration/compiled/server/track-async-serialization.js +88 -70
- package/tests/hydration/compiled/server/try.js +31 -35
- package/tests/hydration/components/basic.tsrx +216 -258
- package/tests/hydration/components/composite.tsrx +32 -42
- package/tests/hydration/components/events.tsrx +81 -101
- package/tests/hydration/components/for.tsrx +270 -336
- package/tests/hydration/components/head.tsrx +43 -39
- package/tests/hydration/components/hmr.tsrx +16 -22
- package/tests/hydration/components/html-in-template.tsrx +15 -21
- package/tests/hydration/components/html.tsrx +442 -526
- package/tests/hydration/components/if-children.tsrx +107 -125
- package/tests/hydration/components/if.tsrx +68 -90
- package/tests/hydration/components/mixed-control-flow.tsrx +65 -72
- package/tests/hydration/components/nested-control-flow.tsrx +202 -216
- package/tests/hydration/components/portal.tsrx +33 -41
- package/tests/hydration/components/reactivity.tsrx +26 -34
- package/tests/hydration/components/return.tsrx +4 -6
- package/tests/hydration/components/switch.tsrx +73 -78
- package/tests/hydration/components/track-async-serialization.tsrx +83 -93
- package/tests/hydration/components/try.tsrx +37 -51
- package/tests/hydration/switch.test.js +8 -8
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +117 -162
- package/tests/server/basic.components.test.tsrx +163 -193
- package/tests/server/basic.test.tsrx +298 -198
- package/tests/server/compiler.test.tsrx +142 -72
- package/tests/server/composite.props.test.tsrx +54 -58
- package/tests/server/composite.test.tsrx +165 -167
- package/tests/server/context.test.tsrx +13 -17
- package/tests/server/dynamic-elements.test.tsrx +103 -135
- package/tests/server/for.test.tsrx +115 -84
- package/tests/server/head.test.tsrx +31 -31
- package/tests/server/html-nesting-validation.test.tsrx +16 -8
- package/tests/server/if.test.tsrx +49 -59
- package/tests/server/lazy-destructuring.test.tsrx +288 -366
- package/tests/server/return.test.tsrx +58 -36
- package/tests/server/streaming-ssr.test.tsrx +4 -4
- package/tests/server/style-identifier.test.tsrx +58 -66
- package/tests/server/switch.test.tsrx +89 -97
- package/tests/server/track-async-serialization.test.tsrx +85 -103
- package/tests/server/try.test.tsrx +275 -360
- package/tests/utils/ref-types.test.js +72 -0
- package/tests/utils/vite-plugin-config.test.js +41 -74
- package/types/index.d.ts +1 -0
- package/src/runtime/internal/client/compat.js +0 -40
- package/tests/utils/compiler-compat-config.test.js +0 -38
|
@@ -2,189 +2,187 @@ import { RippleArray, RippleMap } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('composite > generics', () => {
|
|
4
4
|
it('handles advanced generic ambiguity and edge cases', () => {
|
|
5
|
-
function App() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function App() @{
|
|
6
|
+
const maybe = {
|
|
7
|
+
factory: function <T>() {
|
|
8
|
+
return {
|
|
9
|
+
make: function <U>() {
|
|
10
|
+
return 1;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
const g = maybe?.factory<number>()?.make<boolean>();
|
|
16
|
+
// 8. Comparison operator (ensure '<' here NOT misparsed as generics)
|
|
17
|
+
let x = 10, y = 20;
|
|
18
|
+
const h =
|
|
19
|
+
x < y ? 'lt' : 'ge';
|
|
20
|
+
// 9. Chained comparisons with intervening generics
|
|
21
|
+
class Box<T> {
|
|
22
|
+
value: T;
|
|
23
|
+
|
|
24
|
+
constructor(value: T) {
|
|
25
|
+
this.value = value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
open<U>() {
|
|
29
|
+
return new Box<number>(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const limit = 100;
|
|
33
|
+
const i =
|
|
34
|
+
new Box<number>(2).value < limit ? 'ok' : 'no';
|
|
35
|
+
// 11. Generic function call vs Element: Identifier followed by generic args
|
|
36
|
+
function identity<T>(value: T): T {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
const j = identity<number>(42);
|
|
40
|
+
// 12. Member + generic call immediately followed by another call
|
|
41
|
+
class Factory {
|
|
42
|
+
create<T>() {
|
|
43
|
+
return (value: T) => value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const factory = new Factory();
|
|
47
|
+
const k = factory.create<number>()(123);
|
|
48
|
+
// 13. Multiple generic segments in chain
|
|
49
|
+
function foo<T>() {
|
|
50
|
+
return {
|
|
51
|
+
bar: function <U>() {
|
|
9
52
|
return {
|
|
10
|
-
|
|
11
|
-
return
|
|
53
|
+
baz: function <V>() {
|
|
54
|
+
return true;
|
|
12
55
|
},
|
|
13
56
|
};
|
|
14
57
|
},
|
|
15
58
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
constructor(value: T) {
|
|
26
|
-
this.value = value;
|
|
27
|
-
}
|
|
59
|
+
}
|
|
60
|
+
const l = foo<number>().bar<string>().baz<boolean>();
|
|
61
|
+
// 14. Generic with constraint + default
|
|
62
|
+
type Extractor<T extends { id: number } = { id: number }> = (v: T) => number;
|
|
63
|
+
const m: Extractor = (v) => v.id;
|
|
64
|
+
// 15. Generic in angle after "new" + trailing call
|
|
65
|
+
class Wrapper<T> {
|
|
66
|
+
value: T;
|
|
28
67
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
68
|
+
constructor() {
|
|
69
|
+
this.value = null as unknown as T;
|
|
32
70
|
}
|
|
33
|
-
const limit = 100;
|
|
34
|
-
const i =
|
|
35
|
-
new Box<number>(2).value < limit ? 'ok' : 'no';
|
|
36
|
-
// 10. JSX / Element should still work
|
|
37
|
-
<div class="still-works">
|
|
38
|
-
<span>{'Test'}</span>
|
|
39
|
-
</div>
|
|
40
|
-
// 11. Generic function call vs Element: Identifier followed by generic args
|
|
41
|
-
function identity<T>(value: T): T {
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
const j = identity<number>(42);
|
|
45
|
-
// 12. Member + generic call immediately followed by another call
|
|
46
|
-
class Factory {
|
|
47
|
-
create<T>() {
|
|
48
|
-
return (value: T) => value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const factory = new Factory();
|
|
52
|
-
const k = factory.create<number>()(123);
|
|
53
|
-
// 13. Multiple generic segments in chain
|
|
54
|
-
function foo<T>() {
|
|
55
|
-
return {
|
|
56
|
-
bar: function <U>() {
|
|
57
|
-
return {
|
|
58
|
-
baz: function <V>() {
|
|
59
|
-
return true;
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const l = foo<number>().bar<string>().baz<boolean>();
|
|
66
|
-
// 14. Generic with constraint + default
|
|
67
|
-
type Extractor<T extends { id: number } = { id: number }> = (v: T) => number;
|
|
68
|
-
const m: Extractor = (v) => v.id;
|
|
69
|
-
// 15. Generic in angle after "new" + trailing call
|
|
70
|
-
class Wrapper<T> {
|
|
71
|
-
value: T;
|
|
72
|
-
|
|
73
|
-
constructor() {
|
|
74
|
-
this.value = null as unknown as T;
|
|
75
|
-
}
|
|
76
71
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
72
|
+
unwrap<U>() {
|
|
73
|
+
return null as unknown as U;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const n = new Wrapper<number>().unwrap<string>();
|
|
77
|
+
// 16. Angle brackets inside type assertion vs generic call
|
|
78
|
+
function getUnknown(): unknown {
|
|
79
|
+
return new Map<string, number>([['a', 1]]);
|
|
80
|
+
}
|
|
81
|
+
getUnknown.factory = function <T>() {
|
|
82
|
+
return {
|
|
83
|
+
make: function <U>() {
|
|
84
|
+
return 2;
|
|
85
|
+
},
|
|
92
86
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
};
|
|
88
|
+
const raw = getUnknown();
|
|
89
|
+
const o = (raw as Map<string, number>).get('a');
|
|
90
|
+
// 17. Generic with comma + trailing less-than comparison on next token
|
|
91
|
+
class Pair<T1, T2> {
|
|
92
|
+
first: T1;
|
|
98
93
|
|
|
99
|
-
|
|
94
|
+
second: T2;
|
|
100
95
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
96
|
+
constructor() {
|
|
97
|
+
this.first = null as unknown as T1;
|
|
98
|
+
this.second = null as unknown as T2;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const p = new Pair<number, string>();
|
|
102
|
+
const q =
|
|
103
|
+
1 < 2 ? p : null;
|
|
104
|
+
// 18. Nested generics with line breaks resembling JSX indentation
|
|
105
|
+
interface Node<T> {
|
|
106
|
+
value: T;
|
|
107
|
+
}
|
|
108
|
+
interface Edge<W> {
|
|
109
|
+
weight: W;
|
|
110
|
+
}
|
|
111
|
+
class Graph<N, E> {
|
|
112
|
+
nodes: N[];
|
|
118
113
|
|
|
119
|
-
|
|
114
|
+
edges: E[];
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
116
|
+
constructor() {
|
|
117
|
+
this.nodes = [];
|
|
118
|
+
this.edges = [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const r = new Graph<Node<string>, Edge<number>>();
|
|
122
|
+
// 19. Ternary containing generics in both branches
|
|
123
|
+
let flag = true;
|
|
124
|
+
const s = flag ? new Box<number>(1) : new Box<string>('string');
|
|
125
|
+
// 20. Generic inside template expression
|
|
126
|
+
const t = `length=${new RippleArray<number>().length}`;
|
|
127
|
+
// 21. Optional chaining + generic + property access
|
|
128
|
+
const registry = new RippleMap<string, number>();
|
|
129
|
+
const u = registry.get('id')?.toString();
|
|
130
|
+
// 22. Generic call used as callee for another call
|
|
131
|
+
function make<T>() {
|
|
132
|
+
return (value: T) => value;
|
|
133
|
+
}
|
|
134
|
+
const v = make<number>()(10);
|
|
135
|
+
// 23. Generic followed by tagged template (ensure not confused with JSX)
|
|
136
|
+
function tagFn<T>(strings: TemplateStringsArray, ...values) {
|
|
137
|
+
return values[0];
|
|
138
|
+
}
|
|
139
|
+
const tagResult = tagFn`value`;
|
|
140
|
+
// 24. Sequence mixing: (a < b) + generic call in same statement
|
|
141
|
+
function compute<T>(x: T, y: T): T {
|
|
142
|
+
return y;
|
|
143
|
+
}
|
|
144
|
+
const w = x < y && compute<number>(x, y);
|
|
145
|
+
// Additional component focusing on edge crankers
|
|
151
146
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
const builder = new Builder<Number>();
|
|
163
|
-
const result = (function () {
|
|
164
|
-
return builder;
|
|
165
|
-
}() as Builder<Number>).finalize<boolean>();
|
|
166
|
-
// 30. Angle bracket start of conditional expression line
|
|
167
|
-
function adjust<T>(value: T): T {
|
|
168
|
-
return value;
|
|
147
|
+
// 28. Generic after parenthesized new expression
|
|
148
|
+
const aa = (new Box<number>(2)).open<string>();
|
|
149
|
+
// 29. Generic chain right after closing paren of IIFE
|
|
150
|
+
class Builder<Kind> {
|
|
151
|
+
finalize<Result>() {
|
|
152
|
+
return {
|
|
153
|
+
result: null as unknown as Result,
|
|
154
|
+
};
|
|
169
155
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
156
|
+
}
|
|
157
|
+
const builder = new Builder<Number>();
|
|
158
|
+
const result = (function () {
|
|
159
|
+
return builder;
|
|
160
|
+
}() as Builder<Number>).finalize<boolean>();
|
|
161
|
+
// 30. Angle bracket start of conditional expression line
|
|
162
|
+
function adjust<T>(value: T): T {
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
const val =
|
|
166
|
+
new Wrapper<number>().value < 100 ? adjust<number>(10) : adjust<number>(20);
|
|
167
|
+
// 32. Generic with comments inside angle list
|
|
168
|
+
class Mapper<Key, Value> {
|
|
169
|
+
map: Map<Key, Value>;
|
|
175
170
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
171
|
+
constructor() {
|
|
172
|
+
this.map = new Map<Key, Value>();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const gg = new Mapper<
|
|
176
|
+
// key type
|
|
177
|
+
string /* value type */,
|
|
178
|
+
number
|
|
179
|
+
>();
|
|
180
|
+
// 33. Map of generic instance as key
|
|
181
|
+
const mm = new Map<RippleArray<number>, RippleArray<string>>();
|
|
182
|
+
// 10. JSX / Element should still work
|
|
183
|
+
<div class="still-works">
|
|
184
|
+
<span>{'Test'}</span>
|
|
185
|
+
</div>
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
render(App);
|
|
@@ -3,16 +3,16 @@ import { effect, flushSync, track } from 'ripple';
|
|
|
3
3
|
|
|
4
4
|
describe('composite > props', () => {
|
|
5
5
|
it('correctly handles default prop values', () => {
|
|
6
|
-
function Child({ foo = 456 }) {
|
|
7
|
-
|
|
6
|
+
function Child({ foo = 456 }) @{
|
|
7
|
+
<div>{foo}</div>
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function App() {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function App() @{
|
|
11
|
+
let &[foo] = track(123);
|
|
12
|
+
<>
|
|
13
13
|
<Child />
|
|
14
14
|
<Child {foo} />
|
|
15
|
-
|
|
15
|
+
</>
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
render(App);
|
|
@@ -22,16 +22,16 @@ describe('composite > props', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('correctly handles default prop values #2', () => {
|
|
25
|
-
function Child({ foo = 456 }) {
|
|
26
|
-
|
|
25
|
+
function Child({ foo = 456 }) @{
|
|
26
|
+
<div>{foo}</div>
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function App() {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
function App() @{
|
|
30
|
+
let foo = 123;
|
|
31
|
+
<>
|
|
32
32
|
<Child />
|
|
33
33
|
<Child {foo} />
|
|
34
|
-
|
|
34
|
+
</>
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
render(App);
|
|
@@ -41,16 +41,18 @@ describe('composite > props', () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('correctly handles no props', () => {
|
|
44
|
-
function Child(props: { foo?: Tracked<number> }) {
|
|
45
|
-
|
|
44
|
+
function Child(props: { foo?: Tracked<number> }) @{
|
|
45
|
+
<div>
|
|
46
|
+
{props.foo?.value}
|
|
47
|
+
</div>
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
function App() {
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
function App() @{
|
|
51
|
+
let foo = track(123);
|
|
52
|
+
<>
|
|
51
53
|
<Child />
|
|
52
54
|
<Child {foo} />
|
|
53
|
-
|
|
55
|
+
</>
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
render(App);
|
|
@@ -60,16 +62,16 @@ describe('composite > props', () => {
|
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
it('correctly handles no props #2', () => {
|
|
63
|
-
function Child({ foo }: { foo?: number }) {
|
|
64
|
-
|
|
65
|
+
function Child({ foo }: { foo?: number }) @{
|
|
66
|
+
<div>{foo}</div>
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
function App() {
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
function App() @{
|
|
70
|
+
let &[foo] = track(123);
|
|
71
|
+
<>
|
|
70
72
|
<Child />
|
|
71
73
|
<Child {foo} />
|
|
72
|
-
|
|
74
|
+
</>
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
render(App);
|
|
@@ -81,22 +83,18 @@ describe('composite > props', () => {
|
|
|
81
83
|
it('mutating a tracked value prop should work as intended', () => {
|
|
82
84
|
const logs: number[] = [];
|
|
83
85
|
|
|
84
|
-
function Counter({ count }: { count: Tracked<number> }) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<button onClick={() => (count.value = count.value + 1)}>{'+'}</button>
|
|
90
|
-
</>;
|
|
86
|
+
function Counter({ count }: { count: Tracked<number> }) @{
|
|
87
|
+
effect(() => {
|
|
88
|
+
logs.push(count.value);
|
|
89
|
+
});
|
|
90
|
+
<button onClick={() => (count.value = count.value + 1)}>{'+'}</button>
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
function App() {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
</div>
|
|
99
|
-
</>;
|
|
93
|
+
function App() @{
|
|
94
|
+
const count = track(0);
|
|
95
|
+
<div>
|
|
96
|
+
<Counter {count} />
|
|
97
|
+
</div>
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
render(App);
|
|
@@ -112,8 +110,8 @@ describe('composite > props', () => {
|
|
|
112
110
|
});
|
|
113
111
|
|
|
114
112
|
it('correctly retains prop accessors and reactivity when using rest props', () => {
|
|
115
|
-
function Button(&{ children, ...rest }: Props) {
|
|
116
|
-
|
|
113
|
+
function Button(&{ children, ...rest }: Props) @{
|
|
114
|
+
<>
|
|
117
115
|
<button {...rest}>{children}</button>
|
|
118
116
|
<style>
|
|
119
117
|
.on {
|
|
@@ -123,22 +121,20 @@ describe('composite > props', () => {
|
|
|
123
121
|
color: red;
|
|
124
122
|
}
|
|
125
123
|
</style>
|
|
126
|
-
|
|
124
|
+
</>
|
|
127
125
|
}
|
|
128
126
|
|
|
129
|
-
function Toggle(&{ pressed, ...rest }: { pressed: Tracked<boolean> }) {
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
function Toggle(&{ pressed, ...rest }: { pressed: Tracked<boolean> }) @{
|
|
128
|
+
const onClick = () => (pressed.value = !pressed.value);
|
|
129
|
+
<>
|
|
132
130
|
<Button {...rest} class={pressed.value ? 'on' : 'off'} {onClick}>{'button 1'}</Button>
|
|
133
131
|
<Button class={pressed.value ? 'on' : 'off'} {onClick}>{'button 2'}</Button>
|
|
134
|
-
|
|
132
|
+
</>
|
|
135
133
|
}
|
|
136
134
|
|
|
137
|
-
function App() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
<Toggle {pressed} />
|
|
141
|
-
</>;
|
|
135
|
+
function App() @{
|
|
136
|
+
const pressed = track(true);
|
|
137
|
+
<Toggle {pressed} />
|
|
142
138
|
}
|
|
143
139
|
|
|
144
140
|
render(App);
|
|
@@ -166,30 +162,26 @@ describe('composite > props', () => {
|
|
|
166
162
|
price: number;
|
|
167
163
|
}
|
|
168
164
|
|
|
169
|
-
function Product({ id, name, organizationName, description, imageUrl, price }: ProductInfo) {
|
|
170
|
-
|
|
171
|
-
<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
imageUrl="https://picsum.photos/300/200"
|
|
190
|
-
price={15}
|
|
191
|
-
/>
|
|
192
|
-
</>;
|
|
165
|
+
function Product({ id, name, organizationName, description, imageUrl, price }: ProductInfo) @{
|
|
166
|
+
<article class="no-padding">
|
|
167
|
+
<img class="responsive small" src={imageUrl} alt={name} />
|
|
168
|
+
<span>{id}</span>
|
|
169
|
+
<h5>{name}</h5>
|
|
170
|
+
<h3>{organizationName}</h3>
|
|
171
|
+
<p>{description}</p>
|
|
172
|
+
<price class="price">{price}</price>
|
|
173
|
+
</article>
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function App() @{
|
|
177
|
+
<Product
|
|
178
|
+
id="1"
|
|
179
|
+
name="Product 1"
|
|
180
|
+
organizationName="Org 1"
|
|
181
|
+
description="Description 1"
|
|
182
|
+
imageUrl="https://picsum.photos/300/200"
|
|
183
|
+
price={15}
|
|
184
|
+
/>
|
|
193
185
|
}
|
|
194
186
|
|
|
195
187
|
render(App);
|