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.
- package/package.json +1 -1
- package/src/compiler/phases/1-parse/index.js +8 -1
- package/src/compiler/phases/2-analyze/index.js +640 -650
- package/src/compiler/phases/3-transform/index.js +1877 -1813
- package/src/compiler/phases/3-transform/segments.js +2 -2
- package/src/compiler/utils.js +600 -523
- package/src/jsx-runtime.js +12 -12
- package/src/runtime/array.js +611 -609
- package/src/runtime/index.js +29 -17
- package/src/runtime/internal/client/array.js +128 -128
- package/src/runtime/internal/client/blocks.js +206 -207
- package/src/runtime/internal/client/constants.js +2 -2
- package/src/runtime/internal/client/context.js +40 -40
- package/src/runtime/internal/client/events.js +191 -191
- package/src/runtime/internal/client/for.js +355 -355
- package/src/runtime/internal/client/if.js +25 -25
- package/src/runtime/internal/client/index.js +57 -52
- package/src/runtime/internal/client/operations.js +32 -32
- package/src/runtime/internal/client/portal.js +20 -20
- package/src/runtime/internal/client/render.js +132 -132
- package/src/runtime/internal/client/runtime.js +858 -824
- package/src/runtime/internal/client/template.js +36 -36
- package/src/runtime/internal/client/try.js +113 -113
- package/src/runtime/internal/client/types.d.ts +10 -10
- package/src/runtime/internal/client/utils.js +5 -5
- package/src/runtime/map.js +139 -139
- package/src/runtime/set.js +130 -130
- package/src/utils/ast.js +189 -189
- package/src/utils/builders.js +244 -244
- package/src/utils/sanitize_template_string.js +1 -1
- package/tests/__snapshots__/composite.test.ripple.snap +1 -1
- package/tests/accessors-props.test.ripple +9 -9
- package/tests/basic.test.ripple +4 -4
- package/tests/boundaries.test.ripple +17 -17
- package/tests/composite.test.ripple +43 -72
- package/types/index.d.ts +6 -2
package/src/runtime/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/** @import { Block } from '#client' */
|
|
1
|
+
/** @import { Block, Derived, Tracked } from '#client' */
|
|
2
2
|
|
|
3
3
|
import { destroy_block, root } from './internal/client/blocks.js';
|
|
4
4
|
import { handle_root_events } from './internal/client/events.js';
|
|
5
5
|
import { init_operations } from './internal/client/operations.js';
|
|
6
|
-
import { active_block } from './internal/client/runtime.js';
|
|
6
|
+
import { active_block, tracked, derived } from './internal/client/runtime.js';
|
|
7
7
|
import { create_anchor } from './internal/client/utils.js';
|
|
8
8
|
|
|
9
9
|
// Re-export JSX runtime functions for jsxImportSource: "ripple"
|
|
@@ -15,28 +15,40 @@ export { jsx, jsxs, Fragment } from '../jsx-runtime.js';
|
|
|
15
15
|
* @returns {() => void}
|
|
16
16
|
*/
|
|
17
17
|
export function mount(component, options) {
|
|
18
|
-
|
|
18
|
+
init_operations();
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const props = options.props || {};
|
|
21
|
+
const target = options.target;
|
|
22
|
+
const anchor = create_anchor();
|
|
23
|
+
target.append(anchor);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const cleanup_events = handle_root_events(target);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const _root = root(() => {
|
|
28
|
+
component(anchor, props, active_block);
|
|
29
|
+
});
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
return () => {
|
|
32
|
+
cleanup_events();
|
|
33
|
+
destroy_block(_root);
|
|
34
|
+
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export { create_context as createContext } from './internal/client/context.js';
|
|
38
38
|
|
|
39
|
-
export { flush_sync as flushSync, untrack, deferred
|
|
39
|
+
export { flush_sync as flushSync, untrack, deferred } from './internal/client/runtime.js';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {any} v
|
|
43
|
+
* @param {Block} b
|
|
44
|
+
* @returns {Tracked | Derived}
|
|
45
|
+
*/
|
|
46
|
+
export function track(v, b) {
|
|
47
|
+
if (typeof v === 'function') {
|
|
48
|
+
return derived(v, b);
|
|
49
|
+
}
|
|
50
|
+
return tracked(v, b);
|
|
51
|
+
}
|
|
40
52
|
|
|
41
53
|
export { RippleArray } from './array.js';
|
|
42
54
|
|
|
@@ -50,4 +62,4 @@ export { user_effect as effect } from './internal/client/blocks.js';
|
|
|
50
62
|
|
|
51
63
|
export { Portal } from './internal/client/portal.js';
|
|
52
64
|
|
|
53
|
-
export { ref_prop as createRefKey } from './internal/client/runtime.js';
|
|
65
|
+
export { ref_prop as createRefKey } from './internal/client/runtime.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TRACKED_OBJECT } from './constants';
|
|
2
|
-
import {
|
|
2
|
+
import { old_get_property } from './runtime';
|
|
3
3
|
|
|
4
4
|
const array_proto = Array.prototype;
|
|
5
5
|
|
|
@@ -11,20 +11,20 @@ const array_proto = Array.prototype;
|
|
|
11
11
|
* @returns {T}
|
|
12
12
|
*/
|
|
13
13
|
export function array_reduce(array, callback, initial_value) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (tracked_properties === undefined || array.reduce !== array_proto.reduce) {
|
|
18
|
+
return array.reduce(callback, initial_value);
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
let accumulator = initial_value;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
for (let i = 0; i < array.length; i++) {
|
|
24
|
+
accumulator = callback(accumulator, old_get_property(array, i), i, array);
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
return accumulator;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -34,21 +34,21 @@ export function array_reduce(array, callback, initial_value) {
|
|
|
34
34
|
* @returns {string}
|
|
35
35
|
*/
|
|
36
36
|
export function array_join(array, separator) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
39
|
+
if (tracked_properties === undefined || array.join !== array_proto.join) {
|
|
40
|
+
return array.join(separator);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let result = '';
|
|
44
|
+
for (let i = 0; i < array.length; i++) {
|
|
45
|
+
if (i > 0 && separator !== undefined) {
|
|
46
|
+
result += separator;
|
|
47
|
+
}
|
|
48
|
+
result += String(old_get_property(array, i));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -59,20 +59,20 @@ export function array_join(array, separator) {
|
|
|
59
59
|
* @returns {Array<U>}
|
|
60
60
|
*/
|
|
61
61
|
export function array_map(array, callback) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
64
|
+
if (tracked_properties === undefined || array.map !== array_proto.map) {
|
|
65
|
+
return array.map(callback);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const result = [];
|
|
69
|
+
for (let i = 0; i < array.length; i++) {
|
|
70
|
+
if (i in array) {
|
|
71
|
+
result[i] = callback(old_get_property(array, i), i, array);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -82,23 +82,23 @@ export function array_map(array, callback) {
|
|
|
82
82
|
* @returns {Array<T>}
|
|
83
83
|
*/
|
|
84
84
|
export function array_filter(array, callback) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
// @ts-expect-error
|
|
86
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
87
|
+
if (tracked_properties === undefined || array.filter !== array_proto.filter) {
|
|
88
|
+
return array.filter(callback);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const result = [];
|
|
92
|
+
for (let i = 0; i < array.length; i++) {
|
|
93
|
+
if (i in array) {
|
|
94
|
+
const value = old_get_property(array, i);
|
|
95
|
+
if (callback(value, i, array)) {
|
|
96
|
+
result.push(value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return result;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -108,17 +108,17 @@ export function array_filter(array, callback) {
|
|
|
108
108
|
* @returns {void}
|
|
109
109
|
*/
|
|
110
110
|
export function array_forEach(array, callback) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
// @ts-expect-error
|
|
112
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
113
|
+
if (tracked_properties === undefined || array.forEach !== array_proto.forEach) {
|
|
114
|
+
return array.forEach(callback);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (let i = 0; i < array.length; i++) {
|
|
118
|
+
if (i in array) {
|
|
119
|
+
callback(old_get_property(array, i), i, array);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
@@ -128,19 +128,19 @@ export function array_forEach(array, callback) {
|
|
|
128
128
|
* @returns {boolean}
|
|
129
129
|
*/
|
|
130
130
|
export function array_includes(array, value) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
131
|
+
// @ts-expect-error
|
|
132
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
133
|
+
if (tracked_properties === undefined || array.includes !== array_proto.includes) {
|
|
134
|
+
return array.includes(value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (let i = 0; i < array.length; i++) {
|
|
138
|
+
if (i in array && old_get_property(array, i) === value) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return false;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
@@ -150,19 +150,19 @@ export function array_includes(array, value) {
|
|
|
150
150
|
* @returns {number}
|
|
151
151
|
*/
|
|
152
152
|
export function array_indexOf(array, value) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
// @ts-expect-error
|
|
154
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
155
|
+
if (tracked_properties === undefined || array.indexOf !== array_proto.indexOf) {
|
|
156
|
+
return array.indexOf(value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for (let i = 0; i < array.length; i++) {
|
|
160
|
+
if (i in array && old_get_property(array, i) === value) {
|
|
161
|
+
return i;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return -1;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
@@ -172,19 +172,19 @@ export function array_indexOf(array, value) {
|
|
|
172
172
|
* @returns {number}
|
|
173
173
|
*/
|
|
174
174
|
export function array_lastIndexOf(array, value) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
// @ts-expect-error
|
|
176
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
177
|
+
if (tracked_properties === undefined || array.lastIndexOf !== array_proto.lastIndexOf) {
|
|
178
|
+
return array.lastIndexOf(value);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
182
|
+
if (i in array && old_get_property(array, i) === value) {
|
|
183
|
+
return i;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return -1;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
/**
|
|
@@ -201,7 +201,7 @@ export function array_every(array, callback) {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
for (let i = 0; i < array.length; i++) {
|
|
204
|
-
if (i in array && !callback(
|
|
204
|
+
if (i in array && !callback(old_get_property(array, i), i, array)) {
|
|
205
205
|
return false;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -223,7 +223,7 @@ export function array_some(array, callback) {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
for (let i = 0; i < array.length; i++) {
|
|
226
|
-
if (i in array && callback(
|
|
226
|
+
if (i in array && callback(old_get_property(array, i), i, array)) {
|
|
227
227
|
return true;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
@@ -249,7 +249,7 @@ export function array_toString(array) {
|
|
|
249
249
|
result += ',';
|
|
250
250
|
}
|
|
251
251
|
if (i in array) {
|
|
252
|
-
result += String(
|
|
252
|
+
result += String(old_get_property(array, i));
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -272,7 +272,7 @@ export function array_toSorted(array, compare_fn) {
|
|
|
272
272
|
const result = [];
|
|
273
273
|
for (let i = 0; i < array.length; i++) {
|
|
274
274
|
if (i in array) {
|
|
275
|
-
result.push(
|
|
275
|
+
result.push(old_get_property(array, i));
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
|
|
@@ -297,7 +297,7 @@ export function array_toSpliced(array, start, delete_count, ...items) {
|
|
|
297
297
|
const result = [];
|
|
298
298
|
for (let i = 0; i < array.length; i++) {
|
|
299
299
|
if (i in array) {
|
|
300
|
-
result.push(
|
|
300
|
+
result.push(old_get_property(array, i));
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
|
|
@@ -321,7 +321,7 @@ export function array_values(array) {
|
|
|
321
321
|
const result = [];
|
|
322
322
|
for (let i = 0; i < array.length; i++) {
|
|
323
323
|
if (i in array) {
|
|
324
|
-
result.push(
|
|
324
|
+
result.push(old_get_property(array, i));
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
|
|
@@ -334,19 +334,19 @@ export function array_values(array) {
|
|
|
334
334
|
* @returns {IterableIterator<[number, T]>}
|
|
335
335
|
*/
|
|
336
336
|
export function array_entries(array) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
337
|
+
// @ts-expect-error
|
|
338
|
+
var tracked_properties = array[TRACKED_OBJECT];
|
|
339
|
+
if (tracked_properties === undefined || array.entries !== array_proto.entries) {
|
|
340
|
+
return array.entries();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** @type {Array<[number, T]>} */
|
|
344
|
+
const result = [];
|
|
345
|
+
for (let i = 0; i < array.length; i++) {
|
|
346
|
+
if (i in array) {
|
|
347
|
+
result.push([i, old_get_property(array, i)]);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return result[Symbol.iterator]();
|
|
352
352
|
}
|