ripple 0.3.68 → 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.
Files changed (182) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/package.json +3 -3
  3. package/src/jsx-runtime.d.ts +2 -2
  4. package/src/runtime/element.js +1 -1
  5. package/src/runtime/index-client.js +11 -11
  6. package/src/runtime/index-server.js +7 -4
  7. package/src/runtime/internal/client/bindings.js +1 -1
  8. package/src/runtime/internal/client/blocks.js +13 -4
  9. package/src/runtime/internal/client/component.js +55 -0
  10. package/src/runtime/internal/client/composite.js +4 -2
  11. package/src/runtime/internal/client/expression.js +65 -7
  12. package/src/runtime/internal/client/hmr.js +54 -43
  13. package/src/runtime/internal/client/index.js +5 -1
  14. package/src/runtime/internal/client/portal.js +70 -69
  15. package/src/runtime/internal/client/render.js +3 -0
  16. package/src/runtime/internal/server/index.js +92 -8
  17. package/tests/client/__snapshots__/html.test.tsrx.snap +3 -3
  18. package/tests/client/array/array.copy-within.test.tsrx +33 -31
  19. package/tests/client/array/array.derived.test.tsrx +186 -169
  20. package/tests/client/array/array.iteration.test.tsrx +40 -37
  21. package/tests/client/array/array.mutations.test.tsrx +113 -101
  22. package/tests/client/array/array.static.test.tsrx +119 -101
  23. package/tests/client/array/array.to-methods.test.tsrx +24 -21
  24. package/tests/client/async-suspend.test.tsrx +247 -246
  25. package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +0 -1
  26. package/tests/client/basic/basic.attributes.test.tsrx +428 -423
  27. package/tests/client/basic/basic.collections.test.tsrx +109 -102
  28. package/tests/client/basic/basic.components.test.tsrx +323 -205
  29. package/tests/client/basic/basic.errors.test.tsrx +91 -91
  30. package/tests/client/basic/basic.events.test.tsrx +114 -115
  31. package/tests/client/basic/basic.get-set.test.tsrx +97 -87
  32. package/tests/client/basic/basic.hmr.test.tsrx +19 -16
  33. package/tests/client/basic/basic.reactivity.test.tsrx +199 -191
  34. package/tests/client/basic/basic.rendering.test.tsrx +272 -182
  35. package/tests/client/basic/basic.styling.test.tsrx +23 -22
  36. package/tests/client/basic/basic.utilities.test.tsrx +10 -8
  37. package/tests/client/boundaries.test.tsrx +26 -26
  38. package/tests/client/compiler/__snapshots__/compiler.assignments.test.rsrx.snap +5 -5
  39. package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +5 -5
  40. package/tests/client/compiler/compiler.assignments.test.tsrx +77 -81
  41. package/tests/client/compiler/compiler.attributes.test.tsrx +15 -15
  42. package/tests/client/compiler/compiler.basic.test.tsrx +322 -314
  43. package/tests/client/compiler/compiler.regex.test.tsrx +44 -47
  44. package/tests/client/compiler/compiler.tracked-access.test.tsrx +38 -38
  45. package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
  46. package/tests/client/compiler/compiler.typescript.test.tsrx +2 -2
  47. package/tests/client/composite/composite.dynamic-components.test.tsrx +47 -48
  48. package/tests/client/composite/composite.generics.test.tsrx +168 -192
  49. package/tests/client/composite/composite.props.test.tsrx +97 -81
  50. package/tests/client/composite/composite.reactivity.test.tsrx +177 -147
  51. package/tests/client/composite/composite.render.test.tsrx +122 -105
  52. package/tests/client/computed-properties.test.tsrx +28 -28
  53. package/tests/client/context.test.tsrx +21 -21
  54. package/tests/client/css/global-additional-cases.test.tsrx +58 -58
  55. package/tests/client/css/global-advanced-selectors.test.tsrx +16 -16
  56. package/tests/client/css/global-at-rules.test.tsrx +10 -10
  57. package/tests/client/css/global-basic.test.tsrx +14 -14
  58. package/tests/client/css/global-classes-ids.test.tsrx +14 -14
  59. package/tests/client/css/global-combinators.test.tsrx +10 -10
  60. package/tests/client/css/global-complex-nesting.test.tsrx +14 -14
  61. package/tests/client/css/global-edge-cases.test.tsrx +18 -18
  62. package/tests/client/css/global-keyframes.test.tsrx +12 -12
  63. package/tests/client/css/global-nested.test.tsrx +10 -10
  64. package/tests/client/css/global-pseudo.test.tsrx +12 -12
  65. package/tests/client/css/global-scoping.test.tsrx +20 -20
  66. package/tests/client/css/style-identifier.test.tsrx +143 -291
  67. package/tests/client/date.test.tsrx +146 -133
  68. package/tests/client/dynamic-elements.test.tsrx +398 -365
  69. package/tests/client/events.test.tsrx +292 -290
  70. package/tests/client/for.test.tsrx +156 -153
  71. package/tests/client/head.test.tsrx +105 -96
  72. package/tests/client/html.test.tsrx +122 -26
  73. package/tests/client/input-value.test.tsrx +1361 -1314
  74. package/tests/client/lazy-array.test.tsrx +16 -13
  75. package/tests/client/lazy-destructuring.test.tsrx +257 -213
  76. package/tests/client/map.test.tsrx +65 -60
  77. package/tests/client/media-query.test.tsrx +22 -20
  78. package/tests/client/object.test.tsrx +87 -81
  79. package/tests/client/portal.test.tsrx +57 -51
  80. package/tests/client/ref.test.tsrx +233 -202
  81. package/tests/client/return.test.tsrx +71 -2560
  82. package/tests/client/set.test.tsrx +54 -45
  83. package/tests/client/svg.test.tsrx +216 -186
  84. package/tests/client/switch.test.tsrx +194 -193
  85. package/tests/client/track-async-hydration.test.tsrx +18 -14
  86. package/tests/client/tracked-index-access.test.tsrx +28 -18
  87. package/tests/client/try.test.tsrx +675 -548
  88. package/tests/client/tsx.test.tsrx +373 -311
  89. package/tests/client/typescript-generics.test.tsrx +145 -145
  90. package/tests/client/url/url.derived.test.tsrx +33 -28
  91. package/tests/client/url/url.parsing.test.tsrx +61 -51
  92. package/tests/client/url/url.partial-removal.test.tsrx +56 -48
  93. package/tests/client/url/url.reactivity.test.tsrx +142 -125
  94. package/tests/client/url/url.serialization.test.tsrx +13 -11
  95. package/tests/client/url-search-params/url-search-params.derived.test.tsrx +34 -29
  96. package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +25 -21
  97. package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +50 -45
  98. package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +111 -99
  99. package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +49 -43
  100. package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +14 -12
  101. package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +16 -14
  102. package/tests/hydration/basic.test.js +3 -3
  103. package/tests/hydration/compiled/client/basic.js +586 -651
  104. package/tests/hydration/compiled/client/composite.js +79 -104
  105. package/tests/hydration/compiled/client/events.js +140 -148
  106. package/tests/hydration/compiled/client/for.js +1005 -1018
  107. package/tests/hydration/compiled/client/head.js +124 -134
  108. package/tests/hydration/compiled/client/hmr.js +41 -48
  109. package/tests/hydration/compiled/client/html-in-template.js +38 -41
  110. package/tests/hydration/compiled/client/html.js +970 -1314
  111. package/tests/hydration/compiled/client/if-children.js +234 -249
  112. package/tests/hydration/compiled/client/if.js +182 -189
  113. package/tests/hydration/compiled/client/mixed-control-flow.js +347 -303
  114. package/tests/hydration/compiled/client/nested-control-flow.js +1084 -832
  115. package/tests/hydration/compiled/client/portal.js +65 -85
  116. package/tests/hydration/compiled/client/reactivity.js +84 -90
  117. package/tests/hydration/compiled/client/return.js +38 -1939
  118. package/tests/hydration/compiled/client/switch.js +218 -224
  119. package/tests/hydration/compiled/client/track-async-serialization.js +250 -259
  120. package/tests/hydration/compiled/client/try.js +123 -132
  121. package/tests/hydration/compiled/server/basic.js +773 -831
  122. package/tests/hydration/compiled/server/composite.js +166 -191
  123. package/tests/hydration/compiled/server/events.js +170 -184
  124. package/tests/hydration/compiled/server/for.js +851 -909
  125. package/tests/hydration/compiled/server/head.js +206 -216
  126. package/tests/hydration/compiled/server/hmr.js +64 -72
  127. package/tests/hydration/compiled/server/html-in-template.js +42 -76
  128. package/tests/hydration/compiled/server/html.js +1362 -1667
  129. package/tests/hydration/compiled/server/if-children.js +419 -445
  130. package/tests/hydration/compiled/server/if.js +194 -208
  131. package/tests/hydration/compiled/server/mixed-control-flow.js +249 -257
  132. package/tests/hydration/compiled/server/nested-control-flow.js +491 -515
  133. package/tests/hydration/compiled/server/portal.js +152 -160
  134. package/tests/hydration/compiled/server/reactivity.js +94 -106
  135. package/tests/hydration/compiled/server/return.js +28 -2172
  136. package/tests/hydration/compiled/server/switch.js +274 -286
  137. package/tests/hydration/compiled/server/track-async-serialization.js +340 -358
  138. package/tests/hydration/compiled/server/try.js +167 -185
  139. package/tests/hydration/components/basic.tsrx +320 -272
  140. package/tests/hydration/components/composite.tsrx +44 -32
  141. package/tests/hydration/components/events.tsrx +101 -91
  142. package/tests/hydration/components/for.tsrx +510 -452
  143. package/tests/hydration/components/head.tsrx +87 -80
  144. package/tests/hydration/components/hmr.tsrx +22 -17
  145. package/tests/hydration/components/html-in-template.tsrx +22 -17
  146. package/tests/hydration/components/html.tsrx +525 -443
  147. package/tests/hydration/components/if-children.tsrx +158 -148
  148. package/tests/hydration/components/if.tsrx +109 -95
  149. package/tests/hydration/components/mixed-control-flow.tsrx +100 -96
  150. package/tests/hydration/components/nested-control-flow.tsrx +215 -203
  151. package/tests/hydration/components/portal.tsrx +41 -34
  152. package/tests/hydration/components/reactivity.tsrx +37 -27
  153. package/tests/hydration/components/return.tsrx +12 -556
  154. package/tests/hydration/components/switch.tsrx +120 -114
  155. package/tests/hydration/components/track-async-serialization.tsrx +107 -91
  156. package/tests/hydration/components/try.tsrx +55 -40
  157. package/tests/hydration/html.test.js +4 -4
  158. package/tests/hydration/return.test.js +13 -532
  159. package/tests/server/await.test.tsrx +3 -3
  160. package/tests/server/basic.attributes.test.tsrx +264 -195
  161. package/tests/server/basic.components.test.tsrx +296 -169
  162. package/tests/server/basic.test.tsrx +300 -198
  163. package/tests/server/compiler.test.tsrx +62 -60
  164. package/tests/server/composite.props.test.tsrx +77 -63
  165. package/tests/server/composite.test.tsrx +168 -192
  166. package/tests/server/context.test.tsrx +18 -12
  167. package/tests/server/dynamic-elements.test.tsrx +197 -180
  168. package/tests/server/for.test.tsrx +85 -78
  169. package/tests/server/head.test.tsrx +50 -43
  170. package/tests/server/html-nesting-validation.test.tsrx +8 -8
  171. package/tests/server/if.test.tsrx +57 -51
  172. package/tests/server/lazy-destructuring.test.tsrx +366 -294
  173. package/tests/server/return.test.tsrx +76 -1355
  174. package/tests/server/streaming-ssr.test.tsrx +4 -75
  175. package/tests/server/style-identifier.test.tsrx +169 -148
  176. package/tests/server/switch.test.tsrx +91 -85
  177. package/tests/server/track-async-serialization.test.tsrx +105 -85
  178. package/tests/server/try.test.tsrx +374 -280
  179. package/tests/utils/compiler-compat-config.test.js +2 -2
  180. package/tests/utils/runtime-imports.test.js +10 -0
  181. package/types/index.d.ts +8 -0
  182. 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
- component Test() {
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 = `component Child({ pair: &[first, second] }) {
53
+ const source = `function Child({ pair: &[first, second] }) { return <>
54
54
  second = 10;
55
55
  <div>{first}</div>
56
- }
57
- component App() {
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 = `component Child({ pair: &[first] }) {
68
+ const source = `function Child({ pair: &[first] }) { return <>
69
69
  let value = first[0];
70
70
  <div>{value}</div>
71
- }
72
- component App() {
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
- component App() {
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
- component App() {
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
- component Child({ pair: &[value, tracked_ref] }) {
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
- component App() {
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 component Layout({ children }) {
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 component Layout(props) {
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 component A() {
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
- `component App() {
201
+ `function App() { return <>
202
202
  <div>"Rock &amp; &quot;Roll&quot;"</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 = component(props) => {
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 legacy anonymous component expressions as functions in SSR output', () => {
226
+ it('emits function-expression components as functions in SSR output', () => {
225
227
  const source = `
226
- const Inline = component(props) {
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 component Layout({ children }) {
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 component Layout(props) {
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
- component Card(props) {
265
+ function Card(props) { return <>
262
266
  <div>{props.children}</div>
263
- }
267
+ </>; }
264
268
 
265
- export component App() {
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
- component App() {
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
- component App() {
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 component App() {
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' })).toThrowError(
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' })).toThrowError();
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' })).toThrowError();
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' })).toThrowError();
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' })).toThrowError();
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
- component Card(props) {
445
+ function Card(props) { return <>
444
446
  <div>{props.children}</div>
445
- }
447
+ </>; }
446
448
 
447
- export component App() {
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
- component Card(props) {
463
+ function Card(props) { return <>
462
464
  <div>{props.children}</div>
463
- }
465
+ </>; }
464
466
 
465
- export component App() {
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
- component Child({ foo = 456 }) {
7
- <div>{foo}</div>
6
+ function Child({ foo = 456 }) {
7
+ return <><div>{foo}</div></>;
8
8
  }
9
9
 
10
- component App() {
11
- let &[foo] = track(123);
12
-
13
- <Child />
14
- <Child {foo} />
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
- component Child({ foo = 456 }) {
26
- <div>{foo}</div>
26
+ function Child({ foo = 456 }) {
27
+ return <><div>{foo}</div></>;
27
28
  }
28
29
 
29
- component App() {
30
- let foo = 123;
31
-
32
- <Child />
33
- <Child {foo} />
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
- component Child(props: { foo?: Tracked<number> }) {
45
- <div>{props.foo?.value}</div>
46
+ function Child(props: { foo?: Tracked<number> }) {
47
+ return <><div>{props.foo?.value}</div></>;
46
48
  }
47
49
 
48
- component App() {
49
- let foo = track(123);
50
-
51
- <Child />
52
- <Child {foo} />
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
- component Child({ foo }: { foo?: number }) {
64
- <div>{foo}</div>
66
+ function Child({ foo }: { foo?: number }) {
67
+ return <><div>{foo}</div></>;
65
68
  }
66
69
 
67
- component App() {
68
- let &[foo] = track(123);
69
-
70
- <Child />
71
- <Child {foo} />
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
- component Button(&{ children, ...rest }: Props) {
83
- <button {...rest}>{children}</button>
84
- <style>
85
- .on {
86
- color: blue;
87
- }
88
- .off {
89
- color: red;
90
- }
91
- </style>
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
- component Toggle(&{ pressed, ...rest }: { pressed: Tracked<boolean> }) {
95
- const onClick = () => (pressed.value = !pressed.value);
96
- <Button {...rest} class={pressed.value ? 'on' : 'off'} {onClick}>{'button 1'}</Button>
97
- <Button class={pressed.value ? 'on' : 'off'} {onClick}>{'button 2'}</Button>
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
- component App() {
101
- const pressed = track(true);
102
- <Toggle {pressed} />
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
- component Product({ id, name, organizationName, description, imageUrl, price }: ProductInfo) {
126
- <article class="no-padding">
127
- <img class="responsive small" src={imageUrl} alt={name} />
128
- <span>{id}</span>
129
- <h5>{name}</h5>
130
- <h3>{organizationName}</h3>
131
- <p>{description}</p>
132
- <price class="price">{price}</price>
133
- </article>
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
- component App() {
137
- <Product
138
- id="1"
139
- name="Product 1"
140
- organizationName="Org 1"
141
- description="Description 1"
142
- imageUrl="https://picsum.photos/300/200"
143
- price={15}
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);