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
@@ -2,34 +2,34 @@ import { branch, destroy_block, render } from './blocks';
2
2
  import { IF_BLOCK, UNINITIALIZED } from './constants';
3
3
 
4
4
  export function if_block(node, fn) {
5
- var anchor = node;
6
- var has_branch = false;
7
- var condition = UNINITIALIZED;
8
- var b = null;
5
+ var anchor = node;
6
+ var has_branch = false;
7
+ var condition = UNINITIALIZED;
8
+ var b = null;
9
9
 
10
- var set_branch = (fn, flag = true) => {
11
- has_branch = true;
12
- update_branch(flag, fn);
13
- };
10
+ var set_branch = (fn, flag = true) => {
11
+ has_branch = true;
12
+ update_branch(flag, fn);
13
+ };
14
14
 
15
- var update_branch = (new_condition, fn) => {
16
- if (condition === (condition = new_condition)) return;
15
+ var update_branch = (new_condition, fn) => {
16
+ if (condition === (condition = new_condition)) return;
17
17
 
18
- if (b !== null) {
19
- destroy_block(b);
20
- b = null;
21
- }
18
+ if (b !== null) {
19
+ destroy_block(b);
20
+ b = null;
21
+ }
22
22
 
23
- if (fn !== null) {
24
- b = branch(() => fn(anchor));
25
- }
26
- };
23
+ if (fn !== null) {
24
+ b = branch(() => fn(anchor));
25
+ }
26
+ };
27
27
 
28
- render(() => {
29
- has_branch = false;
30
- fn(set_branch);
31
- if (!has_branch) {
32
- update_branch(null, null);
33
- }
34
- }, IF_BLOCK);
28
+ render(() => {
29
+ has_branch = false;
30
+ fn(set_branch);
31
+ if (!has_branch) {
32
+ update_branch(null, null);
33
+ }
34
+ }, IF_BLOCK);
35
35
  }
@@ -1,12 +1,12 @@
1
1
  export { first_child as child, child_frag, next_sibling as sibling } from './operations.js';
2
2
 
3
3
  export {
4
- set_text,
5
- set_class,
6
- set_attribute,
7
- set_value,
8
- set_checked,
9
- set_selected,
4
+ set_text,
5
+ set_class,
6
+ set_attribute,
7
+ set_value,
8
+ set_checked,
9
+ set_selected,
10
10
  } from './render.js';
11
11
 
12
12
  export { render, render_spread, async, ref } from './blocks.js';
@@ -14,59 +14,60 @@ export { render, render_spread, async, ref } from './blocks.js';
14
14
  export { event, delegate } from './events.js';
15
15
 
16
16
  export {
17
- active_block,
18
- scope,
19
- safe_scope,
20
- with_scope,
21
- get_tracked,
22
- get_computed,
23
- set,
24
- computed,
25
- async_computed,
26
- tracked,
27
- tracked_object,
28
- tracked_spread_object,
29
- computed_property,
30
- call_property,
31
- get_property,
32
- old_get_property,
33
- old_set_property,
34
- set_property,
35
- update,
36
- update_pre,
37
- old_update_property,
38
- update_property,
39
- old_update_pre_property,
40
- update_pre_property,
41
- object_values,
42
- object_entries,
43
- object_keys,
44
- spread_object,
45
- structured_clone,
46
- push_component,
47
- pop_component,
48
- untrack,
49
- ref_prop,
50
- fallback,
51
- exclude_from_object,
17
+ active_block,
18
+ scope,
19
+ safe_scope,
20
+ with_scope,
21
+ get,
22
+ get_tracked,
23
+ get_derived,
24
+ set,
25
+ async_computed,
26
+ tracked,
27
+ tracked_object,
28
+ tracked_spread_object,
29
+ computed_property,
30
+ call_property,
31
+ get_property,
32
+ old_get_property,
33
+ old_set_property,
34
+ set_property,
35
+ update,
36
+ update_pre,
37
+ old_update_property,
38
+ update_property,
39
+ old_update_pre_property,
40
+ update_pre_property,
41
+ object_values,
42
+ object_entries,
43
+ object_keys,
44
+ spread_object,
45
+ structured_clone,
46
+ push_component,
47
+ pop_component,
48
+ untrack,
49
+ ref_prop,
50
+ fallback,
51
+ exclude_from_object,
52
+ derived,
52
53
  } from './runtime.js';
53
54
 
54
55
  export {
55
- array_reduce,
56
- array_join,
57
- array_map,
58
- array_filter,
59
- array_forEach,
60
- array_includes,
61
- array_indexOf,
62
- array_lastIndexOf,
63
- array_every,
64
- array_some,
65
- array_toString,
66
- array_toSorted,
67
- array_toSpliced,
68
- array_values,
69
- array_entries,
56
+ array_reduce,
57
+ array_join,
58
+ array_map,
59
+ array_filter,
60
+ array_forEach,
61
+ array_includes,
62
+ array_indexOf,
63
+ array_lastIndexOf,
64
+ array_every,
65
+ array_some,
66
+ array_toString,
67
+ array_toSorted,
68
+ array_toSpliced,
69
+ array_values,
70
+ array_entries,
70
71
  } from './array.js';
71
72
 
72
73
  export { for_block as for } from './for.js';
@@ -9,33 +9,33 @@ var next_sibling_getter;
9
9
  export var is_firefox;
10
10
 
11
11
  export function init_operations() {
12
- var node_prototype = Node.prototype;
13
- var element_prototype = Element.prototype;
14
- var object_prototype = Object.prototype;
15
- var event_target_prototype = EventTarget.prototype;
12
+ var node_prototype = Node.prototype;
13
+ var element_prototype = Element.prototype;
14
+ var object_prototype = Object.prototype;
15
+ var event_target_prototype = EventTarget.prototype;
16
16
 
17
- is_firefox = /Firefox/.test(navigator.userAgent);
17
+ is_firefox = /Firefox/.test(navigator.userAgent);
18
18
 
19
- // @ts-ignore
20
- first_child_getter = get_descriptor(node_prototype, 'firstChild').get;
21
- // @ts-ignore
22
- next_sibling_getter = get_descriptor(node_prototype, 'nextSibling').get;
19
+ // @ts-ignore
20
+ first_child_getter = get_descriptor(node_prototype, 'firstChild').get;
21
+ // @ts-ignore
22
+ next_sibling_getter = get_descriptor(node_prototype, 'nextSibling').get;
23
23
 
24
- // the following assignments improve perf of lookups on DOM nodes
25
- // @ts-expect-error
26
- element_prototype.__click = undefined;
27
- // @ts-expect-error
28
- element_prototype.__className = '';
29
- // @ts-expect-error
30
- element_prototype.__attributes = null;
31
- // @ts-expect-error
32
- element_prototype.__styles = null;
33
- // @ts-expect-error
34
- element_prototype.__e = undefined;
35
- // @ts-expect-error
36
- object_prototype[TRACKED_OBJECT] = undefined;
37
- // @ts-expect-error
38
- event_target_prototype.__root = undefined;
24
+ // the following assignments improve perf of lookups on DOM nodes
25
+ // @ts-expect-error
26
+ element_prototype.__click = undefined;
27
+ // @ts-expect-error
28
+ element_prototype.__className = '';
29
+ // @ts-expect-error
30
+ element_prototype.__attributes = null;
31
+ // @ts-expect-error
32
+ element_prototype.__styles = null;
33
+ // @ts-expect-error
34
+ element_prototype.__e = undefined;
35
+ // @ts-expect-error
36
+ object_prototype[TRACKED_OBJECT] = undefined;
37
+ // @ts-expect-error
38
+ event_target_prototype.__root = undefined;
39
39
  }
40
40
 
41
41
  /**
@@ -45,16 +45,16 @@ export function init_operations() {
45
45
  */
46
46
  /*@__NO_SIDE_EFFECTS__*/
47
47
  export function first_child(node) {
48
- return first_child_getter.call(node);
48
+ return first_child_getter.call(node);
49
49
  }
50
50
 
51
51
  export function child_frag(node) {
52
- var child = first_child(node);
52
+ var child = first_child(node);
53
53
 
54
- if (child.nodeType === 8 && child.data === '') {
55
- return next_sibling(child);
56
- }
57
- return child;
54
+ if (child.nodeType === 8 && child.data === '') {
55
+ return next_sibling(child);
56
+ }
57
+ return child;
58
58
  }
59
59
 
60
60
  /**
@@ -64,9 +64,9 @@ export function child_frag(node) {
64
64
  */
65
65
  /*@__NO_SIDE_EFFECTS__*/
66
66
  export function next_sibling(node) {
67
- return next_sibling_getter.call(node);
67
+ return next_sibling_getter.call(node);
68
68
  }
69
69
 
70
70
  export function create_text(value = '') {
71
- return document.createTextNode(value);
71
+ return document.createTextNode(value);
72
72
  }
@@ -5,29 +5,29 @@ import { create_text } from './operations';
5
5
  import { old_get_property } from './runtime';
6
6
 
7
7
  export function Portal(_, props) {
8
- let $target = UNINITIALIZED;
9
- let children = UNINITIALIZED;
10
- var b = null;
11
- var anchor = null;
8
+ let $target = UNINITIALIZED;
9
+ let children = UNINITIALIZED;
10
+ var b = null;
11
+ var anchor = null;
12
12
 
13
- render(() => {
14
- if ($target === ($target = old_get_property(props, '$target'))) return;
15
- if (children === (children = old_get_property(props, 'children'))) return;
13
+ render(() => {
14
+ if ($target === ($target = old_get_property(props, '$target'))) return;
15
+ if (children === (children = old_get_property(props, 'children'))) return;
16
16
 
17
- if (b !== null) {
18
- destroy_block(b);
19
- }
17
+ if (b !== null) {
18
+ destroy_block(b);
19
+ }
20
20
 
21
- anchor = create_text();
22
- $target.append(anchor);
21
+ anchor = create_text();
22
+ $target.append(anchor);
23
23
 
24
- const cleanup_events = handle_root_events($target);
24
+ const cleanup_events = handle_root_events($target);
25
25
 
26
- b = branch(() => children(anchor));
26
+ b = branch(() => children(anchor));
27
27
 
28
- return () => {
29
- cleanup_events();
30
- anchor.remove();
31
- };
32
- });
28
+ return () => {
29
+ cleanup_events();
30
+ anchor.remove();
31
+ };
32
+ });
33
33
  }
@@ -3,76 +3,76 @@ import { REF_PROP } from './constants';
3
3
  import { get_descriptors, get_own_property_symbols, get_prototype_of } from './utils';
4
4
 
5
5
  export function set_text(text, value) {
6
- // For objects, we apply string coercion (which might make things like $state array references in the template reactive) before diffing
7
- var str = value == null ? '' : typeof value === 'object' ? value + '' : value;
8
- // @ts-expect-error
9
- if (str !== (text.__t ??= text.nodeValue)) {
10
- // @ts-expect-error
11
- text.__t = str;
12
- text.nodeValue = str + '';
13
- }
6
+ // For objects, we apply string coercion (which might make things like $state array references in the template reactive) before diffing
7
+ var str = value == null ? '' : typeof value === 'object' ? value + '' : value;
8
+ // @ts-expect-error
9
+ if (str !== (text.__t ??= text.nodeValue)) {
10
+ // @ts-expect-error
11
+ text.__t = str;
12
+ text.nodeValue = str + '';
13
+ }
14
14
  }
15
15
 
16
16
  var setters_cache = new Map();
17
17
 
18
18
  function get_setters(element) {
19
- var setters = setters_cache.get(element.nodeName);
20
- if (setters) return setters;
21
- setters_cache.set(element.nodeName, (setters = []));
19
+ var setters = setters_cache.get(element.nodeName);
20
+ if (setters) return setters;
21
+ setters_cache.set(element.nodeName, (setters = []));
22
22
 
23
- var descriptors;
24
- var proto = element; // In the case of custom elements there might be setters on the instance
25
- var element_proto = Element.prototype;
23
+ var descriptors;
24
+ var proto = element; // In the case of custom elements there might be setters on the instance
25
+ var element_proto = Element.prototype;
26
26
 
27
- // Stop at Element, from there on there's only unnecessary setters we're not interested in
28
- // Do not use constructor.name here as that's unreliable in some browser environments
29
- while (element_proto !== proto) {
30
- descriptors = get_descriptors(proto);
27
+ // Stop at Element, from there on there's only unnecessary setters we're not interested in
28
+ // Do not use constructor.name here as that's unreliable in some browser environments
29
+ while (element_proto !== proto) {
30
+ descriptors = get_descriptors(proto);
31
31
 
32
- for (var key in descriptors) {
33
- if (descriptors[key].set) {
34
- setters.push(key);
35
- }
36
- }
32
+ for (var key in descriptors) {
33
+ if (descriptors[key].set) {
34
+ setters.push(key);
35
+ }
36
+ }
37
37
 
38
- proto = get_prototype_of(proto);
39
- }
38
+ proto = get_prototype_of(proto);
39
+ }
40
40
 
41
- return setters;
41
+ return setters;
42
42
  }
43
43
 
44
44
  export function set_attribute(element, attribute, value) {
45
- // @ts-expect-error
46
- var attributes = (element.__attributes ??= {});
47
-
48
- if (attributes[attribute] === (attributes[attribute] = value)) return;
49
-
50
- if (attribute === 'style' && '__styles' in element) {
51
- // reset styles to force style: directive to update
52
- element.__styles = {};
53
- }
54
-
55
- if (value == null) {
56
- element.removeAttribute(attribute);
57
- } else if (typeof value !== 'string' && get_setters(element).includes(attribute)) {
58
- element[attribute] = value;
59
- } else {
60
- element.setAttribute(attribute, value);
61
- }
45
+ // @ts-expect-error
46
+ var attributes = (element.__attributes ??= {});
47
+
48
+ if (attributes[attribute] === (attributes[attribute] = value)) return;
49
+
50
+ if (attribute === 'style' && '__styles' in element) {
51
+ // reset styles to force style: directive to update
52
+ element.__styles = {};
53
+ }
54
+
55
+ if (value == null) {
56
+ element.removeAttribute(attribute);
57
+ } else if (typeof value !== 'string' && get_setters(element).includes(attribute)) {
58
+ element[attribute] = value;
59
+ } else {
60
+ element.setAttribute(attribute, value);
61
+ }
62
62
  }
63
63
 
64
64
  export function set_attributes(element, attributes) {
65
- for (const key in attributes) {
66
- if (key === '$children') continue;
65
+ for (const key in attributes) {
66
+ if (key === 'children') continue;
67
67
 
68
- let value = attributes[key];
68
+ let value = attributes[key];
69
69
 
70
- if (key === 'class') {
71
- set_class(element, value);
72
- } else {
73
- set_attribute(element, key, value);
74
- }
75
- }
70
+ if (key === 'class') {
71
+ set_class(element, value);
72
+ } else {
73
+ set_attribute(element, key, value);
74
+ }
75
+ }
76
76
  }
77
77
 
78
78
  /**
@@ -82,7 +82,7 @@ export function set_attributes(element, attributes) {
82
82
  * @returns {string | V}
83
83
  */
84
84
  function to_class(value, hash) {
85
- return (value == null ? '' : value) + (hash ? ' ' + hash : '');
85
+ return (value == null ? '' : value) + (hash ? ' ' + hash : '');
86
86
  }
87
87
 
88
88
  /**
@@ -92,102 +92,102 @@ function to_class(value, hash) {
92
92
  * @returns {void}
93
93
  */
94
94
  export function set_class(dom, value, hash) {
95
- // @ts-expect-error need to add __className to patched prototype
96
- var prev_class_name = dom.__className;
97
- var next_class_name = to_class(value, hash);
98
-
99
- if (prev_class_name !== next_class_name) {
100
- // Removing the attribute when the value is only an empty string causes
101
- // peformance issues vs simply making the className an empty string. So
102
- // we should only remove the class if the the value is nullish.
103
- if (value == null && !hash) {
104
- dom.removeAttribute('class');
105
- } else {
106
- dom.className = next_class_name;
107
- }
108
-
109
- // @ts-expect-error need to add __className to patched prototype
110
- dom.__className = next_class_name;
111
- }
95
+ // @ts-expect-error need to add __className to patched prototype
96
+ var prev_class_name = dom.__className;
97
+ var next_class_name = to_class(value, hash);
98
+
99
+ if (prev_class_name !== next_class_name) {
100
+ // Removing the attribute when the value is only an empty string causes
101
+ // peformance issues vs simply making the className an empty string. So
102
+ // we should only remove the class if the the value is nullish.
103
+ if (value == null && !hash) {
104
+ dom.removeAttribute('class');
105
+ } else {
106
+ dom.className = next_class_name;
107
+ }
108
+
109
+ // @ts-expect-error need to add __className to patched prototype
110
+ dom.__className = next_class_name;
111
+ }
112
112
  }
113
113
 
114
114
  export function set_value(element, value) {
115
- // @ts-expect-error
116
- var attributes = (element.__attributes ??= {});
117
-
118
- if (
119
- attributes.value ===
120
- (attributes.value =
121
- // treat null and undefined the same for the initial value
122
- value ?? undefined) ||
123
- // @ts-expect-error
124
- // `progress` elements always need their value set when it's `0`
125
- (element.value === value && (value !== 0 || element.nodeName !== 'PROGRESS'))
126
- ) {
127
- return;
128
- }
129
-
130
- // @ts-expect-error
131
- element.value = value ?? '';
115
+ // @ts-expect-error
116
+ var attributes = (element.__attributes ??= {});
117
+
118
+ if (
119
+ attributes.value ===
120
+ (attributes.value =
121
+ // treat null and undefined the same for the initial value
122
+ value ?? undefined) ||
123
+ // @ts-expect-error
124
+ // `progress` elements always need their value set when it's `0`
125
+ (element.value === value && (value !== 0 || element.nodeName !== 'PROGRESS'))
126
+ ) {
127
+ return;
128
+ }
129
+
130
+ // @ts-expect-error
131
+ element.value = value ?? '';
132
132
  }
133
133
 
134
134
  export function set_checked(element, checked) {
135
- // @ts-expect-error
136
- var attributes = (element.__attributes ??= {});
137
-
138
- if (
139
- attributes.checked ===
140
- (attributes.checked =
141
- // treat null and undefined the same for the initial value
142
- checked ?? undefined)
143
- ) {
144
- return;
145
- }
146
-
147
- // @ts-expect-error
148
- element.checked = checked;
135
+ // @ts-expect-error
136
+ var attributes = (element.__attributes ??= {});
137
+
138
+ if (
139
+ attributes.checked ===
140
+ (attributes.checked =
141
+ // treat null and undefined the same for the initial value
142
+ checked ?? undefined)
143
+ ) {
144
+ return;
145
+ }
146
+
147
+ // @ts-expect-error
148
+ element.checked = checked;
149
149
  }
150
150
 
151
151
  export function set_selected(element, selected) {
152
- if (selected) {
153
- // The selected option could've changed via user selection, and
154
- // setting the value without this check would set it back.
155
- if (!element.hasAttribute('selected')) {
156
- element.setAttribute('selected', '');
157
- }
158
- } else {
159
- element.removeAttribute('selected');
160
- }
152
+ if (selected) {
153
+ // The selected option could've changed via user selection, and
154
+ // setting the value without this check would set it back.
155
+ if (!element.hasAttribute('selected')) {
156
+ element.setAttribute('selected', '');
157
+ }
158
+ } else {
159
+ element.removeAttribute('selected');
160
+ }
161
161
  }
162
162
 
163
163
  export function apply_element_spread(element, fn) {
164
- var prev;
165
- var effects = {};
164
+ var prev;
165
+ var effects = {};
166
166
 
167
- return () => {
168
- var next = fn();
167
+ return () => {
168
+ var next = fn();
169
169
 
170
- for (let symbol of get_own_property_symbols(effects)) {
171
- if (!next[symbol]) {
172
- destroy_block(effects[symbol]);
173
- }
174
- }
170
+ for (let symbol of get_own_property_symbols(effects)) {
171
+ if (!next[symbol]) {
172
+ destroy_block(effects[symbol]);
173
+ }
174
+ }
175
175
 
176
- for (const symbol of get_own_property_symbols(next)) {
177
- var ref_fn = next[symbol];
176
+ for (const symbol of get_own_property_symbols(next)) {
177
+ var ref_fn = next[symbol];
178
178
 
179
- if (symbol.description === REF_PROP && (!prev || ref_fn !== prev[symbol])) {
180
- if (effects[symbol]) {
181
- destroy_block(effects[symbol]);
182
- }
183
- effects[symbol] = ref(element, () => ref_fn);
184
- }
179
+ if (symbol.description === REF_PROP && (!prev || ref_fn !== prev[symbol])) {
180
+ if (effects[symbol]) {
181
+ destroy_block(effects[symbol]);
182
+ }
183
+ effects[symbol] = ref(element, () => ref_fn);
184
+ }
185
185
 
186
- next[symbol] = ref_fn;
187
- }
186
+ next[symbol] = ref_fn;
187
+ }
188
188
 
189
- set_attributes(element, next);
189
+ set_attributes(element, next);
190
190
 
191
- prev = next;
192
- };
191
+ prev = next;
192
+ };
193
193
  }