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
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
/** @import { Block,
|
|
1
|
+
/** @import { Block, Derived } from '#client' */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
BLOCK_HAS_RUN,
|
|
5
|
+
BRANCH_BLOCK,
|
|
6
|
+
DERIVED,
|
|
7
|
+
CONTAINS_TEARDOWN,
|
|
8
|
+
DESTROYED,
|
|
9
|
+
EFFECT_BLOCK,
|
|
10
|
+
PAUSED,
|
|
11
|
+
RENDER_BLOCK,
|
|
12
|
+
ROOT_BLOCK,
|
|
13
|
+
TRY_BLOCK,
|
|
14
14
|
} from './constants';
|
|
15
15
|
import { next_sibling } from './operations';
|
|
16
16
|
import { apply_element_spread } from './render';
|
|
17
17
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
set_property,
|
|
18
|
+
active_block,
|
|
19
|
+
active_component,
|
|
20
|
+
active_reaction,
|
|
21
|
+
is_block_dirty,
|
|
22
|
+
run_block,
|
|
23
|
+
run_teardown,
|
|
24
|
+
schedule_update,
|
|
26
25
|
} from './runtime';
|
|
27
26
|
import { suspend } from './try';
|
|
28
27
|
|
|
@@ -30,32 +29,32 @@ import { suspend } from './try';
|
|
|
30
29
|
* @param {Function} fn
|
|
31
30
|
*/
|
|
32
31
|
export function user_effect(fn) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
if (active_block === null) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
'effect() must be called within an active context, such as a component or effect',
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var component = active_component;
|
|
39
|
+
if (component !== null && !component.m) {
|
|
40
|
+
var e = (component.e ??= []);
|
|
41
|
+
e.push({
|
|
42
|
+
b: active_block,
|
|
43
|
+
fn,
|
|
44
|
+
r: active_reaction,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return block(EFFECT_BLOCK, fn);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* @param {Function} fn
|
|
56
55
|
*/
|
|
57
56
|
export function effect(fn) {
|
|
58
|
-
|
|
57
|
+
return block(EFFECT_BLOCK, fn);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
/**
|
|
@@ -63,7 +62,7 @@ export function effect(fn) {
|
|
|
63
62
|
* @param {number} [flags]
|
|
64
63
|
*/
|
|
65
64
|
export function render(fn, flags = 0) {
|
|
66
|
-
|
|
65
|
+
return block(RENDER_BLOCK | flags, fn);
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
/**
|
|
@@ -72,7 +71,7 @@ export function render(fn, flags = 0) {
|
|
|
72
71
|
* @param {number} [flags]
|
|
73
72
|
*/
|
|
74
73
|
export function render_spread(element, fn, flags = 0) {
|
|
75
|
-
|
|
74
|
+
return block(RENDER_BLOCK | flags, apply_element_spread(element, fn));
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/**
|
|
@@ -80,18 +79,18 @@ export function render_spread(element, fn, flags = 0) {
|
|
|
80
79
|
* @param {number} [flags]
|
|
81
80
|
*/
|
|
82
81
|
export function branch(fn, flags = 0) {
|
|
83
|
-
|
|
82
|
+
return block(BRANCH_BLOCK | flags, fn);
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
/**
|
|
87
86
|
* @param {() => any} fn
|
|
88
87
|
*/
|
|
89
88
|
export function async(fn) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
return block(BRANCH_BLOCK, async () => {
|
|
90
|
+
const unsuspend = suspend();
|
|
91
|
+
await fn();
|
|
92
|
+
unsuspend();
|
|
93
|
+
});
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
/**
|
|
@@ -100,27 +99,27 @@ export function async(fn) {
|
|
|
100
99
|
* @returns {Block}
|
|
101
100
|
*/
|
|
102
101
|
export function ref(element, get_fn) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
102
|
+
/** @type {(element: Element) => (void | (() => void) | undefined)} */
|
|
103
|
+
var ref_fn;
|
|
104
|
+
/** @type {Block | null} */
|
|
105
|
+
var e;
|
|
106
|
+
|
|
107
|
+
return block(RENDER_BLOCK, () => {
|
|
108
|
+
if (ref_fn !== (ref_fn = get_fn())) {
|
|
109
|
+
if (e) {
|
|
110
|
+
destroy_block(e);
|
|
111
|
+
e = null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (ref_fn) {
|
|
115
|
+
e = branch(() => {
|
|
116
|
+
effect(() => {
|
|
117
|
+
return ref_fn(element);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
/**
|
|
@@ -128,7 +127,7 @@ export function ref(element, get_fn) {
|
|
|
128
127
|
* @returns {Block}
|
|
129
128
|
*/
|
|
130
129
|
export function root(fn) {
|
|
131
|
-
|
|
130
|
+
return block(ROOT_BLOCK, fn);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/**
|
|
@@ -137,7 +136,7 @@ export function root(fn) {
|
|
|
137
136
|
* @returns {Block}
|
|
138
137
|
*/
|
|
139
138
|
export function create_try_block(fn, state) {
|
|
140
|
-
|
|
139
|
+
return block(TRY_BLOCK, fn, state);
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
/**
|
|
@@ -145,14 +144,14 @@ export function create_try_block(fn, state) {
|
|
|
145
144
|
* @param {Block} parent_block
|
|
146
145
|
*/
|
|
147
146
|
function push_block(block, parent_block) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
147
|
+
var parent_last = parent_block.last;
|
|
148
|
+
if (parent_last === null) {
|
|
149
|
+
parent_block.last = parent_block.first = block;
|
|
150
|
+
} else {
|
|
151
|
+
parent_last.next = block;
|
|
152
|
+
block.prev = parent_last;
|
|
153
|
+
parent_block.last = block;
|
|
154
|
+
}
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
/**
|
|
@@ -162,37 +161,37 @@ function push_block(block, parent_block) {
|
|
|
162
161
|
* @returns {Block}
|
|
163
162
|
*/
|
|
164
163
|
export function block(flags, fn, state = null) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
164
|
+
/** @type {Block} */
|
|
165
|
+
var block = {
|
|
166
|
+
c: active_component,
|
|
167
|
+
d: null,
|
|
168
|
+
first: null,
|
|
169
|
+
f: flags,
|
|
170
|
+
fn,
|
|
171
|
+
last: null,
|
|
172
|
+
next: null,
|
|
173
|
+
p: active_block,
|
|
174
|
+
prev: null,
|
|
175
|
+
s: state,
|
|
176
|
+
t: null,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
|
|
180
|
+
/** @type {Derived} */ ((active_reaction).blocks ??= []).push(block);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (active_block !== null) {
|
|
184
|
+
push_block(block, active_block);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if ((flags & EFFECT_BLOCK) !== 0) {
|
|
188
|
+
schedule_update(block);
|
|
189
|
+
} else {
|
|
190
|
+
run_block(block);
|
|
191
|
+
block.f ^= BLOCK_HAS_RUN;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return block;
|
|
196
195
|
}
|
|
197
196
|
|
|
198
197
|
/**
|
|
@@ -200,16 +199,16 @@ export function block(flags, fn, state = null) {
|
|
|
200
199
|
* @param {boolean} [remove_dom]
|
|
201
200
|
*/
|
|
202
201
|
export function destroy_block_children(parent, remove_dom = false) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
202
|
+
var block = parent.first;
|
|
203
|
+
parent.first = parent.last = null;
|
|
204
|
+
|
|
205
|
+
if ((parent.f & CONTAINS_TEARDOWN) !== 0) {
|
|
206
|
+
while (block !== null) {
|
|
207
|
+
var next = block.next;
|
|
208
|
+
destroy_block(block, remove_dom);
|
|
209
|
+
block = next;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
213
212
|
}
|
|
214
213
|
|
|
215
214
|
/**
|
|
@@ -217,82 +216,82 @@ export function destroy_block_children(parent, remove_dom = false) {
|
|
|
217
216
|
* @param {boolean} [remove_dom]
|
|
218
217
|
*/
|
|
219
218
|
export function destroy_non_branch_children(parent, remove_dom = false) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
219
|
+
var block = parent.first;
|
|
220
|
+
|
|
221
|
+
if (
|
|
222
|
+
(parent.f & CONTAINS_TEARDOWN) === 0 &&
|
|
223
|
+
parent.first !== null &&
|
|
224
|
+
(parent.first.f & BRANCH_BLOCK) === 0
|
|
225
|
+
) {
|
|
226
|
+
parent.first = parent.last = null;
|
|
227
|
+
} else {
|
|
228
|
+
while (block !== null) {
|
|
229
|
+
var next = block.next;
|
|
230
|
+
if ((block.f & BRANCH_BLOCK) === 0) {
|
|
231
|
+
destroy_block(block, remove_dom);
|
|
232
|
+
}
|
|
233
|
+
block = next;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
237
236
|
}
|
|
238
237
|
|
|
239
238
|
/**
|
|
240
239
|
* @param {Block} block
|
|
241
240
|
*/
|
|
242
241
|
export function unlink_block(block) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
var parent = block.p;
|
|
243
|
+
var prev = block.prev;
|
|
244
|
+
var next = block.next;
|
|
246
245
|
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
if (prev !== null) prev.next = next;
|
|
247
|
+
if (next !== null) next.prev = prev;
|
|
249
248
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
if (parent !== null) {
|
|
250
|
+
if (parent.first === block) parent.first = next;
|
|
251
|
+
if (parent.last === block) parent.last = prev;
|
|
252
|
+
}
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
/**
|
|
257
256
|
* @param {Block} block
|
|
258
257
|
*/
|
|
259
258
|
export function pause_block(block) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
if ((block.f & PAUSED) !== 0) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
block.f ^= PAUSED;
|
|
264
263
|
|
|
265
|
-
|
|
264
|
+
var child = block.first;
|
|
266
265
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
266
|
+
while (child !== null) {
|
|
267
|
+
var next = child.next;
|
|
268
|
+
pause_block(child);
|
|
269
|
+
child = next;
|
|
270
|
+
}
|
|
272
271
|
|
|
273
|
-
|
|
272
|
+
run_teardown(block);
|
|
274
273
|
}
|
|
275
274
|
|
|
276
275
|
/**
|
|
277
276
|
* @param {Block} block
|
|
278
277
|
*/
|
|
279
278
|
export function resume_block(block) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
279
|
+
if ((block.f & PAUSED) === 0) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
block.f ^= PAUSED;
|
|
283
|
+
|
|
284
|
+
if (is_block_dirty(block)) {
|
|
285
|
+
schedule_update(block);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
var child = block.first;
|
|
289
|
+
|
|
290
|
+
while (child !== null) {
|
|
291
|
+
var next = child.next;
|
|
292
|
+
resume_block(child);
|
|
293
|
+
child = next;
|
|
294
|
+
}
|
|
296
295
|
}
|
|
297
296
|
|
|
298
297
|
/**
|
|
@@ -300,21 +299,21 @@ export function resume_block(block) {
|
|
|
300
299
|
* @returns {boolean}
|
|
301
300
|
*/
|
|
302
301
|
export function is_destroyed(target_block) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
302
|
+
/** @type {Block | null} */
|
|
303
|
+
var block = target_block;
|
|
304
|
+
|
|
305
|
+
while (block !== null) {
|
|
306
|
+
var flags = block.f;
|
|
307
|
+
|
|
308
|
+
if ((flags & DESTROYED) !== 0) {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
if ((flags & ROOT_BLOCK) !== 0) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
block = block.p;
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
318
317
|
}
|
|
319
318
|
|
|
320
319
|
/**
|
|
@@ -322,34 +321,34 @@ export function is_destroyed(target_block) {
|
|
|
322
321
|
* @param {boolean} [remove_dom]
|
|
323
322
|
*/
|
|
324
323
|
export function destroy_block(block, remove_dom = true) {
|
|
325
|
-
|
|
324
|
+
block.f ^= DESTROYED;
|
|
326
325
|
|
|
327
|
-
|
|
326
|
+
var removed = false;
|
|
328
327
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
328
|
+
if (remove_dom && (block.f & (BRANCH_BLOCK | ROOT_BLOCK)) !== 0) {
|
|
329
|
+
var node = block.s.start;
|
|
330
|
+
var end = block.s.end;
|
|
332
331
|
|
|
333
|
-
|
|
334
|
-
|
|
332
|
+
while (node !== null) {
|
|
333
|
+
var next = node === end ? null : next_sibling(node);
|
|
335
334
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
node.remove();
|
|
336
|
+
node = next;
|
|
337
|
+
}
|
|
339
338
|
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
removed = true;
|
|
340
|
+
}
|
|
342
341
|
|
|
343
|
-
|
|
342
|
+
destroy_block_children(block, remove_dom && !removed);
|
|
344
343
|
|
|
345
|
-
|
|
344
|
+
run_teardown(block);
|
|
346
345
|
|
|
347
|
-
|
|
346
|
+
var parent = block.p;
|
|
348
347
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
348
|
+
// If the parent doesn't have any children, then skip this work altogether
|
|
349
|
+
if (parent !== null && parent.first !== null) {
|
|
350
|
+
unlink_block(block);
|
|
351
|
+
}
|
|
353
352
|
|
|
354
|
-
|
|
353
|
+
block.fn = block.s = block.d = block.p = null;
|
|
355
354
|
}
|
|
@@ -11,7 +11,7 @@ export var CONTAINS_UPDATE = 1 << 10;
|
|
|
11
11
|
export var CONTAINS_TEARDOWN = 1 << 11;
|
|
12
12
|
export var BLOCK_HAS_RUN = 1 << 12;
|
|
13
13
|
export var TRACKED = 1 << 13;
|
|
14
|
-
export var
|
|
14
|
+
export var DERIVED = 1 << 14;
|
|
15
15
|
export var DEFERRED = 1 << 15;
|
|
16
16
|
export var PAUSED = 1 << 16;
|
|
17
17
|
export var DESTROYED = 1 << 17;
|
|
@@ -26,4 +26,4 @@ export var COMPUTED_PROPERTY = Symbol();
|
|
|
26
26
|
export var REF_PROP = 'ref';
|
|
27
27
|
/** @type {unique symbol} */
|
|
28
28
|
export const ARRAY_SET_INDEX_AT = Symbol();
|
|
29
|
-
export const MAX_ARRAY_LENGTH = 2**32 - 1;
|
|
29
|
+
export const MAX_ARRAY_LENGTH = 2 ** 32 - 1;
|
|
@@ -6,57 +6,57 @@ import { active_component } from './runtime';
|
|
|
6
6
|
* @template T
|
|
7
7
|
*/
|
|
8
8
|
export class Context {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {T} initial_value
|
|
11
|
+
*/
|
|
12
|
+
constructor(initial_value) {
|
|
13
|
+
/** @type {T} */
|
|
14
|
+
this._v = initial_value;
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
get() {
|
|
18
|
+
const component = active_component;
|
|
19
|
+
const context = this;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (component === null) {
|
|
22
|
+
throw new Error('No active component found, cannot get context');
|
|
23
|
+
}
|
|
24
|
+
/** @type {Component | null} */
|
|
25
|
+
let current_component = component;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
while (current_component !== null) {
|
|
28
|
+
const context_map = current_component.c;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (context_map?.has(context)) {
|
|
31
|
+
return context_map.get(context);
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
current_component = current_component.p;
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
return context._v;
|
|
38
|
+
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
/**
|
|
41
|
+
* @template T
|
|
42
|
+
* @param {T} value
|
|
43
|
+
*/
|
|
44
|
+
set(value) {
|
|
45
|
+
const component = active_component;
|
|
46
|
+
const context = this;
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (component === null) {
|
|
49
|
+
throw new Error('No active component found, cannot set context');
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
let current_context = component.c;
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (current_context === null) {
|
|
55
|
+
current_context = component.c = new Map();
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
current_context.set(context, value);
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|