ripple 0.2.44 → 0.2.46
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 +83 -0
- package/src/compiler/phases/2-analyze/index.js +48 -9
- package/src/compiler/phases/2-analyze/prune.js +3 -1
- package/src/compiler/phases/3-transform/index.js +136 -43
- package/src/compiler/utils.js +48 -14
- package/src/runtime/array.js +118 -25
- package/src/runtime/index.js +1 -1
- package/src/runtime/internal/client/array.js +16 -16
- package/src/runtime/internal/client/blocks.js +0 -1
- package/src/runtime/internal/client/constants.js +5 -2
- package/src/runtime/internal/client/index.js +4 -0
- package/src/runtime/internal/client/portal.js +3 -3
- package/src/runtime/internal/client/runtime.js +47 -15
- package/tests/array.test.ripple +125 -37
- package/tests/basic.test.ripple +11 -5
package/src/compiler/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ const VOID_ELEMENT_NAMES = [
|
|
|
19
19
|
'param',
|
|
20
20
|
'source',
|
|
21
21
|
'track',
|
|
22
|
-
'wbr'
|
|
22
|
+
'wbr',
|
|
23
23
|
];
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -374,6 +374,30 @@ export function is_inside_component(context, includes_functions = false) {
|
|
|
374
374
|
return false;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
export function is_component_level_function(context) {
|
|
378
|
+
for (let i = context.path.length - 1; i >= 0; i -= 1) {
|
|
379
|
+
const context_node = context.path[i];
|
|
380
|
+
const type = context_node.type;
|
|
381
|
+
|
|
382
|
+
if (type === 'BlockStatement') {
|
|
383
|
+
if (context_node.body.find((n) => n.type === 'Component')) {
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
debugger
|
|
387
|
+
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (
|
|
391
|
+
type === 'FunctionExpression' ||
|
|
392
|
+
type === 'ArrowFunctionExpression' ||
|
|
393
|
+
type === 'FunctionDeclaration'
|
|
394
|
+
) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
|
|
377
401
|
export function is_inside_call_expression(context) {
|
|
378
402
|
for (let i = context.path.length - 1; i >= 0; i -= 1) {
|
|
379
403
|
const context_node = context.path[i];
|
|
@@ -452,7 +476,7 @@ export function is_ripple_import(callee, context) {
|
|
|
452
476
|
return false;
|
|
453
477
|
}
|
|
454
478
|
|
|
455
|
-
export function
|
|
479
|
+
export function is_declared_function_within_component(node, context) {
|
|
456
480
|
const component = context.path.find((n) => n.type === 'Component');
|
|
457
481
|
|
|
458
482
|
if (node.type === 'Identifier' && component) {
|
|
@@ -460,6 +484,14 @@ export function is_declared_within_component(node, context) {
|
|
|
460
484
|
const component_scope = context.state.scopes.get(component);
|
|
461
485
|
|
|
462
486
|
if (binding !== null && component_scope !== null) {
|
|
487
|
+
if (
|
|
488
|
+
binding.declaration_kind !== 'function' &&
|
|
489
|
+
binding.initial?.type !== 'FunctionDeclaration' &&
|
|
490
|
+
binding.initial?.type !== 'ArrowFunctionExpression' &&
|
|
491
|
+
binding.initial?.type !== 'FunctionExpression'
|
|
492
|
+
) {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
463
495
|
let scope = binding.scope;
|
|
464
496
|
|
|
465
497
|
while (scope !== null) {
|
|
@@ -564,19 +596,21 @@ export function build_assignment(operator, left, right, context) {
|
|
|
564
596
|
const transform = binding.transform;
|
|
565
597
|
|
|
566
598
|
// reassignment
|
|
567
|
-
if (
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
);
|
|
599
|
+
if (object === left || (left.type === 'MemberExpression' && left.computed && operator === '=')) {
|
|
600
|
+
const assign_fn = transform?.assign || transform?.assign_tracked;
|
|
601
|
+
if (assign_fn) {
|
|
602
|
+
let value = /** @type {Expression} */ (
|
|
603
|
+
context.visit(build_assignment_value(operator, left, right))
|
|
604
|
+
);
|
|
574
605
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
606
|
+
return assign_fn(
|
|
607
|
+
object,
|
|
608
|
+
value,
|
|
609
|
+
left.type === 'MemberExpression' && left.computed
|
|
610
|
+
? context.visit(left.property)
|
|
611
|
+
: undefined,
|
|
612
|
+
);
|
|
613
|
+
}
|
|
580
614
|
}
|
|
581
615
|
|
|
582
616
|
// mutation
|
package/src/runtime/array.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { TRACKED_OBJECT, ARRAY_SET_INDEX_AT } from './internal/client/constants.js';
|
|
1
|
+
import { TRACKED_OBJECT, ARRAY_SET_INDEX_AT, MAX_ARRAY_LENGTH } from './internal/client/constants.js';
|
|
2
2
|
import { get, safe_scope, set, tracked } from './internal/client/runtime.js';
|
|
3
3
|
import { is_ripple_array } from './internal/client/utils.js';
|
|
4
4
|
/** @import { Block, Tracked } from '#client' */
|
|
5
5
|
|
|
6
|
+
/** @type {unique symbol} */
|
|
7
|
+
const INIT_AFTER_NEW = Symbol();
|
|
8
|
+
|
|
6
9
|
/** @type {(symbol | string | any)[]} */
|
|
7
10
|
const introspect_methods = [
|
|
8
11
|
'concat',
|
|
@@ -36,7 +39,7 @@ const introspect_methods = [
|
|
|
36
39
|
'with',
|
|
37
40
|
];
|
|
38
41
|
|
|
39
|
-
let
|
|
42
|
+
let is_proto_set = false;
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
45
|
* @template T
|
|
@@ -45,6 +48,8 @@ let init = false;
|
|
|
45
48
|
export class RippleArray extends Array {
|
|
46
49
|
/** @type {Array<Tracked>} */
|
|
47
50
|
#tracked_elements = [];
|
|
51
|
+
/** @type {Tracked} */
|
|
52
|
+
// @ts-expect-error
|
|
48
53
|
#tracked_index;
|
|
49
54
|
|
|
50
55
|
/**
|
|
@@ -55,11 +60,11 @@ export class RippleArray extends Array {
|
|
|
55
60
|
* @returns {RippleArray<U>}
|
|
56
61
|
*/
|
|
57
62
|
static from(arrayLike, mapFn, thisArg) {
|
|
58
|
-
|
|
59
|
-
mapFn ?
|
|
63
|
+
var arr = mapFn ?
|
|
60
64
|
Array.from(arrayLike, mapFn, thisArg)
|
|
61
|
-
: Array.from(arrayLike)
|
|
62
|
-
|
|
65
|
+
: Array.from(arrayLike);
|
|
66
|
+
|
|
67
|
+
return get_instance_from_static(arr);
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
/**
|
|
@@ -70,11 +75,30 @@ export class RippleArray extends Array {
|
|
|
70
75
|
* @returns {Promise<RippleArray<U>>}
|
|
71
76
|
*/
|
|
72
77
|
static async fromAsync(arrayLike, mapFn, thisArg) {
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
var block = safe_scope();
|
|
79
|
+
// create empty array to get the right scope
|
|
80
|
+
var result = new RippleArray();
|
|
81
|
+
|
|
82
|
+
var arr = mapFn ?
|
|
75
83
|
await Array.fromAsync(arrayLike, mapFn, thisArg)
|
|
76
84
|
: await Array.fromAsync(arrayLike)
|
|
77
|
-
|
|
85
|
+
|
|
86
|
+
var first = get_first_if_length(arr);
|
|
87
|
+
|
|
88
|
+
if (first) {
|
|
89
|
+
result[0] = first;
|
|
90
|
+
} else {
|
|
91
|
+
result.length = arr.length;
|
|
92
|
+
for (let i = 0; i < arr.length; i++) {
|
|
93
|
+
if (i in arr) {
|
|
94
|
+
result[i] = arr[i];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
result[INIT_AFTER_NEW](block);
|
|
100
|
+
|
|
101
|
+
return result
|
|
78
102
|
}
|
|
79
103
|
|
|
80
104
|
/**
|
|
@@ -83,7 +107,9 @@ export class RippleArray extends Array {
|
|
|
83
107
|
* @returns {RippleArray<U>}
|
|
84
108
|
*/
|
|
85
109
|
static of(...elements) {
|
|
86
|
-
|
|
110
|
+
var arr = Array.of(...elements);
|
|
111
|
+
|
|
112
|
+
return get_instance_from_static(arr);
|
|
87
113
|
}
|
|
88
114
|
|
|
89
115
|
/**
|
|
@@ -92,24 +118,33 @@ export class RippleArray extends Array {
|
|
|
92
118
|
constructor(...elements) {
|
|
93
119
|
super(...elements);
|
|
94
120
|
|
|
95
|
-
|
|
96
|
-
var tracked_elements = this.#tracked_elements;
|
|
121
|
+
this[INIT_AFTER_NEW]();
|
|
97
122
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
123
|
+
if (!is_proto_set) {
|
|
124
|
+
is_proto_set = true;
|
|
125
|
+
this.#set_proto();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
[INIT_AFTER_NEW](block = safe_scope()) {
|
|
130
|
+
if (this.length !== 0) {
|
|
131
|
+
var tracked_elements = this.#tracked_elements;
|
|
132
|
+
for (var i = 0; i < this.length; i++) {
|
|
133
|
+
if (!(i in this)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
tracked_elements[i] = tracked(this[i], block);
|
|
101
137
|
}
|
|
102
|
-
tracked_elements[i] = tracked(this[i], block);
|
|
103
138
|
}
|
|
104
|
-
this.#tracked_index = tracked(this.length, block);
|
|
105
139
|
|
|
106
|
-
if (!
|
|
107
|
-
|
|
108
|
-
|
|
140
|
+
if (!this.#tracked_index) {
|
|
141
|
+
this.#tracked_index = tracked(this.length, block);
|
|
142
|
+
} else if (this.#tracked_index.v !== this.length) {
|
|
143
|
+
set(this.#tracked_index, this.length, block);
|
|
109
144
|
}
|
|
110
145
|
}
|
|
111
146
|
|
|
112
|
-
#
|
|
147
|
+
#set_proto() {
|
|
113
148
|
var proto = RippleArray.prototype;
|
|
114
149
|
var array_proto = Array.prototype;
|
|
115
150
|
|
|
@@ -138,7 +173,7 @@ export class RippleArray extends Array {
|
|
|
138
173
|
// the caller reruns on length changes
|
|
139
174
|
this.$length;
|
|
140
175
|
// the caller reruns on element changes
|
|
141
|
-
|
|
176
|
+
establish_trackable_deps(this);
|
|
142
177
|
return result;
|
|
143
178
|
};
|
|
144
179
|
}
|
|
@@ -564,14 +599,72 @@ export class RippleArray extends Array {
|
|
|
564
599
|
export function get_all_elements(array) {
|
|
565
600
|
/** @type {Tracked[]} */
|
|
566
601
|
var tracked_elements = /** @type {Tracked[]} */ (array[TRACKED_OBJECT]);
|
|
567
|
-
|
|
602
|
+
// pre-allocate to support holey arrays
|
|
603
|
+
var result = new Array(array.length);
|
|
604
|
+
|
|
605
|
+
for (var i = 0; i < array.length; i++) {
|
|
606
|
+
if (tracked_elements[i] !== undefined) {
|
|
607
|
+
get(tracked_elements[i]);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (i in array) {
|
|
611
|
+
result[i] = array[i];
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return result;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* @template T
|
|
620
|
+
* @param {RippleArray<T>} array
|
|
621
|
+
* @returns {void}
|
|
622
|
+
*/
|
|
623
|
+
function establish_trackable_deps (array) {
|
|
624
|
+
var tracked_elements = array[TRACKED_OBJECT];
|
|
568
625
|
|
|
569
626
|
for (var i = 0; i < tracked_elements.length; i++) {
|
|
570
627
|
if (tracked_elements[i] !== undefined) {
|
|
571
628
|
get(tracked_elements[i]);
|
|
572
629
|
}
|
|
573
|
-
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* @template T
|
|
635
|
+
* @param {T[]} array
|
|
636
|
+
* @returns {RippleArray<T>}
|
|
637
|
+
*/
|
|
638
|
+
function get_instance_from_static(array) {
|
|
639
|
+
/** @type RippleArray<T> */
|
|
640
|
+
var result;
|
|
641
|
+
/** @type {T | void} */
|
|
642
|
+
var first = get_first_if_length(array);
|
|
643
|
+
|
|
644
|
+
if (first) {
|
|
645
|
+
result = new RippleArray();
|
|
646
|
+
result[0] = first;
|
|
647
|
+
result[INIT_AFTER_NEW]();
|
|
648
|
+
} else {
|
|
649
|
+
result = new RippleArray(...array);
|
|
574
650
|
}
|
|
575
651
|
|
|
576
|
-
return
|
|
652
|
+
return result;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* @template T
|
|
657
|
+
* @param {T[]} array
|
|
658
|
+
* @returns {T | void}
|
|
659
|
+
*/
|
|
660
|
+
function get_first_if_length (array) {
|
|
661
|
+
var first = array[0];
|
|
662
|
+
|
|
663
|
+
if (
|
|
664
|
+
array.length === 1 && (0 in array) && Number.isInteger(first)
|
|
665
|
+
&& /** @type {number} */ (first) >= 0
|
|
666
|
+
&& /** @type {number} */ (first) <= MAX_ARRAY_LENGTH
|
|
667
|
+
) {
|
|
668
|
+
return first;
|
|
669
|
+
}
|
|
577
670
|
}
|
package/src/runtime/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export function mount(component, options) {
|
|
|
36
36
|
|
|
37
37
|
export { create_context as createContext } from './internal/client/context.js';
|
|
38
38
|
|
|
39
|
-
export { flush_sync as flushSync, untrack, deferred } from './internal/client/runtime.js';
|
|
39
|
+
export { flush_sync as flushSync, untrack, deferred, tracked } from './internal/client/runtime.js';
|
|
40
40
|
|
|
41
41
|
export { RippleArray } from './array.js';
|
|
42
42
|
|
|
@@ -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
|
|
|
@@ -21,7 +21,7 @@ export function array_reduce(array, callback, initial_value) {
|
|
|
21
21
|
let accumulator = initial_value;
|
|
22
22
|
|
|
23
23
|
for (let i = 0; i < array.length; i++) {
|
|
24
|
-
accumulator = callback(accumulator,
|
|
24
|
+
accumulator = callback(accumulator, old_get_property(array, i), i, array);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
return accumulator;
|
|
@@ -45,7 +45,7 @@ export function array_join(array, separator) {
|
|
|
45
45
|
if (i > 0 && separator !== undefined) {
|
|
46
46
|
result += separator;
|
|
47
47
|
}
|
|
48
|
-
result += String(
|
|
48
|
+
result += String(old_get_property(array, i));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
return result;
|
|
@@ -68,7 +68,7 @@ export function array_map(array, callback) {
|
|
|
68
68
|
const result = [];
|
|
69
69
|
for (let i = 0; i < array.length; i++) {
|
|
70
70
|
if (i in array) {
|
|
71
|
-
result[i] = callback(
|
|
71
|
+
result[i] = callback(old_get_property(array, i), i, array);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -91,7 +91,7 @@ export function array_filter(array, callback) {
|
|
|
91
91
|
const result = [];
|
|
92
92
|
for (let i = 0; i < array.length; i++) {
|
|
93
93
|
if (i in array) {
|
|
94
|
-
const value =
|
|
94
|
+
const value = old_get_property(array, i);
|
|
95
95
|
if (callback(value, i, array)) {
|
|
96
96
|
result.push(value);
|
|
97
97
|
}
|
|
@@ -116,7 +116,7 @@ export function array_forEach(array, callback) {
|
|
|
116
116
|
|
|
117
117
|
for (let i = 0; i < array.length; i++) {
|
|
118
118
|
if (i in array) {
|
|
119
|
-
callback(
|
|
119
|
+
callback(old_get_property(array, i), i, array);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -135,7 +135,7 @@ export function array_includes(array, value) {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
for (let i = 0; i < array.length; i++) {
|
|
138
|
-
if (i in array &&
|
|
138
|
+
if (i in array && old_get_property(array, i) === value) {
|
|
139
139
|
return true;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -157,7 +157,7 @@ export function array_indexOf(array, value) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
for (let i = 0; i < array.length; i++) {
|
|
160
|
-
if (i in array &&
|
|
160
|
+
if (i in array && old_get_property(array, i) === value) {
|
|
161
161
|
return i;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -179,7 +179,7 @@ export function array_lastIndexOf(array, value) {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
for (let i = array.length - 1; i >= 0; i--) {
|
|
182
|
-
if (i in array &&
|
|
182
|
+
if (i in array && old_get_property(array, i) === value) {
|
|
183
183
|
return i;
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -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
|
|
|
@@ -344,7 +344,7 @@ export function array_entries(array) {
|
|
|
344
344
|
const result = [];
|
|
345
345
|
for (let i = 0; i < array.length; i++) {
|
|
346
346
|
if (i in array) {
|
|
347
|
-
result.push([i,
|
|
347
|
+
result.push([i, old_get_property(array, i)]);
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
|
|
@@ -19,8 +19,11 @@ export var DESTROYED = 1 << 17;
|
|
|
19
19
|
export var LOGIC_BLOCK = FOR_BLOCK | IF_BLOCK | TRY_BLOCK;
|
|
20
20
|
|
|
21
21
|
export var UNINITIALIZED = Symbol();
|
|
22
|
-
|
|
22
|
+
/** @type {unique symbol} */
|
|
23
|
+
export const TRACKED_OBJECT = Symbol();
|
|
23
24
|
export var SPREAD_OBJECT = Symbol();
|
|
24
25
|
export var COMPUTED_PROPERTY = Symbol();
|
|
25
26
|
export var REF_PROP = 'ref';
|
|
26
|
-
|
|
27
|
+
/** @type {unique symbol} */
|
|
28
|
+
export const ARRAY_SET_INDEX_AT = Symbol();
|
|
29
|
+
export const MAX_ARRAY_LENGTH = 2**32 - 1;
|
|
@@ -29,10 +29,14 @@ export {
|
|
|
29
29
|
computed_property,
|
|
30
30
|
call_property,
|
|
31
31
|
get_property,
|
|
32
|
+
old_get_property,
|
|
33
|
+
old_set_property,
|
|
32
34
|
set_property,
|
|
33
35
|
update,
|
|
34
36
|
update_pre,
|
|
37
|
+
old_update_property,
|
|
35
38
|
update_property,
|
|
39
|
+
old_update_pre_property,
|
|
36
40
|
update_pre_property,
|
|
37
41
|
object_values,
|
|
38
42
|
object_entries,
|
|
@@ -2,7 +2,7 @@ import { branch, destroy_block, render } from './blocks';
|
|
|
2
2
|
import { UNINITIALIZED } from './constants';
|
|
3
3
|
import { handle_root_events } from './events';
|
|
4
4
|
import { create_text } from './operations';
|
|
5
|
-
import {
|
|
5
|
+
import { old_get_property } from './runtime';
|
|
6
6
|
|
|
7
7
|
export function Portal(_, props) {
|
|
8
8
|
let $target = UNINITIALIZED;
|
|
@@ -11,8 +11,8 @@ export function Portal(_, props) {
|
|
|
11
11
|
var anchor = null;
|
|
12
12
|
|
|
13
13
|
render(() => {
|
|
14
|
-
if ($target === ($target =
|
|
15
|
-
if (children === (children =
|
|
14
|
+
if ($target === ($target = old_get_property(props, '$target'))) return;
|
|
15
|
+
if (children === (children = old_get_property(props, 'children'))) return;
|
|
16
16
|
|
|
17
17
|
if (b !== null) {
|
|
18
18
|
destroy_block(b);
|
|
@@ -260,6 +260,7 @@ export function run_block(block) {
|
|
|
260
260
|
* @returns {Tracked}
|
|
261
261
|
*/
|
|
262
262
|
export function tracked(v, b) {
|
|
263
|
+
// TODO: now we expose tracked, we should likely block access in DEV somehow
|
|
263
264
|
return {
|
|
264
265
|
b,
|
|
265
266
|
c: 0,
|
|
@@ -430,7 +431,7 @@ export function deferred(fn) {
|
|
|
430
431
|
var value = fn();
|
|
431
432
|
|
|
432
433
|
res[0] = value;
|
|
433
|
-
|
|
434
|
+
old_set_property(res, 0, value, block);
|
|
434
435
|
|
|
435
436
|
if (prev_value !== UNINITIALIZED) {
|
|
436
437
|
if ((t.f & DEFERRED) === 0) {
|
|
@@ -869,7 +870,7 @@ export function computed_property(fn) {
|
|
|
869
870
|
export function call_property(obj, property, chain_obj, chain_prop, ...args) {
|
|
870
871
|
// don't swallow errors if either the object or property is nullish,
|
|
871
872
|
// respect optional chaining as provided
|
|
872
|
-
if(!chain_obj && !chain_prop) {
|
|
873
|
+
if (!chain_obj && !chain_prop) {
|
|
873
874
|
return obj[property].call(obj, ...args);
|
|
874
875
|
} else if (chain_obj && chain_prop) {
|
|
875
876
|
return obj?.[property]?.call(obj, ...args);
|
|
@@ -887,6 +888,20 @@ export function call_property(obj, property, chain_obj, chain_prop, ...args) {
|
|
|
887
888
|
* @returns {any}
|
|
888
889
|
*/
|
|
889
890
|
export function get_property(obj, property, chain = false) {
|
|
891
|
+
if (chain && obj == null) {
|
|
892
|
+
return undefined;
|
|
893
|
+
}
|
|
894
|
+
var tracked = obj[property];
|
|
895
|
+
return get(tracked);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* @param {any} obj
|
|
900
|
+
* @param {string | number | symbol} property
|
|
901
|
+
* @param {boolean} [chain=false]
|
|
902
|
+
* @returns {any}
|
|
903
|
+
*/
|
|
904
|
+
export function old_get_property(obj, property, chain = false) {
|
|
890
905
|
if (chain && obj == null) {
|
|
891
906
|
return undefined;
|
|
892
907
|
}
|
|
@@ -902,7 +917,7 @@ export function get_property(obj, property, chain = false) {
|
|
|
902
917
|
} else if (SPREAD_OBJECT in obj) {
|
|
903
918
|
var spread_fn = obj[SPREAD_OBJECT];
|
|
904
919
|
var properties = spread_fn();
|
|
905
|
-
return
|
|
920
|
+
return old_get_property(properties, property, chain);
|
|
906
921
|
} else if (is_ripple_array(obj)) {
|
|
907
922
|
obj.$length;
|
|
908
923
|
}
|
|
@@ -910,6 +925,11 @@ export function get_property(obj, property, chain = false) {
|
|
|
910
925
|
return value;
|
|
911
926
|
}
|
|
912
927
|
|
|
928
|
+
export function set_property(obj, property, value, block) {
|
|
929
|
+
var tracked = obj[property];
|
|
930
|
+
set(tracked, value, block);
|
|
931
|
+
}
|
|
932
|
+
|
|
913
933
|
/**
|
|
914
934
|
* @param {any} obj
|
|
915
935
|
* @param {string | number | symbol} property
|
|
@@ -917,7 +937,7 @@ export function get_property(obj, property, chain = false) {
|
|
|
917
937
|
* @param {Block} block
|
|
918
938
|
* @returns {any}
|
|
919
939
|
*/
|
|
920
|
-
export function
|
|
940
|
+
export function old_set_property(obj, property, value, block) {
|
|
921
941
|
var tracked_properties = obj[TRACKED_OBJECT];
|
|
922
942
|
var rip_arr = is_ripple_array(obj);
|
|
923
943
|
var tracked = !(rip_arr && property === 'length') ? tracked_properties?.[property] : undefined;
|
|
@@ -954,9 +974,7 @@ export function set_property(obj, property, value, block) {
|
|
|
954
974
|
export function update(tracked, block, d = 1) {
|
|
955
975
|
var value = get(tracked);
|
|
956
976
|
var result = d === 1 ? value++ : value--;
|
|
957
|
-
|
|
958
977
|
set(tracked, value, block);
|
|
959
|
-
|
|
960
978
|
return result;
|
|
961
979
|
}
|
|
962
980
|
|
|
@@ -987,9 +1005,15 @@ export function decrement(tracked, block) {
|
|
|
987
1005
|
export function update_pre(tracked, block, d = 1) {
|
|
988
1006
|
var value = get(tracked);
|
|
989
1007
|
var new_value = d === 1 ? ++value : --value;
|
|
990
|
-
|
|
991
1008
|
set(tracked, new_value, block);
|
|
1009
|
+
return new_value;
|
|
1010
|
+
}
|
|
992
1011
|
|
|
1012
|
+
export function update_property(obj, property, block, d = 1) {
|
|
1013
|
+
var tracked = obj[property];
|
|
1014
|
+
var value = get(tracked);
|
|
1015
|
+
var new_value = d === 1 ? value++ : value++;
|
|
1016
|
+
set(tracked, value, block);
|
|
993
1017
|
return new_value;
|
|
994
1018
|
}
|
|
995
1019
|
|
|
@@ -1000,7 +1024,7 @@ export function update_pre(tracked, block, d = 1) {
|
|
|
1000
1024
|
* @param {number} [d]
|
|
1001
1025
|
* @returns {number}
|
|
1002
1026
|
*/
|
|
1003
|
-
export function
|
|
1027
|
+
export function old_update_property(obj, property, block, d = 1) {
|
|
1004
1028
|
var tracked_properties = obj[TRACKED_OBJECT];
|
|
1005
1029
|
var tracked = tracked_properties?.[property];
|
|
1006
1030
|
var tracked_exists = tracked !== undefined;
|
|
@@ -1018,11 +1042,19 @@ export function update_property(obj, property, block, d = 1) {
|
|
|
1018
1042
|
}
|
|
1019
1043
|
}
|
|
1020
1044
|
|
|
1021
|
-
obj[property] = value
|
|
1045
|
+
obj[property] = value;
|
|
1022
1046
|
|
|
1023
1047
|
return value;
|
|
1024
1048
|
}
|
|
1025
1049
|
|
|
1050
|
+
export function update_pre_property(obj, property, block, d = 1) {
|
|
1051
|
+
var tracked = obj[property];
|
|
1052
|
+
var value = get(tracked);
|
|
1053
|
+
var new_value = d === 1 ? ++value : --value;
|
|
1054
|
+
set(tracked, new_value, block);
|
|
1055
|
+
return new_value;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1026
1058
|
/**
|
|
1027
1059
|
* @param {any} obj
|
|
1028
1060
|
* @param {string | number | symbol} property
|
|
@@ -1030,19 +1062,19 @@ export function update_property(obj, property, block, d = 1) {
|
|
|
1030
1062
|
* @param {number} [d]
|
|
1031
1063
|
* @returns {number}
|
|
1032
1064
|
*/
|
|
1033
|
-
export function
|
|
1065
|
+
export function old_update_pre_property(obj, property, block, d = 1) {
|
|
1034
1066
|
var tracked_properties = obj[TRACKED_OBJECT];
|
|
1035
1067
|
var tracked = tracked_properties?.[property];
|
|
1036
1068
|
var tracked_exists = tracked !== undefined;
|
|
1037
1069
|
var value = tracked_exists ? get(tracked) : obj[property];
|
|
1038
1070
|
|
|
1039
1071
|
if (d === 1) {
|
|
1040
|
-
++value
|
|
1072
|
+
++value;
|
|
1041
1073
|
if (tracked_exists) {
|
|
1042
1074
|
increment(tracked, block);
|
|
1043
1075
|
}
|
|
1044
1076
|
} else {
|
|
1045
|
-
--value
|
|
1077
|
+
--value;
|
|
1046
1078
|
if (tracked_exists) {
|
|
1047
1079
|
decrement(tracked, block);
|
|
1048
1080
|
}
|
|
@@ -1091,7 +1123,7 @@ export function object_values(obj) {
|
|
|
1091
1123
|
var values = [];
|
|
1092
1124
|
|
|
1093
1125
|
for (var i = 0; i < keys.length; i++) {
|
|
1094
|
-
values.push(
|
|
1126
|
+
values.push(old_get_property(obj, keys[i]));
|
|
1095
1127
|
}
|
|
1096
1128
|
|
|
1097
1129
|
return values;
|
|
@@ -1111,7 +1143,7 @@ export function object_entries(obj) {
|
|
|
1111
1143
|
|
|
1112
1144
|
for (var i = 0; i < keys.length; i++) {
|
|
1113
1145
|
var key = keys[i];
|
|
1114
|
-
entries.push([key,
|
|
1146
|
+
entries.push([key, old_get_property(obj, key)]);
|
|
1115
1147
|
}
|
|
1116
1148
|
|
|
1117
1149
|
return entries;
|
|
@@ -1128,7 +1160,7 @@ export function spread_object(obj) {
|
|
|
1128
1160
|
|
|
1129
1161
|
for (var i = 0; i < keys.length; i++) {
|
|
1130
1162
|
var key = keys[i];
|
|
1131
|
-
values[key] =
|
|
1163
|
+
values[key] = old_get_property(obj, key);
|
|
1132
1164
|
}
|
|
1133
1165
|
|
|
1134
1166
|
return values;
|