ripple 0.2.46 → 0.2.48

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 (38) hide show
  1. package/package.json +1 -1
  2. package/src/compiler/phases/1-parse/index.js +52 -2
  3. package/src/compiler/phases/2-analyze/index.js +640 -667
  4. package/src/compiler/phases/3-transform/index.js +1878 -1879
  5. package/src/compiler/phases/3-transform/segments.js +2 -2
  6. package/src/compiler/utils.js +598 -550
  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 +121 -121
  11. package/src/runtime/internal/client/blocks.js +206 -206
  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 -56
  18. package/src/runtime/internal/client/operations.js +32 -32
  19. package/src/runtime/internal/client/portal.js +19 -19
  20. package/src/runtime/internal/client/render.js +132 -132
  21. package/src/runtime/internal/client/runtime.js +839 -835
  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 +12 -11
  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/compiler.test.ripple +14 -14
  36. package/tests/composite.test.ripple +43 -72
  37. package/tests/context.test.ripple +35 -12
  38. package/types/index.d.ts +38 -34
@@ -3,49 +3,49 @@ import { first_child, is_firefox } from './operations.js';
3
3
  import { active_block } from './runtime.js';
4
4
 
5
5
  export function assign_nodes(start, end) {
6
- var block = /** @type {Effect} */ (active_block);
7
- if (block.s === null) {
8
- block.s = {
9
- start,
10
- end,
11
- };
12
- }
6
+ var block = /** @type {Effect} */ (active_block);
7
+ if (block.s === null) {
8
+ block.s = {
9
+ start,
10
+ end,
11
+ };
12
+ }
13
13
  }
14
14
 
15
15
  function create_fragment_from_html(html) {
16
- var elem = document.createElement('template');
17
- elem.innerHTML = html;
18
- return elem.content;
16
+ var elem = document.createElement('template');
17
+ elem.innerHTML = html;
18
+ return elem.content;
19
19
  }
20
20
 
21
21
  export function template(content, flags) {
22
- var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
23
- var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
24
- var node;
25
- var has_start = !content.startsWith('<!>');
26
-
27
- return () => {
28
- if (node === undefined) {
29
- node = create_fragment_from_html(has_start ? content : '<!>' + content);
30
- if (!is_fragment) node = first_child(node);
31
- }
32
-
33
- var clone =
34
- use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true);
35
-
36
- if (is_fragment) {
37
- var start = first_child(clone);
38
- var end = clone.lastChild;
39
-
40
- assign_nodes(start, end);
41
- } else {
42
- assign_nodes(clone, clone);
43
- }
44
-
45
- return clone;
46
- };
22
+ var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
23
+ var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
24
+ var node;
25
+ var has_start = !content.startsWith('<!>');
26
+
27
+ return () => {
28
+ if (node === undefined) {
29
+ node = create_fragment_from_html(has_start ? content : '<!>' + content);
30
+ if (!is_fragment) node = first_child(node);
31
+ }
32
+
33
+ var clone =
34
+ use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true);
35
+
36
+ if (is_fragment) {
37
+ var start = first_child(clone);
38
+ var end = clone.lastChild;
39
+
40
+ assign_nodes(start, end);
41
+ } else {
42
+ assign_nodes(clone, clone);
43
+ }
44
+
45
+ return clone;
46
+ };
47
47
  }
48
48
 
49
49
  export function append(anchor, dom) {
50
- anchor.before(/** @type {Node} */ (dom));
50
+ anchor.before(/** @type {Node} */ (dom));
51
51
  }
@@ -2,138 +2,138 @@ import { branch, create_try_block, destroy_block, is_destroyed, resume_block } f
2
2
  import { TRY_BLOCK } from './constants';
3
3
  import { next_sibling } from './operations';
4
4
  import {
5
- active_block,
6
- active_component,
7
- active_reaction,
8
- queue_microtask,
9
- set_active_block,
10
- set_active_component,
11
- set_active_reaction,
12
- set_tracking,
13
- tracking,
5
+ active_block,
6
+ active_component,
7
+ active_reaction,
8
+ queue_microtask,
9
+ set_active_block,
10
+ set_active_component,
11
+ set_active_reaction,
12
+ set_tracking,
13
+ tracking,
14
14
  } from './runtime';
15
15
 
16
16
  export function try_block(node, fn, catch_fn, pending_fn = null) {
17
- var anchor = node;
18
- var b = null;
19
- var suspended = null;
20
- var pending_count = 0;
21
- var offscreen_fragment = null;
22
-
23
- function move_block(block, fragment) {
24
- var state = block.s;
25
- var node = state.start;
26
- var end = state.end;
27
-
28
- while (node !== null) {
29
- var next = node === end ? null : next_sibling(node);
30
-
31
- fragment.append(node);
32
- node = next;
33
- }
34
- }
35
-
36
- function handle_await() {
37
- if (pending_count++ === 0) {
38
- queue_microtask(() => {
39
- if (b !== null) {
40
- suspended = b;
41
- offscreen_fragment = document.createDocumentFragment();
42
- move_block(b, offscreen_fragment);
43
-
44
- b = branch(() => {
45
- pending_fn(anchor);
46
- });
47
- }
48
- });
49
- }
50
-
51
- return () => {
52
- if (--pending_count === 0) {
53
- if (b !== null) {
54
- destroy_block(b);
55
- }
56
- anchor.before(offscreen_fragment);
57
- offscreen_fragment = null;
58
- resume_block(suspended);
59
- b = suspended;
60
- suspended = null;
61
- }
62
- };
63
- }
64
-
65
- function handle_error(error) {
66
- if (b !== null) {
67
- destroy_block(b);
68
- }
69
-
70
- b = branch(() => {
71
- catch_fn(anchor, error);
72
- });
73
- }
74
-
75
- var state = {
76
- a: pending_fn !== null ? handle_await : null,
77
- c: catch_fn !== null ? handle_error : null,
78
- };
79
-
80
- create_try_block(() => {
81
- b = branch(() => {
82
- fn(anchor);
83
- });
84
- }, state);
17
+ var anchor = node;
18
+ var b = null;
19
+ var suspended = null;
20
+ var pending_count = 0;
21
+ var offscreen_fragment = null;
22
+
23
+ function move_block(block, fragment) {
24
+ var state = block.s;
25
+ var node = state.start;
26
+ var end = state.end;
27
+
28
+ while (node !== null) {
29
+ var next = node === end ? null : next_sibling(node);
30
+
31
+ fragment.append(node);
32
+ node = next;
33
+ }
34
+ }
35
+
36
+ function handle_await() {
37
+ if (pending_count++ === 0) {
38
+ queue_microtask(() => {
39
+ if (b !== null) {
40
+ suspended = b;
41
+ offscreen_fragment = document.createDocumentFragment();
42
+ move_block(b, offscreen_fragment);
43
+
44
+ b = branch(() => {
45
+ pending_fn(anchor);
46
+ });
47
+ }
48
+ });
49
+ }
50
+
51
+ return () => {
52
+ if (--pending_count === 0) {
53
+ if (b !== null) {
54
+ destroy_block(b);
55
+ }
56
+ anchor.before(offscreen_fragment);
57
+ offscreen_fragment = null;
58
+ resume_block(suspended);
59
+ b = suspended;
60
+ suspended = null;
61
+ }
62
+ };
63
+ }
64
+
65
+ function handle_error(error) {
66
+ if (b !== null) {
67
+ destroy_block(b);
68
+ }
69
+
70
+ b = branch(() => {
71
+ catch_fn(anchor, error);
72
+ });
73
+ }
74
+
75
+ var state = {
76
+ a: pending_fn !== null ? handle_await : null,
77
+ c: catch_fn !== null ? handle_error : null,
78
+ };
79
+
80
+ create_try_block(() => {
81
+ b = branch(() => {
82
+ fn(anchor);
83
+ });
84
+ }, state);
85
85
  }
86
86
 
87
87
  export function suspend() {
88
- var current = active_block;
88
+ var current = active_block;
89
89
 
90
- while (current !== null) {
91
- var state = current.s;
92
- if ((current.f & TRY_BLOCK) !== 0 && state.a !== null) {
93
- return state.a();
94
- }
95
- current = current.p;
96
- }
90
+ while (current !== null) {
91
+ var state = current.s;
92
+ if ((current.f & TRY_BLOCK) !== 0 && state.a !== null) {
93
+ return state.a();
94
+ }
95
+ current = current.p;
96
+ }
97
97
 
98
- throw new Error('Missing parent `try { ... } async { ... }` statement');
98
+ throw new Error('Missing parent `try { ... } async { ... }` statement');
99
99
  }
100
100
 
101
101
  function exit() {
102
- set_tracking(false);
103
- set_active_reaction(null);
104
- set_active_block(null);
105
- set_active_component(null);
102
+ set_tracking(false);
103
+ set_active_reaction(null);
104
+ set_active_block(null);
105
+ set_active_component(null);
106
106
  }
107
107
 
108
108
  export function capture() {
109
- var previous_tracking = tracking;
110
- var previous_block = active_block;
111
- var previous_reaction = active_reaction;
112
- var previous_component = active_component;
113
-
114
- return () => {
115
- set_tracking(previous_tracking);
116
- set_active_block(previous_block);
117
- set_active_reaction(previous_reaction);
118
- set_active_component(previous_component);
119
-
120
- queue_microtask(exit);
121
- };
109
+ var previous_tracking = tracking;
110
+ var previous_block = active_block;
111
+ var previous_reaction = active_reaction;
112
+ var previous_component = active_component;
113
+
114
+ return () => {
115
+ set_tracking(previous_tracking);
116
+ set_active_block(previous_block);
117
+ set_active_reaction(previous_reaction);
118
+ set_active_component(previous_component);
119
+
120
+ queue_microtask(exit);
121
+ };
122
122
  }
123
123
 
124
124
  export function aborted() {
125
- if (active_block === null) {
126
- return true;
127
- }
128
- return is_destroyed(active_block);
125
+ if (active_block === null) {
126
+ return true;
127
+ }
128
+ return is_destroyed(active_block);
129
129
  }
130
130
 
131
131
  export async function resume_context(promise) {
132
- var restore = capture();
133
- var value = await promise;
132
+ var restore = capture();
133
+ var value = await promise;
134
134
 
135
- return () => {
136
- restore();
137
- return value;
138
- };
135
+ return () => {
136
+ restore();
137
+ return value;
138
+ };
139
139
  }
@@ -5,7 +5,7 @@ export type Component = {
5
5
  e: null | Array<{
6
6
  b: Block;
7
7
  fn: Function;
8
- r: null | Block | Computed;
8
+ r: null | Block | Derived;
9
9
  }>;
10
10
  p: null | Component;
11
11
  m: boolean;
@@ -13,7 +13,7 @@ export type Component = {
13
13
 
14
14
  export type Dependency = {
15
15
  c: number;
16
- t: Tracked | Computed;
16
+ t: Tracked | Derived;
17
17
  n: null | Dependency;
18
18
  };
19
19
 
@@ -24,18 +24,19 @@ export type Tracked = {
24
24
  v: any;
25
25
  };
26
26
 
27
- export type Computed = {
28
- b: Block,
29
- blocks: null | Block[],
30
- c: number,
31
- d: null,
32
- f: number,
33
- fn: Function,
34
- v: any,
27
+ export type Derived = {
28
+ b: Block;
29
+ blocks: null | Block[];
30
+ c: number;
31
+ co: null | Component;
32
+ d: null;
33
+ f: number;
34
+ fn: Function;
35
+ v: any;
35
36
  };
36
37
 
37
38
  export type Block = {
38
- c: null | Component;
39
+ co: null | Component;
39
40
  d: null | Dependency;
40
41
  first: null | Block;
41
42
  f: number;
@@ -13,9 +13,9 @@ export var get_own_property_symbols = Object.getOwnPropertySymbols;
13
13
  export var structured_clone = structuredClone;
14
14
 
15
15
  export function create_anchor() {
16
- var t = document.createTextNode('');
17
- t.__t = '';
18
- return t;
16
+ var t = document.createTextNode('');
17
+ t.__t = '';
18
+ return t;
19
19
  }
20
20
 
21
21
  /**
@@ -23,7 +23,7 @@ export function create_anchor() {
23
23
  * @returns {boolean}
24
24
  */
25
25
  export function is_ripple_array(obj) {
26
- return is_array(obj) && TRACKED_OBJECT in obj && '$length' in obj;
26
+ return is_array(obj) && TRACKED_OBJECT in obj && '$length' in obj;
27
27
  }
28
28
 
29
29
  /**
@@ -31,5 +31,5 @@ export function is_ripple_array(obj) {
31
31
  * @returns {boolean}
32
32
  */
33
33
  export function is_positive_integer(value) {
34
- return Number.isInteger(value) && /**@type {number} */ (value) >= 0;
34
+ return Number.isInteger(value) && /**@type {number} */ (value) >= 0;
35
35
  }