Skip to content

Commit 9d9c0b0

Browse files
committed
chore: only specify use_clone_node when necessary
1 parent 89f4e8d commit 9d9c0b0

File tree

6 files changed

+31
-38
lines changed

6 files changed

+31
-38
lines changed

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,18 +1169,14 @@ function create_block(parent, name, nodes, context) {
11691169
)
11701170
);
11711171

1172-
body.push(
1173-
b.var(
1174-
id,
1175-
b.call(
1176-
'$.open',
1177-
b.id('$$anchor'),
1178-
b.literal(!state.metadata.context.template_needs_import_node),
1179-
template_name
1180-
)
1181-
),
1182-
...state.init
1183-
);
1172+
/** @type {import('estree').Expression[]} */
1173+
const args = [b.id('$$anchor'), template_name];
1174+
1175+
if (state.metadata.context.template_needs_import_node) {
1176+
args.push(b.false);
1177+
}
1178+
1179+
body.push(b.var(id, b.call('$.open', ...args)), ...state.init);
11841180
close = b.stmt(b.call('$.close', b.id('$$anchor'), id));
11851181
} else if (is_single_child_not_needing_template) {
11861182
context.visit(trimmed[0], state);
@@ -1227,17 +1223,14 @@ function create_block(parent, name, nodes, context) {
12271223
)
12281224
);
12291225

1230-
body.push(
1231-
b.var(
1232-
id,
1233-
b.call(
1234-
'$.open_frag',
1235-
b.id('$$anchor'),
1236-
b.literal(!state.metadata.context.template_needs_import_node),
1237-
template_name
1238-
)
1239-
)
1240-
);
1226+
/** @type {import('estree').Expression[]} */
1227+
const args = [b.id('$$anchor'), template_name];
1228+
1229+
if (state.metadata.context.template_needs_import_node) {
1230+
args.push(b.false);
1231+
}
1232+
1233+
body.push(b.var(id, b.call('$.open_frag', ...args)));
12411234
}
12421235

12431236
body.push(...state.init);

packages/svelte/src/internal/client/dom/elements/custom-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ if (typeof HTMLElement === 'function') {
9898
* @param {Element} anchor
9999
*/
100100
return (anchor) => {
101-
const node = open(anchor, true, () => {
101+
const node = open(anchor, () => {
102102
const slot = document.createElement('slot');
103103
if (name !== 'default') {
104104
slot.name = name;

packages/svelte/src/internal/client/dom/template.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,23 @@ function open_template(is_fragment, use_clone_node, anchor, template_element_fn)
106106

107107
/**
108108
* @param {null | Text | Comment | Element} anchor
109-
* @param {boolean} use_clone_node
110-
* @param {() => Node} [template_element_fn]
109+
* @param {() => Node} template_element_fn
110+
* @param {boolean} [use_clone_node]
111111
* @returns {Element | DocumentFragment | Node[]}
112112
*/
113113
/*#__NO_SIDE_EFFECTS__*/
114-
export function open(anchor, use_clone_node, template_element_fn) {
114+
export function open(anchor, template_element_fn, use_clone_node = true) {
115115
return open_template(false, use_clone_node, anchor, template_element_fn);
116116
}
117117

118118
/**
119119
* @param {null | Text | Comment | Element} anchor
120-
* @param {boolean} use_clone_node
121-
* @param {() => Node} [template_element_fn]
120+
* @param {() => Node} template_element_fn
121+
* @param {boolean} [use_clone_node]
122122
* @returns {Element | DocumentFragment | Node[]}
123123
*/
124124
/*#__NO_SIDE_EFFECTS__*/
125-
export function open_frag(anchor, use_clone_node, template_element_fn) {
125+
export function open_frag(anchor, template_element_fn, use_clone_node = true) {
126126
return open_template(true, use_clone_node, anchor, template_element_fn);
127127
}
128128

@@ -135,7 +135,7 @@ const comment_template = template('<!>', true);
135135
/*#__NO_SIDE_EFFECTS__*/
136136
export function space_frag(anchor) {
137137
/** @type {Node | null} */
138-
var node = /** @type {any} */ (open(anchor, true, space_template));
138+
var node = /** @type {any} */ (open(anchor, space_template));
139139
// if an {expression} is empty during SSR, there might be no
140140
// text node to hydrate (or an anchor comment is falsely detected instead)
141141
// — we must therefore create one
@@ -169,7 +169,7 @@ export function space(anchor) {
169169
*/
170170
/*#__NO_SIDE_EFFECTS__*/
171171
export function comment(anchor) {
172-
return open_frag(anchor, true, comment_template);
172+
return open_frag(anchor, comment_template);
173173
}
174174

175175
/**

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/client/main.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Main($$anchor, $$props) {
1212
let x = 'test';
1313
let y = () => 'test';
1414
/* Init */
15-
var fragment = $.open_frag($$anchor, false, frag);
15+
var fragment = $.open_frag($$anchor, frag, false);
1616
var div = $.child_frag(fragment);
1717
var svg = $.sibling($.sibling(div, true));
1818
var custom_element = $.sibling($.sibling(svg, true));
@@ -45,4 +45,4 @@ export default function Main($$anchor, $$props) {
4545

4646
$.close_frag($$anchor, fragment);
4747
$.pop();
48-
}
48+
}

packages/svelte/tests/snapshot/samples/hello-world/_expected/client/index.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export default function Hello_world($$anchor, $$props) {
1010
$.init();
1111

1212
/* Init */
13-
var h1 = $.open($$anchor, true, frag);
13+
var h1 = $.open($$anchor, frag);
1414

1515
$.close($$anchor, h1);
1616
$.pop();
17-
}
17+
}

packages/svelte/tests/snapshot/samples/state-proxy-literal/_expected/client/index.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function State_proxy_literal($$anchor, $$props) {
1818
let str = $.source('');
1919
let tpl = $.source(``);
2020
/* Init */
21-
var fragment = $.open_frag($$anchor, true, frag);
21+
var fragment = $.open_frag($$anchor, frag);
2222
var input = $.child_frag(fragment);
2323

2424
$.remove_input_attr_defaults(input);
@@ -36,4 +36,4 @@ export default function State_proxy_literal($$anchor, $$props) {
3636
$.pop();
3737
}
3838

39-
$.delegate(["click"]);
39+
$.delegate(["click"]);

0 commit comments

Comments
 (0)