Skip to content

Commit 085f902

Browse files
committed
Merge branch 'main' into use-get-descriptors
2 parents ad0fef3 + a990e57 commit 085f902

File tree

42 files changed

+568
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+568
-454
lines changed

.changeset/chilly-dolphins-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: remove selector api

.changeset/eight-steaks-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: correct update_block index type

.changeset/khaki-mails-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: tighten up signals implementation

.changeset/quiet-camels-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: improve keyblock treeshaking

.changeset/small-papayas-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
breaking: remove Component type, keep using SvelteComponent instead

.changeset/tall-shrimps-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: add snippet marker symbol to children prop

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
## Svelte compiler rewrite
1+
## Svelte 5 rewrite
22

3-
Please note that [the Svelte codebase is currently being rewritten](https://svelte.dev/blog/runes). Thus, it's best to hold off on new features or refactorings for the time being.
3+
Please note that [the Svelte codebase is currently being rewritten for Svelte 5](https://svelte.dev/blog/runes). Changes should target Svelte 5, which lives on the default branch (`main`).
4+
5+
If your PR concerns Svelte 4 (including updates to [svelte.dev.docs](https://svelte.dev/docs)), please ensure the base branch is `svelte-4` and not `main`.
46

57
### Before submitting the PR, please make sure you do the following
68

packages/svelte/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ await createBundle({
2727
[`${pkg.name}/animate`]: `${dir}/src/animate/public.d.ts`,
2828
[`${pkg.name}/compiler`]: `${dir}/src/compiler/index.js`,
2929
[`${pkg.name}/easing`]: `${dir}/src/easing/index.js`,
30-
[`${pkg.name}/legacy`]: `${dir}/src/legacy/public.d.ts`,
30+
[`${pkg.name}/legacy`]: `${dir}/src/legacy/legacy-client.js`,
3131
[`${pkg.name}/motion`]: `${dir}/src/motion/public.d.ts`,
3232
[`${pkg.name}/server`]: `${dir}/src/server/index.js`,
3333
[`${pkg.name}/store`]: `${dir}/src/store/public.d.ts`,

packages/svelte/src/compiler/phases/3-transform/client/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ export const function_visitor = (node, context) => {
251251
const in_constructor = parent.type === 'MethodDefinition' && parent.kind === 'constructor';
252252

253253
state = { ...context.state, in_constructor };
254+
} else {
255+
state = { ...context.state, in_constructor: false };
254256
}
255257

256258
if (metadata?.hoistable === true) {

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,21 @@ function serialize_inline_component(node, component_name, context) {
819819
const body = create_block(node, `${node.name}_${slot_name}`, children[slot_name], context);
820820
if (body.length === 0) continue;
821821

822-
const fn = b.arrow(
822+
const slot_fn = b.arrow(
823823
[b.id('$$anchor'), b.id('$$slotProps')],
824824
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
825825
);
826826

827827
if (slot_name === 'default') {
828-
push_prop(b.prop('init', b.id('children'), fn));
828+
push_prop(
829+
b.prop(
830+
'init',
831+
b.id('children'),
832+
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
833+
)
834+
);
829835
} else {
830-
serialized_slots.push(b.prop('init', b.key(slot_name), fn));
836+
serialized_slots.push(b.prop('init', b.key(slot_name), slot_fn));
831837
}
832838
}
833839

@@ -2221,19 +2227,34 @@ export const template_visitors = {
22212227
declarations.push(b.let(node.index, index));
22222228
}
22232229

2224-
context.state.after_update.push(
2225-
b.stmt(
2226-
b.call(
2227-
'$.each',
2228-
context.state.node,
2229-
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2230-
b.literal(each_type),
2231-
key_function,
2232-
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children))),
2233-
else_block
2230+
if ((each_type & EACH_KEYED) !== 0) {
2231+
context.state.after_update.push(
2232+
b.stmt(
2233+
b.call(
2234+
'$.each_keyed',
2235+
context.state.node,
2236+
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2237+
b.literal(each_type),
2238+
key_function,
2239+
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children))),
2240+
else_block
2241+
)
22342242
)
2235-
)
2236-
);
2243+
);
2244+
} else {
2245+
context.state.after_update.push(
2246+
b.stmt(
2247+
b.call(
2248+
'$.each_indexed',
2249+
context.state.node,
2250+
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2251+
b.literal(each_type),
2252+
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children))),
2253+
else_block
2254+
)
2255+
)
2256+
);
2257+
}
22372258
},
22382259
IfBlock(node, context) {
22392260
context.state.template.push('<!>');

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,26 +847,21 @@ function serialize_inline_component(node, component_name, context) {
847847
const body = create_block(node, children[slot_name], context);
848848
if (body.length === 0) continue;
849849

850+
const slot_fn = b.arrow(
851+
[b.id('$$payload'), b.id('$$slotProps')],
852+
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
853+
);
854+
850855
if (slot_name === 'default') {
851856
push_prop(
852857
b.prop(
853858
'init',
854859
b.id('children'),
855-
b.arrow(
856-
[b.id('$$payload'), b.id('$$slotProps')],
857-
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
858-
)
860+
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
859861
)
860862
);
861863
} else {
862-
const slot = b.prop(
863-
'init',
864-
b.literal(slot_name),
865-
b.arrow(
866-
[b.id('$$payload'), b.id('$$slotProps')],
867-
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
868-
)
869-
);
864+
const slot = b.prop('init', b.literal(slot_name), slot_fn);
870865
serialized_slots.push(slot);
871866
}
872867
}

packages/svelte/src/internal/client/operations.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ const has_browser_globals = typeof window !== 'undefined';
88
// than megamorphic.
99
const node_prototype = /** @type {Node} */ (has_browser_globals ? Node.prototype : {});
1010
const element_prototype = /** @type {Element} */ (has_browser_globals ? Element.prototype : {});
11-
const event_target_prototype = /** @type {EventTarget} */ (
12-
has_browser_globals ? EventTarget.prototype : {}
13-
);
11+
const text_prototype = /** @type {Text} */ (has_browser_globals ? Text.prototype : {});
1412
const map_prototype = Map.prototype;
1513
const append_child_method = node_prototype.appendChild;
1614
const clone_node_method = node_prototype.cloneNode;
1715
const map_set_method = map_prototype.set;
1816
const map_get_method = map_prototype.get;
1917
const map_delete_method = map_prototype.delete;
20-
// @ts-expect-error improve perf of expando on DOM nodes for events
21-
event_target_prototype.__click = undefined;
22-
// @ts-expect-error improve perf of expando on DOM textValue updates
23-
event_target_prototype.__nodeValue = ' ';
18+
// @ts-expect-error improve perf of expando on DOM events
19+
element_prototype.__click = undefined;
20+
// @ts-expect-error improve perf of expando on DOM text updates
21+
text_prototype.__nodeValue = ' ';
2422
// @ts-expect-error improve perf of expando on DOM className updates
25-
event_target_prototype.__className = '';
23+
element_prototype.__className = '';
2624

2725
const first_child_get = /** @type {(this: Node) => ChildNode | null} */ (
2826
// @ts-ignore
@@ -162,11 +160,10 @@ export function set_class_name(node, class_name) {
162160
/**
163161
* @template {Node} N
164162
* @param {N} node
165-
* @param {string} text
166163
* @returns {void}
167164
*/
168-
export function text_content(node, text) {
169-
text_content_set.call(node, text);
165+
export function clear_text_content(node) {
166+
text_content_set.call(node, '');
170167
}
171168

172169
/** @param {string} name */

packages/svelte/src/internal/client/reconciler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { append_child, map_get, map_set, text_content } from './operations.js';
1+
import { append_child, map_get, map_set, clear_text_content } from './operations.js';
22
import {
33
current_hydration_fragment,
44
get_hydration_fragment,
@@ -198,7 +198,7 @@ export function reconcile_indexed_array(
198198
b_blocks = [];
199199
// Remove old blocks
200200
if (is_controlled && a !== 0) {
201-
text_content(dom, '');
201+
clear_text_content(dom);
202202
}
203203
while (index < length) {
204204
block = a_blocks[index++];
@@ -260,9 +260,9 @@ export function reconcile_indexed_array(
260260
* @param {Element | Comment | Text} dom
261261
* @param {boolean} is_controlled
262262
* @param {(anchor: null, item: V, index: number | import('./types.js').Signal<number>) => void} render_fn
263-
* @param {Array<string> | null} keys
264263
* @param {number} flags
265264
* @param {boolean} apply_transitions
265+
* @param {Array<string> | null} keys
266266
* @returns {void}
267267
*/
268268
export function reconcile_tracked_array(
@@ -271,9 +271,9 @@ export function reconcile_tracked_array(
271271
dom,
272272
is_controlled,
273273
render_fn,
274-
keys,
275274
flags,
276-
apply_transitions
275+
apply_transitions,
276+
keys
277277
) {
278278
var a_blocks = each_block.items;
279279
const is_computed_key = keys !== null;
@@ -295,7 +295,7 @@ export function reconcile_tracked_array(
295295
b_blocks = [];
296296
// Remove old blocks
297297
if (is_controlled && a !== 0) {
298-
text_content(dom, '');
298+
clear_text_content(dom);
299299
}
300300
while (a > 0) {
301301
block = a_blocks[--a];

0 commit comments

Comments
 (0)