Skip to content

Commit 3f68750

Browse files
committed
simplify
1 parent 13f5c21 commit 3f68750

File tree

2 files changed

+23
-40
lines changed

2 files changed

+23
-40
lines changed

packages/svelte/src/compiler/phases/3-transform/client/types.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export interface ComponentClientTransformState extends ClientTransformState {
3232
/** Stuff that happens before the render effect(s) */
3333
readonly init: Statement[];
3434
/** Stuff that happens inside the render effect */
35-
readonly update: {
36-
/** Used if condition for singular prop is false (see comment above) */
37-
grouped: Statement;
38-
}[];
35+
readonly update: Statement[];
3936
/** Stuff that happens after the render effect (control blocks, dynamic elements, bindings, actions, etc) */
4037
readonly after_update: Statement[];
4138
/** The HTML template string */

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

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function serialize_style_directives(style_directives, element_id, context, is_at
106106
if (!is_attributes_reactive && contains_call_expression) {
107107
state.init.push(singular);
108108
} else if (is_attributes_reactive || directive.metadata.dynamic || contains_call_expression) {
109-
state.update.push({ grouped });
109+
state.update.push(grouped);
110110
} else {
111111
state.init.push(grouped);
112112
}
@@ -155,7 +155,7 @@ function serialize_class_directives(class_directives, element_id, context, is_at
155155
if (!is_attributes_reactive && contains_call_expression) {
156156
state.init.push(singular);
157157
} else if (is_attributes_reactive || directive.metadata.dynamic || contains_call_expression) {
158-
state.update.push({ grouped });
158+
state.update.push(grouped);
159159
} else {
160160
state.init.push(grouped);
161161
}
@@ -333,17 +333,15 @@ function serialize_element_spread_attributes(
333333
context.state.init.push(standalone);
334334
}
335335
} else {
336-
context.state.update.push({
337-
grouped: inside_effect
338-
});
336+
context.state.update.push(inside_effect);
339337
}
340338

341339
if (needs_select_handling) {
342340
context.state.init.push(
343341
b.stmt(b.call('$.init_select', element_id, b.thunk(b.member(b.id(id), b.id('value')))))
344342
);
345-
context.state.update.push({
346-
grouped: b.if(
343+
context.state.update.push(
344+
b.if(
347345
b.binary('in', b.literal('value'), b.id(id)),
348346
b.block([
349347
// This ensures a one-way street to the DOM in case it's <select {value}>
@@ -353,7 +351,7 @@ function serialize_element_spread_attributes(
353351
b.stmt(b.call('$.select_option', element_id, b.member(b.id(id), b.id('value'))))
354352
])
355353
)
356-
});
354+
);
357355
}
358356
}
359357

@@ -412,8 +410,8 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
412410
} else if (is_reactive) {
413411
const id = context.state.scope.generate('spread_attributes');
414412
context.state.init.push(b.let(id));
415-
context.state.update.push({
416-
grouped: b.stmt(
413+
context.state.update.push(
414+
b.stmt(
417415
b.assignment(
418416
'=',
419417
b.id(id),
@@ -426,7 +424,7 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
426424
)
427425
)
428426
)
429-
});
427+
);
430428
return true;
431429
} else {
432430
context.state.init.push(
@@ -564,7 +562,7 @@ function serialize_element_attribute_update_assignment(element, node_id, attribu
564562
if (contains_call_expression && singular) {
565563
state.init.push(singular);
566564
} else {
567-
state.update.push({ grouped });
565+
state.update.push(grouped);
568566
}
569567
return true;
570568
} else {
@@ -707,26 +705,18 @@ function serialize_update_assignment(state, id, init, value, assignment, contain
707705
} else {
708706
if (assignment.skip_condition) {
709707
if (assignment.singular) {
710-
state.update.push({
711-
grouped: assignment.grouped
712-
});
708+
state.update.push(assignment.grouped);
713709
} else {
714710
state.init.push(b.var(id, init));
715-
state.update.push({
716-
grouped
717-
});
711+
state.update.push(grouped);
718712
}
719713
} else {
720714
if (assignment.singular) {
721715
state.init.push(b.var(id, init));
722-
state.update.push({
723-
grouped
724-
});
716+
state.update.push(grouped);
725717
} else {
726718
state.init.push(b.var(id, init));
727-
state.update.push({
728-
grouped
729-
});
719+
state.update.push(grouped);
730720
}
731721
}
732722
}
@@ -1275,7 +1265,7 @@ function get_template_function(namespace, state) {
12751265
* @param {import('../types.js').ComponentClientTransformState} state
12761266
*/
12771267
function serialize_render_stmt(state) {
1278-
return b.stmt(b.call('$.render_effect', b.thunk(b.block(state.update.map((n) => n.grouped)))));
1268+
return b.stmt(b.call('$.render_effect', b.thunk(b.block(state.update))));
12791269
}
12801270

12811271
/**
@@ -1511,16 +1501,15 @@ function process_children(nodes, expression, is_element, { visit, state }) {
15111501
if (node.metadata.contains_call_expression && !within_bound_contenteditable) {
15121502
state.init.push(singular);
15131503
} else if (node.metadata.dynamic && !within_bound_contenteditable) {
1514-
state.update.push({
1515-
singular,
1516-
grouped: b.stmt(
1504+
state.update.push(
1505+
b.stmt(
15171506
b.call(
15181507
'$.text',
15191508
text_id,
15201509
/** @type {import('estree').Expression} */ (visit(node.expression))
15211510
)
15221511
)
1523-
});
1512+
);
15241513
} else {
15251514
state.init.push(
15261515
b.stmt(
@@ -1556,10 +1545,7 @@ function process_children(nodes, expression, is_element, { visit, state }) {
15561545
sequence.some((node) => node.type === 'ExpressionTag' && node.metadata.dynamic) &&
15571546
!within_bound_contenteditable
15581547
) {
1559-
state.update.push({
1560-
singular,
1561-
grouped: b.stmt(b.call('$.text', text_id, assignment))
1562-
});
1548+
state.update.push(b.stmt(b.call('$.text', text_id, assignment)));
15631549
} else {
15641550
state.init.push(init);
15651551
}
@@ -3120,15 +3106,15 @@ export const template_visitors = {
31203106
)
31213107
);
31223108
} else {
3123-
state.update.push({
3124-
grouped: b.stmt(
3109+
state.update.push(
3110+
b.stmt(
31253111
b.assignment(
31263112
'=',
31273113
b.member(b.id('$.document'), b.id('title')),
31283114
serialize_template_literal(/** @type {any} */ (node.fragment.nodes), visit, state)[1]
31293115
)
31303116
)
3131-
});
3117+
);
31323118
}
31333119
},
31343120
SvelteBody(node, context) {

0 commit comments

Comments
 (0)