ripple 0.2.87 → 0.2.88
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 +30 -1
- package/src/compiler/phases/2-analyze/index.js +3 -1
- package/src/compiler/phases/3-transform/client/index.js +23 -10
- package/src/runtime/internal/client/for.js +403 -403
- package/src/runtime/internal/client/if.js +29 -29
- package/src/runtime/internal/client/index.js +2 -0
- package/src/runtime/internal/client/script.js +16 -0
- package/tests/client/__snapshots__/basic.test.ripple.snap +13 -0
- package/tests/client/basic.test.ripple +15 -0
package/package.json
CHANGED
|
@@ -793,7 +793,36 @@ function RipplePlugin(config) {
|
|
|
793
793
|
this.next();
|
|
794
794
|
}
|
|
795
795
|
} else {
|
|
796
|
-
if (open.name.name === '
|
|
796
|
+
if (open.name.name === 'script') {
|
|
797
|
+
let content = '';
|
|
798
|
+
|
|
799
|
+
// TODO implement this where we get a string for content of the content of the script tag
|
|
800
|
+
// This is a temporary workaround to get the content of the script tag
|
|
801
|
+
const start = open.end;
|
|
802
|
+
const input = this.input.slice(start);
|
|
803
|
+
const end = input.indexOf('</script>');
|
|
804
|
+
content = input.slice(0, end);
|
|
805
|
+
|
|
806
|
+
const newLines = content.match(regex_newline_characters)?.length;
|
|
807
|
+
if (newLines) {
|
|
808
|
+
this.curLine = open.loc.end.line + newLines;
|
|
809
|
+
this.lineStart = start + content.lastIndexOf('\n') + 1;
|
|
810
|
+
}
|
|
811
|
+
this.pos = start + content.length + 1;
|
|
812
|
+
|
|
813
|
+
this.type = tok.jsxTagStart;
|
|
814
|
+
this.next();
|
|
815
|
+
if (this.value === '/') {
|
|
816
|
+
this.next();
|
|
817
|
+
this.jsx_parseElementName();
|
|
818
|
+
this.exprAllowed = true;
|
|
819
|
+
this.#path.pop();
|
|
820
|
+
this.next();
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
element.content = content;
|
|
824
|
+
this.finishNode(element, 'Element');
|
|
825
|
+
} else if (open.name.name === 'style') {
|
|
797
826
|
// jsx_parseOpeningElementAt treats ID selectors (ie. #myid) or type selectors (ie. div) as identifier and read it
|
|
798
827
|
// So backtrack to the end of the <style> tag to make sure everything is included
|
|
799
828
|
const start = open.end;
|
|
@@ -488,7 +488,9 @@ const visitors = {
|
|
|
488
488
|
if (attr.name.type === 'Identifier') {
|
|
489
489
|
attribute_names.add(attr.name);
|
|
490
490
|
}
|
|
491
|
-
|
|
491
|
+
if (attr.value !== null) {
|
|
492
|
+
visit(attr.value, state);
|
|
493
|
+
}
|
|
492
494
|
} else if (attr.type === 'SpreadAttribute') {
|
|
493
495
|
visit(attr.argument, state);
|
|
494
496
|
} else if (attr.type === 'RefAttribute') {
|
|
@@ -137,12 +137,6 @@ function visit_title_element(node, context) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
function visit_style_element(node, context) {
|
|
141
|
-
context.state.template.push(
|
|
142
|
-
b.literal(`<style>${sanitize_template_string(node.css)}</style>`),
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
140
|
const visitors = {
|
|
147
141
|
_: function set_scope(node, { next, state }) {
|
|
148
142
|
const scope = state.scopes.get(node);
|
|
@@ -487,9 +481,19 @@ const visitors = {
|
|
|
487
481
|
Element(node, context) {
|
|
488
482
|
const { state, visit } = context;
|
|
489
483
|
|
|
490
|
-
if (context.state.inside_head
|
|
491
|
-
|
|
492
|
-
|
|
484
|
+
if (context.state.inside_head) {
|
|
485
|
+
if (node.id.type === 'Identifier' && node.id.name === 'style') {
|
|
486
|
+
state.template.push(`<style>${sanitize_template_string(node.css)}</style>`);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (node.id.type === 'Identifier' && node.id.name === 'script') {
|
|
490
|
+
const id = state.flush_node();
|
|
491
|
+
state.template.push('<!>');
|
|
492
|
+
context.state.init.push(
|
|
493
|
+
b.stmt(b.call('_$_.script', id, b.literal(sanitize_template_string(node.content)))),
|
|
494
|
+
);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
493
497
|
}
|
|
494
498
|
|
|
495
499
|
const is_dom_element = is_element_dom_element(node);
|
|
@@ -766,7 +770,8 @@ const visitors = {
|
|
|
766
770
|
if (attr.type === 'Attribute') {
|
|
767
771
|
if (attr.name.type === 'Identifier') {
|
|
768
772
|
const metadata = { tracking: false, await: false };
|
|
769
|
-
let property =
|
|
773
|
+
let property =
|
|
774
|
+
attr.value === null ? b.literal(true) : visit(attr.value, { ...state, metadata });
|
|
770
775
|
|
|
771
776
|
if (metadata.tracking || attr.name.tracked) {
|
|
772
777
|
if (attr.name.name === 'children') {
|
|
@@ -1139,6 +1144,14 @@ const visitors = {
|
|
|
1139
1144
|
return context.next();
|
|
1140
1145
|
},
|
|
1141
1146
|
|
|
1147
|
+
ExportNamedDeclaration(node, context) {
|
|
1148
|
+
if (!context.state.to_ts && node.exportKind === 'type') {
|
|
1149
|
+
return b.empty;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
return context.next();
|
|
1153
|
+
},
|
|
1154
|
+
|
|
1142
1155
|
TryStatement(node, context) {
|
|
1143
1156
|
if (!is_inside_component(context)) {
|
|
1144
1157
|
context.next();
|
|
@@ -17,29 +17,29 @@ import { array_from, is_array } from './utils.js';
|
|
|
17
17
|
* @returns {Block}
|
|
18
18
|
*/
|
|
19
19
|
function create_item(anchor, value, index, render_fn, is_indexed) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
var b = branch(() => {
|
|
21
|
+
var tracked_index;
|
|
22
|
+
|
|
23
|
+
if (is_indexed) {
|
|
24
|
+
var block = /** @type {Block} */ (active_block);
|
|
25
|
+
|
|
26
|
+
if (block.s === null) {
|
|
27
|
+
tracked_index = tracked(index, block);
|
|
28
|
+
|
|
29
|
+
block.s = {
|
|
30
|
+
start: null,
|
|
31
|
+
end: null,
|
|
32
|
+
i: tracked_index,
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
tracked_index = block.s.i;
|
|
36
|
+
}
|
|
37
|
+
render_fn(anchor, value, tracked_index);
|
|
38
|
+
} else {
|
|
39
|
+
render_fn(anchor, value);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return b;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -48,22 +48,22 @@ function create_item(anchor, value, index, render_fn, is_indexed) {
|
|
|
48
48
|
* @returns {void}
|
|
49
49
|
*/
|
|
50
50
|
function move(block, anchor) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
var node = block.s.start;
|
|
52
|
+
var end = block.s.end;
|
|
53
|
+
|
|
54
|
+
if (node === end) {
|
|
55
|
+
anchor.before(node);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
while (node !== null) {
|
|
59
|
+
var next_node = /** @type {Node} */ (next_sibling(node));
|
|
60
|
+
anchor.before(node);
|
|
61
|
+
node = next_node;
|
|
62
|
+
if (node === end) {
|
|
63
|
+
anchor.before(end);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -72,15 +72,15 @@ function move(block, anchor) {
|
|
|
72
72
|
* @returns {V[]}
|
|
73
73
|
*/
|
|
74
74
|
function collection_to_array(collection) {
|
|
75
|
-
|
|
75
|
+
var array = is_array(collection) ? collection : collection == null ? [] : array_from(collection);
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// If we are working with a tracked array, then we need to get a copy of
|
|
78
|
+
// the elements, as the array itself is proxied, and not useful in diffing
|
|
79
|
+
if (TRACKED_ARRAY in array) {
|
|
80
|
+
array = array_from(array);
|
|
81
|
+
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
return array;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
@@ -92,23 +92,23 @@ function collection_to_array(collection) {
|
|
|
92
92
|
* @returns {void}
|
|
93
93
|
*/
|
|
94
94
|
export function for_block(node, get_collection, render_fn, flags) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
var is_controlled = (flags & IS_CONTROLLED) !== 0;
|
|
96
|
+
var is_indexed = (flags & IS_INDEXED) !== 0;
|
|
97
|
+
var anchor = /** @type {Element | Text} */ (node);
|
|
98
|
+
|
|
99
|
+
if (is_controlled) {
|
|
100
|
+
anchor = node.appendChild(create_text());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
render(() => {
|
|
104
|
+
var block = /** @type {Block} */ (active_block);
|
|
105
|
+
var collection = get_collection();
|
|
106
|
+
var array = collection_to_array(collection);
|
|
107
|
+
|
|
108
|
+
untrack(() => {
|
|
109
|
+
reconcile(anchor, block, array, render_fn, is_controlled, is_indexed);
|
|
110
|
+
});
|
|
111
|
+
}, FOR_BLOCK);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
@@ -119,13 +119,13 @@ export function for_block(node, get_collection, render_fn, flags) {
|
|
|
119
119
|
* @returns {void}
|
|
120
120
|
*/
|
|
121
121
|
function reconcile_fast_clear(anchor, block, array) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
var state = block.s;
|
|
123
|
+
var parent_node = /** @type {Element} */ (anchor.parentNode);
|
|
124
|
+
parent_node.textContent = '';
|
|
125
|
+
destroy_block_children(block);
|
|
126
|
+
parent_node.append(anchor);
|
|
127
|
+
state.array = array;
|
|
128
|
+
state.blocks = [];
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -134,7 +134,7 @@ function reconcile_fast_clear(anchor, block, array) {
|
|
|
134
134
|
* @returns {void}
|
|
135
135
|
*/
|
|
136
136
|
function update_index(block, index) {
|
|
137
|
-
|
|
137
|
+
set(block.s.i, index, block);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -148,248 +148,248 @@ function update_index(block, index) {
|
|
|
148
148
|
* @returns {void}
|
|
149
149
|
*/
|
|
150
150
|
function reconcile(anchor, block, b, render_fn, is_controlled, is_indexed) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
151
|
+
var state = block.s;
|
|
152
|
+
|
|
153
|
+
// Variables used in conditional branches - declare with initial values
|
|
154
|
+
/** @type {number} */
|
|
155
|
+
var a_start = 0;
|
|
156
|
+
/** @type {number} */
|
|
157
|
+
var b_start = 0;
|
|
158
|
+
/** @type {number} */
|
|
159
|
+
var a_left = 0;
|
|
160
|
+
/** @type {number} */
|
|
161
|
+
var b_left = 0;
|
|
162
|
+
/** @type {Int32Array} */
|
|
163
|
+
var sources = new Int32Array(0);
|
|
164
|
+
/** @type {boolean} */
|
|
165
|
+
var moved = false;
|
|
166
|
+
/** @type {number} */
|
|
167
|
+
var pos = 0;
|
|
168
|
+
/** @type {number} */
|
|
169
|
+
var patched = 0;
|
|
170
|
+
/** @type {number} */
|
|
171
|
+
var i = 0;
|
|
172
|
+
|
|
173
|
+
if (state === null) {
|
|
174
|
+
state = block.s = {
|
|
175
|
+
array: [],
|
|
176
|
+
blocks: [],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
var a = state.array;
|
|
181
|
+
var a_length = a.length;
|
|
182
|
+
var b_length = b.length;
|
|
183
|
+
var j = 0;
|
|
184
|
+
|
|
185
|
+
// Fast-path for clear
|
|
186
|
+
if (is_controlled && b_length === 0) {
|
|
187
|
+
if (a_length > 0) {
|
|
188
|
+
reconcile_fast_clear(anchor, block, b);
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var b_blocks = Array(b_length);
|
|
193
|
+
|
|
194
|
+
// Fast-path for create
|
|
195
|
+
if (a_length === 0) {
|
|
196
|
+
for (; j < b_length; j++) {
|
|
197
|
+
b_blocks[j] = create_item(anchor, b[j], j, render_fn, is_indexed);
|
|
198
|
+
}
|
|
199
|
+
state.array = b;
|
|
200
|
+
state.blocks = b_blocks;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var a_blocks = state.blocks;
|
|
205
|
+
var a_val = a[j];
|
|
206
|
+
var b_val = b[j];
|
|
207
|
+
var a_end = a_length - 1;
|
|
208
|
+
var b_end = b_length - 1;
|
|
209
|
+
var b_block;
|
|
210
|
+
|
|
211
|
+
outer: {
|
|
212
|
+
while (a_val === b_val) {
|
|
213
|
+
a[j] = b_val;
|
|
214
|
+
b_block = b_blocks[j] = a_blocks[j];
|
|
215
|
+
if (is_indexed) {
|
|
216
|
+
update_index(b_block, j);
|
|
217
|
+
}
|
|
218
|
+
++j;
|
|
219
|
+
if (j > a_end || j > b_end) {
|
|
220
|
+
break outer;
|
|
221
|
+
}
|
|
222
|
+
a_val = a[j];
|
|
223
|
+
b_val = b[j];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
a_val = a[a_end];
|
|
227
|
+
b_val = b[b_end];
|
|
228
|
+
|
|
229
|
+
while (a_val === b_val) {
|
|
230
|
+
a[a_end] = b_val;
|
|
231
|
+
b_block = b_blocks[b_end] = a_blocks[a_end];
|
|
232
|
+
if (is_indexed) {
|
|
233
|
+
update_index(b_block, b_end);
|
|
234
|
+
}
|
|
235
|
+
a_end--;
|
|
236
|
+
b_end--;
|
|
237
|
+
if (j > a_end || j > b_end) {
|
|
238
|
+
break outer;
|
|
239
|
+
}
|
|
240
|
+
a_val = a[a_end];
|
|
241
|
+
b_val = b[b_end];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
var fast_path_removal = false;
|
|
246
|
+
|
|
247
|
+
if (j > a_end) {
|
|
248
|
+
if (j <= b_end) {
|
|
249
|
+
while (j <= b_end) {
|
|
250
|
+
b_val = b[j];
|
|
251
|
+
var target = j >= a_length ? anchor : a_blocks[j].s.start;
|
|
252
|
+
b_blocks[j] = create_item(target, b_val, j, render_fn, is_indexed);
|
|
253
|
+
j++;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} else if (j > b_end) {
|
|
257
|
+
while (j <= a_end) {
|
|
258
|
+
destroy_block(a_blocks[j++]);
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
a_start = j;
|
|
262
|
+
b_start = j;
|
|
263
|
+
a_left = a_end - j + 1;
|
|
264
|
+
b_left = b_end - j + 1;
|
|
265
|
+
sources = new Int32Array(b_left + 1);
|
|
266
|
+
moved = false;
|
|
267
|
+
pos = 0;
|
|
268
|
+
patched = 0;
|
|
269
|
+
i = 0;
|
|
270
|
+
|
|
271
|
+
fast_path_removal = is_controlled && a_left === a_length;
|
|
272
|
+
|
|
273
|
+
// When sizes are small, just loop them through
|
|
274
|
+
if (b_length < 4 || (a_left | b_left) < 32) {
|
|
275
|
+
for (i = a_start; i <= a_end; ++i) {
|
|
276
|
+
a_val = a[i];
|
|
277
|
+
if (patched < b_left) {
|
|
278
|
+
for (j = b_start; j <= b_end; j++) {
|
|
279
|
+
b_val = b[j];
|
|
280
|
+
if (a_val === b_val) {
|
|
281
|
+
sources[j - b_start] = i + 1;
|
|
282
|
+
if (fast_path_removal) {
|
|
283
|
+
fast_path_removal = false;
|
|
284
|
+
while (a_start < i) {
|
|
285
|
+
destroy_block(a_blocks[a_start++]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (pos > j) {
|
|
289
|
+
moved = true;
|
|
290
|
+
} else {
|
|
291
|
+
pos = j;
|
|
292
|
+
}
|
|
293
|
+
b_block = b_blocks[j] = a_blocks[i];
|
|
294
|
+
if (is_indexed) {
|
|
295
|
+
update_index(b_block, j);
|
|
296
|
+
}
|
|
297
|
+
++patched;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (!fast_path_removal && j > b_end) {
|
|
302
|
+
destroy_block(a_blocks[i]);
|
|
303
|
+
}
|
|
304
|
+
} else if (!fast_path_removal) {
|
|
305
|
+
destroy_block(a_blocks[i]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
var map = new Map();
|
|
310
|
+
|
|
311
|
+
for (i = b_start; i <= b_end; ++i) {
|
|
312
|
+
map.set(b[i], i);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
for (i = a_start; i <= a_end; ++i) {
|
|
316
|
+
a_val = a[i];
|
|
317
|
+
|
|
318
|
+
if (patched < b_left) {
|
|
319
|
+
j = map.get(a_val);
|
|
320
|
+
|
|
321
|
+
if (j !== undefined) {
|
|
322
|
+
if (fast_path_removal) {
|
|
323
|
+
fast_path_removal = false;
|
|
324
|
+
// while (i > a_start) {
|
|
325
|
+
// destroy_block(a[a_start++]);
|
|
326
|
+
// }
|
|
327
|
+
}
|
|
328
|
+
sources[j - b_start] = i + 1;
|
|
329
|
+
if (pos > j) {
|
|
330
|
+
moved = true;
|
|
331
|
+
} else {
|
|
332
|
+
pos = j;
|
|
333
|
+
}
|
|
334
|
+
b_val = b[j];
|
|
335
|
+
block = b_blocks[j] = a_blocks[i];
|
|
336
|
+
if (is_indexed) {
|
|
337
|
+
update_index(block, j);
|
|
338
|
+
}
|
|
339
|
+
++patched;
|
|
340
|
+
} else if (!fast_path_removal) {
|
|
341
|
+
destroy_block(a_blocks[i]);
|
|
342
|
+
}
|
|
343
|
+
} else if (!fast_path_removal) {
|
|
344
|
+
destroy_block(a_blocks[i]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (fast_path_removal) {
|
|
351
|
+
reconcile_fast_clear(anchor, block, []);
|
|
352
|
+
reconcile(anchor, block, b, render_fn, is_controlled, is_indexed);
|
|
353
|
+
return;
|
|
354
|
+
} else if (moved) {
|
|
355
|
+
var next_pos = 0;
|
|
356
|
+
var seq = lis_algorithm(sources);
|
|
357
|
+
j = seq.length - 1;
|
|
358
|
+
|
|
359
|
+
for (i = b_left - 1; i >= 0; i--) {
|
|
360
|
+
if (sources[i] === 0) {
|
|
361
|
+
pos = i + b_start;
|
|
362
|
+
b_val = b[pos];
|
|
363
|
+
next_pos = pos + 1;
|
|
364
|
+
|
|
365
|
+
var target = next_pos < b_length ? b_blocks[next_pos].s.start : anchor;
|
|
366
|
+
b_blocks[pos] = create_item(target, b_val, pos, render_fn, is_indexed);
|
|
367
|
+
} else if (j < 0 || i !== seq[j]) {
|
|
368
|
+
pos = i + b_start;
|
|
369
|
+
b_val = b[pos];
|
|
370
|
+
next_pos = pos + 1;
|
|
371
|
+
|
|
372
|
+
var target = next_pos < b_length ? b_blocks[next_pos].s.start : anchor;
|
|
373
|
+
move(b_blocks[pos], target);
|
|
374
|
+
} else {
|
|
375
|
+
j--;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
} else if (patched !== b_left) {
|
|
379
|
+
for (i = b_left - 1; i >= 0; i--) {
|
|
380
|
+
if (sources[i] === 0) {
|
|
381
|
+
pos = i + b_start;
|
|
382
|
+
b_val = b[pos];
|
|
383
|
+
next_pos = pos + 1;
|
|
384
|
+
|
|
385
|
+
var target = next_pos < b_length ? b_blocks[next_pos].s.start : anchor;
|
|
386
|
+
b_blocks[pos] = create_item(target, b_val, pos, render_fn, is_indexed);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
state.array = b;
|
|
392
|
+
state.blocks = b_blocks;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/** @type {Int32Array} */
|
|
@@ -403,64 +403,64 @@ let maxLen = 0;
|
|
|
403
403
|
* @returns {Int32Array}
|
|
404
404
|
*/
|
|
405
405
|
function lis_algorithm(arr) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
406
|
+
let arrI = 0;
|
|
407
|
+
let i = 0;
|
|
408
|
+
let j = 0;
|
|
409
|
+
let k = 0;
|
|
410
|
+
let u = 0;
|
|
411
|
+
let v = 0;
|
|
412
|
+
let c = 0;
|
|
413
|
+
var len = arr.length;
|
|
414
|
+
|
|
415
|
+
if (len > maxLen) {
|
|
416
|
+
maxLen = len;
|
|
417
|
+
result = new Int32Array(len);
|
|
418
|
+
p = new Int32Array(len);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
for (; i < len; ++i) {
|
|
422
|
+
arrI = arr[i];
|
|
423
|
+
|
|
424
|
+
if (arrI !== 0) {
|
|
425
|
+
j = result[k];
|
|
426
|
+
if (arr[j] < arrI) {
|
|
427
|
+
p[i] = j;
|
|
428
|
+
result[++k] = i;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
u = 0;
|
|
433
|
+
v = k;
|
|
434
|
+
|
|
435
|
+
while (u < v) {
|
|
436
|
+
c = (u + v) >> 1;
|
|
437
|
+
if (arr[result[c]] < arrI) {
|
|
438
|
+
u = c + 1;
|
|
439
|
+
} else {
|
|
440
|
+
v = c;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (arrI < arr[result[u]]) {
|
|
445
|
+
if (u > 0) {
|
|
446
|
+
p[i] = result[u - 1];
|
|
447
|
+
}
|
|
448
|
+
result[u] = i;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
u = k + 1;
|
|
454
|
+
var seq = new Int32Array(u);
|
|
455
|
+
v = result[u - 1];
|
|
456
|
+
|
|
457
|
+
while (u-- > 0) {
|
|
458
|
+
seq[u] = v;
|
|
459
|
+
v = p[v];
|
|
460
|
+
result[u] = 0;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return seq;
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
/**
|
|
@@ -471,46 +471,46 @@ function lis_algorithm(arr) {
|
|
|
471
471
|
* @returns {V[]}
|
|
472
472
|
*/
|
|
473
473
|
export function keyed(collection, key_fn) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
474
|
+
var block = active_block;
|
|
475
|
+
if (block === null || (block.f & FOR_BLOCK) === 0) {
|
|
476
|
+
throw new Error('keyed() must be used inside a for block');
|
|
477
|
+
}
|
|
478
478
|
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
var b_array = collection_to_array(collection);
|
|
480
|
+
var b_keys = b_array.map(key_fn);
|
|
481
481
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
482
|
+
// We only need to do this in DEV
|
|
483
|
+
var b = new Set(b_keys);
|
|
484
|
+
if (b.size !== b_keys.length) {
|
|
485
|
+
throw new Error('Duplicate keys are not allowed');
|
|
486
|
+
}
|
|
487
487
|
|
|
488
|
-
|
|
488
|
+
var state = block.s;
|
|
489
489
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
490
|
+
if (state === null) {
|
|
491
|
+
return b_array;
|
|
492
|
+
}
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
494
|
+
var a_array = state.array;
|
|
495
|
+
var a_keys = a_array.map(key_fn);
|
|
496
|
+
var a = new Map();
|
|
497
497
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
498
|
+
for (let i = 0; i < a_keys.length; i++) {
|
|
499
|
+
a.set(a_keys[i], i);
|
|
500
|
+
}
|
|
501
501
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
502
|
+
if (a.size !== a_keys.length) {
|
|
503
|
+
throw new Error('Duplicate keys are not allowed');
|
|
504
|
+
}
|
|
505
505
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
for (let i = 0; i < b_keys.length; i++) {
|
|
507
|
+
var b_val = b_keys[i];
|
|
508
|
+
var index = a.get(b_val);
|
|
509
509
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
510
|
+
if (index !== undefined) {
|
|
511
|
+
b_array[i] = a_array[index];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
514
|
|
|
515
|
-
|
|
515
|
+
return b_array;
|
|
516
516
|
}
|
|
@@ -9,38 +9,38 @@ import { IF_BLOCK, UNINITIALIZED } from './constants.js';
|
|
|
9
9
|
* @returns {void}
|
|
10
10
|
*/
|
|
11
11
|
export function if_block(node, fn) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
var anchor = node;
|
|
13
|
+
var has_branch = false;
|
|
14
|
+
/** @type {any} */
|
|
15
|
+
var condition = UNINITIALIZED;
|
|
16
|
+
/** @type {Block | null} */
|
|
17
|
+
var b = null;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
/** @type {(fn: (anchor: Node) => void, flag?: boolean) => void} */
|
|
20
|
+
var set_branch = (fn, flag = true) => {
|
|
21
|
+
has_branch = true;
|
|
22
|
+
update_branch(flag, fn);
|
|
23
|
+
};
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/** @type {(new_condition: any, fn: ((anchor: Node) => void) | null) => void} */
|
|
26
|
+
var update_branch = (new_condition, fn) => {
|
|
27
|
+
if (condition === (condition = new_condition)) return;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (b !== null) {
|
|
30
|
+
destroy_block(b);
|
|
31
|
+
b = null;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (fn !== null) {
|
|
35
|
+
b = branch(() => fn(anchor));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
render(() => {
|
|
40
|
+
has_branch = false;
|
|
41
|
+
fn(set_branch);
|
|
42
|
+
if (!has_branch) {
|
|
43
|
+
update_branch(null, null);
|
|
44
|
+
}
|
|
45
|
+
}, IF_BLOCK);
|
|
46
46
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { effect } from './blocks';
|
|
2
|
+
/**
|
|
3
|
+
* @param {Text | Comment} node
|
|
4
|
+
* @param {string} content
|
|
5
|
+
*/
|
|
6
|
+
export function script(node, content) {
|
|
7
|
+
effect(() => {
|
|
8
|
+
var script = document.createElement('script');
|
|
9
|
+
script.textContent = content;
|
|
10
|
+
node.before(script);
|
|
11
|
+
|
|
12
|
+
return () => {
|
|
13
|
+
script.remove();
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -37,6 +37,19 @@ exports[`basic client > handles boolean attributes with no prop value provides 1
|
|
|
37
37
|
</div>
|
|
38
38
|
`;
|
|
39
39
|
|
|
40
|
+
exports[`basic client > handles boolean props correctly 1`] = `
|
|
41
|
+
<div>
|
|
42
|
+
<div
|
|
43
|
+
data-disabled=""
|
|
44
|
+
/>
|
|
45
|
+
<input
|
|
46
|
+
disabled=""
|
|
47
|
+
/>
|
|
48
|
+
<!---->
|
|
49
|
+
|
|
50
|
+
</div>
|
|
51
|
+
`;
|
|
52
|
+
|
|
40
53
|
exports[`basic client > render semi-dynamic text 1`] = `
|
|
41
54
|
<div>
|
|
42
55
|
<div>
|
|
@@ -1547,5 +1547,20 @@ describe('basic client', () => {
|
|
|
1547
1547
|
expect(pre1.textContent).toBe('4');
|
|
1548
1548
|
expect(pre2.textContent).toBe('2');
|
|
1549
1549
|
});
|
|
1550
|
+
|
|
1551
|
+
it('handles boolean props correctly', () => {
|
|
1552
|
+
component App() {
|
|
1553
|
+
<div data-disabled />
|
|
1554
|
+
|
|
1555
|
+
<Child isDisabled />
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
component Child({ isDisabled }) {
|
|
1559
|
+
<input disabled={isDisabled} />
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
render(App);
|
|
1563
|
+
expect(container).toMatchSnapshot();
|
|
1564
|
+
});
|
|
1550
1565
|
});
|
|
1551
1566
|
|