Skip to content

chore: only specify use_clone_node when necessary #10895

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

Merged
merged 1 commit into from
Mar 23, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1169,18 +1169,14 @@ function create_block(parent, name, nodes, context) {
)
);

body.push(
b.var(
id,
b.call(
'$.open',
b.id('$$anchor'),
b.literal(!state.metadata.context.template_needs_import_node),
template_name
)
),
...state.init
);
/** @type {import('estree').Expression[]} */
const args = [b.id('$$anchor'), template_name];

if (state.metadata.context.template_needs_import_node) {
args.push(b.false);
}

body.push(b.var(id, b.call('$.open', ...args)), ...state.init);
close = b.stmt(b.call('$.close', b.id('$$anchor'), id));
} else if (is_single_child_not_needing_template) {
context.visit(trimmed[0], state);
Expand Down Expand Up @@ -1227,17 +1223,14 @@ function create_block(parent, name, nodes, context) {
)
);

body.push(
b.var(
id,
b.call(
'$.open_frag',
b.id('$$anchor'),
b.literal(!state.metadata.context.template_needs_import_node),
template_name
)
)
);
/** @type {import('estree').Expression[]} */
const args = [b.id('$$anchor'), template_name];

if (state.metadata.context.template_needs_import_node) {
args.push(b.false);
}

body.push(b.var(id, b.call('$.open_frag', ...args)));
}

body.push(...state.init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if (typeof HTMLElement === 'function') {
* @param {Element} anchor
*/
return (anchor) => {
const node = open(anchor, true, () => {
const node = open(anchor, () => {
const slot = document.createElement('slot');
if (name !== 'default') {
slot.name = name;
Expand Down
16 changes: 8 additions & 8 deletions packages/svelte/src/internal/client/dom/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ function open_template(is_fragment, use_clone_node, anchor, template_element_fn)

/**
* @param {null | Text | Comment | Element} anchor
* @param {boolean} use_clone_node
* @param {() => Node} [template_element_fn]
* @param {() => Node} template_element_fn
* @param {boolean} [use_clone_node]
* @returns {Element | DocumentFragment | Node[]}
*/
/*#__NO_SIDE_EFFECTS__*/
export function open(anchor, use_clone_node, template_element_fn) {
export function open(anchor, template_element_fn, use_clone_node = true) {
return open_template(false, use_clone_node, anchor, template_element_fn);
}

/**
* @param {null | Text | Comment | Element} anchor
* @param {boolean} use_clone_node
* @param {() => Node} [template_element_fn]
* @param {() => Node} template_element_fn
* @param {boolean} [use_clone_node]
* @returns {Element | DocumentFragment | Node[]}
*/
/*#__NO_SIDE_EFFECTS__*/
export function open_frag(anchor, use_clone_node, template_element_fn) {
export function open_frag(anchor, template_element_fn, use_clone_node = true) {
return open_template(true, use_clone_node, anchor, template_element_fn);
}

Expand All @@ -135,7 +135,7 @@ const comment_template = template('<!>', true);
/*#__NO_SIDE_EFFECTS__*/
export function space_frag(anchor) {
/** @type {Node | null} */
var node = /** @type {any} */ (open(anchor, true, space_template));
var node = /** @type {any} */ (open(anchor, space_template));
// if an {expression} is empty during SSR, there might be no
// text node to hydrate (or an anchor comment is falsely detected instead)
// — we must therefore create one
Expand Down Expand Up @@ -169,7 +169,7 @@ export function space(anchor) {
*/
/*#__NO_SIDE_EFFECTS__*/
export function comment(anchor) {
return open_frag(anchor, true, comment_template);
return open_frag(anchor, comment_template);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Main($$anchor, $$props) {
let x = 'test';
let y = () => 'test';
/* Init */
var fragment = $.open_frag($$anchor, false, frag);
var fragment = $.open_frag($$anchor, frag, false);
var div = $.child_frag(fragment);
var svg = $.sibling($.sibling(div, true));
var custom_element = $.sibling($.sibling(svg, true));
Expand Down Expand Up @@ -45,4 +45,4 @@ export default function Main($$anchor, $$props) {

$.close_frag($$anchor, fragment);
$.pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function Hello_world($$anchor, $$props) {
$.init();

/* Init */
var h1 = $.open($$anchor, true, frag);
var h1 = $.open($$anchor, frag);

$.close($$anchor, h1);
$.pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function State_proxy_literal($$anchor, $$props) {
let str = $.source('');
let tpl = $.source(``);
/* Init */
var fragment = $.open_frag($$anchor, true, frag);
var fragment = $.open_frag($$anchor, frag);
var input = $.child_frag(fragment);

$.remove_input_attr_defaults(input);
Expand All @@ -36,4 +36,4 @@ export default function State_proxy_literal($$anchor, $$props) {
$.pop();
}

$.delegate(["click"]);
$.delegate(["click"]);