ripple 0.3.67 → 0.3.69
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 +57 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +2 -2
- package/src/runtime/element.js +1 -1
- package/src/runtime/index-client.js +11 -11
- package/src/runtime/index-server.js +7 -4
- package/src/runtime/internal/client/bindings.js +1 -1
- package/src/runtime/internal/client/blocks.js +13 -4
- package/src/runtime/internal/client/component.js +55 -0
- package/src/runtime/internal/client/composite.js +4 -2
- package/src/runtime/internal/client/expression.js +65 -7
- package/src/runtime/internal/client/hmr.js +54 -43
- package/src/runtime/internal/client/index.js +5 -1
- package/src/runtime/internal/client/portal.js +70 -69
- package/src/runtime/internal/client/render.js +3 -0
- package/src/runtime/internal/server/index.js +92 -8
- package/tests/client/__snapshots__/html.test.tsrx.snap +3 -3
- package/tests/client/array/array.copy-within.test.tsrx +33 -31
- package/tests/client/array/array.derived.test.tsrx +186 -169
- package/tests/client/array/array.iteration.test.tsrx +40 -37
- package/tests/client/array/array.mutations.test.tsrx +113 -101
- package/tests/client/array/array.static.test.tsrx +119 -101
- package/tests/client/array/array.to-methods.test.tsrx +24 -21
- package/tests/client/async-suspend.test.tsrx +247 -246
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +0 -1
- package/tests/client/basic/basic.attributes.test.tsrx +428 -423
- package/tests/client/basic/basic.collections.test.tsrx +109 -102
- package/tests/client/basic/basic.components.test.tsrx +323 -205
- package/tests/client/basic/basic.errors.test.tsrx +91 -91
- package/tests/client/basic/basic.events.test.tsrx +114 -115
- package/tests/client/basic/basic.get-set.test.tsrx +97 -87
- package/tests/client/basic/basic.hmr.test.tsrx +19 -16
- package/tests/client/basic/basic.reactivity.test.tsrx +199 -191
- package/tests/client/basic/basic.rendering.test.tsrx +272 -182
- package/tests/client/basic/basic.styling.test.tsrx +23 -22
- package/tests/client/basic/basic.utilities.test.tsrx +10 -8
- package/tests/client/boundaries.test.tsrx +26 -26
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.rsrx.snap +5 -5
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +5 -5
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -81
- package/tests/client/compiler/compiler.attributes.test.tsrx +15 -15
- package/tests/client/compiler/compiler.basic.test.tsrx +322 -314
- package/tests/client/compiler/compiler.regex.test.tsrx +44 -47
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +38 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +2 -2
- package/tests/client/composite/composite.dynamic-components.test.tsrx +47 -48
- package/tests/client/composite/composite.generics.test.tsrx +168 -192
- package/tests/client/composite/composite.props.test.tsrx +97 -81
- package/tests/client/composite/composite.reactivity.test.tsrx +177 -147
- package/tests/client/composite/composite.render.test.tsrx +122 -105
- package/tests/client/computed-properties.test.tsrx +28 -28
- package/tests/client/context.test.tsrx +21 -21
- package/tests/client/css/global-additional-cases.test.tsrx +58 -58
- package/tests/client/css/global-advanced-selectors.test.tsrx +16 -16
- package/tests/client/css/global-at-rules.test.tsrx +10 -10
- package/tests/client/css/global-basic.test.tsrx +14 -14
- package/tests/client/css/global-classes-ids.test.tsrx +14 -14
- package/tests/client/css/global-combinators.test.tsrx +10 -10
- package/tests/client/css/global-complex-nesting.test.tsrx +14 -14
- package/tests/client/css/global-edge-cases.test.tsrx +18 -18
- package/tests/client/css/global-keyframes.test.tsrx +12 -12
- package/tests/client/css/global-nested.test.tsrx +10 -10
- package/tests/client/css/global-pseudo.test.tsrx +12 -12
- package/tests/client/css/global-scoping.test.tsrx +20 -20
- package/tests/client/css/style-identifier.test.tsrx +143 -291
- package/tests/client/date.test.tsrx +146 -133
- package/tests/client/dynamic-elements.test.tsrx +398 -365
- package/tests/client/events.test.tsrx +292 -290
- package/tests/client/for.test.tsrx +156 -153
- package/tests/client/head.test.tsrx +105 -96
- package/tests/client/html.test.tsrx +122 -26
- package/tests/client/input-value.test.tsrx +1361 -1314
- package/tests/client/lazy-array.test.tsrx +16 -13
- package/tests/client/lazy-destructuring.test.tsrx +257 -213
- package/tests/client/map.test.tsrx +65 -60
- package/tests/client/media-query.test.tsrx +22 -20
- package/tests/client/object.test.tsrx +87 -81
- package/tests/client/portal.test.tsrx +57 -51
- package/tests/client/ref.test.tsrx +233 -202
- package/tests/client/return.test.tsrx +71 -2560
- package/tests/client/set.test.tsrx +54 -45
- package/tests/client/svg.test.tsrx +216 -186
- package/tests/client/switch.test.tsrx +194 -193
- package/tests/client/track-async-hydration.test.tsrx +18 -14
- package/tests/client/tracked-index-access.test.tsrx +28 -18
- package/tests/client/try.test.tsrx +675 -548
- package/tests/client/tsx.test.tsrx +373 -311
- package/tests/client/typescript-generics.test.tsrx +145 -145
- package/tests/client/url/url.derived.test.tsrx +33 -28
- package/tests/client/url/url.parsing.test.tsrx +61 -51
- package/tests/client/url/url.partial-removal.test.tsrx +56 -48
- package/tests/client/url/url.reactivity.test.tsrx +142 -125
- package/tests/client/url/url.serialization.test.tsrx +13 -11
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +34 -29
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +25 -21
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +50 -45
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +111 -99
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +49 -43
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +14 -12
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +16 -14
- package/tests/hydration/basic.test.js +3 -3
- package/tests/hydration/compiled/client/basic.js +586 -651
- package/tests/hydration/compiled/client/composite.js +79 -104
- package/tests/hydration/compiled/client/events.js +140 -148
- package/tests/hydration/compiled/client/for.js +1005 -1018
- package/tests/hydration/compiled/client/head.js +124 -134
- package/tests/hydration/compiled/client/hmr.js +41 -48
- package/tests/hydration/compiled/client/html-in-template.js +38 -41
- package/tests/hydration/compiled/client/html.js +970 -1314
- package/tests/hydration/compiled/client/if-children.js +234 -249
- package/tests/hydration/compiled/client/if.js +182 -189
- package/tests/hydration/compiled/client/mixed-control-flow.js +347 -303
- package/tests/hydration/compiled/client/nested-control-flow.js +1084 -832
- package/tests/hydration/compiled/client/portal.js +65 -85
- package/tests/hydration/compiled/client/reactivity.js +84 -90
- package/tests/hydration/compiled/client/return.js +38 -1939
- package/tests/hydration/compiled/client/switch.js +218 -224
- package/tests/hydration/compiled/client/track-async-serialization.js +250 -259
- package/tests/hydration/compiled/client/try.js +123 -132
- package/tests/hydration/compiled/server/basic.js +773 -831
- package/tests/hydration/compiled/server/composite.js +166 -191
- package/tests/hydration/compiled/server/events.js +170 -184
- package/tests/hydration/compiled/server/for.js +851 -909
- package/tests/hydration/compiled/server/head.js +206 -216
- package/tests/hydration/compiled/server/hmr.js +64 -72
- package/tests/hydration/compiled/server/html-in-template.js +42 -76
- package/tests/hydration/compiled/server/html.js +1362 -1667
- package/tests/hydration/compiled/server/if-children.js +419 -445
- package/tests/hydration/compiled/server/if.js +194 -208
- package/tests/hydration/compiled/server/mixed-control-flow.js +249 -257
- package/tests/hydration/compiled/server/nested-control-flow.js +491 -515
- package/tests/hydration/compiled/server/portal.js +152 -160
- package/tests/hydration/compiled/server/reactivity.js +94 -106
- package/tests/hydration/compiled/server/return.js +28 -2172
- package/tests/hydration/compiled/server/switch.js +274 -286
- package/tests/hydration/compiled/server/track-async-serialization.js +340 -358
- package/tests/hydration/compiled/server/try.js +167 -185
- package/tests/hydration/components/basic.tsrx +320 -272
- package/tests/hydration/components/composite.tsrx +44 -32
- package/tests/hydration/components/events.tsrx +101 -91
- package/tests/hydration/components/for.tsrx +510 -452
- package/tests/hydration/components/head.tsrx +87 -80
- package/tests/hydration/components/hmr.tsrx +22 -17
- package/tests/hydration/components/html-in-template.tsrx +22 -17
- package/tests/hydration/components/html.tsrx +525 -443
- package/tests/hydration/components/if-children.tsrx +158 -148
- package/tests/hydration/components/if.tsrx +109 -95
- package/tests/hydration/components/mixed-control-flow.tsrx +100 -96
- package/tests/hydration/components/nested-control-flow.tsrx +215 -203
- package/tests/hydration/components/portal.tsrx +41 -34
- package/tests/hydration/components/reactivity.tsrx +37 -27
- package/tests/hydration/components/return.tsrx +12 -556
- package/tests/hydration/components/switch.tsrx +120 -114
- package/tests/hydration/components/track-async-serialization.tsrx +107 -91
- package/tests/hydration/components/try.tsrx +55 -40
- package/tests/hydration/html.test.js +4 -4
- package/tests/hydration/return.test.js +13 -532
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +264 -195
- package/tests/server/basic.components.test.tsrx +296 -169
- package/tests/server/basic.test.tsrx +300 -198
- package/tests/server/compiler.test.tsrx +62 -60
- package/tests/server/composite.props.test.tsrx +77 -63
- package/tests/server/composite.test.tsrx +168 -192
- package/tests/server/context.test.tsrx +18 -12
- package/tests/server/dynamic-elements.test.tsrx +197 -180
- package/tests/server/for.test.tsrx +85 -78
- package/tests/server/head.test.tsrx +50 -43
- package/tests/server/html-nesting-validation.test.tsrx +8 -8
- package/tests/server/if.test.tsrx +57 -51
- package/tests/server/lazy-destructuring.test.tsrx +366 -294
- package/tests/server/return.test.tsrx +76 -1355
- package/tests/server/streaming-ssr.test.tsrx +4 -75
- package/tests/server/style-identifier.test.tsrx +169 -148
- package/tests/server/switch.test.tsrx +91 -85
- package/tests/server/track-async-serialization.test.tsrx +105 -85
- package/tests/server/try.test.tsrx +374 -280
- package/tests/utils/compiler-compat-config.test.js +2 -2
- package/tests/utils/runtime-imports.test.js +10 -0
- package/types/index.d.ts +8 -0
- package/tests/client/__snapshots__/html.test.rsrx.snap +0 -40
|
@@ -31,11 +31,11 @@ beforeAll(() => {
|
|
|
31
31
|
(global as any).count++;
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
function Test() { return <>
|
|
35
35
|
let toggle: { value: boolean } | undefined;
|
|
36
36
|
toggle!.value = false;
|
|
37
37
|
toggle!.value++;
|
|
38
|
-
}`;
|
|
38
|
+
</>; }`;
|
|
39
39
|
|
|
40
40
|
const { code } = compile(source, 'test.tsrx', { mode: 'server' });
|
|
41
41
|
|
|
@@ -50,13 +50,13 @@ component Test() {
|
|
|
50
50
|
it(
|
|
51
51
|
'compiles writes to unknown lazy array index 1 through lazy array helpers in SSR output',
|
|
52
52
|
() => {
|
|
53
|
-
const source = `
|
|
53
|
+
const source = `function Child({ pair: &[first, second] }) { return <>
|
|
54
54
|
second = 10;
|
|
55
55
|
<div>{first}</div>
|
|
56
|
-
}
|
|
57
|
-
|
|
56
|
+
</>; }
|
|
57
|
+
function App() { return <>
|
|
58
58
|
<Child pair={[0, 1]} />
|
|
59
|
-
}`;
|
|
59
|
+
</>; }`;
|
|
60
60
|
const { code } = compile(source, 'test.tsrx', { mode: 'server' });
|
|
61
61
|
|
|
62
62
|
expect(code).toContain('_$_.lazy_array_set(lazy, 10, 1)');
|
|
@@ -65,13 +65,13 @@ component App() {
|
|
|
65
65
|
);
|
|
66
66
|
|
|
67
67
|
it('does not double-wrap member access on lazy array value bindings in SSR output', () => {
|
|
68
|
-
const source = `
|
|
68
|
+
const source = `function Child({ pair: &[first] }) { return <>
|
|
69
69
|
let value = first[0];
|
|
70
70
|
<div>{value}</div>
|
|
71
|
-
}
|
|
72
|
-
|
|
71
|
+
</>; }
|
|
72
|
+
function App() { return <>
|
|
73
73
|
<Child pair={[{ 0: 'x' }]} />
|
|
74
|
-
}`;
|
|
74
|
+
</>; }`;
|
|
75
75
|
const { code } = compile(source, 'test.tsrx', { mode: 'server' });
|
|
76
76
|
|
|
77
77
|
expect(code).toContain('let value = _$_.lazy_array_get(lazy, 0)[0];');
|
|
@@ -80,13 +80,13 @@ component App() {
|
|
|
80
80
|
|
|
81
81
|
it('throws on indexed access through known tracked lazy destructures in SSR output', () => {
|
|
82
82
|
const source = `import { track } from 'ripple';
|
|
83
|
-
|
|
83
|
+
function App() { return <>
|
|
84
84
|
let &[value, tracked_ref] = track({ 0: 'x' });
|
|
85
85
|
let nested = value[0];
|
|
86
86
|
tracked_ref[0] = { 0: 'y' };
|
|
87
87
|
let next = value[0];
|
|
88
88
|
<div>{nested}{next}</div>
|
|
89
|
-
}`;
|
|
89
|
+
</>; }`;
|
|
90
90
|
|
|
91
91
|
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow(
|
|
92
92
|
/Use \.value or &\[\] lazy destructuring/,
|
|
@@ -95,7 +95,7 @@ component App() {
|
|
|
95
95
|
|
|
96
96
|
it('throws on known tracked indexed access in SSR output', () => {
|
|
97
97
|
const source = `import { track } from 'ripple';
|
|
98
|
-
|
|
98
|
+
function App() { return <>
|
|
99
99
|
let tracked = track(0);
|
|
100
100
|
++tracked[0];
|
|
101
101
|
tracked[0]++;
|
|
@@ -103,7 +103,7 @@ component App() {
|
|
|
103
103
|
let value = tracked[0];
|
|
104
104
|
let ref = tracked[1];
|
|
105
105
|
<div>{value}</div>
|
|
106
|
-
}`;
|
|
106
|
+
</>; }`;
|
|
107
107
|
|
|
108
108
|
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow(
|
|
109
109
|
/Use \.value or &\[\] lazy destructuring/,
|
|
@@ -114,15 +114,15 @@ component App() {
|
|
|
114
114
|
'compiles indexed access on unknown lazy tracked refs through lazy array helpers in SSR output',
|
|
115
115
|
() => {
|
|
116
116
|
const source = `import { track } from 'ripple';
|
|
117
|
-
|
|
117
|
+
function Child({ pair: &[value, tracked_ref] }) { return <>
|
|
118
118
|
++tracked_ref[0];
|
|
119
119
|
tracked_ref[0]++;
|
|
120
120
|
<div>{value}</div>
|
|
121
|
-
}
|
|
122
|
-
|
|
121
|
+
</>; }
|
|
122
|
+
function App() { return <>
|
|
123
123
|
let tracked = track(0);
|
|
124
124
|
<Child pair={tracked} />
|
|
125
|
-
}`;
|
|
125
|
+
</>; }`;
|
|
126
126
|
const { code } = compile(source, 'test.tsrx', { mode: 'server' });
|
|
127
127
|
|
|
128
128
|
expect(code).toContain('_$_.lazy_array_get(lazy, 1)');
|
|
@@ -166,29 +166,29 @@ class PrintEvent implements BaseEvent {
|
|
|
166
166
|
|
|
167
167
|
it('throws error for interpolating children as text in SSR mode', () => {
|
|
168
168
|
const source = `
|
|
169
|
-
export
|
|
169
|
+
export function Layout({ children }) { return <>
|
|
170
170
|
<div>{children}</div>
|
|
171
|
-
}`;
|
|
171
|
+
</>; }`;
|
|
172
172
|
|
|
173
173
|
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).not.toThrow();
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
it('throws error for interpolating props.children as text in SSR mode', () => {
|
|
177
177
|
const source = `
|
|
178
|
-
export
|
|
178
|
+
export function Layout(props) { return <>
|
|
179
179
|
<div>{props.children}</div>
|
|
180
|
-
}`;
|
|
180
|
+
</>; }`;
|
|
181
181
|
|
|
182
182
|
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).not.toThrow();
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it('compiles indented direct double-quoted text children in SSR mode', () => {
|
|
186
186
|
const source = `
|
|
187
|
-
export default
|
|
187
|
+
export default function A() { return <>
|
|
188
188
|
<div>
|
|
189
189
|
"Hello"
|
|
190
190
|
</div>
|
|
191
|
-
}`;
|
|
191
|
+
</>; }`;
|
|
192
192
|
|
|
193
193
|
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
194
194
|
|
|
@@ -198,9 +198,9 @@ export default component A() {
|
|
|
198
198
|
|
|
199
199
|
it('decodes JSX-style entities before server text escaping', () => {
|
|
200
200
|
const result = compile(
|
|
201
|
-
`
|
|
201
|
+
`function App() { return <>
|
|
202
202
|
<div>"Rock & "Roll""</div>
|
|
203
|
-
}`,
|
|
203
|
+
</>; }`,
|
|
204
204
|
'/src/App.tsrx',
|
|
205
205
|
{ mode: 'server' },
|
|
206
206
|
);
|
|
@@ -210,35 +210,39 @@ export default component A() {
|
|
|
210
210
|
|
|
211
211
|
it('emits anonymous component expressions as arrows in SSR output', () => {
|
|
212
212
|
const source = `
|
|
213
|
-
const Inline =
|
|
213
|
+
const Inline = (props) => <>
|
|
214
214
|
<div>{props.x}</div>
|
|
215
|
-
|
|
215
|
+
</>
|
|
216
216
|
`;
|
|
217
217
|
const result = compile(source, 'anonymous-component.tsrx', { mode: 'server' }).code;
|
|
218
218
|
|
|
219
219
|
expect(result).toContain('const Inline = (props) => {');
|
|
220
|
+
expect(result).toContain('(props) => {');
|
|
221
|
+
expect(result).toContain('return _$_.tsrx_element(() =>');
|
|
220
222
|
expect(result).not.toContain('function Inline');
|
|
221
223
|
expect(result).not.toContain('function (props');
|
|
222
224
|
});
|
|
223
225
|
|
|
224
|
-
it('emits
|
|
226
|
+
it('emits function-expression components as functions in SSR output', () => {
|
|
225
227
|
const source = `
|
|
226
|
-
const Inline =
|
|
228
|
+
const Inline = function(props) { return <>
|
|
227
229
|
<div>{props.x}</div>
|
|
228
|
-
}
|
|
230
|
+
</>; }
|
|
229
231
|
`;
|
|
230
232
|
const result = compile(source, 'anonymous-component.tsrx', { mode: 'server' }).code;
|
|
231
233
|
|
|
232
234
|
expect(result).toContain('const Inline = function (props) {');
|
|
235
|
+
expect(result).toContain('function (props) {');
|
|
236
|
+
expect(result).toContain('return _$_.tsrx_element(() =>');
|
|
233
237
|
expect(result).not.toContain('function Inline');
|
|
234
238
|
expect(result).not.toContain('const Inline = (props) => {');
|
|
235
239
|
});
|
|
236
240
|
|
|
237
241
|
it('throws error for calling children as a function in SSR mode', () => {
|
|
238
242
|
const source = `
|
|
239
|
-
export
|
|
243
|
+
export function Layout({ children }) { return <>
|
|
240
244
|
{children()}
|
|
241
|
-
}`;
|
|
245
|
+
</>; }`;
|
|
242
246
|
|
|
243
247
|
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow(
|
|
244
248
|
'`children` cannot be called like a regular function. Render it with `{children}` or `{props.children}` instead.',
|
|
@@ -247,9 +251,9 @@ export component Layout({ children }) {
|
|
|
247
251
|
|
|
248
252
|
it('throws error for calling props.children as a function in SSR mode', () => {
|
|
249
253
|
const source = `
|
|
250
|
-
export
|
|
254
|
+
export function Layout(props) { return <>
|
|
251
255
|
{props.children()}
|
|
252
|
-
}`;
|
|
256
|
+
</>; }`;
|
|
253
257
|
|
|
254
258
|
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow(
|
|
255
259
|
'`children` cannot be called like a regular function. Render it with `{children}` or `{props.children}` instead.',
|
|
@@ -258,17 +262,17 @@ export component Layout(props) {
|
|
|
258
262
|
|
|
259
263
|
it('merges explicit children prop with implicit children in SSR output', () => {
|
|
260
264
|
const source = `
|
|
261
|
-
|
|
265
|
+
function Card(props) { return <>
|
|
262
266
|
<div>{props.children}</div>
|
|
263
|
-
}
|
|
267
|
+
</>; }
|
|
264
268
|
|
|
265
|
-
export
|
|
269
|
+
export function App() { return <>
|
|
266
270
|
const fallback = 'fallback';
|
|
267
271
|
|
|
268
272
|
<Card children={fallback}>
|
|
269
273
|
<span>{'content'}</span>
|
|
270
274
|
</Card>
|
|
271
|
-
}
|
|
275
|
+
</>; }
|
|
272
276
|
`;
|
|
273
277
|
|
|
274
278
|
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
@@ -280,7 +284,7 @@ export component App() {
|
|
|
280
284
|
|
|
281
285
|
it('routes calls to functions with nested template returns through render_expression', () => {
|
|
282
286
|
const source = `
|
|
283
|
-
|
|
287
|
+
function App() { return <>
|
|
284
288
|
function make(flag) {
|
|
285
289
|
if (flag) {
|
|
286
290
|
return <tsx><span>{'nested'}</span></tsx>;
|
|
@@ -290,7 +294,7 @@ component App() {
|
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
<div>{make(true)}</div>
|
|
293
|
-
}
|
|
297
|
+
</>; }
|
|
294
298
|
`;
|
|
295
299
|
|
|
296
300
|
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
@@ -301,7 +305,7 @@ component App() {
|
|
|
301
305
|
|
|
302
306
|
it('does not treat nested function template returns as outer function returns', () => {
|
|
303
307
|
const source = `
|
|
304
|
-
|
|
308
|
+
function App() { return <>
|
|
305
309
|
function make() {
|
|
306
310
|
function nested() {
|
|
307
311
|
return <tsx><span>{'nested'}</span></tsx>;
|
|
@@ -311,7 +315,7 @@ component App() {
|
|
|
311
315
|
}
|
|
312
316
|
|
|
313
317
|
<div>{make()}</div>
|
|
314
|
-
}
|
|
318
|
+
</>; }
|
|
315
319
|
`;
|
|
316
320
|
|
|
317
321
|
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
@@ -370,10 +374,10 @@ module server {
|
|
|
370
374
|
|
|
371
375
|
import { loadUser as getUser } from server;
|
|
372
376
|
|
|
373
|
-
export
|
|
377
|
+
export function App() { return <>
|
|
374
378
|
const user = getUser('1');
|
|
375
379
|
<div>{user.id}</div>
|
|
376
|
-
}`;
|
|
380
|
+
</>; }`;
|
|
377
381
|
|
|
378
382
|
const result = compile(source, 'test.tsrx', { mode: 'server' });
|
|
379
383
|
expect(result.code).toContain('const getUser = function (...args)');
|
|
@@ -389,9 +393,7 @@ module server {
|
|
|
389
393
|
|
|
390
394
|
server.loadUser();`;
|
|
391
395
|
|
|
392
|
-
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).
|
|
393
|
-
/Import server exports/,
|
|
394
|
-
);
|
|
396
|
+
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow(/Import server exports/);
|
|
395
397
|
});
|
|
396
398
|
|
|
397
399
|
it('throws error for unsupported exported object pattern in server module', () => {
|
|
@@ -402,7 +404,7 @@ module server {
|
|
|
402
404
|
export const { fn1, fn2 } = obj;
|
|
403
405
|
}`;
|
|
404
406
|
|
|
405
|
-
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).
|
|
407
|
+
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow();
|
|
406
408
|
});
|
|
407
409
|
|
|
408
410
|
it('throws error for unsupported exported array pattern in server module', () => {
|
|
@@ -413,7 +415,7 @@ module server {
|
|
|
413
415
|
export const [fnarr1, fnarr2] = arr;
|
|
414
416
|
}`;
|
|
415
417
|
|
|
416
|
-
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).
|
|
418
|
+
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow();
|
|
417
419
|
});
|
|
418
420
|
|
|
419
421
|
it('throws error for unsupported exported member expression via object in server module', () => {
|
|
@@ -424,7 +426,7 @@ module server {
|
|
|
424
426
|
export const objProp = obj.fn1;
|
|
425
427
|
}`;
|
|
426
428
|
|
|
427
|
-
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).
|
|
429
|
+
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow();
|
|
428
430
|
});
|
|
429
431
|
|
|
430
432
|
it('throws error for unsupported exported member expression via array in server module', () => {
|
|
@@ -435,20 +437,20 @@ module server {
|
|
|
435
437
|
export const arrIndex0 = arr[0];
|
|
436
438
|
}`;
|
|
437
439
|
|
|
438
|
-
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).
|
|
440
|
+
expect(() => compile(source, 'test.tsrx', { mode: 'server' })).toThrow();
|
|
439
441
|
});
|
|
440
442
|
|
|
441
443
|
it('wraps children in normalize_children for explicit children prop passed to component', () => {
|
|
442
444
|
const source = `
|
|
443
|
-
|
|
445
|
+
function Card(props) { return <>
|
|
444
446
|
<div>{props.children}</div>
|
|
445
|
-
}
|
|
447
|
+
</>; }
|
|
446
448
|
|
|
447
|
-
export
|
|
449
|
+
export function App() { return <>
|
|
448
450
|
const content = 'hello';
|
|
449
451
|
|
|
450
452
|
<Card children={content} />
|
|
451
|
-
}
|
|
453
|
+
</>; }
|
|
452
454
|
`;
|
|
453
455
|
|
|
454
456
|
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
@@ -458,15 +460,15 @@ export component App() {
|
|
|
458
460
|
|
|
459
461
|
it('passes spread through to component when spread may contain children', () => {
|
|
460
462
|
const source = `
|
|
461
|
-
|
|
463
|
+
function Card(props) { return <>
|
|
462
464
|
<div>{props.children}</div>
|
|
463
|
-
}
|
|
465
|
+
</>; }
|
|
464
466
|
|
|
465
|
-
export
|
|
467
|
+
export function App() { return <>
|
|
466
468
|
const props = { children: 'hello' };
|
|
467
469
|
|
|
468
470
|
<Card {...props} />
|
|
469
|
-
}
|
|
471
|
+
</>; }
|
|
470
472
|
`;
|
|
471
473
|
|
|
472
474
|
const result = compile(source, 'test.tsrx', { mode: 'server' }).code;
|
|
@@ -3,15 +3,16 @@ import type { Tracked, Props } from 'ripple';
|
|
|
3
3
|
|
|
4
4
|
describe('composite > props', () => {
|
|
5
5
|
it('correctly handles default prop values', async () => {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function Child({ foo = 456 }) {
|
|
7
|
+
return <><div>{foo}</div></>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
function App() {
|
|
11
|
+
return <>
|
|
12
|
+
let &[foo] = track(123);
|
|
13
|
+
<Child />
|
|
14
|
+
<Child {foo} />
|
|
15
|
+
</>;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const { body } = await render(App);
|
|
@@ -22,15 +23,16 @@ describe('composite > props', () => {
|
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
it('correctly handles default prop values #2', async () => {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
function Child({ foo = 456 }) {
|
|
27
|
+
return <><div>{foo}</div></>;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
function App() {
|
|
31
|
+
return <>
|
|
32
|
+
let foo = 123;
|
|
33
|
+
<Child />
|
|
34
|
+
<Child {foo} />
|
|
35
|
+
</>;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
const { body } = await render(App);
|
|
@@ -41,15 +43,16 @@ describe('composite > props', () => {
|
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
it('correctly handles no props', async () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
function Child(props: { foo?: Tracked<number> }) {
|
|
47
|
+
return <><div>{props.foo?.value}</div></>;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
function App() {
|
|
51
|
+
return <>
|
|
52
|
+
let foo = track(123);
|
|
53
|
+
<Child />
|
|
54
|
+
<Child {foo} />
|
|
55
|
+
</>;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
const { body } = await render(App);
|
|
@@ -60,15 +63,16 @@ describe('composite > props', () => {
|
|
|
60
63
|
});
|
|
61
64
|
|
|
62
65
|
it('correctly handles no props #2', async () => {
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
function Child({ foo }: { foo?: number }) {
|
|
67
|
+
return <><div>{foo}</div></>;
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
function App() {
|
|
71
|
+
return <>
|
|
72
|
+
let &[foo] = track(123);
|
|
73
|
+
<Child />
|
|
74
|
+
<Child {foo} />
|
|
75
|
+
</>;
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
const { body } = await render(App);
|
|
@@ -79,27 +83,33 @@ describe('composite > props', () => {
|
|
|
79
83
|
});
|
|
80
84
|
|
|
81
85
|
it('correctly retains prop accessors and reactivity when using rest props', async () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
function Button(&{ children, ...rest }: Props) {
|
|
87
|
+
return <>
|
|
88
|
+
<button {...rest}>{children}</button>
|
|
89
|
+
<style>
|
|
90
|
+
.on {
|
|
91
|
+
color: blue;
|
|
92
|
+
}
|
|
93
|
+
.off {
|
|
94
|
+
color: red;
|
|
95
|
+
}
|
|
96
|
+
</style>
|
|
97
|
+
</>;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
function Toggle(&{ pressed, ...rest }: { pressed: Tracked<boolean> }) {
|
|
101
|
+
return <>
|
|
102
|
+
const onClick = () => (pressed.value = !pressed.value);
|
|
103
|
+
<Button {...rest} class={pressed.value ? 'on' : 'off'} {onClick}>{'button 1'}</Button>
|
|
104
|
+
<Button class={pressed.value ? 'on' : 'off'} {onClick}>{'button 2'}</Button>
|
|
105
|
+
</>;
|
|
98
106
|
}
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
function App() {
|
|
109
|
+
return <>
|
|
110
|
+
const pressed = track(true);
|
|
111
|
+
<Toggle {pressed} />
|
|
112
|
+
</>;
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
const { body } = await render(App);
|
|
@@ -122,26 +132,30 @@ describe('composite > props', () => {
|
|
|
122
132
|
price: number;
|
|
123
133
|
}
|
|
124
134
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
function Product({ id, name, organizationName, description, imageUrl, price }: ProductInfo) {
|
|
136
|
+
return <>
|
|
137
|
+
<article class="no-padding">
|
|
138
|
+
<img class="responsive small" src={imageUrl} alt={name} />
|
|
139
|
+
<span>{id}</span>
|
|
140
|
+
<h5>{name}</h5>
|
|
141
|
+
<h3>{organizationName}</h3>
|
|
142
|
+
<p>{description}</p>
|
|
143
|
+
<price class="price">{price}</price>
|
|
144
|
+
</article>
|
|
145
|
+
</>;
|
|
134
146
|
}
|
|
135
147
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
function App() {
|
|
149
|
+
return <>
|
|
150
|
+
<Product
|
|
151
|
+
id="1"
|
|
152
|
+
name="Product 1"
|
|
153
|
+
organizationName="Org 1"
|
|
154
|
+
description="Description 1"
|
|
155
|
+
imageUrl="https://picsum.photos/300/200"
|
|
156
|
+
price={15}
|
|
157
|
+
/>
|
|
158
|
+
</>;
|
|
145
159
|
}
|
|
146
160
|
|
|
147
161
|
const { body } = await render(App);
|