Skip to content

Commit d45a62a

Browse files
committed
we don't actually need the function, we can flatten it. more efficient
1 parent 57999d3 commit d45a62a

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ function serialize_inline_component(node, component_name, context) {
896896
'$.spread_props',
897897
...props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p))
898898
);
899-
/** @param {import('estree').Identifier} node_id */
899+
/** @param {import('estree').Expression} node_id */
900900
let fn = (node_id) =>
901901
b.call(
902902
context.state.options.dev
@@ -937,34 +937,24 @@ function serialize_inline_component(node, component_name, context) {
937937
};
938938
}
939939

940+
const statements = [...snippet_declarations, ...binding_initializers];
941+
940942
if (Object.keys(custom_css_props).length > 0) {
941943
context.state.template.push(
942944
context.state.metadata.namespace === 'svg'
943945
? '<g><!></g>'
944946
: '<div style="display: contents"><!></div>'
945947
);
946948

947-
return b.stmt(
948-
b.call(
949-
'$.css_props',
950-
context.state.node,
951-
b.thunk(b.object(custom_css_props)),
952-
b.arrow(
953-
[b.id('$$node')],
954-
b.block([...snippet_declarations, ...binding_initializers, b.stmt(fn(b.id('$$node')))])
955-
)
956-
)
949+
statements.push(
950+
b.stmt(b.call('$.css_props', context.state.node, b.thunk(b.object(custom_css_props)))),
951+
b.stmt(fn(b.member(context.state.node, b.id('lastChild'))))
957952
);
953+
} else {
954+
context.state.template.push('<!>');
955+
statements.push(b.stmt(fn(context.state.node)));
958956
}
959957

960-
context.state.template.push('<!>');
961-
962-
const statements = [
963-
...snippet_declarations,
964-
...binding_initializers,
965-
b.stmt(fn(context.state.node))
966-
];
967-
968958
return statements.length > 1 ? b.block(statements) : statements[0];
969959
}
970960

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,6 @@ function serialize_element_spread_attributes(
907907
* @param {import('#compiler').Component | import('#compiler').SvelteComponent | import('#compiler').SvelteSelf} node
908908
* @param {string | import('estree').Expression} component_name
909909
* @param {import('./types').ComponentContext} context
910-
* @returns {import('estree').Statement}
911910
*/
912911
function serialize_inline_component(node, component_name, context) {
913912
/** @type {Array<import('estree').Property[] | import('estree').Expression>} */

packages/svelte/src/internal/client/dom/blocks/css-props.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import { render_effect } from '../../reactivity/effects.js';
44
/**
55
* @param {HTMLDivElement | SVGGElement} element
66
* @param {() => Record<string, string>} get_styles
7-
* @param {(anchor: Element | Text | Comment) => any} component
87
* @returns {void}
98
*/
10-
export function css_props(element, get_styles, component) {
9+
export function css_props(element, get_styles) {
1110
if (hydrating) {
1211
set_hydrate_nodes(
1312
/** @type {import('#client').TemplateNode[]} */ ([...element.childNodes]).slice(0, -1)
1413
);
1514
}
1615

17-
component(/** @type {Comment} */ (element.lastChild));
18-
1916
render_effect(() => {
2017
render_effect(() => {
2118
var styles = get_styles();

0 commit comments

Comments
 (0)