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.
- package/package.json +1 -1
- package/src/compiler/phases/1-parse/index.js +52 -2
- package/src/compiler/phases/2-analyze/index.js +640 -667
- package/src/compiler/phases/3-transform/index.js +1878 -1879
- package/src/compiler/phases/3-transform/segments.js +2 -2
- package/src/compiler/utils.js +598 -550
- 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 +121 -121
- package/src/runtime/internal/client/blocks.js +206 -206
- 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 -56
- package/src/runtime/internal/client/operations.js +32 -32
- package/src/runtime/internal/client/portal.js +19 -19
- package/src/runtime/internal/client/render.js +132 -132
- package/src/runtime/internal/client/runtime.js +839 -835
- 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 +12 -11
- 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/compiler.test.ripple +14 -14
- package/tests/composite.test.ripple +43 -72
- package/tests/context.test.ripple +35 -12
- package/types/index.d.ts +38 -34
|
@@ -1,27 +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
|
-
|
|
18
|
+
active_block,
|
|
19
|
+
active_component,
|
|
20
|
+
active_reaction,
|
|
21
|
+
is_block_dirty,
|
|
22
|
+
run_block,
|
|
23
|
+
run_teardown,
|
|
24
|
+
schedule_update,
|
|
25
25
|
} from './runtime';
|
|
26
26
|
import { suspend } from './try';
|
|
27
27
|
|
|
@@ -29,32 +29,32 @@ import { suspend } from './try';
|
|
|
29
29
|
* @param {Function} fn
|
|
30
30
|
*/
|
|
31
31
|
export function user_effect(fn) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* @param {Function} fn
|
|
55
55
|
*/
|
|
56
56
|
export function effect(fn) {
|
|
57
|
-
|
|
57
|
+
return block(EFFECT_BLOCK, fn);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
@@ -62,7 +62,7 @@ export function effect(fn) {
|
|
|
62
62
|
* @param {number} [flags]
|
|
63
63
|
*/
|
|
64
64
|
export function render(fn, flags = 0) {
|
|
65
|
-
|
|
65
|
+
return block(RENDER_BLOCK | flags, fn);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -71,7 +71,7 @@ export function render(fn, flags = 0) {
|
|
|
71
71
|
* @param {number} [flags]
|
|
72
72
|
*/
|
|
73
73
|
export function render_spread(element, fn, flags = 0) {
|
|
74
|
-
|
|
74
|
+
return block(RENDER_BLOCK | flags, apply_element_spread(element, fn));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -79,18 +79,18 @@ export function render_spread(element, fn, flags = 0) {
|
|
|
79
79
|
* @param {number} [flags]
|
|
80
80
|
*/
|
|
81
81
|
export function branch(fn, flags = 0) {
|
|
82
|
-
|
|
82
|
+
return block(BRANCH_BLOCK | flags, fn);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* @param {() => any} fn
|
|
87
87
|
*/
|
|
88
88
|
export function async(fn) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
return block(BRANCH_BLOCK, async () => {
|
|
90
|
+
const unsuspend = suspend();
|
|
91
|
+
await fn();
|
|
92
|
+
unsuspend();
|
|
93
|
+
});
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -99,27 +99,27 @@ export function async(fn) {
|
|
|
99
99
|
* @returns {Block}
|
|
100
100
|
*/
|
|
101
101
|
export function ref(element, get_fn) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
});
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -127,7 +127,7 @@ export function ref(element, get_fn) {
|
|
|
127
127
|
* @returns {Block}
|
|
128
128
|
*/
|
|
129
129
|
export function root(fn) {
|
|
130
|
-
|
|
130
|
+
return block(ROOT_BLOCK, fn);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
@@ -136,7 +136,7 @@ export function root(fn) {
|
|
|
136
136
|
* @returns {Block}
|
|
137
137
|
*/
|
|
138
138
|
export function create_try_block(fn, state) {
|
|
139
|
-
|
|
139
|
+
return block(TRY_BLOCK, fn, state);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -144,14 +144,14 @@ export function create_try_block(fn, state) {
|
|
|
144
144
|
* @param {Block} parent_block
|
|
145
145
|
*/
|
|
146
146
|
function push_block(block, parent_block) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
/**
|
|
@@ -161,37 +161,37 @@ function push_block(block, parent_block) {
|
|
|
161
161
|
* @returns {Block}
|
|
162
162
|
*/
|
|
163
163
|
export function block(flags, fn, state = null) {
|
|
164
|
-
|
|
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
|
-
|
|
164
|
+
/** @type {Block} */
|
|
165
|
+
var block = {
|
|
166
|
+
co: 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;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
/**
|
|
@@ -199,16 +199,16 @@ export function block(flags, fn, state = null) {
|
|
|
199
199
|
* @param {boolean} [remove_dom]
|
|
200
200
|
*/
|
|
201
201
|
export function destroy_block_children(parent, remove_dom = false) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
+
}
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
@@ -216,82 +216,82 @@ export function destroy_block_children(parent, remove_dom = false) {
|
|
|
216
216
|
* @param {boolean} [remove_dom]
|
|
217
217
|
*/
|
|
218
218
|
export function destroy_non_branch_children(parent, remove_dom = false) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
+
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
239
|
* @param {Block} block
|
|
240
240
|
*/
|
|
241
241
|
export function unlink_block(block) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
var parent = block.p;
|
|
243
|
+
var prev = block.prev;
|
|
244
|
+
var next = block.next;
|
|
245
245
|
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
if (prev !== null) prev.next = next;
|
|
247
|
+
if (next !== null) next.prev = prev;
|
|
248
248
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
if (parent !== null) {
|
|
250
|
+
if (parent.first === block) parent.first = next;
|
|
251
|
+
if (parent.last === block) parent.last = prev;
|
|
252
|
+
}
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
256
|
* @param {Block} block
|
|
257
257
|
*/
|
|
258
258
|
export function pause_block(block) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
259
|
+
if ((block.f & PAUSED) !== 0) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
block.f ^= PAUSED;
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
var child = block.first;
|
|
265
265
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
while (child !== null) {
|
|
267
|
+
var next = child.next;
|
|
268
|
+
pause_block(child);
|
|
269
|
+
child = next;
|
|
270
|
+
}
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
run_teardown(block);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
/**
|
|
276
276
|
* @param {Block} block
|
|
277
277
|
*/
|
|
278
278
|
export function resume_block(block) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
}
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
/**
|
|
@@ -299,21 +299,21 @@ export function resume_block(block) {
|
|
|
299
299
|
* @returns {boolean}
|
|
300
300
|
*/
|
|
301
301
|
export function is_destroyed(target_block) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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;
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
/**
|
|
@@ -321,34 +321,34 @@ export function is_destroyed(target_block) {
|
|
|
321
321
|
* @param {boolean} [remove_dom]
|
|
322
322
|
*/
|
|
323
323
|
export function destroy_block(block, remove_dom = true) {
|
|
324
|
-
|
|
324
|
+
block.f ^= DESTROYED;
|
|
325
325
|
|
|
326
|
-
|
|
326
|
+
var removed = false;
|
|
327
327
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
328
|
+
if (remove_dom && (block.f & (BRANCH_BLOCK | ROOT_BLOCK)) !== 0) {
|
|
329
|
+
var node = block.s.start;
|
|
330
|
+
var end = block.s.end;
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
while (node !== null) {
|
|
333
|
+
var next = node === end ? null : next_sibling(node);
|
|
334
334
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
node.remove();
|
|
336
|
+
node = next;
|
|
337
|
+
}
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
removed = true;
|
|
340
|
+
}
|
|
341
341
|
|
|
342
|
-
|
|
342
|
+
destroy_block_children(block, remove_dom && !removed);
|
|
343
343
|
|
|
344
|
-
|
|
344
|
+
run_teardown(block);
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
var parent = block.p;
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
+
}
|
|
352
352
|
|
|
353
|
-
|
|
353
|
+
block.fn = block.s = block.d = block.p = null;
|
|
354
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
|
/**
|