ripple 0.2.126 → 0.2.128

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ripple is an elegant TypeScript UI framework",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.126",
6
+ "version": "0.2.128",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index-client.js",
9
9
  "main": "src/runtime/index-client.js",
@@ -109,7 +109,7 @@ const visitors = {
109
109
  const parent = context.path.at(-1);
110
110
 
111
111
  if (
112
- is_reference(node, /** @type {Node} */ (parent)) &&
112
+ is_reference(node, /** @type {Node} */(parent)) &&
113
113
  binding &&
114
114
  context.state.inside_server_block &&
115
115
  context.state.scope.server_block
@@ -144,7 +144,7 @@ const visitors = {
144
144
  }
145
145
 
146
146
  if (
147
- is_reference(node, /** @type {Node} */ (parent)) &&
147
+ is_reference(node, /** @type {Node} */(parent)) &&
148
148
  node.tracked &&
149
149
  binding?.node !== node
150
150
  ) {
@@ -155,7 +155,7 @@ const visitors = {
155
155
  }
156
156
 
157
157
  if (
158
- is_reference(node, /** @type {Node} */ (parent)) &&
158
+ is_reference(node, /** @type {Node} */(parent)) &&
159
159
  node.tracked &&
160
160
  binding?.node !== node
161
161
  ) {
@@ -174,6 +174,18 @@ const visitors = {
174
174
  context.state.metadata.tracking = true;
175
175
  }
176
176
 
177
+ if (node.object.type === 'Identifier' && !node.object.tracked) {
178
+ const binding = context.state.scope.get(node.object.name);
179
+
180
+ if (binding !== null && binding.initial?.type === 'CallExpression' && is_ripple_track_call(binding.initial.callee, context)) {
181
+ error(
182
+ `Accessing a tracked object directly is not allowed, use the \`@\` prefix to read the value inside a tracked object - for example \`@${node.object.name}${node.property.type === 'Identifier' ? `.${node.property.name}` : ''}\``,
183
+ context.state.analysis.module.filename,
184
+ node,
185
+ )
186
+ }
187
+ }
188
+
177
189
  context.next();
178
190
  },
179
191
 
@@ -424,10 +436,10 @@ const visitors = {
424
436
 
425
437
  if (!node.metadata.has_template && !node.metadata.has_await) {
426
438
  error(
427
- 'Component for...of loops must contain a template or an await expression in their body. Move the for loop into an effect if it does not render anything.',
428
- context.state.analysis.module.filename,
429
- node,
430
- );
439
+ 'Component for...of loops must contain a template or an await expression in their body. Move the for loop into an effect if it does not render anything.',
440
+ context.state.analysis.module.filename,
441
+ node,
442
+ );
431
443
  }
432
444
  },
433
445
 
@@ -477,10 +489,10 @@ const visitors = {
477
489
 
478
490
  if (!node.metadata.has_template && !node.metadata.has_await) {
479
491
  error(
480
- 'Component if statements must contain a template or an await expression in their "then" body. Move the if statement into an effect if it does not render anything.',
481
- context.state.analysis.module.filename,
482
- node,
483
- );
492
+ 'Component if statements must contain a template or an await expression in their "then" body. Move the if statement into an effect if it does not render anything.',
493
+ context.state.analysis.module.filename,
494
+ node,
495
+ );
484
496
  }
485
497
 
486
498
  if (node.alternate) {
@@ -490,10 +502,10 @@ const visitors = {
490
502
 
491
503
  if (!node.metadata.has_template && !node.metadata.has_await) {
492
504
  error(
493
- 'Component if statements must contain a template or an await expression in their "else" body. Move the if statement into an effect if it does not render anything.',
494
- context.state.analysis.module.filename,
495
- node,
496
- );
505
+ 'Component if statements must contain a template or an await expression in their "else" body. Move the if statement into an effect if it does not render anything.',
506
+ context.state.analysis.module.filename,
507
+ node,
508
+ );
497
509
  }
498
510
  }
499
511
  },
@@ -599,9 +611,9 @@ const visitors = {
599
611
  state.elements.push(node);
600
612
  // Mark dynamic elements as scoped by default since we can't match CSS at compile time
601
613
  if (state.component?.css) {
602
- node.metadata.scoped = true;
614
+ node.metadata.scoped = true;
603
615
  }
604
- }
616
+ }
605
617
  }
606
618
 
607
619
  if (is_dom_element) {
@@ -756,12 +768,12 @@ const visitors = {
756
768
  mark_control_flow_has_template(context.path);
757
769
  context.next();
758
770
  },
759
-
760
- /**
761
- *
762
- * @param {any} node
763
- * @param {any} context
764
- */
771
+
772
+ /**
773
+ *
774
+ * @param {any} node
775
+ * @param {any} context
776
+ */
765
777
  AwaitExpression(node, context) {
766
778
  if (is_inside_component(context)) {
767
779
  if (context.state.metadata?.await === false) {
@@ -786,7 +798,7 @@ const visitors = {
786
798
  }
787
799
  parent_block.metadata.has_await = true;
788
800
  }
789
-
801
+
790
802
  context.next();
791
803
  },
792
804
  };
@@ -167,6 +167,7 @@ export function bindValue(maybe_tracked) {
167
167
  value = [].map.call(select.querySelectorAll(query), get_option_value);
168
168
  } else {
169
169
  /** @type {HTMLOptionElement | null} */
170
+ // @ts-ignore
170
171
  var selected_option =
171
172
  select.querySelector(query) ??
172
173
  // will fall back to first non-disabled option if no option is selected
@@ -184,6 +185,7 @@ export function bindValue(maybe_tracked) {
184
185
  // Mounting and value undefined -> take selection from dom
185
186
  if (mounting && value === undefined) {
186
187
  /** @type {HTMLOptionElement | null} */
188
+ // @ts-ignore
187
189
  var selected_option = select.querySelector(':checked');
188
190
  if (selected_option !== null) {
189
191
  value = get_option_value(selected_option);
@@ -1,5 +1,6 @@
1
1
  /** @import { Block, Component, Dependency, Derived, Tracked } from '#client' */
2
2
 
3
+ import { DEV } from 'esm-env';
3
4
  import {
4
5
  destroy_block,
5
6
  destroy_non_branch_children,
@@ -138,13 +139,13 @@ export function run_teardown(block) {
138
139
  * @param {Derived} computed
139
140
  */
140
141
  function update_derived(computed) {
141
- var value = computed.v;
142
+ var value = computed.__v;
142
143
 
143
144
  if (value === UNINITIALIZED || is_tracking_dirty(computed.d)) {
144
145
  value = run_derived(computed);
145
146
 
146
- if (value !== computed.v) {
147
- computed.v = value;
147
+ if (value !== computed.__v) {
148
+ computed.__v = value;
148
149
  computed.c = increment_clock();
149
150
  }
150
151
  }
@@ -277,12 +278,23 @@ var empty_get_set = { get: undefined, set: undefined };
277
278
  */
278
279
  export function tracked(v, block, get, set) {
279
280
  // TODO: now we expose tracked, we should likely block access in DEV somehow
281
+ if (DEV) {
282
+ return {
283
+ DO_NOT_ACCESS_THIS_OBJECT_DIRECTLY: true,
284
+ a: get || set ? { get, set } : empty_get_set,
285
+ b: block || active_block,
286
+ c: 0,
287
+ f: TRACKED,
288
+ __v: v,
289
+ };
290
+ }
291
+
280
292
  return {
281
293
  a: get || set ? { get, set } : empty_get_set,
282
294
  b: block || active_block,
283
295
  c: 0,
284
296
  f: TRACKED,
285
- v,
297
+ __v: v,
286
298
  };
287
299
  }
288
300
 
@@ -294,6 +306,21 @@ export function tracked(v, block, get, set) {
294
306
  * @returns {Derived}
295
307
  */
296
308
  export function derived(fn, block, get, set) {
309
+ if (DEV) {
310
+ return {
311
+ DO_NOT_ACCESS_THIS_OBJECT_DIRECTLY: true,
312
+ a: get || set ? { get, set } : empty_get_set,
313
+ b: block || active_block,
314
+ blocks: null,
315
+ c: 0,
316
+ co: active_component,
317
+ d: null,
318
+ f: TRACKED | DERIVED,
319
+ fn,
320
+ __v: UNINITIALIZED,
321
+ };
322
+ }
323
+
297
324
  return {
298
325
  a: get || set ? { get, set } : empty_get_set,
299
326
  b: block || active_block,
@@ -303,7 +330,7 @@ export function derived(fn, block, get, set) {
303
330
  d: null,
304
331
  f: TRACKED | DERIVED,
305
332
  fn,
306
- v: UNINITIALIZED,
333
+ __v: UNINITIALIZED,
307
334
  };
308
335
  }
309
336
 
@@ -354,7 +381,7 @@ export function track_split(v, l, b) {
354
381
  t = tracked(undefined, b);
355
382
  exists = !!descriptors[key];
356
383
  if (exists) {
357
- t = define_property(t, 'v', descriptors[key]);
384
+ t = define_property(t, '__v', descriptors[key]);
358
385
  }
359
386
  }
360
387
 
@@ -468,7 +495,7 @@ export function async_computed(fn, block) {
468
495
  } else {
469
496
  for (var i = 0; i < deferred.length; i++) {
470
497
  var tracked = deferred[i];
471
- new_values.set(tracked, { v: tracked.v, c: tracked.c });
498
+ new_values.set(tracked, { v: tracked.__v, c: tracked.c });
472
499
  }
473
500
  }
474
501
 
@@ -476,11 +503,11 @@ export function async_computed(fn, block) {
476
503
  if (parent && is_destroyed(/** @type {Block} */(parent))) {
477
504
  return;
478
505
  }
479
- if (promise === current && t.v !== v) {
506
+ if (promise === current && t.__v !== v) {
480
507
  restore();
481
508
 
482
- if (t.v === UNINITIALIZED) {
483
- t.v = v;
509
+ if (t.__v === UNINITIALIZED) {
510
+ t.__v = v;
484
511
  } else {
485
512
  set(t, v, block);
486
513
  }
@@ -493,7 +520,7 @@ export function async_computed(fn, block) {
493
520
  var tracked = deferred[i];
494
521
  var stored = /** @type {{ v: any, c: number }} */ (new_values.get(tracked));
495
522
  var { v, c } = stored;
496
- tracked.v = v;
523
+ tracked.__v = v;
497
524
  tracked.c = c;
498
525
  schedule_update(tracked.b);
499
526
  }
@@ -731,10 +758,10 @@ export function get_derived(computed) {
731
758
  }
732
759
  var get = computed.a.get;
733
760
  if (get !== undefined) {
734
- computed.v = trigger_track_get(get, computed.v);
761
+ computed.__v = trigger_track_get(get, computed.__v);
735
762
  }
736
763
 
737
- return computed.v;
764
+ return computed.__v;
738
765
  }
739
766
 
740
767
  /**
@@ -755,7 +782,7 @@ export function get(tracked) {
755
782
  * @param {Tracked} tracked
756
783
  */
757
784
  export function get_tracked(tracked) {
758
- var value = tracked.v;
785
+ var value = tracked.__v;
759
786
  if (tracking) {
760
787
  register_dependency(tracked);
761
788
  }
@@ -791,7 +818,7 @@ export function set(tracked, value, block) {
791
818
  );
792
819
  }
793
820
 
794
- var old_value = tracked.v;
821
+ var old_value = tracked.__v;
795
822
 
796
823
  if (value !== old_value) {
797
824
  var tracked_block = tracked.b;
@@ -809,7 +836,7 @@ export function set(tracked, value, block) {
809
836
  value = untrack(() => set(value, old_value));
810
837
  }
811
838
 
812
- tracked.v = value;
839
+ tracked.__v = value;
813
840
  tracked.c = increment_clock();
814
841
  schedule_update(tracked_block);
815
842
  }
@@ -991,7 +1018,7 @@ export function update(tracked, block, d = 1) {
991
1018
  * @returns {void}
992
1019
  */
993
1020
  export function increment(tracked, block) {
994
- set(tracked, tracked.v + 1, block);
1021
+ set(tracked, tracked.__v + 1, block);
995
1022
  }
996
1023
 
997
1024
  /**
@@ -1000,7 +1027,7 @@ export function increment(tracked, block) {
1000
1027
  * @returns {void}
1001
1028
  */
1002
1029
  export function decrement(tracked, block) {
1003
- set(tracked, tracked.v - 1, block);
1030
+ set(tracked, tracked.__v - 1, block);
1004
1031
  }
1005
1032
 
1006
1033
  /**
@@ -18,14 +18,16 @@ export type Dependency = {
18
18
  };
19
19
 
20
20
  export type Tracked<V = any> = {
21
+ DO_NOT_ACCESS_THIS_OBJECT_DIRECTLY?: true;
21
22
  a: { get?: Function, set?: Function };
22
23
  b: Block;
23
24
  c: number;
24
25
  f: number;
25
- v: V;
26
+ __v: V;
26
27
  };
27
28
 
28
29
  export type Derived = {
30
+ DO_NOT_ACCESS_THIS_OBJECT_DIRECTLY?: true;
29
31
  a: { get?: Function, set?: Function };
30
32
  b: Block;
31
33
  blocks: null | Block[];
@@ -34,7 +36,7 @@ export type Derived = {
34
36
  d: null;
35
37
  f: number;
36
38
  fn: Function;
37
- v: any;
39
+ __v: any;
38
40
  };
39
41
 
40
42
  export type Block = {
@@ -62,7 +62,9 @@ class Output {
62
62
  /** @type {render} */
63
63
  export async function render(component) {
64
64
  const output = new Output(null);
65
- let head, body, css;
65
+ let head = '';
66
+ let body = '';
67
+ let css = new Set();
66
68
 
67
69
  try {
68
70
  if (component.async) {
@@ -40,6 +40,7 @@ export function proxy(value, block) {
40
40
  return value;
41
41
  }
42
42
 
43
+ /** @type {Map<any,Tracked>} */
43
44
  var tracked_elements = new Map();
44
45
  var is_proxied_array = is_array(value);
45
46
  /** @type {Tracked} */
@@ -97,8 +98,8 @@ export function proxy(value, block) {
97
98
  var t = tracked_elements.get(prop);
98
99
  var exists = prop in target;
99
100
 
100
- if (is_proxied_array && prop === 'length') {
101
- for (var i = value; i < t.v; i += 1) {
101
+ if (is_proxied_array && prop === 'length' && t !== undefined) {
102
+ for (var i = value; i < t.__v; i += 1) {
102
103
  var other_t = tracked_elements.get(i + '');
103
104
  if (other_t !== undefined) {
104
105
  set(other_t, UNINITIALIZED, block);
@@ -124,7 +125,7 @@ export function proxy(value, block) {
124
125
  tracked_elements.set(prop, t);
125
126
  }
126
127
  } else {
127
- exists = t.v !== UNINITIALIZED;
128
+ exists = t.__v !== UNINITIALIZED;
128
129
 
129
130
  set(t, value, block);
130
131
  }
@@ -143,7 +144,7 @@ export function proxy(value, block) {
143
144
  // will not cause the length to be out of sync.
144
145
  var n = Number(prop);
145
146
 
146
- if (Number.isInteger(n) && n >= tracked_len.v) {
147
+ if (Number.isInteger(n) && n >= tracked_len.__v) {
147
148
  set(tracked_len, n + 1, block);
148
149
  }
149
150
  }
@@ -180,7 +181,7 @@ export function proxy(value, block) {
180
181
  }
181
182
 
182
183
  var t = tracked_elements.get(prop);
183
- var exists = (t !== undefined && t.v !== UNINITIALIZED) || Reflect.has(target, prop);
184
+ var exists = (t !== undefined && t.__v !== UNINITIALIZED) || Reflect.has(target, prop);
184
185
 
185
186
  if (t !== undefined || !exists || get_descriptor(target, prop)?.writable) {
186
187
  if (t === undefined) {
@@ -229,11 +230,11 @@ export function proxy(value, block) {
229
230
  ownKeys(target) {
230
231
  var own_keys = Reflect.ownKeys(target).filter((key) => {
231
232
  var t = tracked_elements.get(key);
232
- return t === undefined || t.v !== UNINITIALIZED;
233
+ return t === undefined || t.__v !== UNINITIALIZED;
233
234
  });
234
235
 
235
236
  for (var [key, t] of tracked_elements) {
236
- if (t.v !== UNINITIALIZED && !(key in target)) {
237
+ if (t.__v !== UNINITIALIZED && !(key in target)) {
237
238
  own_keys.push(key);
238
239
  }
239
240
  }
@@ -249,7 +250,7 @@ export function proxy(value, block) {
249
250
  if (t) descriptor.value = get(t);
250
251
  } else if (descriptor === undefined) {
251
252
  var t = tracked_elements.get(prop);
252
- var value = t?.v;
253
+ var value = t?.__v;
253
254
 
254
255
  if (t !== undefined && value !== UNINITIALIZED) {
255
256
  return {