Skip to content

feat: omit trailing $.sibling calls where possible #12932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-points-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: omit trailing `$.sibling` calls where possible
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function Fragment(node, context) {
// special case — we can use `$.text` instead of creating a unique template
const id = b.id(context.state.scope.generate('text'));

process_children(trimmed, () => id, false, {
process_children(trimmed, () => id, false, false, {
...context,
state
});
Expand All @@ -157,12 +157,12 @@ export function Fragment(node, context) {
} else {
if (is_standalone) {
// no need to create a template, we can just use the existing block's anchor
process_children(trimmed, () => b.id('$$anchor'), false, { ...context, state });
process_children(trimmed, () => b.id('$$anchor'), false, false, { ...context, state });
} else {
/** @type {(is_text: boolean) => Expression} */
const expression = (is_text) => b.call('$.first_child', id, is_text && b.true);

process_children(trimmed, expression, false, { ...context, state });
process_children(trimmed, expression, false, false, { ...context, state });

let flags = TEMPLATE_FRAGMENT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export function RegularElement(node, context) {
arg = b.member(arg, 'content');
}

process_children(trimmed, () => b.call('$.child', arg), true, {
process_children(trimmed, () => b.call('$.child', arg), true, needs_reset, {
...context,
state: child_state
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { build_template_literal, build_update } from './utils.js';
* corresponding template node references these updates are applied to.
* @param {SvelteNode[]} nodes
* @param {(is_text: boolean) => Expression} initial
* @param {boolean} is_element
* @param {boolean} is_element TODO get rid of this — we should be able to determine controlled status during analysis
* @param {boolean} needs_reset
* @param {ComponentContext} context
*/
export function process_children(nodes, initial, is_element, { visit, state }) {
export function process_children(nodes, initial, is_element, needs_reset, { visit, state }) {
const within_bound_contenteditable = state.metadata.bound_contenteditable;
let prev = initial;
let skipped = 0;
Expand Down Expand Up @@ -116,7 +117,7 @@ export function process_children(nodes, initial, is_element, { visit, state }) {

// if there are trailing static text nodes/elements,
// traverse to the last (n - 1) one when hydrating
if (skipped > 1) {
if (skipped > 1 && !needs_reset) {
skipped -= 1;
state.init.push(b.stmt(b.call('$.next', skipped !== 1 && b.literal(skipped))));
}
Expand Down
Loading