ripple 0.2.45 → 0.2.47

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 (36) hide show
  1. package/package.json +1 -1
  2. package/src/compiler/phases/1-parse/index.js +8 -1
  3. package/src/compiler/phases/2-analyze/index.js +640 -650
  4. package/src/compiler/phases/3-transform/index.js +1877 -1813
  5. package/src/compiler/phases/3-transform/segments.js +2 -2
  6. package/src/compiler/utils.js +600 -523
  7. package/src/jsx-runtime.js +12 -12
  8. package/src/runtime/array.js +611 -609
  9. package/src/runtime/index.js +29 -17
  10. package/src/runtime/internal/client/array.js +128 -128
  11. package/src/runtime/internal/client/blocks.js +206 -207
  12. package/src/runtime/internal/client/constants.js +2 -2
  13. package/src/runtime/internal/client/context.js +40 -40
  14. package/src/runtime/internal/client/events.js +191 -191
  15. package/src/runtime/internal/client/for.js +355 -355
  16. package/src/runtime/internal/client/if.js +25 -25
  17. package/src/runtime/internal/client/index.js +57 -52
  18. package/src/runtime/internal/client/operations.js +32 -32
  19. package/src/runtime/internal/client/portal.js +20 -20
  20. package/src/runtime/internal/client/render.js +132 -132
  21. package/src/runtime/internal/client/runtime.js +858 -824
  22. package/src/runtime/internal/client/template.js +36 -36
  23. package/src/runtime/internal/client/try.js +113 -113
  24. package/src/runtime/internal/client/types.d.ts +10 -10
  25. package/src/runtime/internal/client/utils.js +5 -5
  26. package/src/runtime/map.js +139 -139
  27. package/src/runtime/set.js +130 -130
  28. package/src/utils/ast.js +189 -189
  29. package/src/utils/builders.js +244 -244
  30. package/src/utils/sanitize_template_string.js +1 -1
  31. package/tests/__snapshots__/composite.test.ripple.snap +1 -1
  32. package/tests/accessors-props.test.ripple +9 -9
  33. package/tests/basic.test.ripple +4 -4
  34. package/tests/boundaries.test.ripple +17 -17
  35. package/tests/composite.test.ripple +43 -72
  36. package/types/index.d.ts +6 -2
@@ -1,28 +1,27 @@
1
- /** @import { Block, Computed } from '#client' */
1
+ /** @import { Block, Derived } from '#client' */
2
2
 
3
3
  import {
4
- BLOCK_HAS_RUN,
5
- BRANCH_BLOCK,
6
- COMPUTED,
7
- CONTAINS_TEARDOWN,
8
- DESTROYED,
9
- EFFECT_BLOCK,
10
- PAUSED,
11
- RENDER_BLOCK,
12
- ROOT_BLOCK,
13
- TRY_BLOCK,
4
+ BLOCK_HAS_RUN,
5
+ BRANCH_BLOCK,
6
+ DERIVED,
7
+ CONTAINS_TEARDOWN,
8
+ DESTROYED,
9
+ EFFECT_BLOCK,
10
+ PAUSED,
11
+ RENDER_BLOCK,
12
+ ROOT_BLOCK,
13
+ TRY_BLOCK,
14
14
  } from './constants';
15
15
  import { next_sibling } from './operations';
16
16
  import { apply_element_spread } from './render';
17
17
  import {
18
- active_block,
19
- active_component,
20
- active_reaction,
21
- is_block_dirty,
22
- run_block,
23
- run_teardown,
24
- schedule_update,
25
- set_property,
18
+ active_block,
19
+ active_component,
20
+ active_reaction,
21
+ is_block_dirty,
22
+ run_block,
23
+ run_teardown,
24
+ schedule_update,
26
25
  } from './runtime';
27
26
  import { suspend } from './try';
28
27
 
@@ -30,32 +29,32 @@ import { suspend } from './try';
30
29
  * @param {Function} fn
31
30
  */
32
31
  export function user_effect(fn) {
33
- if (active_block === null) {
34
- throw new Error(
35
- 'effect() must be called within an active context, such as a component or effect',
36
- );
37
- }
38
-
39
- var component = active_component;
40
- if (component !== null && !component.m) {
41
- var e = (component.e ??= []);
42
- e.push({
43
- b: active_block,
44
- fn,
45
- r: active_reaction,
46
- });
47
-
48
- return;
49
- }
50
-
51
- return block(EFFECT_BLOCK, fn);
32
+ if (active_block === null) {
33
+ throw new Error(
34
+ 'effect() must be called within an active context, such as a component or effect',
35
+ );
36
+ }
37
+
38
+ var component = active_component;
39
+ if (component !== null && !component.m) {
40
+ var e = (component.e ??= []);
41
+ e.push({
42
+ b: active_block,
43
+ fn,
44
+ r: active_reaction,
45
+ });
46
+
47
+ return;
48
+ }
49
+
50
+ return block(EFFECT_BLOCK, fn);
52
51
  }
53
52
 
54
53
  /**
55
54
  * @param {Function} fn
56
55
  */
57
56
  export function effect(fn) {
58
- return block(EFFECT_BLOCK, fn);
57
+ return block(EFFECT_BLOCK, fn);
59
58
  }
60
59
 
61
60
  /**
@@ -63,7 +62,7 @@ export function effect(fn) {
63
62
  * @param {number} [flags]
64
63
  */
65
64
  export function render(fn, flags = 0) {
66
- return block(RENDER_BLOCK | flags, fn);
65
+ return block(RENDER_BLOCK | flags, fn);
67
66
  }
68
67
 
69
68
  /**
@@ -72,7 +71,7 @@ export function render(fn, flags = 0) {
72
71
  * @param {number} [flags]
73
72
  */
74
73
  export function render_spread(element, fn, flags = 0) {
75
- return block(RENDER_BLOCK | flags, apply_element_spread(element, fn));
74
+ return block(RENDER_BLOCK | flags, apply_element_spread(element, fn));
76
75
  }
77
76
 
78
77
  /**
@@ -80,18 +79,18 @@ export function render_spread(element, fn, flags = 0) {
80
79
  * @param {number} [flags]
81
80
  */
82
81
  export function branch(fn, flags = 0) {
83
- return block(BRANCH_BLOCK | flags, fn);
82
+ return block(BRANCH_BLOCK | flags, fn);
84
83
  }
85
84
 
86
85
  /**
87
86
  * @param {() => any} fn
88
87
  */
89
88
  export function async(fn) {
90
- return block(BRANCH_BLOCK, async () => {
91
- const unsuspend = suspend();
92
- await fn();
93
- unsuspend();
94
- });
89
+ return block(BRANCH_BLOCK, async () => {
90
+ const unsuspend = suspend();
91
+ await fn();
92
+ unsuspend();
93
+ });
95
94
  }
96
95
 
97
96
  /**
@@ -100,27 +99,27 @@ export function async(fn) {
100
99
  * @returns {Block}
101
100
  */
102
101
  export function ref(element, get_fn) {
103
- /** @type {(element: Element) => (void | (() => void) | undefined)} */
104
- var ref_fn;
105
- /** @type {Block | null} */
106
- var e;
107
-
108
- return block(RENDER_BLOCK, () => {
109
- if (ref_fn !== (ref_fn = get_fn())) {
110
- if (e) {
111
- destroy_block(e);
112
- e = null;
113
- }
114
-
115
- if (ref_fn) {
116
- e = branch(() => {
117
- effect(() => {
118
- return ref_fn(element);
119
- });
120
- });
121
- }
122
- }
123
- });
102
+ /** @type {(element: Element) => (void | (() => void) | undefined)} */
103
+ var ref_fn;
104
+ /** @type {Block | null} */
105
+ var e;
106
+
107
+ return block(RENDER_BLOCK, () => {
108
+ if (ref_fn !== (ref_fn = get_fn())) {
109
+ if (e) {
110
+ destroy_block(e);
111
+ e = null;
112
+ }
113
+
114
+ if (ref_fn) {
115
+ e = branch(() => {
116
+ effect(() => {
117
+ return ref_fn(element);
118
+ });
119
+ });
120
+ }
121
+ }
122
+ });
124
123
  }
125
124
 
126
125
  /**
@@ -128,7 +127,7 @@ export function ref(element, get_fn) {
128
127
  * @returns {Block}
129
128
  */
130
129
  export function root(fn) {
131
- return block(ROOT_BLOCK, fn);
130
+ return block(ROOT_BLOCK, fn);
132
131
  }
133
132
 
134
133
  /**
@@ -137,7 +136,7 @@ export function root(fn) {
137
136
  * @returns {Block}
138
137
  */
139
138
  export function create_try_block(fn, state) {
140
- return block(TRY_BLOCK, fn, state);
139
+ return block(TRY_BLOCK, fn, state);
141
140
  }
142
141
 
143
142
  /**
@@ -145,14 +144,14 @@ export function create_try_block(fn, state) {
145
144
  * @param {Block} parent_block
146
145
  */
147
146
  function push_block(block, parent_block) {
148
- var parent_last = parent_block.last;
149
- if (parent_last === null) {
150
- parent_block.last = parent_block.first = block;
151
- } else {
152
- parent_last.next = block;
153
- block.prev = parent_last;
154
- parent_block.last = block;
155
- }
147
+ var parent_last = parent_block.last;
148
+ if (parent_last === null) {
149
+ parent_block.last = parent_block.first = block;
150
+ } else {
151
+ parent_last.next = block;
152
+ block.prev = parent_last;
153
+ parent_block.last = block;
154
+ }
156
155
  }
157
156
 
158
157
  /**
@@ -162,37 +161,37 @@ function push_block(block, parent_block) {
162
161
  * @returns {Block}
163
162
  */
164
163
  export function block(flags, fn, state = null) {
165
- /** @type {Block} */
166
- var block = {
167
- c: active_component,
168
- d: null,
169
- first: null,
170
- f: flags,
171
- fn,
172
- last: null,
173
- next: null,
174
- p: active_block,
175
- prev: null,
176
- s: state,
177
- t: null,
178
- };
179
-
180
- if (active_reaction !== null && (active_reaction.f & COMPUTED) !== 0) {
181
- (/** @type {Computed} */ (active_reaction).blocks ??= []).push(block);
182
- }
183
-
184
- if (active_block !== null) {
185
- push_block(block, active_block);
186
- }
187
-
188
- if ((flags & EFFECT_BLOCK) !== 0) {
189
- schedule_update(block);
190
- } else {
191
- run_block(block);
192
- block.f ^= BLOCK_HAS_RUN;
193
- }
194
-
195
- return block;
164
+ /** @type {Block} */
165
+ var block = {
166
+ c: active_component,
167
+ d: null,
168
+ first: null,
169
+ f: flags,
170
+ fn,
171
+ last: null,
172
+ next: null,
173
+ p: active_block,
174
+ prev: null,
175
+ s: state,
176
+ t: null,
177
+ };
178
+
179
+ if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
180
+ /** @type {Derived} */ ((active_reaction).blocks ??= []).push(block);
181
+ }
182
+
183
+ if (active_block !== null) {
184
+ push_block(block, active_block);
185
+ }
186
+
187
+ if ((flags & EFFECT_BLOCK) !== 0) {
188
+ schedule_update(block);
189
+ } else {
190
+ run_block(block);
191
+ block.f ^= BLOCK_HAS_RUN;
192
+ }
193
+
194
+ return block;
196
195
  }
197
196
 
198
197
  /**
@@ -200,16 +199,16 @@ export function block(flags, fn, state = null) {
200
199
  * @param {boolean} [remove_dom]
201
200
  */
202
201
  export function destroy_block_children(parent, remove_dom = false) {
203
- var block = parent.first;
204
- parent.first = parent.last = null;
205
-
206
- if ((parent.f & CONTAINS_TEARDOWN) !== 0) {
207
- while (block !== null) {
208
- var next = block.next;
209
- destroy_block(block, remove_dom);
210
- block = next;
211
- }
212
- }
202
+ var block = parent.first;
203
+ parent.first = parent.last = null;
204
+
205
+ if ((parent.f & CONTAINS_TEARDOWN) !== 0) {
206
+ while (block !== null) {
207
+ var next = block.next;
208
+ destroy_block(block, remove_dom);
209
+ block = next;
210
+ }
211
+ }
213
212
  }
214
213
 
215
214
  /**
@@ -217,82 +216,82 @@ export function destroy_block_children(parent, remove_dom = false) {
217
216
  * @param {boolean} [remove_dom]
218
217
  */
219
218
  export function destroy_non_branch_children(parent, remove_dom = false) {
220
- var block = parent.first;
221
-
222
- if (
223
- (parent.f & CONTAINS_TEARDOWN) === 0 &&
224
- parent.first !== null &&
225
- (parent.first.f & BRANCH_BLOCK) === 0
226
- ) {
227
- parent.first = parent.last = null;
228
- } else {
229
- while (block !== null) {
230
- var next = block.next;
231
- if ((block.f & BRANCH_BLOCK) === 0) {
232
- destroy_block(block, remove_dom);
233
- }
234
- block = next;
235
- }
236
- }
219
+ var block = parent.first;
220
+
221
+ if (
222
+ (parent.f & CONTAINS_TEARDOWN) === 0 &&
223
+ parent.first !== null &&
224
+ (parent.first.f & BRANCH_BLOCK) === 0
225
+ ) {
226
+ parent.first = parent.last = null;
227
+ } else {
228
+ while (block !== null) {
229
+ var next = block.next;
230
+ if ((block.f & BRANCH_BLOCK) === 0) {
231
+ destroy_block(block, remove_dom);
232
+ }
233
+ block = next;
234
+ }
235
+ }
237
236
  }
238
237
 
239
238
  /**
240
239
  * @param {Block} block
241
240
  */
242
241
  export function unlink_block(block) {
243
- var parent = block.p;
244
- var prev = block.prev;
245
- var next = block.next;
242
+ var parent = block.p;
243
+ var prev = block.prev;
244
+ var next = block.next;
246
245
 
247
- if (prev !== null) prev.next = next;
248
- if (next !== null) next.prev = prev;
246
+ if (prev !== null) prev.next = next;
247
+ if (next !== null) next.prev = prev;
249
248
 
250
- if (parent !== null) {
251
- if (parent.first === block) parent.first = next;
252
- if (parent.last === block) parent.last = prev;
253
- }
249
+ if (parent !== null) {
250
+ if (parent.first === block) parent.first = next;
251
+ if (parent.last === block) parent.last = prev;
252
+ }
254
253
  }
255
254
 
256
255
  /**
257
256
  * @param {Block} block
258
257
  */
259
258
  export function pause_block(block) {
260
- if ((block.f & PAUSED) !== 0) {
261
- return;
262
- }
263
- block.f ^= PAUSED;
259
+ if ((block.f & PAUSED) !== 0) {
260
+ return;
261
+ }
262
+ block.f ^= PAUSED;
264
263
 
265
- var child = block.first;
264
+ var child = block.first;
266
265
 
267
- while (child !== null) {
268
- var next = child.next;
269
- pause_block(child);
270
- child = next;
271
- }
266
+ while (child !== null) {
267
+ var next = child.next;
268
+ pause_block(child);
269
+ child = next;
270
+ }
272
271
 
273
- run_teardown(block);
272
+ run_teardown(block);
274
273
  }
275
274
 
276
275
  /**
277
276
  * @param {Block} block
278
277
  */
279
278
  export function resume_block(block) {
280
- if ((block.f & PAUSED) === 0) {
281
- return;
282
- }
283
- block.f ^= PAUSED;
284
-
285
- if (is_block_dirty(block)) {
286
- schedule_update(block);
287
- }
288
-
289
- var child = block.first;
290
-
291
- while (child !== null) {
292
- var next = child.next;
293
- resume_block(child);
294
- child = next;
295
- }
279
+ if ((block.f & PAUSED) === 0) {
280
+ return;
281
+ }
282
+ block.f ^= PAUSED;
283
+
284
+ if (is_block_dirty(block)) {
285
+ schedule_update(block);
286
+ }
287
+
288
+ var child = block.first;
289
+
290
+ while (child !== null) {
291
+ var next = child.next;
292
+ resume_block(child);
293
+ child = next;
294
+ }
296
295
  }
297
296
 
298
297
  /**
@@ -300,21 +299,21 @@ export function resume_block(block) {
300
299
  * @returns {boolean}
301
300
  */
302
301
  export function is_destroyed(target_block) {
303
- /** @type {Block | null} */
304
- var block = target_block;
305
-
306
- while (block !== null) {
307
- var flags = block.f;
308
-
309
- if ((flags & DESTROYED) !== 0) {
310
- return true;
311
- }
312
- if ((flags & ROOT_BLOCK) !== 0) {
313
- return false;
314
- }
315
- block = block.p;
316
- }
317
- return true;
302
+ /** @type {Block | null} */
303
+ var block = target_block;
304
+
305
+ while (block !== null) {
306
+ var flags = block.f;
307
+
308
+ if ((flags & DESTROYED) !== 0) {
309
+ return true;
310
+ }
311
+ if ((flags & ROOT_BLOCK) !== 0) {
312
+ return false;
313
+ }
314
+ block = block.p;
315
+ }
316
+ return true;
318
317
  }
319
318
 
320
319
  /**
@@ -322,34 +321,34 @@ export function is_destroyed(target_block) {
322
321
  * @param {boolean} [remove_dom]
323
322
  */
324
323
  export function destroy_block(block, remove_dom = true) {
325
- block.f ^= DESTROYED;
324
+ block.f ^= DESTROYED;
326
325
 
327
- var removed = false;
326
+ var removed = false;
328
327
 
329
- if (remove_dom && (block.f & (BRANCH_BLOCK | ROOT_BLOCK)) !== 0) {
330
- var node = block.s.start;
331
- var end = block.s.end;
328
+ if (remove_dom && (block.f & (BRANCH_BLOCK | ROOT_BLOCK)) !== 0) {
329
+ var node = block.s.start;
330
+ var end = block.s.end;
332
331
 
333
- while (node !== null) {
334
- var next = node === end ? null : next_sibling(node);
332
+ while (node !== null) {
333
+ var next = node === end ? null : next_sibling(node);
335
334
 
336
- node.remove();
337
- node = next;
338
- }
335
+ node.remove();
336
+ node = next;
337
+ }
339
338
 
340
- removed = true;
341
- }
339
+ removed = true;
340
+ }
342
341
 
343
- destroy_block_children(block, remove_dom && !removed);
342
+ destroy_block_children(block, remove_dom && !removed);
344
343
 
345
- run_teardown(block);
344
+ run_teardown(block);
346
345
 
347
- var parent = block.p;
346
+ var parent = block.p;
348
347
 
349
- // If the parent doesn't have any children, then skip this work altogether
350
- if (parent !== null && parent.first !== null) {
351
- unlink_block(block);
352
- }
348
+ // If the parent doesn't have any children, then skip this work altogether
349
+ if (parent !== null && parent.first !== null) {
350
+ unlink_block(block);
351
+ }
353
352
 
354
- block.fn = block.s = block.d = block.p = null;
353
+ block.fn = block.s = block.d = block.p = null;
355
354
  }
@@ -11,7 +11,7 @@ export var CONTAINS_UPDATE = 1 << 10;
11
11
  export var CONTAINS_TEARDOWN = 1 << 11;
12
12
  export var BLOCK_HAS_RUN = 1 << 12;
13
13
  export var TRACKED = 1 << 13;
14
- export var COMPUTED = 1 << 14;
14
+ export var DERIVED = 1 << 14;
15
15
  export var DEFERRED = 1 << 15;
16
16
  export var PAUSED = 1 << 16;
17
17
  export var DESTROYED = 1 << 17;
@@ -26,4 +26,4 @@ export var COMPUTED_PROPERTY = Symbol();
26
26
  export var REF_PROP = 'ref';
27
27
  /** @type {unique symbol} */
28
28
  export const ARRAY_SET_INDEX_AT = Symbol();
29
- export const MAX_ARRAY_LENGTH = 2**32 - 1;
29
+ export const MAX_ARRAY_LENGTH = 2 ** 32 - 1;
@@ -6,57 +6,57 @@ import { active_component } from './runtime';
6
6
  * @template T
7
7
  */
8
8
  export class Context {
9
- /**
10
- * @param {T} initial_value
11
- */
12
- constructor(initial_value) {
13
- /** @type {T} */
14
- this._v = initial_value;
15
- }
9
+ /**
10
+ * @param {T} initial_value
11
+ */
12
+ constructor(initial_value) {
13
+ /** @type {T} */
14
+ this._v = initial_value;
15
+ }
16
16
 
17
- get() {
18
- const component = active_component;
19
- const context = this;
17
+ get() {
18
+ const component = active_component;
19
+ const context = this;
20
20
 
21
- if (component === null) {
22
- throw new Error('No active component found, cannot get context');
23
- }
24
- /** @type {Component | null} */
25
- let current_component = component;
21
+ if (component === null) {
22
+ throw new Error('No active component found, cannot get context');
23
+ }
24
+ /** @type {Component | null} */
25
+ let current_component = component;
26
26
 
27
- while (current_component !== null) {
28
- const context_map = current_component.c;
27
+ while (current_component !== null) {
28
+ const context_map = current_component.c;
29
29
 
30
- if (context_map?.has(context)) {
31
- return context_map.get(context);
32
- }
30
+ if (context_map?.has(context)) {
31
+ return context_map.get(context);
32
+ }
33
33
 
34
- current_component = current_component.p;
35
- }
34
+ current_component = current_component.p;
35
+ }
36
36
 
37
- return context._v;
38
- }
37
+ return context._v;
38
+ }
39
39
 
40
- /**
41
- * @template T
42
- * @param {T} value
43
- */
44
- set(value) {
45
- const component = active_component;
46
- const context = this;
40
+ /**
41
+ * @template T
42
+ * @param {T} value
43
+ */
44
+ set(value) {
45
+ const component = active_component;
46
+ const context = this;
47
47
 
48
- if (component === null) {
49
- throw new Error('No active component found, cannot set context');
50
- }
48
+ if (component === null) {
49
+ throw new Error('No active component found, cannot set context');
50
+ }
51
51
 
52
- let current_context = component.c;
52
+ let current_context = component.c;
53
53
 
54
- if (current_context === null) {
55
- current_context = component.c = new Map();
56
- }
54
+ if (current_context === null) {
55
+ current_context = component.c = new Map();
56
+ }
57
57
 
58
- current_context.set(context, value);
59
- }
58
+ current_context.set(context, value);
59
+ }
60
60
  }
61
61
 
62
62
  /**