Skip to content

Commit 78ab30c

Browse files
committed
simplify
1 parent ddb9f78 commit 78ab30c

File tree

8 files changed

+10
-27
lines changed

8 files changed

+10
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ function create_block(parent, name, nodes, context) {
10721072

10731073
body.push(...state.before_init, ...state.init);
10741074

1075-
close = b.stmt(b.call('$.close_frag', b.id('$$anchor'), id));
1075+
close = b.stmt(b.call('$.close', b.id('$$anchor'), id));
10761076
}
10771077
} else {
10781078
body.push(...state.before_init, ...state.init);

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,15 @@ export const comment = template('<!>', TEMPLATE_FRAGMENT);
155155
/**
156156
* Assign the created (or in hydration mode, traversed) dom elements to the current block
157157
* and insert the elements into the dom (in client mode).
158-
* @param {import('#client').Dom} dom
159-
* @param {boolean} is_fragment
160158
* @param {Text | Comment | Element} anchor
159+
* @param {import('#client').Dom} dom
161160
* @returns {import('#client').Dom}
162161
*/
163-
function close_template(dom, is_fragment, anchor) {
162+
export function close(anchor, dom) {
164163
var current = dom;
165164

166165
if (!hydrating) {
167-
if (is_fragment) {
166+
if (/** @type {Node} */ (dom).nodeType === 11) {
168167
// if hydrating, `dom` is already an array of nodes, but if not then
169168
// we need to create an array to store it on the current effect
170169
current = /** @type {import('#client').Dom} */ ([.../** @type {Node} */ (dom).childNodes]);
@@ -178,19 +177,3 @@ function close_template(dom, is_fragment, anchor) {
178177

179178
return current;
180179
}
181-
182-
/**
183-
* @param {Text | Comment | Element} anchor
184-
* @param {Element | Text} dom
185-
*/
186-
export function close(anchor, dom) {
187-
return close_template(dom, false, anchor);
188-
}
189-
190-
/**
191-
* @param {Text | Comment | Element} anchor
192-
* @param {Element | Text} dom
193-
*/
194-
export function close_frag(anchor, dom) {
195-
return close_template(dom, true, anchor);
196-
}

packages/svelte/tests/snapshot/samples/bind-this/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export default function Bind_this($$anchor, $$props) {
1111
var node = $.first_child(fragment);
1212

1313
$.bind_this(Foo(node, {}), ($$value) => foo = $$value, () => foo);
14-
$.close_frag($$anchor, fragment);
14+
$.close($$anchor, fragment);
1515
$.pop();
1616
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ export default function Main($$anchor, $$props) {
3333
$.set_custom_element_data(custom_element, "fooBar", x);
3434
});
3535

36-
$.close_frag($$anchor, fragment);
36+
$.close($$anchor, fragment);
3737
$.pop();
3838
}

packages/svelte/tests/snapshot/samples/each-string-template/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export default function Each_string_template($$anchor, $$props) {
1717
return $.close($$anchor, text);
1818
});
1919

20-
$.close_frag($$anchor, fragment);
20+
$.close($$anchor, fragment);
2121
$.pop();
2222
}

packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export default function Function_prop_no_getter($$anchor, $$props) {
2828
}
2929
});
3030

31-
$.close_frag($$anchor, fragment);
31+
$.close($$anchor, fragment);
3232
$.pop();
3333
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function State_proxy_literal($$anchor, $$props) {
3131
button.__click = [reset, str, tpl];
3232
$.bind_value(input, () => $.get(str), ($$value) => $.set(str, $$value));
3333
$.bind_value(input_1, () => $.get(tpl), ($$value) => $.set(tpl, $$value));
34-
$.close_frag($$anchor, fragment);
34+
$.close($$anchor, fragment);
3535
$.pop();
3636
}
3737

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export default function Svelte_element($$anchor, $$props) {
1111
var node = $.first_child(fragment);
1212

1313
$.element(node, tag, false);
14-
$.close_frag($$anchor, fragment);
14+
$.close($$anchor, fragment);
1515
$.pop();
1616
}

0 commit comments

Comments
 (0)